From 3cc070df9e718caceaa0fb8e2b2c535cd3063905 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Wed, 29 Apr 2015 08:10:23 +0200 Subject: [PATCH] inc: replace another legacy PHP module function --- src/etc/inc/interfaces.inc | 8 +++++--- src/etc/inc/interfaces.lib.inc | 24 ++++++++++++++++++++++++ src/etc/inc/util.inc | 16 +++++++++------- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/etc/inc/interfaces.inc b/src/etc/inc/interfaces.inc index 39538fecd..dace6a525 100644 --- a/src/etc/inc/interfaces.inc +++ b/src/etc/inc/interfaces.inc @@ -87,12 +87,14 @@ function interfaces_bring_up($interface) { /* * Return the interface array */ -function get_interface_arr($flush = false) { +function get_interface_arr($flush = false) +{ global $interface_arr_cache; /* If the cache doesn't exist, build it */ - if (!isset($interface_arr_cache) or $flush) - $interface_arr_cache = pfSense_interface_listget(); + if (!isset($interface_arr_cache) or $flush) { + $interface_arr_cache = legacy_interface_listget(); + } return $interface_arr_cache; } diff --git a/src/etc/inc/interfaces.lib.inc b/src/etc/inc/interfaces.lib.inc index 4a8f2fa73..f46204ec0 100644 --- a/src/etc/inc/interfaces.lib.inc +++ b/src/etc/inc/interfaces.lib.inc @@ -26,6 +26,30 @@ POSSIBILITY OF SUCH DAMAGE. */ +function legacy_interface_listget($flag = '') +{ + $cmd = '/sbin/ifconfig -l'; + $ifs = null; + + if ($flag === 'up') { + $cmd .= 'u'; + } else if ($flag === 'down') { + $cmd .= 'd'; + } + + exec($cmd . ' 2>&1', $out, $ret); + if ($ret) { + log_error('The command `' . $cmd . '\' failed to execute'); + return ($ifs); + } + + if (isset($out[0])) { + $ifs = explode(' ', $out[0]); + } + + return ($ifs); +} + function legacy_interface_create($ifs) { $cmd = '/sbin/ifconfig ' . escapeshellarg($ifs) . ' create'; diff --git a/src/etc/inc/util.inc b/src/etc/inc/util.inc index 8d91d25a8..dcaae383f 100644 --- a/src/etc/inc/util.inc +++ b/src/etc/inc/util.inc @@ -877,22 +877,24 @@ function get_interface_list($mode = "active", $keyby = "physical", $vfaces = "") ); } switch($mode) { - case "active": - $upints = pfSense_interface_listget(IFF_UP); + case 'active': + $upints = legacy_interface_listget('up'); break; - case "media": - $intlist = pfSense_interface_listget(); + case 'media': + $intlist = legacy_interface_listget(); $ifconfig = ""; exec("/sbin/ifconfig -a", $ifconfig); $regexp = '/(' . implode('|', $intlist) . '):\s/'; $ifstatus = preg_grep('/status:/', $ifconfig); - foreach($ifstatus as $status) { + foreach ($ifstatus as $status) { $int = array_shift($intlist); - if(stristr($status, "active")) $upints[] = $int; + if (stristr($status, 'active')) { + $upints[] = $int; + } } break; default: - $upints = pfSense_interface_listget(); + $upints = legacy_interface_listget(); break; } /* build interface list with netstat */