Handle missing ignore file

This commit is contained in:
Jamie Cameron
2007-08-26 03:30:57 +00:00
parent 1700458b50
commit f49482bab5
2 changed files with 43 additions and 39 deletions

View File

@@ -110,29 +110,31 @@ print "<tr> <td><b>$text{'portsentry_trigger'}</b></td>\n";
printf "<td><input name=trigger size=6 value='%s'></td> </tr>\n",
&find_value("SCAN_TRIGGER", $conf);
print "<tr> <td valign=top><b>$text{'portsentry_ignore'}</b></td>\n";
print "<td><textarea name=ignore rows=5 cols=50>\n";
if ($config{'portsentry_ignore'}) {
$ign = $config{'portsentry_ignore'};
}
else {
$ign = &find_value("IGNORE_FILE", $conf);
}
$lnum = 0;
open(IGN, $ign);
while(<IGN>) {
if (/Do NOT edit below this/i) {
$editbelow = $lnum-1;
last;
if ($ign) {
print "<tr> <td valign=top><b>$text{'portsentry_ignore'}</b></td>\n";
print "<td><textarea name=ignore rows=5 cols=50>\n";
$lnum = 0;
open(IGN, $ign);
while(<IGN>) {
if (/Do NOT edit below this/i) {
$editbelow = $lnum-1;
last;
}
s/#.*$//;
print &html_escape($_) if (/\S/);
$lnum++;
}
s/#.*$//;
print &html_escape($_) if (/\S/);
$lnum++;
close(IGN);
print "</textarea></td> </tr></table>\n";
print "<input type=hidden name=editbelow value='$editbelow'>\n"
if (defined($editbelow));
}
close(IGN);
print "</textarea></td> </tr></table>\n";
print "<input type=hidden name=editbelow value='$editbelow'>\n"
if (defined($editbelow));
print "</td></tr></table>\n";
@pids = &get_portsentry_pids();

View File

@@ -43,31 +43,33 @@ $in{'trigger'} =~ /^\d+$/ || &error($text{'portsentry_etrigger'});
&save_config($conf, "SCAN_TRIGGER", $in{'trigger'});
# Save list of ignored hosts
if ($config{'portsentry_ignore'}) {
$ign = $config{'portsentry_ignore'};
if (defined($in{'ignore'})) {
if ($config{'portsentry_ignore'}) {
$ign = $config{'portsentry_ignore'};
}
else {
$ign = &find_value("IGNORE_FILE", $conf);
}
&lock_file($ign);
$in{'ignore'} =~ s/\r//g;
$in{'ignore'} =~ s/\n*$/\n/;
foreach $h (split(/\s+/, $in{'ignore'})) {
gethostbyname($h) || &check_ipaddress($h) ||
($h =~ /^([0-9\.]+)\/(\d+)/ && &check_ipaddress($1)) ||
&error(&text('portsentry_eignore', $h));
}
if (defined($in{'editbelow'})) {
open(IGNORE, $ign);
@below = <IGNORE>;
close(IGNORE);
@below = @below[$in{'editbelow'} .. $#below];
}
&open_tempfile(IGNORE, ">$ign");
&print_tempfile(IGNORE, $in{'ignore'});
&print_tempfile(IGNORE, @below);
&close_tempfile(IGNORE);
&unlock_file($ign);
}
else {
$ign = &find_value("IGNORE_FILE", $conf);
}
&lock_file($ign);
$in{'ignore'} =~ s/\r//g;
$in{'ignore'} =~ s/\n*$/\n/;
foreach $h (split(/\s+/, $in{'ignore'})) {
gethostbyname($h) || &check_ipaddress($h) ||
($h =~ /^([0-9\.]+)\/(\d+)/ && &check_ipaddress($1)) ||
&error(&text('portsentry_eignore', $h));
}
if (defined($in{'editbelow'})) {
open(IGNORE, $ign);
@below = <IGNORE>;
close(IGNORE);
@below = @below[$in{'editbelow'} .. $#below];
}
&open_tempfile(IGNORE, ">$ign");
&print_tempfile(IGNORE, $in{'ignore'});
&print_tempfile(IGNORE, @below);
&close_tempfile(IGNORE);
&unlock_file($ign);
&flush_file_lines();
&unlock_config_files($conf);