From a90896fd641a24d33af1db55efbf83c5cfac9974 Mon Sep 17 00:00:00 2001 From: jim-p Date: Tue, 24 May 2011 12:21:33 -0400 Subject: [PATCH 01/15] Move the code to touch needs_package_sync into the shell script portion of the post upgrade command. The PHP portion will fail spectacularly during the 1.2.3-to-2.0 upgrade trying to run the new binaries on the old OS. The shell script part still works. Fixes #1251 enough for what we need. The PHP code can never run properly there, but at least we can trigger the package reinstall and the rest can sort itself out when 2.0 boots the first time. --- tmp/post_upgrade_command | 10 +++++++--- tmp/post_upgrade_command.php | 3 --- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tmp/post_upgrade_command b/tmp/post_upgrade_command index 99285e4001..8603a5397c 100755 --- a/tmp/post_upgrade_command +++ b/tmp/post_upgrade_command @@ -2,7 +2,9 @@ /etc/rc.conf_mount_rw +PFSENSETYPE=`cat /etc/platform` KERNELTYPE=`cat /boot/kernel/pfsense_kernel.txt` + if [ $KERNELTYPE = "wrap" ]; then if [ -f /kernels/kernel_wrap.gz ]; then tar xzpf /kernels/kernel_wrap.gz --exclude loader.conf -C /boot/ @@ -26,6 +28,10 @@ if [ $KERNELTYPE = "UP" ]; then fi fi +if [ $PFSENSETYPE = "pfSense" ] || [ $PFSENSETYPE = "nanobsd" ]; then + touch /conf/needs_package_sync +fi + # Detect interactive logins and display the shell echo "if [ \`env | grep SSH_TTY | wc -l\` -gt 0 ] || [ \`env | grep cons25 | wc -l\` -gt 0 ]; then" > $CVS_CO_DIR/root/.shrc echo " /etc/rc.initial" >> $CVS_CO_DIR/root/.shrc @@ -37,7 +43,7 @@ echo " exit" >> $CVS_CO_DIR/root/.profile echo "fi" >> $CVS_CO_DIR/root/.profile # Now turn on or off serial console as needed -php -f /tmp/post_upgrade_command.php +/tmp/post_upgrade_command.php # Remove any previous MD5 sum files rm -f /root/*.md5 @@ -45,7 +51,6 @@ rm -f /root/*.md5 # File moved to pfSense php shell (pfSsh.php) rm -rf /usr/local/sbin/cvs_sync.sh -PFSENSETYPE=`cat /etc/platform` if [ $PFSENSETYPE = "embedded" ]; then cp /etc/ttys_wrap /etc/ttys fi @@ -53,4 +58,3 @@ fi if [ -f /usr/local/sbin/php ]; then rm /usr/local/sbin/php fi - diff --git a/tmp/post_upgrade_command.php b/tmp/post_upgrade_command.php index dfe9342d17..a188710259 100755 --- a/tmp/post_upgrade_command.php +++ b/tmp/post_upgrade_command.php @@ -20,9 +20,6 @@ setup_serial_port(); - if($g['platform'] == "pfSense" or $g['platform'] == "nanobsd") - touch("/conf/needs_package_sync"); - $files_to_process = split("\n", file_get_contents("/etc/pfSense.obsoletedfiles")); foreach($files_to_process as $filename) if(file_exists($filename)) From bdb6bd30651fc219acf5a0171752164d680a1c7b Mon Sep 17 00:00:00 2001 From: jim-p Date: Tue, 24 May 2011 12:49:21 -0400 Subject: [PATCH 02/15] Fix syntax error/typo. Fixes #1372 --- etc/inc/rrd.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/inc/rrd.inc b/etc/inc/rrd.inc index 4d1c456b46..8ae459b34b 100644 --- a/etc/inc/rrd.inc +++ b/etc/inc/rrd.inc @@ -394,7 +394,7 @@ function enable_rrd_graphing() { $rrdupdatesh .= " sleep 0.2\n"; $rrdupdatesh .= " echo \"quit\"\n"; $rrdupdatesh .= "}\n"; - $rrdupdatesh .= "OVPN=`list_current_users | nc -U {$g['varetc_path']}/openvpn/server{$vpnid}.sock | awk -F\",\" '/^CLIENT_LIST/ {print \$2}' | wc -l | awk '{print $1}'` &\n"; + $rrdupdatesh .= "OVPN=`list_current_users | nc -U {$g['varetc_path']}/openvpn/server{$vpnid}.sock | awk -F\",\" '/^CLIENT_LIST/ {print \$2}' | wc -l | awk '{print $1}'`\n"; $rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$vpnusers N:\${OVPN}\n"; } From 4e12754d1ae3405a8910686a7fa0bb012c01d8da Mon Sep 17 00:00:00 2001 From: jim-p Date: Tue, 24 May 2011 13:39:38 -0400 Subject: [PATCH 03/15] Fix automatic and manual outbound NAT for PPTP. Fixes #954 --- etc/inc/filter.inc | 10 ++++------ usr/local/www/firewall_nat_out.php | 12 ++++-------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/etc/inc/filter.inc b/etc/inc/filter.inc index bdb354170d..f0c718a794 100644 --- a/etc/inc/filter.inc +++ b/etc/inc/filter.inc @@ -1326,12 +1326,10 @@ function filter_nat_rules_generate() { } } /* PPTP subnet */ - if(isset($FilterIflist['pptp']) && $FilterIflist['pptp']['mode'] == "server" ) { - $pptp_subnet = $FilterIflist['pptp']['sn']; - if(is_private_ip($FilterIflist['pptp']['sa']) && !empty($pptp_subnet)) { - $numberofnathosts++; - $tonathosts .= "{$FilterIflist['pptp']['sa']}/{$pptp_subnet} "; - } + if(($config['pptpd']['mode'] == "server" ) && is_private_ip($config['pptpd']['remoteip'])) { + $pptp_subnets = ip_range_to_subnet_array($config['pptpd']['remoteip'], long2ip32(ip2long($config['pptpd']['remoteip'])+$config['pptpd']['n_pptp_units'])); + $numberofnathosts += count($pptp_subnets); + $tonathosts .= implode(" ", $pptp_subnets) . " "; } /* PPPoE subnet */ if(isset($FilterIflist['pppoe']) && $FilterIflist['pppoe']['mode'] == "server") { diff --git a/usr/local/www/firewall_nat_out.php b/usr/local/www/firewall_nat_out.php index 4649795b48..e6b5900e12 100755 --- a/usr/local/www/firewall_nat_out.php +++ b/usr/local/www/firewall_nat_out.php @@ -126,15 +126,11 @@ if (isset($_POST['save']) && $_POST['save'] == "Save") { $a_out[] = $natent; /* PPTP subnet */ - if($config['pptpd']['mode'] == "server") { - if (is_ipaddr($config['pptpd']['localip'])) { - if($config['pptpd']['pptp_subnet'] <> "") - $ossubnet = $config['pptpd']['pptp_subnet']; - else - $ossubnet = "32"; - $osn = gen_subnet($config['pptpd']['localip'], $ossubnet); + if (($config['pptpd']['mode'] == "server") && is_private_ip($config['pptpd']['remoteip'])) { + $pptp_subnets = ip_range_to_subnet_array($config['pptpd']['remoteip'], long2ip32(ip2long($config['pptpd']['remoteip'])+$config['pptpd']['n_pptp_units'])); + foreach ($pptp_subnets as $pptpsn) { $natent = array(); - $natent['source']['network'] = "{$osn}/{$ossubnet}"; + $natent['source']['network'] = $pptpsn; $natent['sourceport'] = ""; $natent['descr'] = gettext("Auto created rule for PPTP server"); $natent['target'] = ""; From ee6d2b525127a05121682b1c26dd153496385b36 Mon Sep 17 00:00:00 2001 From: Ermal Date: Tue, 24 May 2011 19:35:54 +0000 Subject: [PATCH 04/15] Resolves #1243. Properly handle pppoe new format of config so correct rulesets are generated. --- etc/inc/filter.inc | 65 +++++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/etc/inc/filter.inc b/etc/inc/filter.inc index f0c718a794..9727d59cbd 100644 --- a/etc/inc/filter.inc +++ b/etc/inc/filter.inc @@ -695,9 +695,15 @@ function filter_get_vpns_list() { } } /* pppoe */ - if($config['pppoe']['remoteip']) { - if(is_subnet($tunnel['remote-subnet'])) { - $vpns_arr[] = $config['pppoe']['remoteip'] ."/". $config['pppoe']['pppoe_subnet']; + if (is_array($config['pppoes']['pppoe'])) { + foreach($config['pppoes']['pppoe'] as $pppoe) { + if ($pppoe['mode'] == "server") { + if(is_ipaddr($pppoe['remoteip'])) { + $pppoesub = gen_subnet($pppoe['remoteip'], $pppoe['pppoe_subnet']); + if (is_subnet($pppoesub)) + $vpns_arr[] = $pppoesub; + } + } } } if(!empty($vpns_arr)) { @@ -788,19 +794,24 @@ function filter_generate_optcfg_array() { $oic['virtual'] = true; $FilterIflist['l2tp'] = $oic; } - if($config['pppoe']['mode'] == "server") { - $oic = array(); - $oic['if'] = 'pppoe'; - $oic['descr'] = 'pppoe'; - $oic['ip'] = $config['pppoe']['localip']; - $oic['sa'] = $config['pppoe']['remoteip']; - $oic['mode'] = $config['pppoe']['mode']; - $oic['virtual'] = true; - if($config['pppoe']['pppoe_subnet'] <> "") - $oic['sn'] = $config['pppoe']['pppoe_subnet']; - else - $oic['sn'] = "32"; - $FilterIflist['pppoe'] = $oic; + if (is_array($config['pppoes']['pppoe'])) { + $FilterIflist['pppoe'] = array(); + foreach($config['pppoes']['pppoe'] as $pppoe) { + if ($pppoe['mode'] == "server") { + $oic = array(); + $oic['if'] = 'pppoe'; + $oic['descr'] = 'pppoe'; + $oic['ip'] = $pppoe['localip']; + $oic['sa'] = $pppoe['remoteip']; + $oic['mode'] = $pppoe['mode']; + $oic['virtual'] = true; + if($pppoe['pppoe_subnet'] <> "") + $oic['sn'] = $pppoe['pppoe_subnet']; + else + $oic['sn'] = "32"; + $FilterIflist['pppoe'][] = $oic; + } + } } /* add ipsec interfaces */ if(isset($config['ipsec']['enable']) || isset($config['ipsec']['client']['enable'])) { @@ -1332,11 +1343,12 @@ function filter_nat_rules_generate() { $tonathosts .= implode(" ", $pptp_subnets) . " "; } /* PPPoE subnet */ - if(isset($FilterIflist['pppoe']) && $FilterIflist['pppoe']['mode'] == "server") { - $pppoe_subnet = $FilterIflist['pppoe']['sn']; - if(is_private_ip($FilterIflist['pppoe']['sa']) && !empty($pppoe_subnet)) { - $numberofnathosts++; - $tonathosts .= "{$FilterIflist['pppoe']['sa']}/{$pppoe_subnet} "; + if (is_array($FilterIflist['pppoe'])) { + foreach ($FilterIflist['pppoe'] as $pppoe) { + if(is_private_ip($pppoe['ip'])) { + $numberofnathosts++; + $tonathosts .= "{$pppoe['ip']}/{$pppoe['sn']} "; + } } } /* L2TP subnet */ @@ -1640,9 +1652,12 @@ function filter_generate_address(& $rule, $target = "source", $isnat = false) { $src = "{$pptpsa}/{$pptpsn}"; break; case 'pppoe': - $pppoesa = gen_subnet($FilterIflist['pppoe']['ip'], $FilterIflist['pppoe']['sn']); - $pppoesn = $FilterIflist['pppoe']['sn']; - $src = "{$pppoesa}/{$pppoesn}"; + /* XXX: This needs to be fixed somehow! */ + if (is_array($FilterIflist['pppoe'])) { + $pppoesa = gen_subnet($FilterIflist['pppoe'][0]['ip'], $FilterIflist['pppoe'][0]['sn']); + $pppoesn = $FilterIflist['pppoe'][0]['sn']; + $src = "{$pppoesa}/{$pppoesn}"; + } break; } if(isset($rule[$target]['not'])) @@ -1701,7 +1716,6 @@ function filter_generate_user_rule($rule) { } update_filter_reload_status("Creating filter rules {$rule['descr']} ..."); $pptpdcfg = $config['pptpd']; - $pppoecfg = $config['pppoe']; $int = ""; $aline = array(); @@ -2011,7 +2025,6 @@ function filter_rules_generate() { } $pptpdcfg = $config['pptpd']; - $pppoecfg = $config['pppoe']; $ipfrules = ""; //$ipfrules .= discover_pkg_rules("filter"); From 7e107d2ef73bc233113fd0cddecd5e0ac21b2e9b Mon Sep 17 00:00:00 2001 From: Ermal Date: Tue, 24 May 2011 20:01:11 +0000 Subject: [PATCH 05/15] Use remoteips here. --- etc/inc/filter.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/inc/filter.inc b/etc/inc/filter.inc index 9727d59cbd..c6443790e3 100644 --- a/etc/inc/filter.inc +++ b/etc/inc/filter.inc @@ -1347,7 +1347,7 @@ function filter_nat_rules_generate() { foreach ($FilterIflist['pppoe'] as $pppoe) { if(is_private_ip($pppoe['ip'])) { $numberofnathosts++; - $tonathosts .= "{$pppoe['ip']}/{$pppoe['sn']} "; + $tonathosts .= "{$pppoe['sa']}/{$pppoe['sn']} "; } } } From d1a44a5f1c64d905f3389eff0ce747a9b810045a Mon Sep 17 00:00:00 2001 From: Ermal Date: Tue, 24 May 2011 20:05:00 +0000 Subject: [PATCH 06/15] Correct the interface alias generation. --- etc/inc/filter.inc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/etc/inc/filter.inc b/etc/inc/filter.inc index c6443790e3..8463d3c7a2 100644 --- a/etc/inc/filter.inc +++ b/etc/inc/filter.inc @@ -513,8 +513,15 @@ function filter_generate_aliases() { $aliases = "loopback = \"{ lo0 }\"\n"; foreach ($FilterIflist as $if => $ifcfg) { - $aliases .= "{$ifcfg['descr']} = \"{ {$ifcfg['if']}"; - $aliases .= " }\"\n"; + if (is_array($ifcfg)) { + if ($ifcfg[0]['if'] == 'pppoe') { + $aliases .= "{$ifcfg[0]['descr']} = \"{ {$ifcfg[0]['if']}"; + $aliases .= " }\"\n"; + } + } else { + $aliases .= "{$ifcfg['descr']} = \"{ {$ifcfg['if']}"; + $aliases .= " }\"\n"; + } } $aliases .= "\n#SSH Lockout Table\n"; From 77bd744e8ffe184168489f465c68573cdb66b7c3 Mon Sep 17 00:00:00 2001 From: Ermal Date: Tue, 24 May 2011 20:11:59 +0000 Subject: [PATCH 07/15] Correct the interface alias generation. --- etc/inc/filter.inc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/etc/inc/filter.inc b/etc/inc/filter.inc index 8463d3c7a2..11ec827c06 100644 --- a/etc/inc/filter.inc +++ b/etc/inc/filter.inc @@ -513,9 +513,9 @@ function filter_generate_aliases() { $aliases = "loopback = \"{ lo0 }\"\n"; foreach ($FilterIflist as $if => $ifcfg) { - if (is_array($ifcfg)) { - if ($ifcfg[0]['if'] == 'pppoe') { - $aliases .= "{$ifcfg[0]['descr']} = \"{ {$ifcfg[0]['if']}"; + if (is_array($ifcfg['pppoe'])) { + if ($ifcfg['pppoe'][0]['if'] == 'pppoe') { + $aliases .= "{$ifcfg['pppoe'][0]['descr']} = \"{ {$ifcfg['pppoe'][0]['if']}"; $aliases .= " }\"\n"; } } else { From b7475a811cf4620112673dc78c5d0afacb4a38c1 Mon Sep 17 00:00:00 2001 From: Ermal Date: Tue, 24 May 2011 20:13:10 +0000 Subject: [PATCH 08/15] Correct the interface alias generation. Wrong copy-pasto before. --- etc/inc/filter.inc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/etc/inc/filter.inc b/etc/inc/filter.inc index 11ec827c06..67bc1f337d 100644 --- a/etc/inc/filter.inc +++ b/etc/inc/filter.inc @@ -513,9 +513,9 @@ function filter_generate_aliases() { $aliases = "loopback = \"{ lo0 }\"\n"; foreach ($FilterIflist as $if => $ifcfg) { - if (is_array($ifcfg['pppoe'])) { - if ($ifcfg['pppoe'][0]['if'] == 'pppoe') { - $aliases .= "{$ifcfg['pppoe'][0]['descr']} = \"{ {$ifcfg['pppoe'][0]['if']}"; + if (is_array($ifcfg[0])) { + if ($ifcfg[0]['if'] == 'pppoe') { + $aliases .= "{$ifcfg[0]['descr']} = \"{ {$ifcfg[0]['if']}"; $aliases .= " }\"\n"; } } else { From f6f1c8474875e91cf297abf28e2fad65ea6152f7 Mon Sep 17 00:00:00 2001 From: Ermal Date: Wed, 25 May 2011 11:02:53 +0000 Subject: [PATCH 09/15] Update some code to be more readble and more compliant to php5 --- etc/inc/voucher.inc | 10 ++++------ usr/local/www/services_captiveportal_vouchers.php | 3 +-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/etc/inc/voucher.inc b/etc/inc/voucher.inc index ec5971688c..8d41e05bb8 100644 --- a/etc/inc/voucher.inc +++ b/etc/inc/voucher.inc @@ -164,8 +164,7 @@ function voucher_auth($voucher_received, $test = 0) { $tickets_per_roll = array(); $minutes_per_roll = array(); if (is_array($config['voucher']['roll'])) { - $a_roll = &$config['voucher']['roll']; - foreach ($a_roll as $rollent) { + foreach ($config['voucher']['roll'] as $rollent) { $tickets_per_roll[$rollent['number']] = $rollent['count']; $minutes_per_roll[$rollent['number']] = $rollent['minutes']; } @@ -192,7 +191,7 @@ function voucher_auth($voucher_received, $test = 0) { list($status, $roll, $nr) = explode(" ", $result); if ($status == "OK") { if (!$first_voucher) { - // store first voucher. Thats the one we give the timecredit + // store first voucher. Thats the one we give the timecredit $first_voucher = $voucher; $first_voucher_roll = $roll; } @@ -352,11 +351,10 @@ function voucher_configure($sync = false) { if (($g['booting'] || $sync == true) && is_array($config['voucher']['roll'])) { - // create active and used DB per roll on ramdisk from config - $a_roll = &$config['voucher']['roll']; $voucherlck = lock('voucher', LOCK_EX); - foreach ($a_roll as $rollent) { + // create active and used DB per roll on ramdisk from config + foreach ($config['voucher']['roll'] as $rollent) { $roll = $rollent['number']; voucher_write_used_db($roll, $rollent['used']); diff --git a/usr/local/www/services_captiveportal_vouchers.php b/usr/local/www/services_captiveportal_vouchers.php index 203906a067..19171f4d05 100644 --- a/usr/local/www/services_captiveportal_vouchers.php +++ b/usr/local/www/services_captiveportal_vouchers.php @@ -116,9 +116,8 @@ if ($_GET['act'] == "del") { exit; } } - /* print all vouchers of the selected roll */ -if ($_GET['act'] == "csv") { +else if ($_GET['act'] == "csv") { $privkey = base64_decode($config['voucher']['privatekey']); if (strstr($privkey,"BEGIN RSA PRIVATE KEY")) { $fd = fopen("{$g['varetc_path']}/voucher.private","w"); From f0e80b72a3c359f52596e9b6948178ad48d6bb1b Mon Sep 17 00:00:00 2001 From: jim-p Date: Wed, 25 May 2011 09:35:23 -0400 Subject: [PATCH 10/15] Correct dhcpd statement for unknown-clients. Fixes #1555 --- etc/inc/services.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/inc/services.inc b/etc/inc/services.inc index 7108bc381c..e7028c64e7 100644 --- a/etc/inc/services.inc +++ b/etc/inc/services.inc @@ -275,7 +275,7 @@ EOPP; $dhcpdconf .= " deny dynamic bootp clients;\n"; if (isset($dhcpifconf['denyunknown'])) - $dhcpdconf .= " deny unknown clients;\n"; + $dhcpdconf .= " deny unknown-clients;\n"; if ($dhcpifconf['gateway']) $routers = $dhcpifconf['gateway']; From c749ef62ec8ecb3d7f38f7de49e5029631614ef5 Mon Sep 17 00:00:00 2001 From: Ermal Date: Wed, 25 May 2011 15:38:54 +0000 Subject: [PATCH 11/15] Check that the returned ip is an ip_address and not blindly trust the returned information. --- etc/inc/dyndns.class | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/etc/inc/dyndns.class b/etc/inc/dyndns.class index 150dedc7d4..8f9a6959ec 100644 --- a/etc/inc/dyndns.class +++ b/etc/inc/dyndns.class @@ -795,13 +795,15 @@ if($successful_update == true) { /* Write WAN IP to cache file */ $wan_ip = $this->_checkIP(); - $currentTime = time(); - log_error("phpDynDNS: updating cache file {$this->_cacheFile}: {$wan_ip}"); - conf_mount_rw(); - $file = fopen($this->_cacheFile, 'w'); - fwrite($file, $wan_ip.':'.$currentTime); - fclose($file); - conf_mount_ro(); + if (is_ipaddr($wan_ip)) { + $currentTime = time(); + log_error("phpDynDNS: updating cache file {$this->_cacheFile}: {$wan_ip}"); + conf_mount_rw(); + $file = fopen($this->_cacheFile, 'w'); + fwrite($file, $wan_ip.':'.$currentTime); + fclose($file); + conf_mount_ro(); + } } $this->status = $status; log_error($status); @@ -957,7 +959,12 @@ $ip_result_decoded = urldecode($ip_result_page); preg_match('/Current IP Address: (.*)<\/body>/', $ip_result_decoded, $matches); $ip_address = trim($matches[1]); - log_error("DynDns debug information: {$ip_address} extracted from {$hosttocheck}"); + if (is_ipaddr($ip_address)) + log_error("DynDns debug information: {$ip_address} extracted from {$hosttocheck}"); + else { + log_error("DynDns debug information: IP address could not be extracted from {$hosttocheck}"); + return 0; + } } else log_error("DynDns debug information: {$ip_address} extracted from local system."); From 7788c76a4e9e04b356f40f2129ff5309617dad99 Mon Sep 17 00:00:00 2001 From: jim-p Date: Wed, 25 May 2011 12:29:09 -0400 Subject: [PATCH 12/15] Don't overwrite the $target variable. Fixes #1415 --- etc/inc/filter.inc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/etc/inc/filter.inc b/etc/inc/filter.inc index 67bc1f337d..3ce44a3175 100644 --- a/etc/inc/filter.inc +++ b/etc/inc/filter.inc @@ -1039,7 +1039,6 @@ function filter_generate_reflection($rule, $nordr, $rdr_ifs, $srcaddr, $dstaddr_ $target = $FilterIflist[$rule['target']]['ip']; else return ""; - $starting_localhost_port_tmp = $starting_localhost_port; $toomanyports = false; /* only install reflection rules for < 19991 items */ @@ -1088,7 +1087,7 @@ function filter_generate_reflection($rule, $nordr, $rdr_ifs, $srcaddr, $dstaddr_ $toadd_array = array_merge($toadd_array, range($loc_pt[0], $loc_pt[0] + $delta)); if(!empty($toadd_array)) { - $target = explode(" ", trim($target)); + $rtarget = explode(" ", trim($target)); foreach($toadd_array as $tda) { if (empty($tda)) continue; @@ -1100,7 +1099,7 @@ function filter_generate_reflection($rule, $nordr, $rdr_ifs, $srcaddr, $dstaddr_ $socktype = "stream"; $dash_u = ""; } - foreach ($target as $targip) { + foreach ($rtarget as $targip) { if (empty($targip)) continue; $reflection_txt[] = "{$inetdport}\t{$socktype}\t{$reflect_proto}\tnowait/0\tnobody\t/usr/bin/nc\tnc {$dash_u}-w {$reflectiontimeout} {$targip} {$tda}\n"; From dd575ea43699b452e1e925518bc9e59f5db78d6f Mon Sep 17 00:00:00 2001 From: Ermal Date: Wed, 25 May 2011 16:41:26 +0000 Subject: [PATCH 13/15] Improve some code and check return value from _checkIP. --- etc/inc/dyndns.class | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/etc/inc/dyndns.class b/etc/inc/dyndns.class index 8f9a6959ec..4697da75c9 100644 --- a/etc/inc/dyndns.class +++ b/etc/inc/dyndns.class @@ -795,15 +795,14 @@ if($successful_update == true) { /* Write WAN IP to cache file */ $wan_ip = $this->_checkIP(); - if (is_ipaddr($wan_ip)) { + conf_mount_rw(); + if ($wan_ip > 0) { $currentTime = time(); log_error("phpDynDNS: updating cache file {$this->_cacheFile}: {$wan_ip}"); - conf_mount_rw(); - $file = fopen($this->_cacheFile, 'w'); - fwrite($file, $wan_ip.':'.$currentTime); - fclose($file); - conf_mount_ro(); - } + @file_put_contents($this->_cacheFile, "{$wan_ip}:{$currentTime}"); + } else + @unlink($this->_cacheFile); + conf_mount_ro(); } $this->status = $status; log_error($status); @@ -861,6 +860,10 @@ $currentTime = time(); $wan_ip = $this->_checkIP(); + if ($wan_ip == 0) { + log_error("DynDns: Current WAN IP could not be determined."); + return true; + } $this->_dnsIP = $wan_ip; log_error("DynDns: Current WAN IP: {$wan_ip}"); @@ -872,11 +875,9 @@ log_error("DynDns: Cached IP: {$cacheIP}"); } else { conf_mount_rw(); - $file = fopen($this->_cacheFile, 'w'); - fwrite($file, '0.0.0.0:'.$currentTime); - fclose($file); - conf_mount_ro(); $cacheIP = '0.0.0.0'; + @file_put_contents($this->_cacheFile, "0.0.0.0:{$currentTime}"); + conf_mount_ro(); $cacheTime = $currentTime; $initial = true; log_error("DynDns: No Cached IP found."); @@ -946,7 +947,7 @@ } if ($try >= 3) { log_error("Dyndns debug information: Could not resolve {$hosttocheck} to ip using interface ip {$ip_address}."); - return $ip_address; /* XXX: Might return private ip address! */ + return 0; } $ip_ch = curl_init("http://{$checkip}"); curl_setopt($ip_ch, CURLOPT_RETURNTRANSFER, 1); From 193ee786a468c7fdcc3fc9086d1747b3d879c4a5 Mon Sep 17 00:00:00 2001 From: Ermal Date: Wed, 25 May 2011 16:51:53 +0000 Subject: [PATCH 14/15] Actually add more error checking and do not schedule a scan if it is not possible to retreive the wan ip address. --- etc/inc/dyndns.class | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/etc/inc/dyndns.class b/etc/inc/dyndns.class index 4697da75c9..d8a350b92d 100644 --- a/etc/inc/dyndns.class +++ b/etc/inc/dyndns.class @@ -861,8 +861,8 @@ $wan_ip = $this->_checkIP(); if ($wan_ip == 0) { - log_error("DynDns: Current WAN IP could not be determined."); - return true; + log_error("DynDns: Current WAN IP could not be determined, skipping update process."); + return false; } $this->_dnsIP = $wan_ip; log_error("DynDns: Current WAN IP: {$wan_ip}"); @@ -935,6 +935,8 @@ log_error("DynDns: _checkIP() starting."); $ip_address = find_interface_ip($this->_if); + if (!is_ipaddr($ip_address)) + return 0; $this->_ifIP = $ip_address; if (is_private_ip($ip_address)) { $hosttocheck = "checkip.dyndns.org"; From dceff62e8144b56cb292e1a3fd69abe307072625 Mon Sep 17 00:00:00 2001 From: Ermal Date: Wed, 25 May 2011 17:08:22 +0000 Subject: [PATCH 15/15] Put some debug info during dyndns update under debug conditionals. --- etc/inc/dyndns.class | 17 +++++++++++------ etc/inc/services.inc | 2 -- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/etc/inc/dyndns.class b/etc/inc/dyndns.class index d8a350b92d..01209b922b 100644 --- a/etc/inc/dyndns.class +++ b/etc/inc/dyndns.class @@ -854,8 +854,10 @@ * | work with other systems. pfSense base is FreeBSD. */ function _detectChange() { - - log_error("DynDns: _detectChange() starting."); + global $debug; + + if ($debug) + log_error("DynDns: _detectChange() starting."); $currentTime = time(); @@ -865,14 +867,14 @@ return false; } $this->_dnsIP = $wan_ip; - log_error("DynDns: Current WAN IP: {$wan_ip}"); + $log_error = "DynDns: Current WAN IP: {$wan_ip} "; if (file_exists($this->_cacheFile)) { $contents = file_get_contents($this->_cacheFile); list($cacheIP,$cacheTime) = split(':', $contents); $this->_debug($cacheIP.'/'.$cacheTime); $initial = false; - log_error("DynDns: Cached IP: {$cacheIP}"); + $log_error .= "Cached IP: {$cacheIP} "; } else { conf_mount_rw(); $cacheIP = '0.0.0.0'; @@ -880,8 +882,9 @@ conf_mount_ro(); $cacheTime = $currentTime; $initial = true; - log_error("DynDns: No Cached IP found."); + $log_error .= "No Cached IP found."; } + log_error($log_error); /* use 2419200 for dyndns, dhs, easydns, noip, hn * zoneedit, dyns, ods @@ -931,8 +934,10 @@ conf_mount_ro(); } function _checkIP() { + global $debug; - log_error("DynDns: _checkIP() starting."); + if ($debug) + log_error("DynDns: _checkIP() starting."); $ip_address = find_interface_ip($this->_if); if (!is_ipaddr($ip_address)) diff --git a/etc/inc/services.inc b/etc/inc/services.inc index e7028c64e7..d5c9ada226 100644 --- a/etc/inc/services.inc +++ b/etc/inc/services.inc @@ -606,8 +606,6 @@ function services_dyndns_configure_client($conf) { /* load up the dyndns.class */ require_once("dyndns.class"); - log_error("DynDns: Running updatedns()"); - $dns = new updatedns($dnsService = $conf['type'], $dnsHost = $conf['host'], $dnsUser = $conf['username'],