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 |
0be93267
|
Ermal Lu?i
|
/* Interface IP address has changed */
|
45 |
0363c100
|
Scott Ullrich
|
|
46 |
|
|
$argument = str_replace("\n", "", $argv[1]);
|
47 |
|
|
|
48 |
5e3ed9bc
|
Ermal Lu?i
|
log_error("rc.newwanip: Informational is starting {$argument}.");
|
49 |
2aa80139
|
Scott Ullrich
|
|
50 |
67ee1ec5
|
Ermal Luçi
|
if(empty($argument)) {
|
51 |
85a5da13
|
Ermal Luçi
|
$curwanip = get_interface_ip();
|
52 |
1cbc2a1c
|
Scott Ullrich
|
$interface = "wan";
|
53 |
85a5da13
|
Ermal Luçi
|
$interface_real = get_real_interface();
|
54 |
67ee1ec5
|
Ermal Luçi
|
} else {
|
55 |
|
|
$interface = convert_real_interface_to_friendly_interface_name($argument);
|
56 |
|
|
$interface_real = $argument;
|
57 |
01f1b601
|
Ermal
|
$curwanip = find_interface_ip($interface_real, true);
|
58 |
67ee1ec5
|
Ermal Luçi
|
if($curwanip == "")
|
59 |
85a5da13
|
Ermal Luçi
|
$curwanip = get_interface_ip($interface);
|
60 |
b1f7e75e
|
Scott Ullrich
|
}
|
61 |
|
|
|
62 |
5e3ed9bc
|
Ermal Lu?i
|
log_error("rc.newwanip: on (IP address: {$curwanip}) (interface: {$interface}) (real interface: {$interface_real}).");
|
63 |
a8840317
|
Scott Ullrich
|
|
64 |
40655051
|
Ermal
|
if($curwanip == "0.0.0.0" || !is_ipaddr($curwanip)) {
|
65 |
ba0be463
|
Ermal Lu?i
|
log_error("rc.newwanip: Failed to update {$interface} IP, restarting...");
|
66 |
5e3ed9bc
|
Ermal Lu?i
|
interface_configure($interface);
|
67 |
5b4c9c6b
|
Scott Ullrich
|
exit;
|
68 |
45f2708c
|
Scott Ullrich
|
}
|
69 |
|
|
|
70 |
40655051
|
Ermal
|
$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 |
166c82ed
|
Chris Buechler
|
/* regenerate resolv.conf if DNS overrides are allowed */
|
75 |
e7ee3bfe
|
Ermal
|
system_resolvconf_generate(true);
|
76 |
0363c100
|
Scott Ullrich
|
|
77 |
|
|
/* write current WAN IP to file */
|
78 |
5e3ed9bc
|
Ermal Lu?i
|
file_put_contents("{$g['vardb_path']}/{$interface}_ip", $curwanip);
|
79 |
461c0a1a
|
Ermal
|
file_put_contents("{$g['vardb_path']}/{$interface}_cacheip", $curwanip);
|
80 |
0363c100
|
Scott Ullrich
|
|
81 |
40655051
|
Ermal
|
if (is_ipaddr($oldip) && $curwanip == $oldip)
|
82 |
|
|
exit;
|
83 |
|
|
|
84 |
01f1b601
|
Ermal
|
/* reconfigure our gateway monitor */
|
85 |
|
|
setup_gateways_monitor();
|
86 |
|
|
|
87 |
17649c87
|
Ermal
|
/* perform RFC 2136 DNS update */
|
88 |
|
|
services_dnsupdate_process($interface);
|
89 |
|
|
|
90 |
5e3ed9bc
|
Ermal Lu?i
|
/* signal dyndns update */
|
91 |
0ae6daf8
|
Ermal
|
send_event("service reload dyndns {$interface}");
|
92 |
0363c100
|
Scott Ullrich
|
|
93 |
e7ee3bfe
|
Ermal
|
/* reconfigure IPsec tunnels */
|
94 |
|
|
vpn_ipsec_force_reload();
|
95 |
|
|
|
96 |
|
|
/* start OpenVPN server & clients */
|
97 |
c7f60193
|
Ermal
|
openvpn_resync_all($interface);
|
98 |
e7ee3bfe
|
Ermal
|
|
99 |
0363c100
|
Scott Ullrich
|
/* signal filter reload */
|
100 |
|
|
unlink_if_exists("/tmp/config.cache");
|
101 |
be38535c
|
Ermal Luçi
|
filter_configure();
|
102 |
0363c100
|
Scott Ullrich
|
|
103 |
|
|
/* reload graphing functions */
|
104 |
|
|
enable_rrd_graphing();
|
105 |
|
|
|
106 |
9c2640a0
|
Scott Ullrich
|
/* restart packages */
|
107 |
329db705
|
Ermal Lu?i
|
mwexec_bg("/usr/local/sbin/ntpdate_sync_once.sh");
|
108 |
e7ee3bfe
|
Ermal
|
mwexec_bg("/etc/rc.start_packages");
|
109 |
40655051
|
Ermal
|
log_error("{$g['product_name']} package system has detected an ip change $oldip -> $curwanip ... Restarting packages.");
|
110 |
8f8f9721
|
Scott Ullrich
|
|
111 |
67ee1ec5
|
Ermal Luçi
|
return 0;
|
112 |
0be93267
|
Ermal Lu?i
|
?>
|