OSDN Git Service

correct TYPO
[opengate/opengate.git] / opengate / doc / rulechk.txt
1 #!/usr/bin/perl
2 #This is a script to remove superfluous rules left bihind at the abnormal termination of opengate process.
3
4 #get opengate process information from 'ps x' output
5 # and save it to $proc table.
6
7 open(pspipe, "ps x|");
8 while(<pspipe>){
9     if(/opengatesrv.cgi: (.*),(.*),/){
10         $rule=$1; $user=$2;
11         $proc{$rule}=$user;
12     }
13 }
14 close(pspipe);
15
16
17 #get firewall rules from 'ipfw list' output,
18 # and delete the superfluous rules that are not included in $proc table.
19
20 open(ipfwpipe, "ipfw list|");
21 $delcount=0;
22 $rule=0;
23 while(<ipfwpipe>){
24     if(/^(\d*) allow/){
25         $rulesave=$rule;
26         $rule=$1;
27         if($rule>=10000 and $rule<=40000 and $rule!=$rulesave){
28             if(!defined($proc{$rule})){
29                 system "ipfw del $rule";
30                 $delcount++;
31             }
32         }
33     }
34 }
35 close(ipfwpipe);
36
37 print $delcount." rules are deleted.\n";
38
39
40