Project

General

Profile

Download (4.28 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php -f
2
<?php
3
/*
4
        rc.newwanip
5
        Copyright (C) 2006 Scott Ullrich (sullrich@gmail.com)
6
        part of pfSense (http://www.pfsense.com)
7

    
8
		Originally part of m0n0wall (http://m0n0.ch)
9
        Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
10
        All rights reserved.
11

    
12
        Redistribution and use in source and binary forms, with or without
13
        modification, are permitted provided that the following conditions are met:
14

    
15
        1. Redistributions of source code must retain the above copyright notice,
16
           this list of conditions and the following disclaimer.
17

    
18
        2. Redistributions in binary form must reproduce the above copyright
19
           notice, this list of conditions and the following disclaimer in the
20
           documentation and/or other materials provided with the distribution.
21

    
22
        THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23
        INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
        AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
        AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26
        OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
        SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
        INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
        CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
        ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
        POSSIBILITY OF SUCH DAMAGE.
32
*/
33

    
34
/* parse the configuration and include all functions used below */
35
require_once("globals.inc");
36
require_once("config.inc");
37
require_once("functions.inc");
38

    
39
/* WAN IP address has changed */
40

    
41
$argument = str_replace("\n", "", $argv[1]);
42

    
43
log_error("Informational: rc.newwanip is starting {$argument}.");
44

    
45
if(empty($argument)) {
46
    $curwanip = get_interface_ip();
47
    $interface = "wan";
48
    $interface_real = get_real_interface();
49
} else {
50
        $interface = convert_real_interface_to_friendly_interface_name($argument);
51
        $interface_real = $argument;
52
        $curwanip = find_interface_ip($interface_real);
53
        if($curwanip == "")
54
                $curwanip = get_interface_ip($interface);
55
}
56

    
57
log_error("rc.newwanip working with (IP address: {$curwanip}) (interface: {$interface}) (interface real: {$interface_real}).");
58

    
59
if($curwanip == "0.0.0.0") {
60
        log_error("Failed to update WAN IP, restarting dhclient.");
61
        exec("dhclient $interface_real");
62
        exit;
63
}
64

    
65
/* fallback to rc.newwanip ip if needed */
66
if(!$old_ip)
67
	if(file_exists("{$g['vardb_path']}/{$interface}_ip"))
68
		$old_ip = trim(file_get_contents("{$g['vardb_path']}/{$interface}_ip", "\r"));
69
if($old_ip) {
70
	$helpers = exec("/bin/ps awux | grep \"{$old_ip}\" | grep -v \"grep\" | awk '{ print $2 }'");
71
	if($helpers)
72
	    mwexec("kill " . trim($helpers));
73
} else {
74
	log_error("WARNING! /etc/rc.newwanip could not deterimine the previous ip address ( $interface ).");
75
}
76

    
77
/* reconfigure IPsec tunnels */
78
vpn_ipsec_force_reload();
79

    
80
/* start OpenVPN server & clients */
81
exec("killall -HUP openvpn 2>/dev/null");
82

    
83
/* regenerate resolv.conf if DNS overrides are allowed or the BigPond
84
   client is enabled */
85
if (isset($config['system']['dnsallowoverride'])) 
86
		system_resolvconf_generate(true);
87

    
88
/* perform RFC 2136 DNS update */
89
services_dnsupdate_process();
90

    
91
/* write current WAN IP to file */
92
$fd = fopen("{$g['vardb_path']}/{$interface}_ip", "w");
93
if ($fd) {
94
	fwrite($fd, $curwanip);
95
	fclose($fd);
96
}
97

    
98
log_error("Informational: DHClient spawned /etc/rc.newwanip and the new ip is {$interface} - {$curwanip}.");
99

    
100
touch("/tmp/update_dyndns");
101

    
102
/* signal filter reload */
103
unlink_if_exists("/tmp/config.cache");
104
filter_configure();
105

    
106
/* reload graphing functions */
107
enable_rrd_graphing();
108

    
109
/* This is DHCP, update the gateway group items default gateway */
110
update_gateway_groups_defaultroute_dhclient($interface);
111

    
112
/* restart packages */
113
if($old_ip <> "") {
114
	if($old_ip <> $curwanip) {
115
		mwexec_bg("/usr/local/sbin/ntpdate_sync_once.sh");
116
		exec("/etc/rc.start_packages");
117
		log_error("{$g['product_name']} package system has detected an ip change $old_ip ->  $curwanip ... Restarting packages.");		
118
	}
119
}
120

    
121
/* reconfigure our gateway monitor */
122
setup_gateways_monitor();
123

    
124
return 0;
125
?>
(64-64/85)