PUSHPROD Settings 0.2
This commit is contained in:
@@ -71,7 +71,6 @@ file_print('\n Permissions check (All should be True)')
|
|||||||
file_print('------------------------------------------------')
|
file_print('------------------------------------------------')
|
||||||
file_print( " " + confPath + " | " + " READ | " + str(os.access(fullConfPath, os.R_OK)))
|
file_print( " " + confPath + " | " + " READ | " + str(os.access(fullConfPath, os.R_OK)))
|
||||||
file_print( " " + confPath + " | " + " WRITE | " + str(os.access(fullConfPath, os.W_OK)))
|
file_print( " " + confPath + " | " + " WRITE | " + str(os.access(fullConfPath, os.W_OK)))
|
||||||
|
|
||||||
file_print( " " + dbPath + " | " + " READ | " + str(os.access(fullDbPath, os.R_OK)))
|
file_print( " " + dbPath + " | " + " READ | " + str(os.access(fullDbPath, os.R_OK)))
|
||||||
file_print( " " + dbPath + " | " + " WRITE | " + str(os.access(fullDbPath, os.W_OK)))
|
file_print( " " + dbPath + " | " + " WRITE | " + str(os.access(fullDbPath, os.W_OK)))
|
||||||
file_print('------------------------------------------------')
|
file_print('------------------------------------------------')
|
||||||
@@ -208,14 +207,14 @@ def main ():
|
|||||||
sql_connection = None
|
sql_connection = None
|
||||||
sql = None
|
sql = None
|
||||||
|
|
||||||
# Upgrade DB if needed
|
|
||||||
upgradeDB()
|
|
||||||
|
|
||||||
# create log files
|
# create log files
|
||||||
write_file(logPath + 'IP_changes.log', '')
|
write_file(logPath + 'IP_changes.log', '')
|
||||||
write_file(logPath + 'stdout.log', '')
|
write_file(logPath + 'stdout.log', '')
|
||||||
write_file(logPath + 'stderr.log', '')
|
write_file(logPath + 'stderr.log', '')
|
||||||
write_file(logPath + 'pialert.log', '')
|
write_file(logPath + 'pialert.log', '')
|
||||||
|
|
||||||
|
# Upgrade DB if needed
|
||||||
|
upgradeDB()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
# update NOW time
|
# update NOW time
|
||||||
@@ -2269,8 +2268,8 @@ def upgradeDB ():
|
|||||||
""").fetchone()[0] == 0
|
""").fetchone()[0] == 0
|
||||||
|
|
||||||
# Drop table if available, but incompatible
|
# Drop table if available, but incompatible
|
||||||
if onlineHistoryAvailable and isIncompatible:
|
if onlineHistoryAvailable and isIncompatible:
|
||||||
print_log ('Table is incompatible, Dropping the Online_History table)')
|
file_print ('[upgradeDB] Table is incompatible, Dropping the Online_History table)')
|
||||||
sql.execute("DROP TABLE Online_History;")
|
sql.execute("DROP TABLE Online_History;")
|
||||||
onlineHistoryAvailable = False
|
onlineHistoryAvailable = False
|
||||||
|
|
||||||
@@ -2288,7 +2287,8 @@ def upgradeDB ():
|
|||||||
""")
|
""")
|
||||||
|
|
||||||
# Settings table
|
# Settings table
|
||||||
if settingsMissing:
|
if settingsMissing:
|
||||||
|
file_print("[upgradeDB] Adding Settings table")
|
||||||
sql.execute("""
|
sql.execute("""
|
||||||
CREATE TABLE "Settings" (
|
CREATE TABLE "Settings" (
|
||||||
"Index" INTEGER,
|
"Index" INTEGER,
|
||||||
@@ -2311,6 +2311,7 @@ def upgradeDB ():
|
|||||||
""").fetchone()[0] == 0
|
""").fetchone()[0] == 0
|
||||||
|
|
||||||
if dev_Network_Node_MAC_ADDR_missing :
|
if dev_Network_Node_MAC_ADDR_missing :
|
||||||
|
file_print("[upgradeDB] Adding dev_Network_Node_MAC_ADDR to the Devices table")
|
||||||
sql.execute("""
|
sql.execute("""
|
||||||
ALTER TABLE "Devices" ADD "dev_Network_Node_MAC_ADDR" TEXT
|
ALTER TABLE "Devices" ADD "dev_Network_Node_MAC_ADDR" TEXT
|
||||||
""")
|
""")
|
||||||
@@ -2321,6 +2322,7 @@ def upgradeDB ():
|
|||||||
""").fetchone()[0] == 0
|
""").fetchone()[0] == 0
|
||||||
|
|
||||||
if dev_Network_Node_port_missing :
|
if dev_Network_Node_port_missing :
|
||||||
|
file_print("[upgradeDB] Adding dev_Network_Node_port to the Devices table")
|
||||||
sql.execute("""
|
sql.execute("""
|
||||||
ALTER TABLE "Devices" ADD "dev_Network_Node_port" INTEGER
|
ALTER TABLE "Devices" ADD "dev_Network_Node_port" INTEGER
|
||||||
""")
|
""")
|
||||||
|
|||||||
@@ -385,6 +385,15 @@ if ($_REQUEST['tab'] == '1') {
|
|||||||
</textarea>
|
</textarea>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="db_info_table_row">
|
||||||
|
<div class="db_tools_table_cell_a" style="">
|
||||||
|
pialert_front.log
|
||||||
|
</div>
|
||||||
|
<div class="db_tools_table_cell_b">
|
||||||
|
<textarea id="pialert_log" class="logs" cols="70" rows="10" ><?php echo file_get_contents( "./log/pialert_front.log" ); ?>
|
||||||
|
</textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="db_info_table_row">
|
<div class="db_info_table_row">
|
||||||
<div class="db_tools_table_cell_a" style="">
|
<div class="db_tools_table_cell_a" style="">
|
||||||
IP_changes.log
|
IP_changes.log
|
||||||
|
|||||||
@@ -8,21 +8,51 @@
|
|||||||
// Puche 2021 pi.alert.application@gmail.com GNU GPLv3
|
// Puche 2021 pi.alert.application@gmail.com GNU GPLv3
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
## TimeZone processing
|
// ###################################
|
||||||
$basePath = "../../../config/";
|
// ## TimeZone processing start
|
||||||
|
// ###################################
|
||||||
|
$configFolderPath = "/home/pi/pialert/config/";
|
||||||
$config_file = "pialert.conf";
|
$config_file = "pialert.conf";
|
||||||
|
$logFolderPath = "/home/pi/pialert/front/log/";
|
||||||
|
$log_file = "pialert_front.log";
|
||||||
|
|
||||||
$fullConfPath = $basePath.$config_file;
|
|
||||||
|
$fullConfPath = $configFolderPath.$config_file;
|
||||||
|
|
||||||
chmod($fullConfPath, 0777);
|
chmod($fullConfPath, 0777);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$config_file_lines = file($fullConfPath);
|
$config_file_lines = file($fullConfPath);
|
||||||
$config_file_lines_timezone = array_values(preg_grep('/^TIMEZONE\s.*/', $config_file_lines));
|
$config_file_lines_timezone = array_values(preg_grep('/^TIMEZONE\s.*/', $config_file_lines));
|
||||||
$timezone_line = explode("'", $config_file_lines_timezone[0]);
|
$timezone_line = explode("'", $config_file_lines_timezone[0]);
|
||||||
$Pia_TimeZone = $timezone_line[1];
|
$Pia_TimeZone = $timezone_line[1];
|
||||||
|
|
||||||
|
$timeZone = "";
|
||||||
|
|
||||||
|
foreach ($config_file_lines as $line)
|
||||||
|
{
|
||||||
|
if( preg_match('/TIMEZONE(.*?)/', $line, $match) == 1 )
|
||||||
|
{
|
||||||
|
if (preg_match('/\'(.*?)\'/', $line, $match) == 1) {
|
||||||
|
$timeZone = $match[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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');
|
||||||
|
|
||||||
|
|
||||||
|
// ###################################
|
||||||
|
// ## TimeZone processing end
|
||||||
|
// ###################################
|
||||||
|
|
||||||
|
|
||||||
$FUNCTION = $_REQUEST['function'];
|
$FUNCTION = $_REQUEST['function'];
|
||||||
$SETTINGS = $_REQUEST['settings'];
|
$SETTINGS = $_REQUEST['settings'];
|
||||||
@@ -99,60 +129,81 @@ function checkPermissions($files)
|
|||||||
// check access to database
|
// check access to database
|
||||||
if(file_exists($file) != 1)
|
if(file_exists($file) != 1)
|
||||||
{
|
{
|
||||||
$message = "File ".$file." not found or inaccessible. Grant read & write permissions to the file to the correct user.";
|
$message = "File '".$file."' not found or inaccessible. Correct file permissions, create one yourself or generate a new one in 'Settings' by clicking the 'Save' button.";
|
||||||
displayMessage($message);
|
displayMessage($message, TRUE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function displayMessage($message)
|
function displayMessage($message, $logAlert = FALSE, $logConsole = TRUE, $logFile = TRUE, $logEcho = FALSE)
|
||||||
{
|
{
|
||||||
echo '<script>alert("'.$message.'")</script>';
|
global $logFolderPath, $log_file, $timestamp;
|
||||||
|
|
||||||
|
// sanitize
|
||||||
|
$message = str_replace(array("\n", "\r", PHP_EOL), '', $message);
|
||||||
|
|
||||||
|
echo "<script>function escape(html, encode) {
|
||||||
|
return html.replace(!encode ? /&(?!#?\w+;)/g : /&/g, '&')
|
||||||
|
.replace(/\t/g, '')
|
||||||
|
}</script>";
|
||||||
|
|
||||||
|
// Javascript Alert pop-up
|
||||||
|
if($logAlert)
|
||||||
|
{
|
||||||
|
echo '<script>alert(escape("'.$message.'"));</script>';
|
||||||
|
}
|
||||||
|
|
||||||
|
// F12 Browser console
|
||||||
|
if($logConsole)
|
||||||
|
{
|
||||||
|
echo '<script>console.log(escape("'.$message.'"));</script>';
|
||||||
|
}
|
||||||
|
|
||||||
|
//File
|
||||||
|
if($logFile)
|
||||||
|
{
|
||||||
|
if(file_exists($logFolderPath.$log_file) != 1) // file doesn't exist, create one
|
||||||
|
{
|
||||||
|
$log = fopen($logFolderPath.$log_file, "w") or die("Unable to open file!");
|
||||||
|
}else // file exists, append
|
||||||
|
{
|
||||||
|
$log = fopen($logFolderPath.$log_file, "a") or die("Unable to open file!");
|
||||||
|
}
|
||||||
|
|
||||||
|
fwrite($log, "[".$timestamp. "] " . $message.PHP_EOL."" );
|
||||||
|
fclose($log);
|
||||||
|
}
|
||||||
|
|
||||||
|
//echo
|
||||||
|
if($logEcho)
|
||||||
|
{
|
||||||
|
echo $message;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function saveSettings()
|
function saveSettings()
|
||||||
{
|
{
|
||||||
global $SETTINGS, $FUNCTION, $fullConfPath, $basePath, $config_file_lines_timezone, $config_file_lines;
|
global $SETTINGS, $FUNCTION, $config_file, $fullConfPath, $configFolderPath, $timestamp;
|
||||||
|
|
||||||
$timeZone = "";
|
|
||||||
|
|
||||||
foreach ($config_file_lines as $line)
|
|
||||||
{
|
|
||||||
if( preg_match('/TIMEZONE(.*?)/', $line, $match) == 1 )
|
|
||||||
{
|
|
||||||
if (preg_match('/\'(.*?)\'/', $line, $match) == 1) {
|
|
||||||
$timeZone = $match[1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
// save in the file
|
||||||
$new_name = "pialert.conf".'_'.$timestamp.'.backup';
|
$new_name = $config_file.'_'.$timestamp.'.backup';
|
||||||
$new_location = $basePath.$new_name;
|
$new_location = $configFolderPath.$new_name;
|
||||||
|
|
||||||
// chmod($fullConfPath, 0755);
|
// chmod($fullConfPath, 0755);
|
||||||
|
|
||||||
if(file_exists( $fullConfPath) != 1)
|
if(file_exists( $fullConfPath) != 1)
|
||||||
{
|
{
|
||||||
echo 'File "'.$fullConfPath.'" not found or missing read permissions. Creating a new <code>pialert.conf</code> file.';
|
displayMessage('File "'.$fullConfPath.'" not found or missing read permissions. Creating a new <code>'.$config_file.'</code> file.', FALSE, TRUE, TRUE, TRUE);
|
||||||
}
|
}
|
||||||
// create a backup copy
|
// create a backup copy
|
||||||
elseif (!copy($fullConfPath, $new_location))
|
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.";
|
displayMessage("Failed to copy file ".$fullConfPath." to ".$new_location." <br/> Check your permissions to allow read/write access to the /config folder.", FALSE, TRUE, TRUE, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -219,12 +270,14 @@ function saveSettings()
|
|||||||
$txt = $txt."#-------------------IMPORTANT INFO-------------------#\n";
|
$txt = $txt."#-------------------IMPORTANT INFO-------------------#\n";
|
||||||
|
|
||||||
// open new file and write the new configuration
|
// open new file and write the new configuration
|
||||||
$newConfig = fopen($basePath."pialert.conf", "w") or die("Unable to open file!");
|
$newConfig = fopen($fullConfPath, "w") or die("Unable to open file!");
|
||||||
fwrite($newConfig, $txt);
|
fwrite($newConfig, $txt);
|
||||||
fclose($newConfig);
|
fclose($newConfig);
|
||||||
|
|
||||||
echo "<br/>Settings saved to the <code>pialert.conf</code> file. Backup of pialert.conf created: <code>".$new_name."</code>.
|
displayMessage("<br/>Settings saved to the <code>".$config_file."</code> file.
|
||||||
<br/><b>Restart the container for the chanegs to take effect.</b>";
|
Backup of ".$config_file." created: <code>".$new_name."</code>.<br/>
|
||||||
|
<b>Restart the container for the chanegs to take effect.</b>",
|
||||||
|
FALSE, TRUE, TRUE, TRUE);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -312,3 +365,5 @@ function setCache($key, $value) {
|
|||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,12 +11,44 @@
|
|||||||
// ###################################
|
// ###################################
|
||||||
// ## TimeZone processing start
|
// ## TimeZone processing start
|
||||||
// ###################################
|
// ###################################
|
||||||
$config_file = "../config/pialert.conf";
|
|
||||||
$config_file_lines = file($config_file);
|
$configFolderPath = "/home/pi/pialert/config/";
|
||||||
|
$config_file = "pialert.conf";
|
||||||
|
$logFolderPath = "/home/pi/pialert/front/log/";
|
||||||
|
$log_file = "pialert_front.log";
|
||||||
|
|
||||||
|
|
||||||
|
$fullConfPath = $configFolderPath.$config_file;
|
||||||
|
|
||||||
|
chmod($fullConfPath, 0777);
|
||||||
|
|
||||||
|
$config_file_lines = file($fullConfPath);
|
||||||
$config_file_lines_timezone = array_values(preg_grep('/^TIMEZONE\s.*/', $config_file_lines));
|
$config_file_lines_timezone = array_values(preg_grep('/^TIMEZONE\s.*/', $config_file_lines));
|
||||||
$timezone_line = explode("'", $config_file_lines_timezone[0]);
|
$timezone_line = explode("'", $config_file_lines_timezone[0]);
|
||||||
$Pia_TimeZone = $timezone_line[1];
|
$Pia_TimeZone = $timezone_line[1];
|
||||||
date_default_timezone_set($Pia_TimeZone);
|
|
||||||
|
$timeZone = "";
|
||||||
|
|
||||||
|
foreach ($config_file_lines as $line)
|
||||||
|
{
|
||||||
|
if( preg_match('/TIMEZONE(.*?)/', $line, $match) == 1 )
|
||||||
|
{
|
||||||
|
if (preg_match('/\'(.*?)\'/', $line, $match) == 1) {
|
||||||
|
$timeZone = $match[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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');
|
||||||
|
|
||||||
// ###################################
|
// ###################################
|
||||||
// ## TimeZone processing end
|
// ## TimeZone processing end
|
||||||
// ###################################
|
// ###################################
|
||||||
|
|||||||
@@ -307,7 +307,7 @@ $db->close();
|
|||||||
data: { function: 'savesettings', settings: collectSettings() },
|
data: { function: 'savesettings', settings: collectSettings() },
|
||||||
success: function(data, textStatus) {
|
success: function(data, textStatus) {
|
||||||
// $("#result").html(data);
|
// $("#result").html(data);
|
||||||
console.log(data);
|
// console.log(data);
|
||||||
showModalDefault ('Result', data );
|
showModalDefault ('Result', data );
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user