1
|
#!/usr/local/bin/php -f
|
2
|
<?php
|
3
|
/* $Id$ */
|
4
|
/*
|
5
|
rc.newwanip
|
6
|
part of m0n0wall (http://m0n0.ch/wall)
|
7
|
|
8
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
9
|
All rights reserved.
|
10
|
|
11
|
Redistribution and use in source and binary forms, with or without
|
12
|
modification, are permitted provided that the following conditions are met:
|
13
|
|
14
|
1. Redistributions of source code must retain the above copyright notice,
|
15
|
this list of conditions and the following disclaimer.
|
16
|
|
17
|
2. Redistributions in binary form must reproduce the above copyright
|
18
|
notice, this list of conditions and the following disclaimer in the
|
19
|
documentation and/or other materials provided with the distribution.
|
20
|
|
21
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
22
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
23
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
24
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
25
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
26
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
27
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
28
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
29
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
|
POSSIBILITY OF SUCH DAMAGE.
|
31
|
*/
|
32
|
|
33
|
/* parse the configuration and include all functions used below */
|
34
|
require_once("config.inc");
|
35
|
require_once("functions.inc");
|
36
|
|
37
|
/* WAN IP address has changed */
|
38
|
|
39
|
/* make sure to wait until the boot scripts have finished
|
40
|
while (file_exists("{$g['varrun_path']}/booting")) {
|
41
|
sleep(1);
|
42
|
}
|
43
|
*/
|
44
|
|
45
|
$curwanip = get_current_wan_address();
|
46
|
|
47
|
/* dhclient or MPD told us that the IP address has changed;
|
48
|
let's see if that's really true to avoid reloading things
|
49
|
when it's not really necessary (dhclient likes to
|
50
|
execute its dhclient-exit-hooks also on renewals)
|
51
|
*/
|
52
|
if (file_exists("{$g['vardb_path']}/wanip")) {
|
53
|
$oldwanip = chop(file_get_contents("{$g['vardb_path']}/wanip"));
|
54
|
|
55
|
if ($curwanip == $oldwanip)
|
56
|
return 0; /* nothing to do */
|
57
|
}
|
58
|
|
59
|
/* relaunch pftpx */
|
60
|
system_start_ftp_helpers();
|
61
|
|
62
|
/* resync ipfilter */
|
63
|
filter_resync();
|
64
|
|
65
|
/* flush NAT table */
|
66
|
//filter_flush_nat_table();
|
67
|
|
68
|
/* reconfigure IPsec tunnels */
|
69
|
vpn_ipsec_configure(true);
|
70
|
|
71
|
/* regenerate resolv.conf if DNS overrides are allowed or the BigPond
|
72
|
client is enabled */
|
73
|
if (isset($config['system']['dnsallowoverride']) ||
|
74
|
($config['interfaces']['wan']['ipaddr'] == "bigpond"))
|
75
|
system_resolvconf_generate(true);
|
76
|
|
77
|
/* fire up the BigPond client, if necessary */
|
78
|
if ($config['interfaces']['wan']['ipaddr'] == "bigpond")
|
79
|
interfaces_wan_bigpond_configure($curwanip);
|
80
|
|
81
|
/* write current WAN IP to file */
|
82
|
$fd = @fopen("{$g['vardb_path']}/wanip", "w");
|
83
|
if ($fd) {
|
84
|
fwrite($fd, $curwanip);
|
85
|
fclose($fd);
|
86
|
}
|
87
|
?>
|