Project

General

Profile

Download (4.68 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
log_error("Informational: rc.newwanip is starting {$argument}.");
44

    
45
if($argument <> "") {
46
	$interface = convert_real_interface_to_friendly_interface_name($argument);
47
	$interface_real = convert_friendly_interface_to_real_interface_name($argument);
48
	$curwanip = find_interface_ip($interface_real);
49
	if($curwanip == "")
50
	        $curwanip = get_current_wan_address();
51
} else {
52
    $curwanip = get_current_wan_address();
53
    $interface = "wan";
54
    $interface_real = $config['interfaces']['wan']['if'];
55
}
56

    
57
log_error("rc.newwanip working with (IP address: {$curwanip}) (interface: {$interface}) (interface real: {$interface_real}).");
58

    
59
if($curwanip == "0.0.0.0") {
60
        log_error("Failed to update WAN IP, restarting dhclient.");
61
        exec("dhclient $interface_real");
62
        exit;
63
}
64

    
65
/* grab the prior ip for pftpx tests */
66
if(file_exists("/tmp/rc.newwanip_oldip")) {
67
	/* grab hint from dhclient */
68
	$old_ip = trim(file_get_contents("/tmp/rc.newwanip_oldip", "\r"));
69
	unlink("/tmp/rc.newwanip_oldip");
70
}
71
/* fallback to rc.newwanip ip if needed */
72
if(!$old_ip)
73
	if(file_exists("{$g['vardb_path']}/{$interface}_ip"))
74
		$old_ip = trim(file_get_contents("{$g['vardb_path']}/{$interface}_ip", "\r"));
75
if($old_ip) {
76
	$helpers = exec("/bin/ps awux | grep \"{$old_ip}\" | grep -v \"grep\" | awk '{ print $2 }'");
77
	if($helpers)
78
	    mwexec("kill " . trim($helpers));
79
} else {
80
	log_error("WARNING! /etc/rc.newwanip could not deterimine the previous ip address ( $interface ).");
81
}
82

    
83
/* reconfigure IPsec tunnels */
84
vpn_ipsec_force_reload();
85

    
86
/* start OpenVPN server & clients */
87
exec("killall -HUP openvpn 2>/dev/null");
88

    
89
/* regenerate resolv.conf if DNS overrides are allowed or the BigPond
90
   client is enabled */
91
if (isset($config['system']['dnsallowoverride']) ||
92
	($config['interfaces'][$interface]['ipaddr'] == "bigpond"))
93
		system_resolvconf_generate(true);
94

    
95
/* fire up the BigPond client, if necessary */
96
if ($config['interfaces'][$interface]['ipaddr'] == "bigpond")
97
	interfaces_wan_bigpond_configure($curwanip);
98

    
99
/* perform RFC 2136 DNS update */
100
services_dnsupdate_process();
101

    
102
/* write current WAN IP to file */
103
$fd = fopen("{$g['vardb_path']}/{$interface}_ip", "w");
104
if ($fd) {
105
	fwrite($fd, $curwanip);
106
	fclose($fd);
107
}
108

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

    
111
touch("/tmp/update_dyndns");
112

    
113
/* signal filter reload */
114
unlink_if_exists("/tmp/config.cache");
115
touch("/tmp/filter_dirty");
116

    
117
/* reload graphing functions */
118
enable_rrd_graphing();
119

    
120
/* restart packages */
121
if($old_ip <> "") 
122
	if($old_ip <> $curwanip) {
123
		exec("/etc/rc.start_packages");		
124
		exec("/etc/rc.start_packages");
125
		log_error("{$g['product_name']} package system has detected an ip change $old_ip ->  $curwanip ... Restarting packages.");
126
	}
127

    
128
/* reload slbd */
129
/* if ($config['load_balancer']['lbpool']['type'] == "gateway") */
130
slbd_configure();
131
log_error("Configuring slbd");
132

    
133

    
134
return 0;
135

    
136
?>
(60-60/81)