mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
Coderabit suggestions
This commit is contained in:
@@ -10,12 +10,47 @@ require dirname(__FILE__).'/../server/init.php';
|
||||
// check if authenticated
|
||||
require_once $_SERVER['DOCUMENT_ROOT'] . '/php/templates/security.php';
|
||||
|
||||
//exec('speedtest-cli --secure --simple', $output);
|
||||
exec('PATH=/usr/bin/:/usr/local/bin:/opt/venv/bin speedtest-cli --secure --simple', $output);
|
||||
echo '<h4>'. lang('Speedtest_Results') .'</h4>';
|
||||
echo '<pre style="border: none;">';
|
||||
foreach($output as $line){
|
||||
echo $line . "\n";
|
||||
// Prefer explicit binary paths, fall back to a sanitised PATH
|
||||
$speedtestCandidates = [
|
||||
'/opt/venv/bin/speedtest-cli',
|
||||
'/usr/local/bin/speedtest-cli',
|
||||
'/usr/bin/speedtest-cli',
|
||||
];
|
||||
|
||||
$candidateDirs = array_unique(array_map('dirname', $speedtestCandidates));
|
||||
$safePath = implode(':', $candidateDirs);
|
||||
|
||||
$resolvedCommand = null;
|
||||
foreach ($speedtestCandidates as $candidate) {
|
||||
if (is_executable($candidate)) {
|
||||
$resolvedCommand = escapeshellcmd($candidate) . ' --secure --simple';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$output = [];
|
||||
$returnCode = 0;
|
||||
|
||||
if ($resolvedCommand === null) {
|
||||
$resolvedCommand = 'env PATH=' . escapeshellarg($safePath) . ' speedtest-cli --secure --simple';
|
||||
}
|
||||
|
||||
exec($resolvedCommand, $output, $returnCode);
|
||||
|
||||
echo '<h4>' . lang('Speedtest_Results') . '</h4>';
|
||||
|
||||
if ($returnCode !== 0 || empty($output)) {
|
||||
$errorMessage = $returnCode === 127
|
||||
? 'speedtest-cli command not found. Checked paths: ' . $safePath
|
||||
: (empty($output) ? 'speedtest-cli returned no output.' : implode("\n", $output));
|
||||
|
||||
echo '<div class="alert alert-danger">' . htmlspecialchars('Speedtest failed: ' . $errorMessage, ENT_QUOTES, 'UTF-8') . '</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
echo '<pre style="border: none;">';
|
||||
foreach ($output as $line) {
|
||||
echo htmlspecialchars($line, ENT_QUOTES, 'UTF-8') . "\n";
|
||||
}
|
||||
echo '</pre>';
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user