mirror of
https://github.com/billz/raspap-webgui.git
synced 2025-03-01 10:31:47 +00:00
Update provider status regex, validate country select
This commit is contained in:
parent
20e3633541
commit
63f2c38f4c
@ -46,7 +46,7 @@
|
|||||||
"log": "status"
|
"log": "status"
|
||||||
},
|
},
|
||||||
"regex": {
|
"regex": {
|
||||||
"status": "\/status: (\\w+)\/",
|
"status": "\/status: disconnected\/",
|
||||||
"pattern": "(\\w+)\\s+",
|
"pattern": "(\\w+)\\s+",
|
||||||
"replace": "$1,$1\\n"
|
"replace": "$1,$1\\n"
|
||||||
}
|
}
|
||||||
|
@ -52,9 +52,10 @@ function DisplayProviderConfig()
|
|||||||
$country = trim($_POST['country']);
|
$country = trim($_POST['country']);
|
||||||
if (strlen($country) == 0) {
|
if (strlen($country) == 0) {
|
||||||
$status->addMessage('Select a country from the server location list', 'danger');
|
$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'])) {
|
} elseif (isset($_POST['StartProviderVPN'])) {
|
||||||
$status->addMessage('Attempting to connect VPN provider', 'info');
|
$status->addMessage('Attempting to connect VPN provider', 'info');
|
||||||
$cmd = getCliOverride($id, 'cmd_overrides', 'connect');
|
$cmd = getCliOverride($id, 'cmd_overrides', 'connect');
|
||||||
@ -70,10 +71,12 @@ function DisplayProviderConfig()
|
|||||||
exec("sudo $binPath $cmd", $return);
|
exec("sudo $binPath $cmd", $return);
|
||||||
$return = stripArtifacts($return);
|
$return = stripArtifacts($return);
|
||||||
foreach ($return as $line) {
|
foreach ($return as $line) {
|
||||||
|
if (strlen(trim($line)) > 0) {
|
||||||
$status->addMessage($line, 'info');
|
$status->addMessage($line, 'info');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
echo renderTemplate(
|
echo renderTemplate(
|
||||||
"provider", compact(
|
"provider", compact(
|
||||||
@ -103,7 +106,7 @@ function DisplayProviderConfig()
|
|||||||
*/
|
*/
|
||||||
function saveProviderConfig($status, $binPath, $country, $id = null)
|
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');
|
$cmd = getCliOverride($id, 'cmd_overrides', 'connect');
|
||||||
if ($id == 2) { // mullvad requires location set
|
if ($id == 2) { // mullvad requires location set
|
||||||
exec("sudo $binPath set location $country", $return);
|
exec("sudo $binPath set location $country", $return);
|
||||||
@ -171,6 +174,7 @@ function getProviderStatus($id, $binPath)
|
|||||||
$pattern = getCliOverride($id, 'regex', 'status');
|
$pattern = getCliOverride($id, 'regex', 'status');
|
||||||
exec("sudo $binPath $cmd", $cmd_raw);
|
exec("sudo $binPath $cmd", $cmd_raw);
|
||||||
$cmd_raw = strtolower(stripArtifacts($cmd_raw[0]));
|
$cmd_raw = strtolower(stripArtifacts($cmd_raw[0]));
|
||||||
|
|
||||||
if (!empty($cmd_raw[0])) {
|
if (!empty($cmd_raw[0])) {
|
||||||
if (preg_match($pattern, $cmd_raw, $match)) {
|
if (preg_match($pattern, $cmd_raw, $match)) {
|
||||||
$status = "down";
|
$status = "down";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user