Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: PHP web app improvements #2343

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions htdocs/api/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,19 @@ function execScript($command) {

function execScriptWithoutCheck($command) {
global $debugLoggingConf;
if($debugLoggingConf['DEBUG_WebApp_API'] == "TRUE") {
file_put_contents("../../logs/debug.log", "\n # function execScriptWithoutCheck: " . $command , FILE_APPEND | LOCK_EX);

// Validate the command to prevent command injection
if (!preg_match('/^[a-zA-Z0-9_\-]+$/', $command)) {
throw new InvalidArgumentException('Invalid command.');
}
$absoluteCommand = realpath(dirname(__FILE__) .'/../../scripts') ."/{$command}";
exec("sudo ".$absoluteCommand);

if ($debugLoggingConf['DEBUG_WebApp_API'] === "TRUE") {
file_put_contents("../../logs/debug.log", "\n # function execScriptWithoutCheck: " . $command, FILE_APPEND | LOCK_EX);
}

$scriptDir = realpath(__DIR__ . '/../../scripts');
$absoluteCommand = $scriptDir . '/' . escapeshellarg($command);
exec("sudo " . $absoluteCommand);
}

function execSuccessfully($command) {
Expand Down
34 changes: 13 additions & 21 deletions htdocs/inc.setWifi.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,28 @@
unset($exec);
if(isset($_POST["submitWifi"]) && $_POST["submitWifi"] == "submit") {
// make multiline bash
$exec = "bash -e <<'END'\n";
$exec = "bash -e <<'END'\n";
$exec .= "source ".$conf['scripts_abs']."/helperscripts/inc.networkHelper.sh\n";
$exec .= "clear_wireless_networks\n";

$tempPOST = $_POST;
$_POST=array(); //clear
foreach ( $tempPOST as $post_key => $post_value ) {
unset($temp_ssid);
unset($temp_pass);
unset($temp_prio);
if ( substr(trim($post_key), 0, 9) == "WIFIssid_" ) {
foreach ($_POST as $post_key => $post_value) {
if (substr(trim($post_key), 0, 9) == "WIFIssid_") {
$ssid_index = substr(trim($post_key), 9);
$temp_ssid = trim($post_value);
$post_key = "WIFIpass_".substr(trim($post_key), 9);
$post_value = $tempPOST[$post_key];
$temp_pass = trim($post_value);
$post_key = "WIFIprio_".substr(trim($post_key), 9);
$post_value = $tempPOST[$post_key];
$temp_prio = trim($post_value);

if (isset($temp_ssid) && $temp_ssid != "" && isset($temp_pass) && strlen($temp_pass) >= 8) {
if(!isset($temp_prio) || !is_numeric($temp_prio)) {
$temp_prio = 0;
}
$exec .= "add_wireless_network wlan0 ".$temp_ssid." ".$temp_pass." ".$temp_prio."\n";
$temp_pass = isset($_POST["WIFIpass_".$ssid_index]) ? trim($_POST["WIFIpass_".$ssid_index]) : '';
$temp_prio = isset($_POST["WIFIprio_".$ssid_index]) ? trim($_POST["WIFIprio_".$ssid_index]) : '0';

// Validate SSID and password
if (!empty($temp_ssid) && strlen($temp_pass) >= 8) {
// Validate priority
$temp_prio = is_numeric($temp_prio) ? $temp_prio : '0';
$exec .= "add_wireless_network wlan0 '{$temp_ssid}' '{$temp_pass}' {$temp_prio}\n";
}
}
}

$exec .= "END\n";
exec("sudo bash -c '". $exec . "'");
exec("sudo bash -c '".escapeshellcmd($exec)."'");
}

/*
Expand Down