]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame_incremental - src/scripts/vpn-watch
DHCP und Squid-Initscripts optimiert fuer ein schnelleres starten und stoppen.
[people/pmueller/ipfire-2.x.git] / src / scripts / vpn-watch
... / ...
CommitLineData
1#!/usr/bin/perl
2##################################################
3##### VPN-Watch.pl Version 0.3 #####
4##################################################
5
6use strict;
7
8require '/var/ipfire/general-functions.pl';
9my @vpnsettings;
10my $i = 0;
11my $file = "/var/run/vpn-watch.pid";
12my $debug = 0;
13
14if ( -e $file ){logger("There my be another vpn-watch runnning $file exists, vpn-watch will not start.");exit 1;}
15if ($debug){logger("Call of vpn-watch pid not is not existing.");}
16
17system("echo $$ > $file");
18
19while ( $i == 0){
20 sleep(300);
21 if ($debug){logger("We will wait 300 seconds before next action.");}
22
23 if (open(FILE, "${General::swroot}/vpn/config")) {
24 @vpnsettings = <FILE>;
25 close(FILE);
26 unless(@vpnsettings) {exit 1;}
27 }
28
29foreach (@vpnsettings){
30 my @settings = split(/,/,$_);
31
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;}
36
37 my $remotehostname = $settings[11];
38
39 if ($debug){logger("Checking connection to $remotehostname.");}
40
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]");
46 next;
47 }
48 if ($debug){logger("All connections may be fine nothing was done.");}
49 }
50}
51
52sub logger {
53 my $log = shift;
54 system("logger -t vpnwatch \"$log\"");
55}