Handle hostnames with upper-case letters
[webmin.git] / spam / edit_header.cgi
1 #!/usr/local/bin/perl
2 # edit_header.cgi
3 # Display extra header and body test
4
5 require './spam-lib.pl';
6 &ReadParse();
7 &set_config_file_in(\%in);
8 &can_use_check("header");
9 &ui_print_header($header_subtext, $text{'header_title'}, "");
10 $conf = &get_config();
11
12 print "$text{'header_desc'}<p>\n";
13 &start_form("save_header.cgi", $text{'header_header'},
14             "<a href='edit_simple.cgi?file=".&urlize($in{'file'}).
15             "&title=".&urlize($in{'title'}).
16             "'>$text{'header_switch'}</a>");
17
18 # Allow user-defined rules?
19 if (!$module_info{'usermin'}) {
20         $allow = &find("allow_user_rules", $conf);
21         print &ui_table_row($text{'header_allow'},
22                 &yes_no_field("allow_user_rules", $allow, 0));
23         }
24
25 # Header tests
26 @header = &find("header", $conf);
27 print &ui_table_row($text{'header_test'},
28         &edit_table("header",
29             [ $text{'header_tname'}, $text{'header_name'}, $text{'header_op'},
30               $text{'header_pat'}, $text{'header_default'} ],
31             [ map { [ &split_header($_->{'value'}) ] } @header ], [ ], \&header_conv, 2));
32
33 print &ui_table_hr();
34
35 push(@body, map { [ &split_body($_->{'value'}), 0 ] } &find("body", $conf));
36 push(@body, map { [ &split_body($_->{'value'}), 1 ] } &find("rawbody", $conf));
37 push(@body, map { [ &split_body($_->{'value'}), 2 ] } &find("fullbody", $conf));
38 push(@body, map { [ &split_body($_->{'value'}), 3 ] } &find("full", $conf));
39 print &ui_table_row($text{'header_body'},
40         &edit_table("body",
41             [ $text{'header_tname'}, $text{'header_mode'}, $text{'header_op'},
42               $text{'header_pat'} ], \@body, [ ], \&body_conv, 2));
43
44 print &ui_table_hr();
45
46 @uri = &find("uri", $conf);
47 print &ui_table_row($text{'header_uri'},
48         &edit_table("uri",
49             [ $text{'header_tname'}, $text{'header_pat'} ],
50             [ map { $_->{'words'} } @uri ], [ 20, 40 ], undef, 2));
51
52 print &ui_table_hr();
53
54 @meta = &find("meta", $conf);
55 print &ui_table_row($text{'header_meta'},
56         &edit_table("meta",
57             [ $text{'header_tname'}, $text{'header_bool'} ],
58             [ map { $_->{'value'} =~ /^(\S+)\s*(.*)$/ ? [ $1, $2 ] : [ ] } @meta ],
59             [ 20, 40 ], undef, 2));
60
61 print &ui_table_hr();
62
63 @score = &find("score", $conf);
64 print &ui_table_row($text{'score_score'},
65         &edit_table("score",
66                     [ $text{'score_name'}, $text{'score_points'} ],
67                     [ map { $_->{'words'} } @score ], [ 30, 6 ]));
68
69 @describe = &find("describe", $conf);
70 print &ui_table_row($text{'score_describe'},
71         &edit_table("describe",
72             [ $text{'score_name'}, $text{'score_descr'} ],
73             [ map { $_->{'value'} =~ /^(\S+)\s*(.*)/ ? [ $1, $2 ] : [ ] }
74               @describe ], [ 30, 40 ]));
75
76 &end_form(undef, $text{'save'});
77 &ui_print_footer($redirect_url, $text{'index_return'});
78
79 # header_conv(col, name, size, value, &values)
80 sub header_conv
81 {
82 if ($_[0] == 0) {
83         return &ui_textbox($_[1], $_[3], 20);
84         }
85 elsif ($_[0] == 1) {
86         local $h = $_[3] =~ /^exists:(\S+)$/ ? $1 : $_[3] =~ /^eval:/ ? "" : $_[3];
87         return &ui_textbox($_[1], $h, 15);
88         }
89 elsif ($_[0] == 2) {
90         local $v = $_[4]->[1] =~ /^exists:/ ? 'exists' :
91                    $_[4]->[1] =~ /^eval:/ ? 'eval' : $_[3];
92         return &ui_select($_[1], $v,
93                           [ [ '=~', $text{'header_op0'} ],
94                             [ '!~', $text{'header_op1'} ],
95                             [ 'exists', $text{'header_op2'} ],
96                             [ 'eval', $text{'header_op3'} ] ], 1, 0, $v);
97         }
98 elsif ($_[0] == 3) {
99         return &ui_textbox($_[1], $_[4]->[1] =~ /^eval:(.*)/ ? $1 : $_[3], 20);
100         }
101 elsif ($_[0] == 4) {
102         return &ui_textbox($_[1], $_[3], 15);
103         }
104 }
105
106 # body_conv(col, name, size, value, &values)
107 sub body_conv
108 {
109 if ($_[0] == 0) {
110         return &ui_textbox($_[1], $_[4]->[0], 20);
111         }
112 elsif ($_[0] == 1) {
113         return &ui_select($_[1], $_[4]->[2],
114                         [ [ 0, $text{'header_mode0'} ],
115                           [ 1, $text{'header_mode1'} ],
116                           [ 2, $text{'header_mode2'} ],
117                           [ 3, $text{'header_mode3'} ] ]);
118         }
119 elsif ($_[0] == 2) {
120         return &ui_select($_[1], $_[4]->[1] =~ /^eval:/ ? 1 : 0,
121                           [ [ 0, $text{'header_op0'} ],
122                             [ 1, $text{'header_op3'} ] ]);
123         }
124 elsif ($_[0] == 3) {
125         return &ui_textbox($_[1], $_[4]->[1] =~ /^eval:(.*)$/ ? $1 : $_[4]->[1],
126                            40);
127         }
128 }
129
130 sub split_header
131 {
132 if ($_[0] =~ /^(\S+)\s+(eval:\S+\(.*\))/) {
133         return ($1, $2);
134         }
135 elsif ($_[0] =~ /^(\S+)\s+(\S+)\s+(\S+)\s+(\/.*\/\S*)\s*(if-unset:\s*(.*))?/) {
136         return ($1, $2, $3, $4, $6);
137         }
138 else {
139         return ( );
140         }
141 }
142
143 sub split_body
144 {
145 if ($_[0] =~ /^(\S+)\s+((\/.*\/\S*)|(eval:\S+\(.*\)))/) {
146         return ($1, $2);
147         }
148 else {
149         return ( );
150         }
151 }
152