From 05044a43a5736001b9cce8fd88af61347c89b822 Mon Sep 17 00:00:00 2001 From: jim-p Date: Sun, 7 Feb 2010 15:36:01 -0500 Subject: Add capability to kill OpenVPN clients from Status > OpenVPN. Commit to HEAD for same will be done shortly. --- config/openvpn-status/status_openvpn.php | 207 +++++++++++++++++++++---------- 1 file changed, 143 insertions(+), 64 deletions(-) (limited to 'config') diff --git a/config/openvpn-status/status_openvpn.php b/config/openvpn-status/status_openvpn.php index a021e951..bd4178c0 100644 --- a/config/openvpn-status/status_openvpn.php +++ b/config/openvpn-status/status_openvpn.php @@ -2,7 +2,12 @@ /* status_ovpenvpn.php + Copyright (C) 2010 Jim Pingle Copyright (C) 2008 Shrew Soft Inc. + + AJAX bits borrowed from diag_dump_states.php + Copyright (C) 2005 Scott Ullrich, Colin Smith + All rights reserved. Redistribution and use in source and binary forms, with or without @@ -32,6 +37,42 @@ require("guiconfig.inc"); require_once("vpn.inc"); include("head.inc"); +/* Handle AJAX */ +if($_GET['action']) { + if($_GET['action'] == "kill") { + $port = $_GET['port']; + $remipp = $_GET['remipp']; + if (!empty($port) and !empty($remipp)) { + $retval = kill_client($port, $remipp); + echo htmlentities("|{$port}|{$remipp}|{$retval}|"); + } else { + echo "invalid input"; + } + exit; + } +} + + +function kill_client($port, $remipp) { + $fp = @fsockopen("127.0.0.1", $port, $errval, $errstr, 1); + $killed = -1; + if ($fp) { + fputs($fp, "kill {$remipp}\n"); + while (!feof($fp)) { + $line = fgets($fp, 1024); + /* parse header list line */ + if (strpos($line, "INFO:")) + continue; + if (strpos($line, "UCCESS")) { + $killed = 0; + } + break; + } + fclose($fp); + } + return $killed; +} + $servers = array(); $ovpnservers = $config['installedpackages']['openvpnserver']['config']; @@ -42,6 +83,7 @@ if (is_array($ovpnservers)) { $port = $settings['local_port']; $server = array(); + $server['port'] = $settings['local_port']; if ($settings['description']) $server['name'] = "{$settings['description']} {$prot}:{$port}"; else @@ -59,7 +101,6 @@ if (is_array($ovpnservers)) { fputs($fp, "status 2\n"); /* recv all response lines */ - $buff = ""; while (!feof($fp)) { /* read the next line */ @@ -102,69 +143,107 @@ if (is_array($ovpnservers)) { $servers[] = $server; } -} +} ?> + +"> + + + + +

+
+ + + + + + + + + + + + + +
+ Client connections for +
+ + + + + + + + + + + + '> + + + + + + + + + + + + + + +
Common NameReal AddressVirtual AddressConnected SinceBytes SentBytes Received
+ + + + + + + + + + + + + /images/icons/icon_x.gif' height='17' width='17' border='0' + onclick="killClient('', '');" style='cursor:pointer;' + name='' + title='Kill client connection from ' alt='' /> +
+
+ + +
+
NOTE: You must enable the OpenVPN management interface for each server you want to monitor. You can do this by placing "management 127.0.0.1 <port>;" in the custom options box for the server, where <port> is the port number set for that server. -- cgit v1.2.3