3 # Display portsentry configuration menu
5 require './sentry-lib.pl';
7 $path = &has_command($config{'portsentry'});
9 &ui_print_header(undef, $text{'portsentry_title'}, "");
10 print "<p>",&text('portsentry_ecommand',
11 "<tt>$config{'portsentry'}</tt>",
12 "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n";
13 &ui_print_footer("", $text{'index_return'});
17 if (!-r $config{'portsentry_config'} && -r $config{'portsentry_alt_config'}) {
18 system("cp $config{'portsentry_alt_config'} $config{'portsentry_config'}");
21 # Get the version, if needed
22 &read_file("$module_config_directory/portsentry", \%portsentry);
24 if ($st[7] != $portsentry{'size'} || $st[9] != $portsentry{'mtime'}) {
25 $out = &backquote_command("$config{'portsentry'} -v 2>&1", 1);
26 if ($out !~ /Version:\s+(\S+)/) {
27 &ui_print_header(undef, $text{'portsentry_title'}, "");
28 print "<p>",&text('portsentry_eversion',
29 "<tt>$config{'portsentry'}</tt>",
30 "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n";
31 &ui_print_footer("", $text{'index_return'});
34 $portsentry{'version'} = $1;
35 $portsentry{'size'} = $st[7];
36 $portsentry{'mtime'} = $st[9];
37 &write_file("$module_config_directory/portsentry", \%portsentry);
40 &ui_print_header(undef, $text{'portsentry_title'}, "", "portsentry", 0, 0, undef,
41 &help_search_link("portsentry", "man", "doc"), undef, undef,
42 &text('portsentry_version', $portsentry{'version'}));
44 if ($portsentry{'version'} >= 2) {
45 print "<p>",&text('portsentry_eversion2',
46 "<tt>$config{'portsentry'}</tt>",
47 $portsentry{'version'}),"<p>\n";
48 &ui_print_footer("", $text{'index_return'});
52 # Show configuration form
53 $conf = &get_portsentry_config();
55 print "<form action=save_portsentry.cgi method=post>\n";
56 print "<table border width=100%>\n";
57 print "<tr $tb> <td><b>$text{'portsentry_header'}</b></td> </tr>\n";
58 print "<tr $cb> <td><table width=100%>\n";
60 $tcp_ports = &find_value("TCP_PORTS", $conf);
61 $udp_ports = &find_value("UDP_PORTS", $conf);
62 $tcp_adv = &find_value("ADVANCED_PORTS_TCP", $conf);
63 $udp_adv = &find_value("ADVANCED_PORTS_UDP", $conf);
64 $tcp_exc = &find_value("ADVANCED_EXCLUDE_TCP", $conf);
65 $udp_exc = &find_value("ADVANCED_EXCLUDE_UDP", $conf);
67 print "<tr> <td valign=top><b>$text{'portsentry_tmode'}</b></td> <td>\n";
68 printf "%s <input name=tports size=50 value='%s'><br>\n",
69 $text{'portsentry_mode0'},
70 join(" ", split(/,/, $tcp_ports));
71 $tcp_exc = join(" ", split(/,/, $tcp_exc));
72 print &text('portsentry_mode1',
73 "<input name=tadv size=8 value='$tcp_adv'>",
74 "<input name=texc size=20 value='$tcp_exc'>"),"</td> </tr>\n";
76 print "<tr> <td valign=top><b>$text{'portsentry_umode'}</b></td> <td>\n";
77 printf "%s <input name=uports size=50 value='%s'><br>\n",
78 $text{'portsentry_mode0'},
79 join(" ", split(/,/, $udp_ports));
80 $udp_exc = join(" ", split(/,/, $udp_exc));
81 print &text('portsentry_mode1',
82 "<input name=uadv size=8 value='$udp_adv'>",
83 "<input name=uexc size=20 value='$udp_exc'>"),"</td> </tr>\n";
85 $tblock = &find_value("BLOCK_TCP", $conf);
86 print "<tr> <td><b>$text{'portsentry_tblock'}</b></td> <td>\n";
87 printf "<input type=radio name=tblock value=1 %s> $text{'yes'}\n",
88 $tblock == 1 ? "checked" : "";
89 printf "<input type=radio name=tblock value=0 %s> $text{'no'}\n",
90 $tblock == 0 ? "checked" : "";
91 printf "<input type=radio name=tblock value=2 %s> $text{'portsentry_kill'}\n",
92 $tblock == 2 ? "checked" : "";
93 print "</td> </tr>\n";
95 $ublock = &find_value("BLOCK_UDP", $conf);
96 print "<tr> <td><b>$text{'portsentry_ublock'}</b></td> <td>\n";
97 printf "<input type=radio name=ublock value=1 %s> $text{'yes'}\n",
98 $ublock == 1 ? "checked" : "";
99 printf "<input type=radio name=ublock value=0 %s> $text{'no'}\n",
100 $ublock == 0 ? "checked" : "";
101 printf "<input type=radio name=ublock value=2 %s> $text{'portsentry_kill'}\n",
102 $ublock == 2 ? "checked" : "";
103 print "</td> </tr>\n";
105 print "<tr> <td><b>$text{'portsentry_banner'}</b></td>\n";
106 printf "<td><input name=banner size=50 value='%s'></td> </tr>\n",
107 &find_value("PORT_BANNER", $conf);
109 print "<tr> <td><b>$text{'portsentry_trigger'}</b></td>\n";
110 printf "<td><input name=trigger size=6 value='%s'></td> </tr>\n",
111 &find_value("SCAN_TRIGGER", $conf);
113 if ($config{'portsentry_ignore'}) {
114 $ign = $config{'portsentry_ignore'};
117 $ign = &find_value("IGNORE_FILE", $conf);
120 print "<tr> <td valign=top><b>$text{'portsentry_ignore'}</b></td>\n";
121 print "<td><textarea name=ignore rows=5 cols=50>\n";
125 if (/Do NOT edit below this/i) {
126 $editbelow = $lnum-1;
130 print &html_escape($_) if (/\S/);
134 print "</textarea></td> </tr></table>\n";
135 print "<input type=hidden name=editbelow value='$editbelow'>\n"
136 if (defined($editbelow));
138 print "</td></tr></table>\n";
140 @pids = &get_portsentry_pids();
142 print "<input type=submit name=apply value='$text{'portsentry_save'}'></form>\n";
145 print "<input type=submit value='$text{'save'}'></form>\n";
148 # Show start/stop buttons
150 print "<table width=100%>\n";
151 $cmd = &portsentry_start_cmd();
153 # Running .. offer to stop
154 print "<form action=stop_portsentry.cgi>\n";
155 print "<tr> <td><input type=submit ",
156 "value='$text{'portsentry_stop'}'></td>\n";
157 print "<td>$text{'portsentry_stopdesc'}</td> </tr>\n";
161 # Not running .. offer to start
162 print "<form action=start_portsentry.cgi>\n";
163 print "<tr> <td><input type=submit ",
164 "value='$text{'portsentry_start'}'></td>\n";
165 print "<td>",&text('portsentry_startdesc', "<tt>$cmd</tt>"),
166 "</td> </tr> </form>\n";
170 &ui_print_footer("", $text{'index_return'});