diff --git a/front/php/server/util.php b/front/php/server/util.php index 719ee09b..81279686 100755 --- a/front/php/server/util.php +++ b/front/php/server/util.php @@ -145,87 +145,86 @@ function saveSettings() // chmod($fullConfPath, 0755); - if(file_exists( $fullConfPath) == 1) - { - // create a backup copy - if (!copy($fullConfPath, $new_location)) - { - echo "Failed to copy file ".$fullConfPath." to ".$new_location."
Check your permissions to allow read/write access to the /config folder."; - } - { - echo "Backup of original pialert.conf created: ".$new_name."
"; - - // generate a clean pialert.conf file - $groups = []; - - $txt = $txt."#-----------------AUTOGENERATED FILE-----------------#\n"; - $txt = $txt."# #\n"; - $txt = $txt."# Generated: ".$timestamp." #\n"; - $txt = $txt."# #\n"; - $txt = $txt."# Config file for the LAN intruder detection app: #\n"; - $txt = $txt."# https://github.com/jokob-sk/Pi.Alert #\n"; - $txt = $txt."# #\n"; - $txt = $txt."#-----------------AUTOGENERATED FILE-----------------#\n"; - - // collect all groups - foreach ($SETTINGS as $setting) { - if( in_array($setting[0] , $groups) == false) { - array_push($groups ,$setting[0]); - } - } - - // go thru the groups and prepare settings to write to file - foreach($groups as $group) - { - $txt = $txt."\n\n# ".$group; - $txt = $txt."\n#---------------------------\n" ; - foreach($SETTINGS as $setting) - { - if($group == $setting[0]) - { - if($setting[3] == 'text' or $setting[3] == 'password' or $setting[3] == 'readonly' or $setting[3] == 'selecttext') - { - $txt = $txt.$setting[1]."='".$setting[2]."'\n" ; - } elseif($setting[3] == 'integer' or $setting[3] == 'selectinteger') - { - $txt = $txt.$setting[1]."=".$setting[2]."\n" ; - } elseif($setting[3] == 'boolean') - { - $val = "False"; - if($setting[2] == 'true') - { - $val = "True"; - } - $txt = $txt.$setting[1]."=".$val."\n" ; - }elseif($setting[3] == 'multiselect' or $setting[3] == 'subnets') - { - $temp = '['; - foreach($setting[2] as $val) - { - $temp = $temp."'". $val."',"; - } - $temp = substr_replace($temp, "", -1).']'; // close brackets and remove last comma ',' - $txt = $txt.$setting[1]."=".$temp."\n" ; - } - } - } - } - - $txt = $txt."\n\n"; - $txt = $txt."#-------------------IMPORTANT INFO-------------------#\n"; - $txt = $txt."# This file is ingested by a python script, so if #\n"; - $txt = $txt."# modified it needs to use python syntax #\n"; - $txt = $txt."#-------------------IMPORTANT INFO-------------------#\n"; - - // open new file and write the new configuration - $newConfig = fopen($basePath."pialert.conf", "w") or die("Unable to open file!"); - fwrite($newConfig, $txt); - fclose($newConfig); - - } - } else { - echo 'File "'.$fullConfPath.'" not found or missing read permissions.'; + if(file_exists( $fullConfPath) != 1) + { + echo 'File "'.$fullConfPath.'" not found or missing read permissions. Creating a new pialert.conf file.'; } + // create a backup copy + elseif (!copy($fullConfPath, $new_location)) + { + echo "Failed to copy file ".$fullConfPath." to ".$new_location."
Check your permissions to allow read/write access to the /config folder."; + } + + + // generate a clean pialert.conf file + $groups = []; + + $txt = $txt."#-----------------AUTOGENERATED FILE-----------------#\n"; + $txt = $txt."# #\n"; + $txt = $txt."# Generated: ".$timestamp." #\n"; + $txt = $txt."# #\n"; + $txt = $txt."# Config file for the LAN intruder detection app: #\n"; + $txt = $txt."# https://github.com/jokob-sk/Pi.Alert #\n"; + $txt = $txt."# #\n"; + $txt = $txt."#-----------------AUTOGENERATED FILE-----------------#\n"; + + // collect all groups + foreach ($SETTINGS as $setting) { + if( in_array($setting[0] , $groups) == false) { + array_push($groups ,$setting[0]); + } + } + + // go thru the groups and prepare settings to write to file + foreach($groups as $group) + { + $txt = $txt."\n\n# ".$group; + $txt = $txt."\n#---------------------------\n" ; + foreach($SETTINGS as $setting) + { + if($group == $setting[0]) + { + if($setting[3] == 'text' or $setting[3] == 'password' or $setting[3] == 'readonly' or $setting[3] == 'selecttext') + { + $txt = $txt.$setting[1]."='".$setting[2]."'\n" ; + } elseif($setting[3] == 'integer' or $setting[3] == 'selectinteger') + { + $txt = $txt.$setting[1]."=".$setting[2]."\n" ; + } elseif($setting[3] == 'boolean') + { + $val = "False"; + if($setting[2] == 'true') + { + $val = "True"; + } + $txt = $txt.$setting[1]."=".$val."\n" ; + }elseif($setting[3] == 'multiselect' or $setting[3] == 'subnets') + { + $temp = '['; + foreach($setting[2] as $val) + { + $temp = $temp."'". $val."',"; + } + $temp = substr_replace($temp, "", -1).']'; // close brackets and remove last comma ',' + $txt = $txt.$setting[1]."=".$temp."\n" ; + } + } + } + } + + $txt = $txt."\n\n"; + $txt = $txt."#-------------------IMPORTANT INFO-------------------#\n"; + $txt = $txt."# This file is ingested by a python script, so if #\n"; + $txt = $txt."# modified it needs to use python syntax #\n"; + $txt = $txt."#-------------------IMPORTANT INFO-------------------#\n"; + + // open new file and write the new configuration + $newConfig = fopen($basePath."pialert.conf", "w") or die("Unable to open file!"); + fwrite($newConfig, $txt); + fclose($newConfig); + + echo "
Settings saved to the pialert.conf file. Backup of pialert.conf created: ".$new_name.". +
Restart the container for the chanegs to take effect."; } @@ -312,7 +311,4 @@ function setCache($key, $value) { } - - - ?> diff --git a/front/settings.php b/front/settings.php index ac4e549f..02961dd8 100644 --- a/front/settings.php +++ b/front/settings.php @@ -308,7 +308,7 @@ $db->close(); success: function(data, textStatus) { // $("#result").html(data); console.log(data); - showModalDefault ('Result', data + "
Restart the container for the chanegs to take effect."); + showModalDefault ('Result', data ); } }) }