mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
PUSHPROD settings v 0.1
This commit is contained in:
@@ -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." <br/> Check your permissions to allow read/write access to the /config folder.";
|
||||
}
|
||||
{
|
||||
echo "Backup of original pialert.conf created: <code>".$new_name."</code><br/>";
|
||||
|
||||
// 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 <code>pialert.conf</code> file.';
|
||||
}
|
||||
// create a backup copy
|
||||
elseif (!copy($fullConfPath, $new_location))
|
||||
{
|
||||
echo "Failed to copy file ".$fullConfPath." to ".$new_location." <br/> 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 "<br/>Settings saved to the <code>pialert.conf</code> file. Backup of pialert.conf created: <code>".$new_name."</code>.
|
||||
<br/><b>Restart the container for the chanegs to take effect.</b>";
|
||||
|
||||
}
|
||||
|
||||
@@ -312,7 +311,4 @@ function setCache($key, $value) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user