Project

General

Profile

Download (4.31 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
require_once("gwlb.inc");
39

    
40
/* WAN IP address has changed */
41

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
125
return 0;
126
?>
(65-65/87)