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("filter.inc");
|
39
|
require_once("shaper.inc");
|
40
|
require_once("ipsec.inc");
|
41
|
require_once("vpn.inc");
|
42
|
require_once("openvpn.inc");
|
43
|
|
44
|
/* Interface IP address has changed */
|
45
|
|
46
|
$argument = str_replace("\n", "", $argv[1]);
|
47
|
|
48
|
log_error("rc.newwanip: Informational is starting {$argument}.");
|
49
|
|
50
|
if(empty($argument)) {
|
51
|
$curwanip = get_interface_ip();
|
52
|
$interface = "wan";
|
53
|
$interface_real = get_real_interface();
|
54
|
} else {
|
55
|
$interface = convert_real_interface_to_friendly_interface_name($argument);
|
56
|
$interface_real = $argument;
|
57
|
$curwanip = find_interface_ip($interface_real);
|
58
|
if($curwanip == "")
|
59
|
$curwanip = get_interface_ip($interface);
|
60
|
}
|
61
|
|
62
|
log_error("rc.newwanip: on (IP address: {$curwanip}) (interface: {$interface}) (real interface: {$interface_real}).");
|
63
|
|
64
|
if($curwanip == "0.0.0.0" || !is_ipaddr($curwanip)) {
|
65
|
log_error("rc.newwanip: Failed to update {$interface} IP, restarting...");
|
66
|
interface_configure($interface);
|
67
|
exit;
|
68
|
}
|
69
|
|
70
|
$oldip = "0.0.0.0";
|
71
|
if (file_exists("{$g['vardb_path']}/{$interface}_cacheip"))
|
72
|
$oldip = file_get_contents("{$g['vardb_path']}/{$interface}_cacheip");
|
73
|
|
74
|
/* regenerate resolv.conf if DNS overrides are allowed */
|
75
|
system_resolvconf_generate(true);
|
76
|
|
77
|
/* write current WAN IP to file */
|
78
|
file_put_contents("{$g['vardb_path']}/{$interface}_ip", $curwanip);
|
79
|
file_put_contents("{$g['vardb_path']}/{$interface}_cacheip", $curwanip);
|
80
|
|
81
|
if (is_ipaddr($oldip) && $curwanip == $oldip)
|
82
|
exit;
|
83
|
|
84
|
/* perform RFC 2136 DNS update */
|
85
|
services_dnsupdate_process($interface);
|
86
|
|
87
|
/* signal dyndns update */
|
88
|
file_put_contents("{$g['tmp_path']}/update_dyndns", $interface);
|
89
|
|
90
|
/* reconfigure IPsec tunnels */
|
91
|
vpn_ipsec_force_reload();
|
92
|
|
93
|
/* start OpenVPN server & clients */
|
94
|
openvpn_resync_all($interface);
|
95
|
|
96
|
/* signal filter reload */
|
97
|
unlink_if_exists("/tmp/config.cache");
|
98
|
filter_configure();
|
99
|
|
100
|
/* reload graphing functions */
|
101
|
enable_rrd_graphing();
|
102
|
|
103
|
/* reconfigure our gateway monitor */
|
104
|
setup_gateways_monitor();
|
105
|
|
106
|
|
107
|
/* restart packages */
|
108
|
mwexec_bg("/usr/local/sbin/ntpdate_sync_once.sh");
|
109
|
mwexec_bg("/etc/rc.start_packages");
|
110
|
log_error("{$g['product_name']} package system has detected an ip change $oldip -> $curwanip ... Restarting packages.");
|
111
|
|
112
|
return 0;
|
113
|
?>
|