File: portsentry-rm-ip

package info (click to toggle)
portsentry 1.2-14
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, stretch
  • size: 636 kB
  • ctags: 202
  • sloc: ansic: 3,670; makefile: 463; sh: 184; perl: 94; csh: 31
file content (40 lines) | stat: -rw-r--r-- 1,020 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/perl -w
# $Id: portsentry-rm-ip,v 1.3 2001/07/01 22:51:00 agx Exp $
#
# remove an IP from portsentry.ignore.static file
#
# by Guido Guenther <agx@debian.org>

use File::Temp qw( tempfile );

$etcdir='/etc/portsentry';			
$static_file="$etcdir/portsentry.ignore.static";
$tmpdir="/var/lib/portsentry";
$ip_regexp='[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}';

if( @ARGV == 0) {
	die 
"Remove an ip from portsentry.ignore.static.
usage: portsentry-add-ip ip-address\n";
} else {
        $rm_ip = $ARGV[0];
}

if ( $rm_ip !~ /^$ip_regexp$/) {
	die "$rm_ip is not in aaa.bbb.ccc.ddd format!\n";
}

open( P, "$static_file") || die "Can't read $static_file: $!\n";
@ignored_ips = <P>;
close( P);

($th, $tfname) = tempfile("portsentry.ignore.static.XXXXXX", DIR => $tmpdir);

# write out everything except the mathing ip
@tmp_ips=grep( !/^\s*$rm_ip[\s#]/, @ignored_ips);
print $th @tmp_ips;
close( $th);

# move temp-file to portsentry.ignore.static
rename($tfname, $static_file);
chmod( 0644, $static_file );