]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/scripts/vpn-watch
IPSecctrl fuer vpnwatch angepasst
[people/pmueller/ipfire-2.x.git] / src / scripts / vpn-watch
1 #!/usr/bin/perl
2 ##################################################
3 ##### VPN-Watch.pl Version 0.1 #####
4 ##################################################
5
6 use strict;
7
8 require '/var/ipfire/general-functions.pl';
9 my @vpnsettings;
10 my $i = 0;
11 my $file = "/var/run/vpn-watch.pid";
12
13 system("echo $$ > $file");
14
15 while ( $i == 0){
16 if (open(FILE, "${General::swroot}/vpn/config")) {
17 @vpnsettings = <FILE>;
18 close(FILE);
19 unless(@vpnsettings) {exit 1;}
20 }
21
22 foreach (@vpnsettings){
23 my @settings = split(/,/,$_);
24
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;}
29
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]");
36 next;
37 }
38 my $hostip = `cat /var/ipfire/red/local-ipaddress 2>/dev/null`;
39 chomp($hostip);
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]");
43 next;}
44 }
45 logger("Nothing was done.");
46 sleep(300);
47 }
48
49 sub logger {
50 my $log = shift;
51 system("logger -t vpnwatch \"$log\"");
52 }