diff options
author | Renato Botelho <renato@netgate.com> | 2015-11-10 16:19:43 -0200 |
---|---|---|
committer | Renato Botelho <renato@netgate.com> | 2015-11-10 16:19:54 -0200 |
commit | 796b7651bc3658a90c3918e2c28db8766501be4e (patch) | |
tree | 59d18adc58ff803232326494031430626131308a /src/etc/inc | |
parent | 3963c87953671c9e608c48ce9a263de33e788ddc (diff) | |
download | pfsense-796b7651bc3658a90c3918e2c28db8766501be4e.zip pfsense-796b7651bc3658a90c3918e2c28db8766501be4e.tar.gz |
Change ipsec_dump_mobile() to parse regular output of ipsec leases, we are removing patch that made it to output xml
Diffstat (limited to 'src/etc/inc')
-rw-r--r-- | src/etc/inc/ipsec.inc | 56 |
1 files changed, 38 insertions, 18 deletions
diff --git a/src/etc/inc/ipsec.inc b/src/etc/inc/ipsec.inc index abd099a..37a6b09 100644 --- a/src/etc/inc/ipsec.inc +++ b/src/etc/inc/ipsec.inc @@ -565,32 +565,52 @@ function ipsec_dump_sad() { * Return dump of mobile user list */ function ipsec_dump_mobile() { - global $g, $custom_listtags; + global $g; - $_gb = exec("/usr/local/sbin/ipsec stroke leases > {$g['tmp_path']}/strongswan_leases.xml"); + $_gb = exec("/usr/local/sbin/ipsec leases 2>/dev/null", $output, $rc); - if (!file_exists("{$g['tmp_path']}/strongswan_leases.xml")) { + if ($rc != 0) { log_error(gettext("Unable to find IPsec daemon leases file. Could not display mobile user stats!")); return array(); } - if (filesize("{$g['tmp_path']}/strongswan_leases.xml") == 0) { - return array(); - } - - if (!function_exists('parse_xml_config')) { - require_once('xmlparse.inc'); - } - - $custom_listtags = array('lease', 'pool'); - $response = parse_xml_config("{$g['tmp_path']}/strongswan_leases.xml", "leases"); - - if ($response == -1) { - return array(); + $response = array(); + $id = -1; + + /* Leases in pool '10.7.200.0/24', usage: 1/254, 1 online */ + $lease_regex='/^Leases *in *pool *\'(?P<name>.+)\', *usage: *(?P<usage>\d+)\/(?P<size>\d+), *(?P<online>\d+) *online/'; + /* 10.7.200.1 online 'jimp' */ + $pool_regex='/\s*(?P<host>[\d\.]+)\s+(?P<status>online|offline)\s+\'(?P<id>.*)\'/'; + /* no matching leases found */ + $nopool_regex='/no *matching *leases *found/'; + + $lease=false; + foreach ($output as $line) { + if (preg_match($lease_regex, $line, $matches)) { + $id++; + $response['pool'][$id] = array( + 'name' => $matches['name'], + 'usage' => $matches['usage'], + 'size' => $matches['size'], + 'online' => $matches['online'], + ); + $lease=true; + } else if ($lease) { + if (preg_match($nopool_regex, $line)) { + $response['pool'][$id]['lease'][] = array(); + $lease=false; + } else if (preg_match($pool_regex, $line, $matches)) { + $response['pool'][$id]['lease'][] = array( + 'host' => $matches['host'], + 'status' => $matches['status'], + 'id' => $matches['id'] + ); + } + } } - @unlink("{$g['tmp_path']}/strongswan_leases.xml"); - unset($custom_listtags, $_gb); + unset($_gb, $lease, $output, $rc, $id, $lease_regex, $pool_regex, + $nopool_regex); return $response; } |