From 0363c1006a1a80b708acd6588955b5f2000a8250 Mon Sep 17 00:00:00 2001 From: Scott Ullrich Date: Tue, 12 Sep 2006 17:31:24 +0000 Subject: Correctly deterimine the previous ip address when running under pppoe, as well. Log an error if we cannot deterimine the ip address for any reason. --- etc/rc.newwanip | 137 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 75 insertions(+), 62 deletions(-) (limited to 'etc/rc.newwanip') diff --git a/etc/rc.newwanip b/etc/rc.newwanip index d22cc22..830186f 100755 --- a/etc/rc.newwanip +++ b/etc/rc.newwanip @@ -2,8 +2,10 @@ . All rights reserved. @@ -29,66 +31,77 @@ POSSIBILITY OF SUCH DAMAGE. */ - /* parse the configuration and include all functions used below */ - require_once("config.inc"); - require_once("functions.inc"); - - /* WAN IP address has changed */ - - $argument = str_replace("\n", "", $argv[1]); - - if($argument <> "") { - $curwanip = find_interface_ip($argument); - $interface = convert_real_interface_to_friendly_interface_name($argument); - if($curwanip == "") - $curwanip = get_current_wan_address(); - } else { - $curwanip = get_current_wan_address(); - $interface = "wan"; - } - - /* grab the prior ip for pftpx tests */ - if(file_exists("/tmp/rc.newwanip_oldip")) { - $old_ip = file_get_contents("/tmp/rc.newwanip_oldip"); - $helpers = exec("/bin/ps awux | grep \"{$old_ip}\" | grep -v \"grep\" | awk '{ print $6 }'"); - if($helpers) - mwexec("kill " . trim($helpers)); - unlink("/tmp/rc.newwanip_oldip"); - } - - /* reconfigure IPsec tunnels */ - vpn_ipsec_configure(true); - - /* regenerate resolv.conf if DNS overrides are allowed or the BigPond - client is enabled */ - if (isset($config['system']['dnsallowoverride']) || - ($config['interfaces'][$interface]['ipaddr'] == "bigpond")) - system_resolvconf_generate(true); - - /* fire up the BigPond client, if necessary */ - if ($config['interfaces'][$interface]['ipaddr'] == "bigpond") - interfaces_wan_bigpond_configure($curwanip); - - /* perform RFC 2136 DNS update */ - services_dnsupdate_process(); - - /* write current WAN IP to file */ - $fd = fopen("{$g['vardb_path']}/{$interface}_ip", "w"); - if ($fd) { - fwrite($fd, $curwanip); - fclose($fd); - } - - log_error("Informational: DHClient spawned /etc/rc.newwanip and the new ip is {$interface} - {$curwanip}."); - - touch("/tmp/update_dyndns"); - - /* signal filter reload */ - touch("/tmp/filter_dirty"); - - /* reload graphing functions */ - enable_rrd_graphing(); - - return 0; +/* parse the configuration and include all functions used below */ +require_once("globals.inc"); +require_once("config.inc"); +require_once("functions.inc"); + +/* WAN IP address has changed */ + +$argument = str_replace("\n", "", $argv[1]); + +if($argument <> "") { + $curwanip = find_interface_ip($argument); + $interface = convert_real_interface_to_friendly_interface_name($argument); + if($curwanip == "") + $curwanip = get_current_wan_address(); +} else { + $curwanip = get_current_wan_address(); + $interface = "wan"; +} + +/* grab the prior ip for pftpx tests */ +if(file_exists("/tmp/rc.newwanip_oldip")) { + /* grab hint from dhclient */ + $old_ip = file_get_contents("/tmp/rc.newwanip_oldip"); + unlink("/tmp/rc.newwanip_oldip"); +} +/* fallback to rc.newwanip ip if needed */ +if(!$old_ip) + if(file_exists("{$g['vardb_path']}/{$interface}_ip")) + $old_ip = file_get_contents("{$g['vardb_path']}/{$interface}_ip"); +if($old_ip) { + $helpers = exec("/bin/ps awux | grep \"{$old_ip}\" | grep -v \"grep\" | awk '{ print $6 }'"); + if($helpers) + mwexec("kill " . trim($helpers)); +} else { + log_error("WARNING! /etc/rc.newwanip could not deterimine the previous ip address ( $interface )."); +} + +/* reconfigure IPsec tunnels */ +vpn_ipsec_configure(true); + +/* regenerate resolv.conf if DNS overrides are allowed or the BigPond + client is enabled */ +if (isset($config['system']['dnsallowoverride']) || + ($config['interfaces'][$interface]['ipaddr'] == "bigpond")) + system_resolvconf_generate(true); + +/* fire up the BigPond client, if necessary */ +if ($config['interfaces'][$interface]['ipaddr'] == "bigpond") + interfaces_wan_bigpond_configure($curwanip); + +/* perform RFC 2136 DNS update */ +services_dnsupdate_process(); + +/* write current WAN IP to file */ +$fd = fopen("{$g['vardb_path']}/{$interface}_ip", "w"); +if ($fd) { + fwrite($fd, $curwanip); + fclose($fd); +} + +log_error("Informational: DHClient spawned /etc/rc.newwanip and the new ip is {$interface} - {$curwanip}."); + +touch("/tmp/update_dyndns"); + +/* signal filter reload */ +unlink_if_exists("/tmp/config.cache"); +touch("/tmp/filter_dirty"); + +/* reload graphing functions */ +enable_rrd_graphing(); + +return 0; ?> \ No newline at end of file -- cgit v1.1