Skip to content

Commit 92a55a0

Browse files
committed
Validate inputs when killing OpenVPN clients. Fixes #15856
While here, fix the JS 'busy' icon switching for both the widget and status page.
1 parent 238ebe4 commit 92a55a0

3 files changed

Lines changed: 66 additions & 21 deletions

File tree

‎src/etc/inc/openvpn.inc‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2241,14 +2241,22 @@ function openvpn_get_client_status($client, $socket) {
22412241

22422242
function openvpn_kill_client($port, $remipp, $client_id) {
22432243
global $g;
2244+
$killed = -1;
22442245

2245-
//$tcpsrv = "tcp://127.0.0.1:{$port}";
2246-
$tcpsrv = "unix://{$g['openvpn_base']}/{$port}/sock";
2246+
$port = basename($port);
2247+
$sock_path = "{$g['openvpn_base']}/{$port}/sock";
2248+
/* If the socket doesn't exist, or if the remote IP address and port are
2249+
* not valid, then do not proceed. */
2250+
if (!file_exists($sock_path) ||
2251+
!is_ipaddrwithport($remipp)) {
2252+
return $killed;
2253+
}
2254+
$socket = "unix://{$sock_path}";
22472255
$errval = null;
22482256
$errstr = null;
22492257

22502258
/* open a tcp connection to the management port of each server */
2251-
$fp = @stream_socket_client($tcpsrv, $errval, $errstr, 1);
2259+
$fp = @stream_socket_client($socket, $errval, $errstr, 1);
22522260
$killed = -1;
22532261
if ($fp) {
22542262
stream_set_timeout($fp, 1);

‎src/usr/local/www/status_openvpn.php‎

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,33 @@
3737
require_once("shortcuts.inc");
3838
require_once("service-utils.inc");
3939

40+
$servers = openvpn_get_active_servers();
41+
$sk_servers = openvpn_get_active_servers("p2p");
42+
$clients = openvpn_get_active_clients();
43+
4044
/* Handle AJAX */
4145
if ($_POST['action']) {
4246
if ($_POST['action'] == "kill") {
43-
$port = $_POST['port'];
44-
$remipp = $_POST['remipp'];
45-
$client_id = $_POST['client_id'];
46-
if (!empty($port) and !empty($remipp)) {
47+
$port = $_POST['port'];
48+
$remipp = $_POST['remipp'];
49+
$client_id = $_POST['client_id'];
50+
$error = false;
51+
52+
/* Validate remote IP address and port. */
53+
if (!is_ipaddrwithport($remipp)) {
54+
$error = true;
55+
}
56+
/* Validate submitted server ID */
57+
$found_server = false;
58+
foreach ($servers as $server) {
59+
if ($port == $server['mgmt']) {
60+
$found_server = true;
61+
} else {
62+
continue;
63+
}
64+
}
65+
66+
if (!$error && $found_server) {
4767
$retval = openvpn_kill_client($port, $remipp, $client_id);
4868
echo htmlentities("|{$port}|{$remipp}|{$retval}|");
4969
} else {
@@ -64,24 +84,18 @@
6484
}
6585
}
6686

67-
$servers = openvpn_get_active_servers();
68-
$sk_servers = openvpn_get_active_servers("p2p");
69-
$clients = openvpn_get_active_clients();
70-
7187
include("head.inc"); ?>
7288

7389
<form action="status_openvpn.php" method="get" name="iform">
7490
<script type="text/javascript">
7591
//<![CDATA[
7692
function killClient(mport, remipp, client_id) {
77-
var busy = function(index,icon) {
78-
$(icon).bind("onclick","");
79-
$(icon).attr('src',$(icon).attr('src').replace("\.gif", "_d.gif"));
80-
$(icon).css("cursor","wait");
93+
if (client_id === '') {
94+
$('a[id="i:' + mport + ":" + remipp + '"]').first().children('i').removeClass().addClass('fa-solid fa-cog fa-spin text-danger');
95+
} else {
96+
$('a[id="i:' + mport + ":" + remipp + '"]').last().children('i').removeClass().addClass('fa-solid fa-cog fa-spin text-danger');
8197
}
8298

83-
$('img[name="i:' + mport + ":" + remipp + '"]').each(busy);
84-
8599
$.ajax(
86100
"<?=$_SERVER['SCRIPT_NAME'];?>",
87101
{

‎src/usr/local/www/widgets/widgets/openvpn.widget.php‎

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,28 @@ function printPanel($widgetkey) {
285285
/* Handle AJAX */
286286
if ($_POST['action']) {
287287
if ($_POST['action'] == "kill") {
288-
$port = $_POST['port'];
289-
$remipp = $_POST['remipp'];
290-
$client_id = $_POST['client_id'];
291-
if (!empty($port) and !empty($remipp)) {
288+
$servers = openvpn_get_active_servers();
289+
290+
$port = $_POST['port'];
291+
$remipp = $_POST['remipp'];
292+
$client_id = $_POST['client_id'];
293+
$error = false;
294+
295+
/* Validate remote IP address and port. */
296+
if (!is_ipaddrwithport($remipp)) {
297+
$error = true;
298+
}
299+
/* Validate submitted server ID */
300+
$found_server = false;
301+
foreach ($servers as $server) {
302+
if ($port == $server['mgmt']) {
303+
$found_server = true;
304+
} else {
305+
continue;
306+
}
307+
}
308+
309+
if (!$error && $found_server) {
292310
$retval = openvpn_kill_client($port, $remipp, $client_id);
293311
echo htmlentities("|{$port}|{$remipp}|{$retval}|");
294312
} else {
@@ -407,6 +425,11 @@ function printPanel($widgetkey) {
407425
<script type="text/javascript">
408426
//<![CDATA[
409427
function killClient(mport, remipp, client_id) {
428+
if (client_id === '') {
429+
$('i[name="i:' + mport + ":" + remipp + '"]').first().removeClass().addClass('fa-solid fa-cog fa-spin text-danger');
430+
} else {
431+
$('i[name="i:' + mport + ":" + remipp + '"]').last().removeClass().addClass('fa-solid fa-cog fa-spin text-danger');
432+
}
410433

411434
$.ajax(
412435
"widgets/widgets/openvpn.widget.php",

0 commit comments

Comments
 (0)