Project

General

Profile

Download (3.7 KB) Statistics
| Branch: | Tag: | Revision:
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

    
39
/* WAN IP address has changed */
40

    
41
$argument = str_replace("\n", "", $argv[1]);
42

    
43
if($argument <> "") {
44
	$curwanip = find_interface_ip($argument);
45
	$interface = convert_real_interface_to_friendly_interface_name($argument);
46
	if($curwanip == "")
47
	        $curwanip = get_current_wan_address();
48
} else {
49
    $curwanip = get_current_wan_address();
50
    $interface = "wan";
51
}
52

    
53
/* grab the prior ip for pftpx tests */
54
if(file_exists("/tmp/rc.newwanip_oldip")) {
55
	/* grab hint from dhclient */
56
	$old_ip = file_get_contents("/tmp/rc.newwanip_oldip");
57
	unlink("/tmp/rc.newwanip_oldip");
58
}
59
/* fallback to rc.newwanip ip if needed */
60
if(!$old_ip)
61
	if(file_exists("{$g['vardb_path']}/{$interface}_ip"))
62
		$old_ip = file_get_contents("{$g['vardb_path']}/{$interface}_ip");
63
if($old_ip) {
64
	$helpers = exec("/bin/ps awux | grep \"{$old_ip}\" | grep -v \"grep\" | awk '{ print $2 }'");
65
	if($helpers)
66
	    mwexec("kill " . trim($helpers));
67
} else {
68
	log_error("WARNING! /etc/rc.newwanip could not deterimine the previous ip address ( $interface ).");
69
}
70

    
71
/* reconfigure IPsec tunnels */
72
vpn_ipsec_configure(true);
73

    
74
/* regenerate resolv.conf if DNS overrides are allowed or the BigPond
75
   client is enabled */
76
if (isset($config['system']['dnsallowoverride']) ||
77
	($config['interfaces'][$interface]['ipaddr'] == "bigpond"))
78
		system_resolvconf_generate(true);
79

    
80
/* fire up the BigPond client, if necessary */
81
if ($config['interfaces'][$interface]['ipaddr'] == "bigpond")
82
	interfaces_wan_bigpond_configure($curwanip);
83

    
84
/* perform RFC 2136 DNS update */
85
services_dnsupdate_process();
86

    
87
/* write current WAN IP to file */
88
$fd = fopen("{$g['vardb_path']}/{$interface}_ip", "w");
89
if ($fd) {
90
	fwrite($fd, $curwanip);
91
	fclose($fd);
92
}
93

    
94
log_error("Informational: DHClient spawned /etc/rc.newwanip and the new ip is {$interface} - {$curwanip}.");
95

    
96
touch("/tmp/update_dyndns");
97

    
98
/* signal filter reload */
99
unlink_if_exists("/tmp/config.cache");
100
touch("/tmp/filter_dirty");
101

    
102
/* reload graphing functions */
103
enable_rrd_graphing();
104

    
105
return 0;
106

    
107
?>
(53-53/72)