From 63f2c38f4c9fadda7c65e6812e8b1cd7abade591 Mon Sep 17 00:00:00 2001 From: billz Date: Wed, 25 Oct 2023 14:38:49 +0100 Subject: [PATCH] Update provider status regex, validate country select --- config/vpn-providers.json | 2 +- includes/provider.php | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/config/vpn-providers.json b/config/vpn-providers.json index 854a661a..3108295f 100644 --- a/config/vpn-providers.json +++ b/config/vpn-providers.json @@ -46,7 +46,7 @@ "log": "status" }, "regex": { - "status": "\/status: (\\w+)\/", + "status": "\/status: disconnected\/", "pattern": "(\\w+)\\s+", "replace": "$1,$1\\n" } diff --git a/includes/provider.php b/includes/provider.php index 18452cf3..2624c169 100755 --- a/includes/provider.php +++ b/includes/provider.php @@ -52,8 +52,9 @@ function DisplayProviderConfig() $country = trim($_POST['country']); if (strlen($country) == 0) { $status->addMessage('Select a country from the server location list', 'danger'); + } else { + $return = saveProviderConfig($status, $binPath, $country, $id); } - $return = saveProviderConfig($status, $binPath, $country, $id); } } elseif (isset($_POST['StartProviderVPN'])) { $status->addMessage('Attempting to connect VPN provider', 'info'); @@ -70,7 +71,9 @@ function DisplayProviderConfig() exec("sudo $binPath $cmd", $return); $return = stripArtifacts($return); foreach ($return as $line) { - $status->addMessage($line, 'info'); + if (strlen(trim($line)) > 0) { + $status->addMessage($line, 'info'); + } } } } @@ -103,7 +106,7 @@ function DisplayProviderConfig() */ function saveProviderConfig($status, $binPath, $country, $id = null) { - $status->addMessage(sprintf(_('Attempting to connect to %s',$country)), 'info'); + $status->addMessage(sprintf(_('Attempting to connect to %s'),$country), 'info'); $cmd = getCliOverride($id, 'cmd_overrides', 'connect'); if ($id == 2) { // mullvad requires location set exec("sudo $binPath set location $country", $return); @@ -171,6 +174,7 @@ function getProviderStatus($id, $binPath) $pattern = getCliOverride($id, 'regex', 'status'); exec("sudo $binPath $cmd", $cmd_raw); $cmd_raw = strtolower(stripArtifacts($cmd_raw[0])); + if (!empty($cmd_raw[0])) { if (preg_match($pattern, $cmd_raw, $match)) { $status = "down";