]>
git.ipfire.org Git - ipfire-2.x.git/blob - src/scripts/vpn-watch
c32dc3c06b41b92fd24b6059534ca34950458b80
2 ##################################################
3 ##### VPN-Watch.pl Version 0.7 #####
4 ##################################################
6 # VPN-Watch is part of the IPFire Firewall #
8 ##################################################
10 # XXX The vpn-watch daemon is disabled, because
11 # apparently, it is not needed anymore after
12 # strongswan has abandoned pluto.
17 require '/var/ipfire/general-functions.pl';
20 my $file = "/var/run/vpn-watch.pid";
24 logger
("There my be another vpn-watch runnning because $file exists, vpn-watch will try kill the process.");
28 system("kill -9 $PID");
31 system("echo $$ > $file");
34 if ($debug){logger
("We will wait 60 seconds before next action.");}
39 # Reset roundcounter after 10 min. To do established check.
40 if ($round > 9) { $round=0; }
42 if (open(FILE
, "<${General::swroot}/vpn/config")) { @vpnsettings = <FILE
>;
44 unless(@vpnsettings) {exit 1;}
47 my $status = `ipsec status`;
48 foreach (@vpnsettings){
49 my @settings = split(/,/,$_);
52 if ($settings[27] ne 'RED'){next;}
53 if ($settings[4] ne 'net'){next;}
54 if ($settings[1] ne 'on'){next;}chomp($settings[29]);
55 if ($settings[29] ne 'on'){next;}
57 my $remotehostname = $settings[11];
59 if ($debug){logger
("Checking connection to $remotehostname.");}
61 my $remoteip = `/usr/bin/ping -c 1 $remotehostname 2>/dev/null | head -n1 | awk '{print \$3}' | tr -d '()' | tr -d ':'`;chomp($remoteip);
62 if ($remoteip eq ""){next;if ($debug){logger
("Unable to resolve $remotehostname.");}}
63 my $ipmatch= `echo "$status" | grep '$remoteip' | grep '$settings[2]'`;
64 my $established= `echo "$status" | grep '$settings[2]' | grep -e 'erouted;' -e 'INSTALLED'`;
65 my $known= `echo "$status" | grep '$settings[2]'`;
67 if ( $ipmatch eq '' && $known ne '' ){
68 logger
("Remote IP for host $remotehostname($remoteip) has changed, restarting ipsec.");
69 system("/usr/local/bin/ipsecctrl S $settings[0]");
73 if ($debug){logger
("Round=".$round." and established=".$established);}
75 if ( ($round == 0) && ($established eq '')) {
76 logger
("Connection to $remotehostname($remoteip) not erouted, restarting ipsec.");
77 system("/usr/local/bin/ipsecctrl S $settings[0]");
82 if ($debug){logger
("All connections may be fine nothing was done.");}
87 system("logger -t vpnwatch \"$log\"");