diff options
author | Phil Davis <phil.davis@inf.org> | 2015-12-17 10:14:17 +0545 |
---|---|---|
committer | Phil Davis <phil.davis@inf.org> | 2015-12-17 10:14:17 +0545 |
commit | 61fce4a6f6f61f25356708df4175d28892a04b4c (patch) | |
tree | 119d4905f375a331ee76a5f87e3c27867df4d8f5 | |
parent | 9851ce32c1c40281fd76ac1ff140acaccbcc1d30 (diff) | |
download | pfsense-61fce4a6f6f61f25356708df4175d28892a04b4c.zip pfsense-61fce4a6f6f61f25356708df4175d28892a04b4c.tar.gz |
Consolidate OpenVPN kill_client routine
After a gitsync just now I started getting "cannot redeclare
kill_client" error messages. Whatever it was that caused this to start
happening, the kill_client() function in these 2 places is identical.
Might as well put it in openvpn.inc
-rw-r--r-- | src/etc/inc/openvpn.inc | 36 | ||||
-rw-r--r-- | src/usr/local/www/status_openvpn.php | 39 | ||||
-rw-r--r-- | src/usr/local/www/widgets/widgets/openvpn.widget.php | 39 |
3 files changed, 38 insertions, 76 deletions
diff --git a/src/etc/inc/openvpn.inc b/src/etc/inc/openvpn.inc index da666e3..9dc83c5 100644 --- a/src/etc/inc/openvpn.inc +++ b/src/etc/inc/openvpn.inc @@ -1611,6 +1611,42 @@ function openvpn_get_client_status($client, $socket) { return $client; } +function openvpn_kill_client($port, $remipp) { + global $g; + + //$tcpsrv = "tcp://127.0.0.1:{$port}"; + $tcpsrv = "unix://{$g['varetc_path']}/openvpn/{$port}.sock"; + $errval = null; + $errstr = null; + + /* open a tcp connection to the management port of each server */ + $fp = @stream_socket_client($tcpsrv, $errval, $errstr, 1); + $killed = -1; + if ($fp) { + stream_set_timeout($fp, 1); + fputs($fp, "kill {$remipp}\n"); + while (!feof($fp)) { + $line = fgets($fp, 1024); + + $info = stream_get_meta_data($fp); + if ($info['timed_out']) { + break; + } + + /* parse header list line */ + if (strpos($line, "INFO:") !== false) { + continue; + } + if (strpos($line, "SUCCESS") !== false) { + $killed = 0; + } + break; + } + fclose($fp); + } + return $killed; +} + function openvpn_refresh_crls() { global $g, $config; diff --git a/src/usr/local/www/status_openvpn.php b/src/usr/local/www/status_openvpn.php index 63c4f89..bc7e266 100644 --- a/src/usr/local/www/status_openvpn.php +++ b/src/usr/local/www/status_openvpn.php @@ -75,7 +75,7 @@ if ($_GET['action']) { $port = $_GET['port']; $remipp = $_GET['remipp']; if (!empty($port) and !empty($remipp)) { - $retval = kill_client($port, $remipp); + $retval = openvpn_kill_client($port, $remipp); echo htmlentities("|{$port}|{$remipp}|{$retval}|"); } else { echo gettext("invalid input"); @@ -84,43 +84,6 @@ if ($_GET['action']) { } } - -function kill_client($port, $remipp) { - global $g; - - //$tcpsrv = "tcp://127.0.0.1:{$port}"; - $tcpsrv = "unix://{$g['varetc_path']}/openvpn/{$port}.sock"; - $errval = null; - $errstr = null; - - /* open a tcp connection to the management port of each server */ - $fp = @stream_socket_client($tcpsrv, $errval, $errstr, 1); - $killed = -1; - if ($fp) { - stream_set_timeout($fp, 1); - fputs($fp, "kill {$remipp}\n"); - while (!feof($fp)) { - $line = fgets($fp, 1024); - - $info = stream_get_meta_data($fp); - if ($info['timed_out']) { - break; - } - - /* parse header list line */ - if (strpos($line, "INFO:") !== false) { - continue; - } - if (strpos($line, "SUCCESS") !== false) { - $killed = 0; - } - break; - } - fclose($fp); - } - return $killed; -} - $servers = openvpn_get_active_servers(); $sk_servers = openvpn_get_active_servers("p2p"); $clients = openvpn_get_active_clients(); diff --git a/src/usr/local/www/widgets/widgets/openvpn.widget.php b/src/usr/local/www/widgets/widgets/openvpn.widget.php index 8a02f3d..2d34401 100644 --- a/src/usr/local/www/widgets/widgets/openvpn.widget.php +++ b/src/usr/local/www/widgets/widgets/openvpn.widget.php @@ -65,7 +65,7 @@ if ($_GET['action']) { $port = $_GET['port']; $remipp = $_GET['remipp']; if (!empty($port) and !empty($remipp)) { - $retval = kill_client($port, $remipp); + $retval = openvpn_kill_client($port, $remipp); echo htmlentities("|{$port}|{$remipp}|{$retval}|"); } else { echo gettext("invalid input"); @@ -74,43 +74,6 @@ if ($_GET['action']) { } } - -function kill_client($port, $remipp) { - global $g; - - //$tcpsrv = "tcp://127.0.0.1:{$port}"; - $tcpsrv = "unix://{$g['varetc_path']}/openvpn/{$port}.sock"; - $errval = null; - $errstr = null; - - /* open a tcp connection to the management port of each server */ - $fp = @stream_socket_client($tcpsrv, $errval, $errstr, 1); - $killed = -1; - if ($fp) { - stream_set_timeout($fp, 1); - fputs($fp, "kill {$remipp}\n"); - while (!feof($fp)) { - $line = fgets($fp, 1024); - - $info = stream_get_meta_data($fp); - if ($info['timed_out']) { - break; - } - - /* parse header list line */ - if (strpos($line, "INFO:") !== false) { - continue; - } - if (strpos($line, "SUCCESS") !== false) { - $killed = 0; - } - break; - } - fclose($fp); - } - return $killed; -} - $servers = openvpn_get_active_servers(); $sk_servers = openvpn_get_active_servers("p2p"); $clients = openvpn_get_active_clients(); |