]>
git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - src/scripts/vpn-watch
2 ##################################################
3 ##### VPN-Watch.pl Version 0.3 #####
4 ##################################################
8 require '/var/ipfire/general-functions.pl';
11 my $file = "/var/run/vpn-watch.pid";
14 if ( -e
$file ){logger
("There my be another vpn-watch runnning $file exists, vpn-watch will not start.");exit 1;}
15 if ($debug){logger
("Call of vpn-watch pid not is not existing.");}
17 system("echo $$ > $file");
21 if ($debug){logger
("We will wait 300 seconds before next action.");}
23 if (open(FILE
, "${General::swroot}/vpn/config")) {
24 @vpnsettings = <FILE
>;
26 unless(@vpnsettings) {exit 1;}
29 foreach (@vpnsettings){
30 my @settings = split(/,/,$_);
32 if ($settings[27] ne 'RED'){next;}
33 if ($settings[4] ne 'net'){next;}
34 if ($settings[1] ne 'on'){next;}chomp($settings[29]);
35 if ($settings[29] ne 'on'){next;}
37 my $remotehostname = $settings[11];
39 if ($debug){logger
("Checking connection to $remotehostname.");}
41 my $remoteip = `/usr/bin/ping -c 1 $remotehostname 2>/dev/null | head -n1 | awk '{print \$3}' | tr -d '()' | tr -d ':'`;chomp($remoteip);
42 if ($remoteip eq ""){next;}
43 if (system("ipsec whack --status | grep $remoteip >/dev/null")){
44 logger
("Remote IP for host $remotehostname has changed or is not connected, restarting connection to $remoteip.");
45 system("/usr/local/bin/ipsecctrl S $settings[0]");
48 if ($debug){logger
("All connections may be fine nothing was done.");}
54 system("logger -t vpnwatch \"$log\"");