]>
git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - src/scripts/vpn-watch
2 ##################################################
3 ##### VPN-Watch.pl Version 0.1 #####
4 ##################################################
8 require '/var/ipfire/general-functions.pl';
11 my $file = "/var/run/vpn-watch.pid";
13 system("echo $$ > $file");
16 if (open(FILE
, "${General::swroot}/vpn/config")) {
17 @vpnsettings = <FILE
>;
19 unless(@vpnsettings) {exit 1;}
22 foreach (@vpnsettings){
23 my @settings = split(/,/,$_);
25 if ($settings[27] ne 'RED'){next;}
26 if ($settings[4] ne 'net'){next;}
27 if ($settings[1] ne 'on'){next;}chomp($settings[29]);
28 if ($settings[29] ne 'on'){next;}
30 my $remotehostname = $settings[11];
31 my $remoteip = `/usr/bin/ping -c 1 $remotehostname 2>/dev/null | head -n1 | awk '{print \$3}' | tr -d '()' | tr -d ':'`;chomp($remoteip);
32 if ($remoteip eq ""){next;}
33 if (system("ipsec whack --status | grep $remoteip >/dev/null")){
34 logger
("Remote IP for host $remotehostname has changed or is not connected, restarting connection to $remoteip.");
35 system("/usr/local/bin/ipsecctrl S $settings[0]");
38 my $hostip = `cat /var/ipfire/red/local-ipaddress 2>/dev/null`;
40 if (system("ipsec whack --status | grep $hostip >/dev/null")){
41 logger
("Our own IP has changed to $hostip restarting connection.");
42 system("/usr/local/bin/ipsecctrl S $settings[1]");
45 logger
("Nothing was done.");
51 system("logger -t vpnwatch \"$log\"");