]>
git.ipfire.org Git - people/ummeegge/ipfire-2.x.git/blob - src/scripts/vpn-watch
466aaa62dc1725fb6a8dccdb2b7c08643a2167f0
2 ##################################################
3 ##### VPN-Watch.pl Version 0.6 #####
4 ##################################################
6 # VPN-Watch is part of the IPFire Firewall #
8 ##################################################
12 require '/var/ipfire/general-functions.pl';
15 my $file = "/var/run/vpn-watch.pid";
19 logger
("There my be another vpn-watch runnning because $file exists, vpn-watch will try kill the process.");
23 system("kill -9 $PID");
26 system("echo $$ > $file");
29 if ($debug){logger
("We will wait 60 seconds before next action.");}
34 # Reset roundcounter after 10 min. To do established check.
35 if ($round > 9) { $round=0; }
37 if (open(FILE
, "<${General::swroot}/vpn/config")) { @vpnsettings = <FILE
>;
39 unless(@vpnsettings) {exit 1;}
42 my $status = `ipsec whack --status`;
43 foreach (@vpnsettings){
44 my @settings = split(/,/,$_);
46 if ($settings[27] ne 'RED'){next;}
47 if ($settings[4] ne 'net'){next;}
48 if ($settings[1] ne 'on'){next;}chomp($settings[29]);
49 if ($settings[29] ne 'on'){next;}
51 my $remotehostname = $settings[11];
53 if ($debug){logger
("Checking connection to $remotehostname.");}
55 my $remoteip = `/usr/bin/ping -c 1 $remotehostname 2>/dev/null | head -n1 | awk '{print \$3}' | tr -d '()' | tr -d ':'`;chomp($remoteip);
56 if ($remoteip eq ""){next;if ($debug){logger
("Unable to resolve $remotehostname.");}}
57 my $ipmatch= `echo "$status" | grep '$remoteip' | grep '$settings[2]'`;
58 my $established= `echo "$status" | grep '$settings[2]' | grep 'erouted;'`;
60 if ( $round == 0 && $ipmatch eq '' && $status ne ''){
61 logger
("Remote IP for host $remotehostname($remoteip) has changed, restarting ipsec.");
62 system("/usr/local/bin/ipsecctrl S $settings[0]");
64 last; #all connections will reloaded
65 #remove this if ipsecctrl can restart single con again
68 if ($debug){logger
("Round=".$round." and established=".$established);}
70 if ( ($round == 0) && ($established eq '')) {
71 logger
("Connection to $remotehostname($remoteip) not erouted, restarting ipsec.");
72 system("/usr/local/bin/ipsecctrl S $settings[0]");
74 last; #all connections will reloaded
75 #remove this if ipsecctrl can restart single con again
79 if ($debug){logger
("All connections may be fine nothing was done.");}
84 system("logger -t vpnwatch \"$log\"");