1
|
#!/usr/local/bin/php -f
|
2
|
<?php
|
3
|
/*
|
4
|
rc.newwanip
|
5
|
part of m0n0wall (http://m0n0.ch/wall)
|
6
|
|
7
|
Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
|
8
|
All rights reserved.
|
9
|
|
10
|
Redistribution and use in source and binary forms, with or without
|
11
|
modification, are permitted provided that the following conditions are met:
|
12
|
|
13
|
1. Redistributions of source code must retain the above copyright notice,
|
14
|
this list of conditions and the following disclaimer.
|
15
|
|
16
|
2. Redistributions in binary form must reproduce the above copyright
|
17
|
notice, this list of conditions and the following disclaimer in the
|
18
|
documentation and/or other materials provided with the distribution.
|
19
|
|
20
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
21
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
22
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
23
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
24
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
25
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
26
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
27
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
28
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
29
|
POSSIBILITY OF SUCH DAMAGE.
|
30
|
*/
|
31
|
|
32
|
/* parse the configuration and include all functions used below */
|
33
|
require_once("config.inc");
|
34
|
require_once("functions.inc");
|
35
|
|
36
|
/* WAN IP address has changed */
|
37
|
|
38
|
$argument = str_replace("\n", "", $argv[1]);
|
39
|
|
40
|
if($argument <> "") {
|
41
|
$curwanip = find_interface_ip($$argument);
|
42
|
$interface = convert_real_interface_to_friendly_interface_name($$argument);
|
43
|
if($curwanip == "")
|
44
|
$curwanip = get_current_wan_address();
|
45
|
} else {
|
46
|
$curwanip = get_current_wan_address();
|
47
|
$interface = "wan";
|
48
|
}
|
49
|
|
50
|
/* grab the prior ip for pftpx tests */
|
51
|
if(file_exists("/tmp/rc.newwanip_oldip")) {
|
52
|
$old_ip = file_get_contents("/tmp/rc.newwanip_oldip");
|
53
|
$helpers = exec("/bin/ps awux | grep {$old_ip} | grep -v grep | cut -d\" \" -f6");
|
54
|
mwexec("kill " . trim($helpers));
|
55
|
unlink("/tmp/rc.newwanip_oldip");
|
56
|
}
|
57
|
|
58
|
/* reconfigure IPsec tunnels */
|
59
|
vpn_ipsec_configure(true);
|
60
|
|
61
|
/* regenerate resolv.conf if DNS overrides are allowed or the BigPond
|
62
|
client is enabled */
|
63
|
if (isset($config['system']['dnsallowoverride']) ||
|
64
|
($config['interfaces'][$interface]['ipaddr'] == "bigpond"))
|
65
|
system_resolvconf_generate(true);
|
66
|
|
67
|
/* fire up the BigPond client, if necessary */
|
68
|
if ($config['interfaces'][$interface]['ipaddr'] == "bigpond")
|
69
|
interfaces_wan_bigpond_configure($curwanip);
|
70
|
|
71
|
/* perform RFC 2136 DNS update */
|
72
|
services_dnsupdate_process();
|
73
|
|
74
|
/* write current WAN IP to file */
|
75
|
$fd = fopen("{$g['vardb_path']}/{$interface}_ip", "w");
|
76
|
if ($fd) {
|
77
|
fwrite($fd, $curwanip);
|
78
|
fclose($fd);
|
79
|
}
|
80
|
|
81
|
log_error("Informational: DHClient spawned /etc/rc.newwanip and the new ip is {$interface} - {$curwanip}.");
|
82
|
|
83
|
touch("/tmp/update_dyndns");
|
84
|
|
85
|
/* signal filter reload */
|
86
|
touch("/tmp/filter_dirty");
|
87
|
|
88
|
/* reload graphing functions */
|
89
|
enable_rrd_graphing();
|
90
|
|
91
|
return 0;
|
92
|
|
93
|
?>
|