3 # Update the portsentry config file
5 require './sentry-lib.pl';
7 &error_setup($text{'portsentry_err'});
8 $conf = &get_portsentry_config();
9 &lock_config_files($conf);
11 # Validate and save inputs
12 @tports = split(/\s+/, $in{'tports'});
13 foreach $t (@tports) {
14 $t > 0 && $t < 65535 || &error(&text('portsentry_etports', $t));
16 &save_config($conf, "TCP_PORTS", join(",", @tports));
17 $in{'tadv'} > 0 && $in{'tadv'} < 65535 || &error($text{'portsentry_etadv'});
18 &save_config($conf, "ADVANCED_PORTS_TCP", $in{'tadv'});
19 @texc = split(/\s+/, $in{'texc'});
21 $t > 0 && $t < 65535 || &error(&text('portsentry_etexc', $t));
23 &save_config($conf, "ADVANCED_EXCLUDE_TCP", join(",", @texc));
25 @uports = split(/\s+/, $in{'uports'});
26 foreach $t (@uports) {
27 $t > 0 && $t < 65535 || &error(&text('portsentry_euports', $t));
29 &save_config($conf, "UDP_PORTS", join(",", @uports));
30 $in{'uadv'} > 0 && $in{'uadv'} < 65535 || &error($text{'portsentry_euadv'});
31 &save_config($conf, "ADVANCED_PORTS_UDP", $in{'uadv'});
32 @uexc = split(/\s+/, $in{'uexc'});
34 $t > 0 && $t < 65535 || &error(&text('portsentry_euexc', $t));
36 &save_config($conf, "ADVANCED_EXCLUDE_UDP", join(",", @uexc));
38 &save_config($conf, "BLOCK_TCP", $in{'tblock'});
39 &save_config($conf, "BLOCK_UDP", $in{'ublock'});
40 &save_config($conf, "PORT_BANNER", $in{'banner'});
42 $in{'trigger'} =~ /^\d+$/ || &error($text{'portsentry_etrigger'});
43 &save_config($conf, "SCAN_TRIGGER", $in{'trigger'});
45 # Save list of ignored hosts
46 if (defined($in{'ignore'})) {
47 if ($config{'portsentry_ignore'}) {
48 $ign = $config{'portsentry_ignore'};
51 $ign = &find_value("IGNORE_FILE", $conf);
54 $in{'ignore'} =~ s/\r//g;
55 $in{'ignore'} =~ s/\n*$/\n/;
56 foreach $h (split(/\s+/, $in{'ignore'})) {
58 ($h =~ /^([0-9\.]+)\/(\d+)/ && &check_ipaddress($1)) ||
59 &error(&text('portsentry_eignore', $h));
61 if (defined($in{'editbelow'})) {
65 @below = @below[$in{'editbelow'} .. $#below];
67 &open_tempfile(IGNORE, ">$ign");
68 &print_tempfile(IGNORE, $in{'ignore'});
69 &print_tempfile(IGNORE, @below);
70 &close_tempfile(IGNORE);
74 &unlock_config_files($conf);
79 $err = &start_portsentry();
80 &error($err) if ($err);
82 &webmin_log("portsentry");