mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
settings prep 2
This commit is contained in:
@@ -8,32 +8,56 @@
|
||||
// Puche 2021 pi.alert.application@gmail.com GNU GPLv3
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// ## TimeZone processing
|
||||
$config_file = "../../../config/pialert.conf";
|
||||
$config_file_lines = file($config_file);
|
||||
## TimeZone processing
|
||||
$basePath = "../../../config/";
|
||||
$config_file = "pialert.conf";
|
||||
|
||||
$fullConfPath = $basePath.$config_file;
|
||||
|
||||
chmod($fullConfPath, 0777);
|
||||
|
||||
|
||||
|
||||
$config_file_lines = file($fullConfPath);
|
||||
$config_file_lines_timezone = array_values(preg_grep('/^TIMEZONE\s.*/', $config_file_lines));
|
||||
$timezone_line = explode("'", $config_file_lines_timezone[0]);
|
||||
$Pia_TimeZone = $timezone_line[1];
|
||||
date_default_timezone_set($Pia_TimeZone);
|
||||
|
||||
|
||||
$FUNCTION = $_REQUEST['function'];
|
||||
$SETTINGS = $_REQUEST['settings'];
|
||||
|
||||
|
||||
if ($FUNCTION == 'savesettings') {
|
||||
saveSettings();
|
||||
} elseif ($PIA_SCAN_MODE == 'test') {
|
||||
// other function
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Formatting data functions
|
||||
//------------------------------------------------------------------------------
|
||||
// Creates a PHP array from a string representing a python array (input format ['...','...'])
|
||||
function createArray($input){
|
||||
$pattern = '/(^\s*\[)|(\]\s*$)/';
|
||||
|
||||
// regex patterns
|
||||
$patternBrackets = '/(^\s*\[)|(\]\s*$)/';
|
||||
$patternQuotes = '/(^\s*\')|(\'\s*$)/';
|
||||
$replacement = '';
|
||||
$noBrackets = preg_replace($pattern, $replacement, $input);
|
||||
|
||||
// remove brackets
|
||||
$noBrackets = preg_replace($patternBrackets, $replacement, $input);
|
||||
|
||||
return $options = explode(",", $noBrackets);
|
||||
$options = array();
|
||||
|
||||
// create array
|
||||
$optionsTmp = explode(",", $noBrackets);
|
||||
|
||||
// remove quotes
|
||||
foreach ($optionsTmp as $item)
|
||||
{
|
||||
array_push($options, preg_replace($patternQuotes, $replacement, $item) );
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
function formatDate ($date1) {
|
||||
@@ -75,7 +99,8 @@ function checkPermissions($files)
|
||||
// check access to database
|
||||
if(file_exists($file) != 1)
|
||||
{
|
||||
displayMessage("File ".$file." not found or inaccessible. Grant read & write permissions to the file to the correct user.");
|
||||
$message = "File ".$file." not found or inaccessible. Grant read & write permissions to the file to the correct user.";
|
||||
displayMessage($message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,25 +115,118 @@ function displayMessage($message)
|
||||
|
||||
function saveSettings()
|
||||
{
|
||||
$config_file = "../../../config/pialert.conf";
|
||||
// save in the file
|
||||
$new_location = $config_file.'_'.strtotime("now").'.backup';
|
||||
global $SETTINGS, $FUNCTION, $fullConfPath, $basePath, $config_file_lines_timezone, $config_file_lines;
|
||||
|
||||
if(file_exists( $config_file) == 1)
|
||||
{
|
||||
// create a backup copy
|
||||
if (!copy($config_file, $new_location))
|
||||
{
|
||||
echo "Failed to copy file ".$config_file." to ".$new_location." <br/> Check your permissions to allow read/write access to the /config folder.";
|
||||
$timeZone = "";
|
||||
|
||||
foreach ($config_file_lines as $line)
|
||||
{
|
||||
if( preg_match('/TIMEZONE(.*?)/', $line, $match) == 1 )
|
||||
{
|
||||
if (preg_match('/\'(.*?)\'/', $line, $match) == 1) {
|
||||
$timeZone = $match[1];
|
||||
}
|
||||
}
|
||||
{
|
||||
echo "Backup of pialert.conf created: <code>".$new_location."</code>";
|
||||
}
|
||||
} else {
|
||||
echo 'File "'.$config_file.'" not found or missing read permissions.';
|
||||
}
|
||||
|
||||
// save in the DB
|
||||
if($timeZone == "")
|
||||
{
|
||||
$timeZone = "Europe/Berlin";
|
||||
}
|
||||
|
||||
date_default_timezone_set($timeZone);
|
||||
|
||||
$date = new DateTime("now", new DateTimeZone($timeZone) );
|
||||
$timestamp = $date->format('Y-m-d_H-i-s');
|
||||
|
||||
// save in the file
|
||||
$new_name = "pialert.conf".'_'.$timestamp.'.backup';
|
||||
$new_location = $basePath.$new_name;
|
||||
|
||||
// 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.';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function getString ($codeName, $default, $pia_lang) {
|
||||
@@ -195,4 +313,6 @@ function setCache($key, $value) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
|
||||
@@ -408,15 +408,17 @@ $pia_lang['HelpFAQ_Cat_Network_600_text'] = 'Diese Seite soll dir die Möglichke
|
||||
//General
|
||||
$pia_lang['SCAN_SUBNETS_name'] = 'Subnets to scan';
|
||||
$pia_lang['SCAN_SUBNETS_description'] = '
|
||||
|
||||
The scan time itself depends on the number of IP addresses to check.
|
||||
The number of Ips to check depends on the <a target="_blank" href="https://www.calculator.net/ip-subnet-calculator.html">network mask</a> you set here.
|
||||
For example, a <code>/24</code> mask results in 256 IPs to check, where as a <code>/16</code>
|
||||
mask checks around 65,536. Every IP takes a couple seconds to scan. This means that with an incorrect configuration
|
||||
the scan will take hours to complete instead of seconds.
|
||||
<ol>
|
||||
<li>Specify the network mask. For example, the filter <code>192.168.1.0/24</code> covers IP ranges 192.168.1.0 to 192.168.1.255.</li>
|
||||
<li>Run <code>iwconfig</code> to find your interface name(s) (e.g.: <code>eth0</code>, <code>eth1</code>)</li>
|
||||
<li>Examples (<g-emoji class="g-emoji" alias="exclamation" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/2757.png">❗</g-emoji> Note the <code>[\'...\', \'...\']</code> format for two and more subnets):
|
||||
<li>Run <code>iwconfig</code> in your ocntainer to find your interface name(s) (e.g.: <code>eth0</code>, <code>eth1</code>)</li>
|
||||
</ol>
|
||||
<ul dir="auto">
|
||||
<li>One subnet: <code>\'192.168.1.0/24 --interface=eth0\'</code></li>
|
||||
<li>Two subnets: <code>[\'192.168.1.0/24 --interface=eth0\', \'192.168.1.0/24 --interface=eth1\']</code></li>
|
||||
</ul>';
|
||||
';
|
||||
$pia_lang['PRINT_LOG_name'] = 'Print additional logging';
|
||||
$pia_lang['PRINT_LOG_description'] = 'This setting will enable more verbose logging. Useful for debugging events writing into the database.';
|
||||
$pia_lang['TIMEZONE_name'] = 'Time zone';
|
||||
@@ -424,7 +426,7 @@ $pia_lang['TIMEZONE_description'] = 'Time zone to display stats correctly. Find
|
||||
$pia_lang['PIALERT_WEB_PROTECTION_name'] = 'Enable login';
|
||||
$pia_lang['PIALERT_WEB_PROTECTION_description'] = 'When enabled a login dialog is displayed. Read below carefully if you get locked out of your instance.';
|
||||
$pia_lang['PIALERT_WEB_PASSWORD_name'] = 'Login password';
|
||||
$pia_lang['PIALERT_WEB_PASSWORD_description'] = 'The default password is <code>123456</code>. To change password run <code>/home/pi/pialert/back/pialert-cli</code>';
|
||||
$pia_lang['PIALERT_WEB_PASSWORD_description'] = 'The default password is <code>123456</code>. To change password run <code>/home/pi/pialert/back/pialert-cli</code> in the container';
|
||||
$pia_lang['INCLUDED_SECTIONS_name'] = 'Notify on';
|
||||
$pia_lang['INCLUDED_SECTIONS_description'] = 'Specifies which events trigger notifications. Remove the event type(s) you don\'t want to get notified on. This setting overrides device-specific settings in the UI. (CTRL + Click to select / deselect).';
|
||||
$pia_lang['SCAN_CYCLE_MINUTES_name'] = 'Scan cycle delay';
|
||||
|
||||
@@ -373,9 +373,9 @@ $pia_lang['HelpFAQ_Cat_General_102_text'] = 'Check in the Pi.Alert directory if
|
||||
</span><br>
|
||||
If the database is still read-only, try reinstalling or restoring a database backup from the maintenance page.';
|
||||
$pia_lang['HelpFAQ_Cat_General_102docker_head'] = '(🐳 Docker only) Database issues (AJAX errors, read-only, not found)';
|
||||
$pia_lang['HelpFAQ_Cat_General_102docker_text'] = 'Double-check you\'ve followed the <a href="https://github.com/jokob-sk/Pi.Alert/tree/main/dockerfiles">dockerfile readme (most up-to-date info)</a>. <br/> <br/> <ul data-sourcepos="49:4-52:146" dir="auto">
|
||||
<li data-sourcepos="49:4-49:106">Download the <a href="https://github.com/jokob-sk/Pi.Alert/blob/main/db/pialert.db">original DB from GitHub</a>.</li>
|
||||
<li data-sourcepos="50:4-50:195">Map the <code>pialert.db</code> file (<g-emoji class="g-emoji" alias="warning" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/26a0.png">⚠</g-emoji> not folder) from above to <code>/home/pi/pialert/db/pialert.db</code> (see <a href="https://github.com/jokob-sk/Pi.Alert/tree/main/dockerfiles#-examples">Examples</a> for details).</li>
|
||||
$pia_lang['HelpFAQ_Cat_General_102docker_text'] = 'Double-check you\'ve followed the <a target="_blank" href="https://github.com/jokob-sk/Pi.Alert/tree/main/dockerfiles">dockerfile readme (most up-to-date info)</a>. <br/> <br/> <ul data-sourcepos="49:4-52:146" dir="auto">
|
||||
<li data-sourcepos="49:4-49:106">Download the <a target="_blank" href="https://github.com/jokob-sk/Pi.Alert/blob/main/db/pialert.db">original DB from GitHub</a>.</li>
|
||||
<li data-sourcepos="50:4-50:195">Map the <code>pialert.db</code> file (<g-emoji class="g-emoji" alias="warning" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/26a0.png">⚠</g-emoji> not folder) from above to <code>/home/pi/pialert/db/pialert.db</code> (see <a target="_blank" href="https://github.com/jokob-sk/Pi.Alert/tree/main/dockerfiles#-examples">Examples</a> for details).</li>
|
||||
<li data-sourcepos="51:4-51:161">If facing issues (AJAX errors, can\'t write to DB, etc,) make sure permissions are set correctly, alternatively check the logs under <code>/home/pi/pialert/front/log</code>.</li>
|
||||
<li data-sourcepos="52:4-52:146">To solve permission issues you can also try to create a DB backup and then run a DB Restore via the <strong>Maintenance > Backup/Restore</strong> section.</li>
|
||||
<li data-sourcepos="53:4-53:228">If the database is in read-only mode you can solve this by setting the owner and group by executing the following command on the host system: <code>docker exec pialert chown -R www-data:www-data /home/pi/pialert/db/pialert.db</code>.</li>
|
||||
@@ -420,15 +420,17 @@ $pia_lang['HelpFAQ_Cat_Network_600_text'] = 'This page should offer you the poss
|
||||
//General
|
||||
$pia_lang['SCAN_SUBNETS_name'] = 'Subnets to scan';
|
||||
$pia_lang['SCAN_SUBNETS_description'] = '
|
||||
|
||||
The scan time itself depends on the number of IP addresses to check.
|
||||
The number of Ips to check depends on the <a target="_blank" href="https://www.calculator.net/ip-subnet-calculator.html">network mask</a> you set here.
|
||||
For example, a <code>/24</code> mask results in 256 IPs to check, where as a <code>/16</code>
|
||||
mask checks around 65,536. Every IP takes a couple seconds to scan. This means that with an incorrect configuration
|
||||
the scan will take hours to complete instead of seconds.
|
||||
<ol>
|
||||
<li>Specify the network mask. For example, the filter <code>192.168.1.0/24</code> covers IP ranges 192.168.1.0 to 192.168.1.255.</li>
|
||||
<li>Run <code>iwconfig</code> to find your interface name(s) (e.g.: <code>eth0</code>, <code>eth1</code>)</li>
|
||||
<li>Examples (<g-emoji class="g-emoji" alias="exclamation" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/2757.png">❗</g-emoji> Note the <code>[\'...\', \'...\']</code> format for two and more subnets):
|
||||
<li>Run <code>iwconfig</code> in your container to find your interface name(s) (e.g.: <code>eth0</code>, <code>eth1</code>)</li>
|
||||
</ol>
|
||||
<ul dir="auto">
|
||||
<li>One subnet: <code>\'192.168.1.0/24 --interface=eth0\'</code></li>
|
||||
<li>Two subnets: <code>[\'192.168.1.0/24 --interface=eth0\', \'192.168.1.0/24 --interface=eth1\']</code></li>
|
||||
</ul>';
|
||||
';
|
||||
$pia_lang['PRINT_LOG_name'] = 'Print additional logging';
|
||||
$pia_lang['PRINT_LOG_description'] = 'This setting will enable more verbose logging. Useful for debugging events writing into the database.';
|
||||
$pia_lang['TIMEZONE_name'] = 'Time zone';
|
||||
@@ -436,7 +438,7 @@ $pia_lang['TIMEZONE_description'] = 'Time zone to display stats correctly. Find
|
||||
$pia_lang['PIALERT_WEB_PROTECTION_name'] = 'Enable login';
|
||||
$pia_lang['PIALERT_WEB_PROTECTION_description'] = 'When enabled a login dialog is displayed. Read below carefully if you get locked out of your instance.';
|
||||
$pia_lang['PIALERT_WEB_PASSWORD_name'] = 'Login password';
|
||||
$pia_lang['PIALERT_WEB_PASSWORD_description'] = 'The default password is <code>123456</code>. To change password run <code>/home/pi/pialert/back/pialert-cli</code>';
|
||||
$pia_lang['PIALERT_WEB_PASSWORD_description'] = 'The default password is <code>123456</code>. To change password run <code>/home/pi/pialert/back/pialert-cli</code> in the container';
|
||||
$pia_lang['INCLUDED_SECTIONS_name'] = 'Notify on';
|
||||
$pia_lang['INCLUDED_SECTIONS_description'] = 'Specifies which events trigger notifications. Remove the event type(s) you don\'t want to get notified on. This setting overrides device-specific settings in the UI. (CTRL + Click to select / deselect).';
|
||||
$pia_lang['SCAN_CYCLE_MINUTES_name'] = 'Scan cycle delay';
|
||||
|
||||
@@ -414,15 +414,17 @@ $pia_lang['HelpFAQ_Cat_Network_600_text'] = 'Esta sección debería ofrecerle la
|
||||
//General
|
||||
$pia_lang['SCAN_SUBNETS_name'] = 'Subnets to scan';
|
||||
$pia_lang['SCAN_SUBNETS_description'] = '
|
||||
|
||||
The scan time itself depends on the number of IP addresses to check.
|
||||
The number of Ips to check depends on the <a target="_blank" href="https://www.calculator.net/ip-subnet-calculator.html">network mask</a> you set here.
|
||||
For example, a <code>/24</code> mask results in 256 IPs to check, where as a <code>/16</code>
|
||||
mask checks around 65,536. Every IP takes a couple seconds to scan. This means that with an incorrect configuration
|
||||
the scan will take hours to complete instead of seconds.
|
||||
<ol>
|
||||
<li>Specify the network mask. For example, the filter <code>192.168.1.0/24</code> covers IP ranges 192.168.1.0 to 192.168.1.255.</li>
|
||||
<li>Run <code>iwconfig</code> to find your interface name(s) (e.g.: <code>eth0</code>, <code>eth1</code>)</li>
|
||||
<li>Examples (<g-emoji class="g-emoji" alias="exclamation" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/2757.png">❗</g-emoji> Note the <code>[\'...\', \'...\']</code> format for two and more subnets):
|
||||
<li>Run <code>iwconfig</code> in your container to find your interface name(s) (e.g.: <code>eth0</code>, <code>eth1</code>)</li>
|
||||
</ol>
|
||||
<ul dir="auto">
|
||||
<li>One subnet: <code>\'192.168.1.0/24 --interface=eth0\'</code></li>
|
||||
<li>Two subnets: <code>[\'192.168.1.0/24 --interface=eth0\', \'192.168.1.0/24 --interface=eth1\']</code></li>
|
||||
</ul>';
|
||||
';
|
||||
$pia_lang['PRINT_LOG_name'] = 'Print additional logging';
|
||||
$pia_lang['PRINT_LOG_description'] = 'This setting will enable more verbose logging. Useful for debugging events writing into the database.';
|
||||
$pia_lang['TIMEZONE_name'] = 'Time zone';
|
||||
@@ -430,7 +432,7 @@ $pia_lang['TIMEZONE_description'] = 'Time zone to display stats correctly. Find
|
||||
$pia_lang['PIALERT_WEB_PROTECTION_name'] = 'Enable login';
|
||||
$pia_lang['PIALERT_WEB_PROTECTION_description'] = 'When enabled a login dialog is displayed. Read below carefully if you get locked out of your instance.';
|
||||
$pia_lang['PIALERT_WEB_PASSWORD_name'] = 'Login password';
|
||||
$pia_lang['PIALERT_WEB_PASSWORD_description'] = 'The default password is <code>123456</code>. To change password run <code>/home/pi/pialert/back/pialert-cli</code>';
|
||||
$pia_lang['PIALERT_WEB_PASSWORD_description'] = 'The default password is <code>123456</code>. To change password run <code>/home/pi/pialert/back/pialert-cli</code> in the container';
|
||||
$pia_lang['INCLUDED_SECTIONS_name'] = 'Notify on';
|
||||
$pia_lang['INCLUDED_SECTIONS_description'] = 'Specifies which events trigger notifications. Remove the event type(s) you don\'t want to get notified on. This setting overrides device-specific settings in the UI. (CTRL + Click to select / deselect).';
|
||||
$pia_lang['SCAN_CYCLE_MINUTES_name'] = 'Scan cycle delay';
|
||||
@@ -531,5 +533,4 @@ $pia_lang['PIHOLE_ACTIVE_description'] = 'If enabled you need to map <code>:/etc
|
||||
$pia_lang['DHCP_ACTIVE_name'] = 'Enable PiHole DHCP';
|
||||
$pia_lang['DHCP_ACTIVE_description'] = 'If enabled you need to map <code>:/etc/pihole/dhcp.leases</code> in your <code>docker-compose.yml</code> file.';
|
||||
|
||||
|
||||
?>
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
|
||||
<div class="modal-header" style="background-color: #d0d0d0;">
|
||||
<div class="modal-header" >
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
<h4 id="modal-default-title" class="modal-title"> Modal Default Title </h4>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user