Project

General

Profile

Download (4.5 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
#!/usr/local/bin/php -f
2
<?php
3
/*
4 e7012ec3 Scott Ullrich
        rc.newwanip
5 0363c100 Scott Ullrich
        Copyright (C) 2006 Scott Ullrich (sullrich@gmail.com)
6
        part of pfSense (http://www.pfsense.com)
7 e7012ec3 Scott Ullrich
8 0363c100 Scott Ullrich
		Originally part of m0n0wall (http://m0n0.ch)
9 e7012ec3 Scott Ullrich
        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 5b237745 Scott Ullrich
*/
33
34 0363c100 Scott Ullrich
/* 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 5f2d078e Scott Ullrich
require_once("filter.inc");
39
require_once("shaper.inc");
40 f973148e Ermal
require_once("ipsec.inc");
41
require_once("vpn.inc");
42 c7f60193 Ermal
require_once("openvpn.inc");
43 0363c100 Scott Ullrich
44 9e18b392 Scott Ullrich
// Do not process while booting
45
if($g['booting']) 
46
	exit;
47
48 0be93267 Ermal Lu?i
/* Interface IP address has changed */
49 0363c100 Scott Ullrich
50
$argument = str_replace("\n", "", $argv[1]);
51
52 5e3ed9bc Ermal Lu?i
log_error("rc.newwanip: Informational is starting {$argument}.");
53 2aa80139 Scott Ullrich
54 67ee1ec5 Ermal Luçi
if(empty($argument)) {
55 85a5da13 Ermal Luçi
    $curwanip = get_interface_ip();
56 1cbc2a1c Scott Ullrich
    $interface = "wan";
57 85a5da13 Ermal Luçi
    $interface_real = get_real_interface();
58 67ee1ec5 Ermal Luçi
} else {
59
        $interface = convert_real_interface_to_friendly_interface_name($argument);
60
        $interface_real = $argument;
61 01f1b601 Ermal
        $curwanip = find_interface_ip($interface_real, true);
62 67ee1ec5 Ermal Luçi
        if($curwanip == "")
63 85a5da13 Ermal Luçi
                $curwanip = get_interface_ip($interface);
64 b1f7e75e Scott Ullrich
}
65
66 5e3ed9bc Ermal Lu?i
log_error("rc.newwanip: on (IP address: {$curwanip}) (interface: {$interface}) (real interface: {$interface_real}).");
67 a8840317 Scott Ullrich
68 40655051 Ermal
if($curwanip == "0.0.0.0" || !is_ipaddr($curwanip)) {
69 ba0be463 Ermal Lu?i
        log_error("rc.newwanip: Failed to update {$interface} IP, restarting...");
70 3c3ba8f0 Ermal
	send_event("interface reconfigure {$interface}");
71 5b4c9c6b Scott Ullrich
        exit;
72 45f2708c Scott Ullrich
}
73
74 40655051 Ermal
$oldip = "0.0.0.0";
75
if (file_exists("{$g['vardb_path']}/{$interface}_cacheip"))
76
	$oldip = file_get_contents("{$g['vardb_path']}/{$interface}_cacheip");
77
78 ed62880b Ermal
$grouptmp = link_interface_to_group($interface);
79
if (!empty($grouptmp))
80
	array_walk($grouptmp, 'interface_group_add_member');
81
82 166c82ed Chris Buechler
/* regenerate resolv.conf if DNS overrides are allowed */
83 e7ee3bfe Ermal
system_resolvconf_generate(true);
84 0363c100 Scott Ullrich
85
/* write current WAN IP to file */
86 5e3ed9bc Ermal Lu?i
file_put_contents("{$g['vardb_path']}/{$interface}_ip", $curwanip);
87 461c0a1a Ermal
file_put_contents("{$g['vardb_path']}/{$interface}_cacheip", $curwanip);
88 0363c100 Scott Ullrich
89 b746dc61 Ermal
/* reconfigure static routes (kernel may have deleted them) */
90
system_routing_configure($interface);
91
92 01f1b601 Ermal
/* reconfigure our gateway monitor */
93
setup_gateways_monitor();
94
95 2c6b0d67 Ermal
/* signal filter reload */
96
filter_configure();
97
98 9c4c5e80 jim-p
if (is_ipaddr($oldip) && $curwanip == $oldip) {
99
	// Still need to sync VPNs on PPPoE and such, as even with the same IP the VPN software is unhappy with the IP disappearing.
100
	if (in_array($config['interfaces'][$interface]['ipaddr'], array('pppoe', 'pptp', 'ppp'))) {
101
		/* reconfigure IPsec tunnels */
102
		vpn_ipsec_force_reload();
103
104
		/* start OpenVPN server & clients */
105
		openvpn_resync_all($interface);
106
	}
107 3640c567 Ermal
	exit;
108 9c4c5e80 jim-p
}
109 3640c567 Ermal
110 17649c87 Ermal
/* perform RFC 2136 DNS update */
111
services_dnsupdate_process($interface);
112
113 5e3ed9bc Ermal Lu?i
/* signal dyndns update */
114 db8e9e53 Ermal
services_dyndns_configure($interface);
115 0363c100 Scott Ullrich
116 ebbae443 jim-p
/* reconfigure IPsec tunnels */
117
vpn_ipsec_force_reload();
118
119
/* start OpenVPN server & clients */
120
openvpn_resync_all($interface);
121
122 0363c100 Scott Ullrich
/* reload graphing functions */
123
enable_rrd_graphing();
124
125 9c2640a0 Scott Ullrich
/* restart packages */
126 329db705 Ermal Lu?i
mwexec_bg("/usr/local/sbin/ntpdate_sync_once.sh");
127 e7ee3bfe Ermal
mwexec_bg("/etc/rc.start_packages");
128 40655051 Ermal
log_error("{$g['product_name']} package system has detected an ip change $oldip ->  $curwanip ... Restarting packages.");		
129 8f8f9721 Scott Ullrich
130 2c6b0d67 Ermal
?>