2 # Show a form for editing or creating a log filter
4 require './syslog-ng-lib.pl';
7 # Show title and get the filter
10 &ui_print_header(undef, $text{'filter_title1'}, "");
13 &ui_print_header(undef, $text{'filter_title2'}, "");
14 @filters = &find("filter", $conf);
15 ($filter) = grep { $_->{'value'} eq $in{'name'} } @filters;
16 $filter || &error($text{'filter_egone'});
20 print &ui_form_start("save_filter.cgi", "post");
21 print &ui_hidden("new", $in{'new'}),"\n";
22 print &ui_hidden("old", $in{'name'}),"\n";
23 print &ui_table_start($text{'filter_header'}, undef, 2);
26 print &ui_table_row($text{'filter_name'},
27 &ui_textbox("name", $filter->{'value'}, 20));
29 # See if the conditions are simple (1 or more of facility, level, matches
30 # and program, and separated)
32 foreach $m (@{$filter->{'members'}}) {
34 if ($simple{$m->{'name'}}) {
35 # Already done this type .. not simple any more
39 $simple{$m->{'name'}} = $m;
43 # 'and' separator .. we can handle this
50 # Build table for simple mode
51 %simple = ( ) if (!$simple);
52 $stable = "<table>\n";
55 $p = $simple{'priority'};
56 @pris = &list_priorities();
58 if ($p->{'values'}->[1] eq "..") {
59 $i1 = &indexof(@pris, $p->{'values'}->[0]);
60 $i2 = &indexof(@pris, $p->{'values'}->[2]);
61 if ($i1 >= 0 && $i2 >= 0) {
62 %gotpris = map { $pris[$_], 1 } ($i1 .. $i2);
66 %gotpris = map { $_, 1 } grep { $_ ne "," } @{$p->{'values'}};
69 $stable .= "<tr> <td><b>".&ui_checkbox("priority", 1, $text{'filter_priority'},
70 $p ? 1 : 0)."</b></td>\n";
73 $stable .= &ui_checkbox("pri", $p, $p, $gotpris{$p})."\n";
75 $stable .= "</td> </tr>\n";
78 $p = $simple{'facility'};
79 @facs = &list_facilities();
81 %gotfacs = map { $_, 1 } grep { $_ ne "," } @{$p->{'values'}};
83 $stable .= "<tr> <td valign=top><b>".
84 &ui_checkbox("facility", 1, $text{'filter_facility'}, $p ? 1 : 0).
86 $stable .= "<td><table>";
89 $stable .= "<tr>\n" if ($i % 8 == 0);
90 $stable .= "<td>".&ui_checkbox("fac", $f, $f, $gotfacs{$f})."</td>\n";
91 $stable .= "<tr>\n" if ($i % 8 == 7);
94 $stable .= "</table></td> </tr>\n";
97 $p = $simple{'program'};
98 $stable .= "<tr> <td><b>".&ui_checkbox("program", 1, $text{'filter_program'},
99 $p ? 1 : 0)."</b></td>\n";
100 $stable .= "<td>".&ui_textbox("prog", $p ? $p->{'value'} : undef, 30).
104 $p = $simple{'match'};
105 $stable .= "<tr> <td><b>".&ui_checkbox("match", 1, $text{'filter_match'},
106 $p ? 1 : 0)."</b></td>\n";
107 $stable .= "<td>".&ui_textbox("re", $p ? $p->{'value'} : undef, 50).
111 $p = $simple{'host'};
112 $stable .= "<tr> <td><b>".&ui_checkbox("host", 1, $text{'filter_host'},
113 $p ? 1 : 0)."</b></td>\n";
114 $stable .= "<td>".&ui_textbox("hn", $p ? $p->{'value'} : undef, 30).
118 $p = $simple{'netmask'};
120 ($net, $mask) = split(/\//, $p->{'value'});
122 $stable .= "<tr> <td><b>".&ui_checkbox("netmask", 1, $text{'filter_netmask'},
123 $p ? 1 : 0)."</b></td>\n";
124 $stable .= "<td>".&ui_textbox("net", $net, 15)."/".
125 &ui_textbox("mask", $mask, 15)."</td> </tr>\n";
127 $stable .= "</table>\n";
129 # Build text area for complex mode
131 foreach $m (@{$filter->{'members'}}) {
133 local ($line) = &directive_lines($m);
134 $line =~ s/\s*;\s*$//;
141 $ctable = &ui_textarea("bool", join(" ", @w), 5, 80);
144 print "<tr> <td colspan=2>\n";
145 print &ui_oneradio("mode", 0, "<b>$text{'filter_mode0'}</b>", $simple),"<br>\n";
146 print $stable,"<br>\n";
147 print &ui_oneradio("mode", 1, "<b>$text{'filter_mode1'}</b>",!$simple),"<br>\n";
148 print $ctable,"<br>\n";
149 print "</td> </tr>\n";
151 # Form footer and buttons
152 print &ui_table_end();
154 print &ui_form_end([ [ "create", $text{'create'} ] ]);
157 print &ui_form_end([ [ "save", $text{'save'} ],
158 [ "delete", $text{'delete'} ] ]);
160 &ui_print_footer("list_filters.cgi", $text{'filters_return'});