Project

General

Profile

Download (4.63 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
39
/* WAN IP address has changed */
40
41
$argument = str_replace("\n", "", $argv[1]);
42
43 2aa80139 Scott Ullrich
log_error("Informational: rc.newwanip is starting {$argument}.");
44
45 0363c100 Scott Ullrich
if($argument <> "") {
46
	$interface = convert_real_interface_to_friendly_interface_name($argument);
47 1cbc2a1c Scott Ullrich
	$interface_real = convert_friendly_interface_to_real_interface_name($argument);
48 e8721ce5 Scott Ullrich
	$curwanip = find_interface_ip($interface_real);
49 0363c100 Scott Ullrich
	if($curwanip == "")
50
	        $curwanip = get_current_wan_address();
51
} else {
52
    $curwanip = get_current_wan_address();
53 1cbc2a1c Scott Ullrich
    $interface = "wan";
54
    $interface_real = $config['interfaces']['wan']['if'];
55 b1f7e75e Scott Ullrich
}
56
57 2ab9b89e Scott Ullrich
log_error("rc.newwanip working with (IP address: {$curwanip}) (interface: {$interface}) (interface real: {$interface_real}).");
58 a8840317 Scott Ullrich
59 45f2708c Scott Ullrich
if($curwanip == "0.0.0.0") {
60
        log_error("Failed to update WAN IP, restarting dhclient.");
61
        exec("dhclient $interface_real");
62 5b4c9c6b Scott Ullrich
        exit;
63 45f2708c Scott Ullrich
}
64
65 0363c100 Scott Ullrich
/* grab the prior ip for pftpx tests */
66
if(file_exists("/tmp/rc.newwanip_oldip")) {
67
	/* grab hint from dhclient */
68 79c0324b Scott Ullrich
	$old_ip = trim(file_get_contents("/tmp/rc.newwanip_oldip", "\r"));
69 0363c100 Scott Ullrich
	unlink("/tmp/rc.newwanip_oldip");
70
}
71
/* fallback to rc.newwanip ip if needed */
72
if(!$old_ip)
73
	if(file_exists("{$g['vardb_path']}/{$interface}_ip"))
74 79c0324b Scott Ullrich
		$old_ip = trim(file_get_contents("{$g['vardb_path']}/{$interface}_ip", "\r"));
75 0363c100 Scott Ullrich
if($old_ip) {
76 411d8c36 Scott Ullrich
	$helpers = exec("/bin/ps awux | grep \"{$old_ip}\" | grep -v \"grep\" | awk '{ print $2 }'");
77 0363c100 Scott Ullrich
	if($helpers)
78
	    mwexec("kill " . trim($helpers));
79
} else {
80
	log_error("WARNING! /etc/rc.newwanip could not deterimine the previous ip address ( $interface ).");
81
}
82
83
/* reconfigure IPsec tunnels */
84 8de68a2c Seth Mos
vpn_ipsec_force_reload();
85 0363c100 Scott Ullrich
86 ae87302c Scott Ullrich
/* start OpenVPN server & clients */
87 cebf4a35 Scott Ullrich
exec("killall -HUP openvpn 2>/dev/null");
88 ae87302c Scott Ullrich
89 0363c100 Scott Ullrich
/* regenerate resolv.conf if DNS overrides are allowed or the BigPond
90
   client is enabled */
91
if (isset($config['system']['dnsallowoverride']) ||
92
	($config['interfaces'][$interface]['ipaddr'] == "bigpond"))
93
		system_resolvconf_generate(true);
94
95
/* fire up the BigPond client, if necessary */
96
if ($config['interfaces'][$interface]['ipaddr'] == "bigpond")
97
	interfaces_wan_bigpond_configure($curwanip);
98
99
/* perform RFC 2136 DNS update */
100
services_dnsupdate_process();
101
102
/* write current WAN IP to file */
103
$fd = fopen("{$g['vardb_path']}/{$interface}_ip", "w");
104
if ($fd) {
105
	fwrite($fd, $curwanip);
106
	fclose($fd);
107
}
108
109
log_error("Informational: DHClient spawned /etc/rc.newwanip and the new ip is {$interface} - {$curwanip}.");
110
111
touch("/tmp/update_dyndns");
112
113
/* signal filter reload */
114
unlink_if_exists("/tmp/config.cache");
115
touch("/tmp/filter_dirty");
116
117
/* reload graphing functions */
118
enable_rrd_graphing();
119
120 9c2640a0 Scott Ullrich
/* restart packages */
121 4a9dfa44 Scott Ullrich
if($old_ip <> "") 
122 460851c6 Scott Ullrich
	if($old_ip <> $curwanip) {
123 4a9dfa44 Scott Ullrich
		exec("/etc/rc.start_packages");
124 460851c6 Scott Ullrich
		log_error("pfSense package system has detected an ip change $old_ip ->  $curwanip ... Restarting packages.");
125
	}
126 9c2640a0 Scott Ullrich
127 401452ec Seth Mos
/* reload slbd */
128
/* if ($config['load_balancer']['lbpool']['type'] == "gateway") */
129
slbd_configure();
130
log_error("Configuring slbd");
131 45f2708c Scott Ullrich
132 401452ec Seth Mos
133 0363c100 Scott Ullrich
return 0;
134 39ac8421 Scott Ullrich
135 8de68a2c Seth Mos
?>