mirror of
https://github.com/billz/raspap-webgui.git
synced 2025-03-01 10:31:47 +00:00
Sanitize CLI output, fetch provider details after page functions
This commit is contained in:
parent
83d9248249
commit
50d0e0be82
@ -16,37 +16,10 @@ function DisplayProviderConfig()
|
|||||||
$providerName = getProviderValue($id, "name");
|
$providerName = getProviderValue($id, "name");
|
||||||
$providerVersion = getProviderVersion($id, $binPath);
|
$providerVersion = getProviderVersion($id, $binPath);
|
||||||
$installPage = getProviderValue($id, "install_page");
|
$installPage = getProviderValue($id, "install_page");
|
||||||
$publicIP = get_public_ip();
|
|
||||||
$serviceStatus = 'down';
|
$serviceStatus = 'down';
|
||||||
$statusDisplay = 'down';
|
$statusDisplay = 'down';
|
||||||
$ctlState = '';
|
$ctlState = '';
|
||||||
|
|
||||||
if (!file_exists($binPath)) {
|
|
||||||
$status->addMessage(sprintf(_('Expected %s binary not found at: %s'), $providerName, $binPath), 'warning');
|
|
||||||
$status->addMessage(sprintf(_('Visit the <a href="%s" target="_blank">installation instructions</a> for %s\'s Linux CLI.'), $installPage, $providerName), 'warning');
|
|
||||||
$ctlState = 'disabled';
|
|
||||||
$providerVersion = 'not found';
|
|
||||||
} elseif (empty($providerVersion)) {
|
|
||||||
$status->addMessage(sprintf(_('Unable to execute %s binary found at: %s'), $providerName, $binPath), 'warning');
|
|
||||||
$status->addMessage(_('Check that binary is executable and permissions exist in raspap.sudoers'), 'warning');
|
|
||||||
$ctlState = 'disabled';
|
|
||||||
$providerVersion = 'not found';
|
|
||||||
} else {
|
|
||||||
// fetch provider status
|
|
||||||
$serviceStatus = getProviderStatus($id, $binPath);
|
|
||||||
$statusDisplay = $serviceStatus == "down" ? "inactive" : "active";
|
|
||||||
|
|
||||||
// fetch provider log
|
|
||||||
$providerLog = getProviderLog($id, $binPath, $country);
|
|
||||||
|
|
||||||
// fetch account info
|
|
||||||
$accountInfo = getAccountInfo($id, $binPath, $providerName);
|
|
||||||
$accountLink = getProviderValue($id, "account_page");
|
|
||||||
|
|
||||||
// fetch available countries
|
|
||||||
$countries = getCountries($id, $binPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!RASPI_MONITOR_ENABLED) {
|
if (!RASPI_MONITOR_ENABLED) {
|
||||||
if (isset($_POST['SaveProviderSettings'])) {
|
if (isset($_POST['SaveProviderSettings'])) {
|
||||||
if (isset($_POST['country'])) {
|
if (isset($_POST['country'])) {
|
||||||
@ -60,7 +33,11 @@ function DisplayProviderConfig()
|
|||||||
} 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');
|
||||||
exec("sudo $binPath $cmd", $return);
|
$country = escapeshellarg(trim($_POST['country']));
|
||||||
|
if ($id = 4) { // AdGuard requires country argument on connect
|
||||||
|
$arg = escapeshellarg(trim($_POST['country']));
|
||||||
|
}
|
||||||
|
exec("sudo $binPath $cmd $arg", $return);
|
||||||
$return = stripArtifacts($return);
|
$return = stripArtifacts($return);
|
||||||
foreach ($return as $line) {
|
foreach ($return as $line) {
|
||||||
if (strlen(trim($line)) > 0) {
|
if (strlen(trim($line)) > 0) {
|
||||||
@ -83,6 +60,33 @@ function DisplayProviderConfig()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!file_exists($binPath)) {
|
||||||
|
$status->addMessage(sprintf(_('Expected %s binary not found at: %s'), $providerName, $binPath), 'warning');
|
||||||
|
$status->addMessage(sprintf(_('Visit the <a href="%s" target="_blank">installation instructions</a> for %s\'s Linux CLI.'), $installPage, $providerName), 'warning');
|
||||||
|
$ctlState = 'disabled';
|
||||||
|
$providerVersion = 'not found';
|
||||||
|
} elseif (empty($providerVersion)) {
|
||||||
|
$status->addMessage(sprintf(_('Unable to execute %s binary found at: %s'), $providerName, $binPath), 'warning');
|
||||||
|
$status->addMessage(_('Check that binary is executable and permissions exist in raspap.sudoers'), 'warning');
|
||||||
|
$ctlState = 'disabled';
|
||||||
|
$providerVersion = 'not found';
|
||||||
|
} else {
|
||||||
|
// fetch provider status
|
||||||
|
$serviceStatus = getProviderStatus($id, $binPath);
|
||||||
|
$statusDisplay = $serviceStatus == "down" ? "inactive" : "active";
|
||||||
|
|
||||||
|
// fetch account info
|
||||||
|
$accountInfo = getAccountInfo($id, $binPath, $providerName);
|
||||||
|
$accountLink = getProviderValue($id, "account_page");
|
||||||
|
|
||||||
|
// fetch available countries
|
||||||
|
$countries = getCountries($id, $binPath);
|
||||||
|
|
||||||
|
// fetch provider log
|
||||||
|
$providerLog = getProviderLog($id, $binPath, $country);
|
||||||
|
}
|
||||||
|
$publicIP = get_public_ip();
|
||||||
|
|
||||||
echo renderTemplate(
|
echo renderTemplate(
|
||||||
"provider", compact(
|
"provider", compact(
|
||||||
"status",
|
"status",
|
||||||
@ -193,8 +197,7 @@ function getProviderStatus($id, $binPath)
|
|||||||
$cmd = getCliOverride($id, 'cmd_overrides', 'status');
|
$cmd = getCliOverride($id, 'cmd_overrides', 'status');
|
||||||
$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(($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";
|
||||||
@ -318,7 +321,9 @@ function getProviderLog($id, $binPath, &$country)
|
|||||||
$providerLog = '';
|
$providerLog = '';
|
||||||
$cmd = getCliOverride($id, 'cmd_overrides', 'log');
|
$cmd = getCliOverride($id, 'cmd_overrides', 'log');
|
||||||
exec("sudo $binPath $cmd", $cmd_raw);
|
exec("sudo $binPath $cmd", $cmd_raw);
|
||||||
$output = stripArtifacts($cmd_raw);
|
$output = array_map(function ($line) {
|
||||||
|
return preg_replace('/\x1b\[[0-9;]*[a-zA-Z]/', '', $line);
|
||||||
|
}, $cmd_raw);
|
||||||
foreach ($output as $item) {
|
foreach ($output as $item) {
|
||||||
if (preg_match('/Country: (\w+)/', $item, $match)) {
|
if (preg_match('/Country: (\w+)/', $item, $match)) {
|
||||||
$country = $match[1];
|
$country = $match[1];
|
||||||
@ -356,6 +361,9 @@ function getAccountInfo($id, $binPath, $providerName)
|
|||||||
$cmd = getCliOverride($id, 'cmd_overrides', 'account');
|
$cmd = getCliOverride($id, 'cmd_overrides', 'account');
|
||||||
exec("sudo $binPath $cmd", $acct);
|
exec("sudo $binPath $cmd", $acct);
|
||||||
|
|
||||||
|
$acct = array_map(function ($line) {
|
||||||
|
return preg_replace('/\x1b\[[0-9;]*[a-zA-Z]/', '', $line);
|
||||||
|
}, $acct);
|
||||||
foreach ($acct as &$item) {
|
foreach ($acct as &$item) {
|
||||||
$item = preg_replace('/^[^\w]+\s*/', '', $item);
|
$item = preg_replace('/^[^\w]+\s*/', '', $item);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user