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

check for valid modules #2851

Merged
merged 1 commit into from
Oct 11, 2024
Merged
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
63 changes: 43 additions & 20 deletions web/settings/saveconfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@
// prepare key/value array
$settingsArray = [];

function checkModule($module){
$modulePath = $_SERVER['DOCUMENT_ROOT'] . "/openWB/modules/";
$path = realpath($modulePath . $module);
if ($path === false || strpos($path, $modulePath) !== 0) {
return false;
}
return basename($path);
}

try {
if ( !file_exists($myConfigFile) ) {
throw new Exception('Konfigurationsdatei nicht gefunden.');
Expand Down Expand Up @@ -98,19 +107,6 @@
}
}

// write config to file
$fp = fopen($myConfigFile, "w");
if ( !$fp ) {
throw new Exception('Konfigurationsdatei konnte nicht geschrieben werden.');
}
foreach($settingsArray as $key => $value) {
// only save to config if $key has some meaningful length
if( strlen($key) > 0 ){
fwrite($fp, $key."=".$value."\n");
}
}
fclose($fp);

// handling of different actions required by some modules

// check for manual ev soc module on lp1
Expand Down Expand Up @@ -139,25 +135,39 @@
}

// start etprovider update if in POST data
if( array_key_exists( 'etprovideraktiv', $_POST ) && ($_POST['etprovideraktiv'] == 1) ){ ?>
if( array_key_exists( 'etprovideraktiv', $_POST ) && ($_POST['etprovideraktiv'] == 1) ){
$module = checkModule($_POST['etprovider']);
if( $module === false ){
throw new Exception('Ungültiger ET-Provider: ' . $_POST['etprovider']);
}?>
<script>$('#feedbackdiv').append("<br>Update des Stromtarifanbieters gestartet.");</script>
<?php
exec( $_SERVER['DOCUMENT_ROOT'] . "/openWB/modules/" . escapeshellcmd($_POST['etprovider']) . "/main.sh >> /var/log/openWB.log 2>&1 &" );
exec( 'mosquitto_pub -t openWB/global/ETProvider/modulePath -r -m ' . escapeshellarg($_POST['etprovider']) );
exec( $_SERVER['DOCUMENT_ROOT'] . "/openWB/modules/" . escapeshellcmd($module) . "/main.sh >> /var/log/openWB.log 2>&1 &" );
exec( 'mosquitto_pub -t openWB/global/ETProvider/modulePath -r -m ' . $module );
}

// start ev-soc updates if in POST data
if( array_key_exists( 'socmodul', $_POST ) && ($_POST['socmodul'] != 'none') ){ ?>
if( array_key_exists( 'socmodul', $_POST ) && ($_POST['socmodul'] != 'none') ){
$module = checkModule($_POST['socmodul']);
if( $module === false ){
throw new Exception('Ungültiges SoC-Modul: ' . $_POST['socmodul']);
}
?>
<script>$('#feedbackdiv').append("<br>Update SoC-Modul an Ladepunkt 1 gestartet.");</script>
<?php
file_put_contents($_SERVER['DOCUMENT_ROOT'].'/openWB/ramdisk/soctimer', "20005");
exec( $_SERVER['DOCUMENT_ROOT'] . "/openWB/modules/" . escapeshellcmd($_POST['socmodul']) . "/main.sh > /dev/null &" );
exec( $_SERVER['DOCUMENT_ROOT'] . "/openWB/modules/" . escapeshellcmd($module) . "/main.sh > /dev/null &" );
}
if( array_key_exists( 'socmodul1', $_POST ) && ($_POST['socmodul1'] != 'none') ){ ?>
if( array_key_exists( 'socmodul1', $_POST ) && ($_POST['socmodul1'] != 'none') ){
$module = checkModule($_POST['socmodul1']);
if( $module === false ){
throw new Exception('Ungültiges SoC-Modul: ' . $_POST['socmodul1']);
}
?>
<script>$('#feedbackdiv').append("<br>Update SoC-Modul an Ladepunkt 2 gestartet.");</script>
<?php
file_put_contents($_SERVER['DOCUMENT_ROOT'].'/openWB/ramdisk/soctimer1', "20005");
exec( $_SERVER['DOCUMENT_ROOT'] . "/openWB/modules/" . escapeshellcmd($_POST['socmodul1']) . "/main.sh > /dev/null &" );
exec( $_SERVER['DOCUMENT_ROOT'] . "/openWB/modules/" . escapeshellcmd($module) . "/main.sh > /dev/null &" );
}

// check for rfid mode and start/stop handler
Expand All @@ -167,6 +177,19 @@
exec( $_SERVER['DOCUMENT_ROOT'] . "/openWB/runs/rfid/rfidSetup.sh >> /var/log/openWB.log 2>&1 &" );
}

// write config to file
$fp = fopen($myConfigFile, "w");
if ( !$fp ) {
throw new Exception('Konfigurationsdatei konnte nicht geschrieben werden.');
}
foreach($settingsArray as $key => $value) {
// only save to config if $key has some meaningful length
if( strlen($key) > 0 ){
fwrite($fp, $key."=".$value."\n");
}
}
fclose($fp);

} catch ( Exception $e ) {
$msg = $e->getMessage();
echo "<script>alert('$msg');</script>";
Expand Down
Loading