settings prep 2
This commit is contained in:
@@ -35,13 +35,53 @@ from base64 import b64encode
|
|||||||
from paho.mqtt import client as mqtt_client
|
from paho.mqtt import client as mqtt_client
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
# CONFIG VARIABLES
|
# PATHS
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
PIALERT_BACK_PATH = os.path.dirname(os.path.abspath(__file__))
|
PIALERT_BACK_PATH = os.path.dirname(os.path.abspath(__file__))
|
||||||
pialertPath = PIALERT_BACK_PATH + "/.."
|
pialertPath = PIALERT_BACK_PATH + "/.."
|
||||||
|
logPath = pialertPath + '/front/log'
|
||||||
|
confPath = "/config/pialert.conf"
|
||||||
|
dbPath = '/db/pialert.db'
|
||||||
|
fullConfPath = pialertPath + confPath
|
||||||
|
fullDbPath = pialertPath + dbPath
|
||||||
STOPARPSCAN = pialertPath + "/db/setting_stoparpscan"
|
STOPARPSCAN = pialertPath + "/db/setting_stoparpscan"
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
def file_print(*args):
|
||||||
|
|
||||||
|
result = ''
|
||||||
|
|
||||||
|
file = open(logPath + "/pialert.log", "a")
|
||||||
|
for arg in args:
|
||||||
|
result += str(arg)
|
||||||
|
print(result)
|
||||||
|
file.write(result + '\n')
|
||||||
|
file.close()
|
||||||
|
|
||||||
|
|
||||||
|
#===============================================================================
|
||||||
|
# USER CONFIG VARIABLES - START
|
||||||
|
#===============================================================================
|
||||||
|
|
||||||
|
# check RW access of DB and config file
|
||||||
|
file_print('\n Permissions check (All should be True)')
|
||||||
|
file_print('------------------------------------------------')
|
||||||
|
file_print( " " + confPath + " | " + " READ | " + str(os.access(fullConfPath, os.R_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 + " | " + " WRITE | " + str(os.access(fullDbPath, os.W_OK)))
|
||||||
|
file_print('------------------------------------------------')
|
||||||
|
|
||||||
|
pialertPath = '/home/pi/pialert'
|
||||||
|
vendorsDB = '/usr/share/arp-scan/ieee-oui.txt'
|
||||||
|
|
||||||
|
piholeDB = '/etc/pihole/pihole-FTL.db'
|
||||||
|
piholeDhcpleases = '/etc/pihole/dhcp.leases'
|
||||||
|
|
||||||
# INITIALIZE VARIABLES from pialert.conf
|
# INITIALIZE VARIABLES from pialert.conf
|
||||||
|
|
||||||
# GENERAL settings
|
# GENERAL settings
|
||||||
@@ -129,24 +169,16 @@ DAYS_TO_KEEP_EVENTS = 90
|
|||||||
|
|
||||||
# load the variables from pialert.conf
|
# load the variables from pialert.conf
|
||||||
if (sys.version_info > (3,0)):
|
if (sys.version_info > (3,0)):
|
||||||
exec(open(pialertPath + "/config/pialert.conf").read())
|
exec(open(fullConfPath).read())
|
||||||
else:
|
else:
|
||||||
execfile (pialertPath + "/config/pialert.conf")
|
execfile (fullConfPath)
|
||||||
|
|
||||||
|
|
||||||
deviceUrl = REPORT_DASHBOARD_URL + '/deviceDetails.php?mac='
|
deviceUrl = REPORT_DASHBOARD_URL + '/deviceDetails.php?mac='
|
||||||
pialertPath = '/home/pi/pialert'
|
|
||||||
dbPath = pialertPath + '/db/pialert.db'
|
|
||||||
vendorsDB = '/usr/share/arp-scan/ieee-oui.txt'
|
|
||||||
logPath = pialertPath + '/front/log'
|
|
||||||
piholeDB = '/etc/pihole/pihole-FTL.db'
|
|
||||||
piholeDhcpleases = '/etc/pihole/dhcp.leases'
|
|
||||||
|
|
||||||
# # load user configuration
|
#===============================================================================
|
||||||
|
# USER CONFIG VARIABLES - END
|
||||||
# if (sys.version_info > (3,0)):
|
#===============================================================================
|
||||||
# exec(open(pialertPath + "/config/pialert.conf").read())
|
|
||||||
# else:
|
|
||||||
# execfile (pialertPath + "/config/pialert.conf")
|
|
||||||
|
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
# MAIN
|
# MAIN
|
||||||
@@ -2138,11 +2170,11 @@ def importConfig ():
|
|||||||
settings = [
|
settings = [
|
||||||
|
|
||||||
# General
|
# General
|
||||||
('SCAN_SUBNETS', 'Subnets to scan', '', 'text', '', '' , str(SCAN_SUBNETS) , 'General'),
|
('SCAN_SUBNETS', 'Subnets to scan', '', 'subnets', '', '' , str(SCAN_SUBNETS) , 'General'),
|
||||||
('PRINT_LOG', 'Print additional logging', '', 'boolean', '', '' , str(PRINT_LOG) , 'General'),
|
('PRINT_LOG', 'Print additional logging', '', 'boolean', '', '' , str(PRINT_LOG) , 'General'),
|
||||||
('TIMEZONE', 'Time zone', '', 'text', '', '' ,str(TIMEZONE) , 'General'),
|
('TIMEZONE', 'Time zone', '', 'text', '', '' ,str(TIMEZONE) , 'General'),
|
||||||
('PIALERT_WEB_PROTECTION', 'Enable logon', '', 'boolean', '', '' , str(PIALERT_WEB_PROTECTION) , 'General'),
|
('PIALERT_WEB_PROTECTION', 'Enable logon', '', 'boolean', '', '' , str(PIALERT_WEB_PROTECTION) , 'General'),
|
||||||
('PIALERT_WEB_PASSWORD', 'Logon password', '', 'password', '', '' , str(PIALERT_WEB_PASSWORD) , 'General'),
|
('PIALERT_WEB_PASSWORD', 'Logon password', '', 'readonly', '', '' , str(PIALERT_WEB_PASSWORD) , 'General'),
|
||||||
('INCLUDED_SECTIONS', 'Notify on changes in', '', 'multiselect', "['internet', 'new_devices', 'down_devices', 'events']", '' , str(INCLUDED_SECTIONS) , 'General'),
|
('INCLUDED_SECTIONS', 'Notify on changes in', '', 'multiselect', "['internet', 'new_devices', 'down_devices', 'events']", '' , str(INCLUDED_SECTIONS) , 'General'),
|
||||||
('SCAN_CYCLE_MINUTES', 'Scan cycle delay (m)', '', 'integer', '', '' , str(SCAN_CYCLE_MINUTES) , 'General'),
|
('SCAN_CYCLE_MINUTES', 'Scan cycle delay (m)', '', 'integer', '', '' , str(SCAN_CYCLE_MINUTES) , 'General'),
|
||||||
('DAYS_TO_KEEP_EVENTS', 'Delete events older than (days)', '', 'integer', '', '' , str(DAYS_TO_KEEP_EVENTS) , 'General'),
|
('DAYS_TO_KEEP_EVENTS', 'Delete events older than (days)', '', 'integer', '', '' , str(DAYS_TO_KEEP_EVENTS) , 'General'),
|
||||||
@@ -2151,7 +2183,7 @@ def importConfig ():
|
|||||||
# Email
|
# Email
|
||||||
('REPORT_MAIL', 'Enable email', '', 'boolean', '', '' , str(REPORT_MAIL) , 'Email'),
|
('REPORT_MAIL', 'Enable email', '', 'boolean', '', '' , str(REPORT_MAIL) , 'Email'),
|
||||||
('SMTP_SERVER', 'SMTP server URL', '', 'text', '', '' , str(SMTP_SERVER) , 'Email'),
|
('SMTP_SERVER', 'SMTP server URL', '', 'text', '', '' , str(SMTP_SERVER) , 'Email'),
|
||||||
('SMTP_PORT', 'SMTP port', '', 'text', '', '' , str(SMTP_PORT) , 'Email'),
|
('SMTP_PORT', 'SMTP port', '', 'integer', '', '' , str(SMTP_PORT) , 'Email'),
|
||||||
('REPORT_TO', 'Email to', '', 'text', '', '' , str(REPORT_TO) , 'Email'),
|
('REPORT_TO', 'Email to', '', 'text', '', '' , str(REPORT_TO) , 'Email'),
|
||||||
('REPORT_FROM', 'Email Subject', '', 'text', '', '' , str(REPORT_FROM) , 'Email'),
|
('REPORT_FROM', 'Email Subject', '', 'text', '', '' , str(REPORT_FROM) , 'Email'),
|
||||||
('SMTP_SKIP_LOGIN', 'SMTP skip login', '', 'boolean', '', '' , str(SMTP_SKIP_LOGIN) , 'Email'),
|
('SMTP_SKIP_LOGIN', 'SMTP skip login', '', 'boolean', '', '' , str(SMTP_SKIP_LOGIN) , 'Email'),
|
||||||
@@ -2162,8 +2194,8 @@ def importConfig ():
|
|||||||
# Webhooks
|
# Webhooks
|
||||||
('REPORT_WEBHOOK', 'Enable Webhooks', '', 'boolean', '', '' , str(REPORT_WEBHOOK) , 'Webhooks'),
|
('REPORT_WEBHOOK', 'Enable Webhooks', '', 'boolean', '', '' , str(REPORT_WEBHOOK) , 'Webhooks'),
|
||||||
('WEBHOOK_URL', 'Target URL', '', 'text', '', '' , str(WEBHOOK_URL) , 'Webhooks'),
|
('WEBHOOK_URL', 'Target URL', '', 'text', '', '' , str(WEBHOOK_URL) , 'Webhooks'),
|
||||||
('WEBHOOK_PAYLOAD', 'Payload type', '', 'select', "['json', 'html', 'text']", '' , str(WEBHOOK_PAYLOAD) , 'Webhooks'),
|
('WEBHOOK_PAYLOAD', 'Payload type', '', 'selecttext', "['json', 'html', 'text']", '' , str(WEBHOOK_PAYLOAD) , 'Webhooks'),
|
||||||
('WEBHOOK_REQUEST_METHOD', 'Request type', '', 'select', "['GET', 'POST', 'PUT']", '' , str(WEBHOOK_REQUEST_METHOD) , 'Webhooks'),
|
('WEBHOOK_REQUEST_METHOD', 'Request type', '', 'selecttext', "['GET', 'POST', 'PUT']", '' , str(WEBHOOK_REQUEST_METHOD) , 'Webhooks'),
|
||||||
|
|
||||||
# Apprise
|
# Apprise
|
||||||
('REPORT_APPRISE', 'Enable Apprise', '', 'boolean', '', '' , str(REPORT_APPRISE) , 'Apprise'),
|
('REPORT_APPRISE', 'Enable Apprise', '', 'boolean', '', '' , str(REPORT_APPRISE) , 'Apprise'),
|
||||||
@@ -2184,11 +2216,11 @@ def importConfig ():
|
|||||||
# MQTT
|
# MQTT
|
||||||
('REPORT_MQTT', 'Enable MQTT', '', 'boolean', '', '' , str(REPORT_MQTT) , 'MQTT'),
|
('REPORT_MQTT', 'Enable MQTT', '', 'boolean', '', '' , str(REPORT_MQTT) , 'MQTT'),
|
||||||
('MQTT_BROKER', 'MQTT broker host URL', '', 'text', '', '' , str(MQTT_BROKER) , 'MQTT'),
|
('MQTT_BROKER', 'MQTT broker host URL', '', 'text', '', '' , str(MQTT_BROKER) , 'MQTT'),
|
||||||
('MQTT_PORT', 'MQTT broker port', '', 'text', '', '' , str(MQTT_PORT) , 'MQTT'),
|
('MQTT_PORT', 'MQTT broker port', '', 'integer', '', '' , str(MQTT_PORT) , 'MQTT'),
|
||||||
('MQTT_USER', 'MQTT user', '', 'text', '', '' , str(MQTT_USER) , 'MQTT'),
|
('MQTT_USER', 'MQTT user', '', 'text', '', '' , str(MQTT_USER) , 'MQTT'),
|
||||||
('MQTT_PASSWORD', 'MQTT password', '', 'password', '', '' , str(MQTT_PASSWORD) , 'MQTT'),
|
('MQTT_PASSWORD', 'MQTT password', '', 'password', '', '' , str(MQTT_PASSWORD) , 'MQTT'),
|
||||||
('MQTT_QOS', 'MQTT Quality of Service', '', 'select', "['0', '1', '2']", '' , str(MQTT_QOS) , 'MQTT'),
|
('MQTT_QOS', 'MQTT Quality of Service', '', 'selectinteger', "['0', '1', '2']", '' , str(MQTT_QOS) , 'MQTT'),
|
||||||
('MQTT_DELAY_SEC', 'MQTT delay per device (s)', '', 'select', "['2', '3', '4', '5']", '' , str(MQTT_DELAY_SEC) , 'MQTT'),
|
('MQTT_DELAY_SEC', 'MQTT delay per device (s)', '', 'selectinteger', "['2', '3', '4', '5']", '' , str(MQTT_DELAY_SEC) , 'MQTT'),
|
||||||
|
|
||||||
#DynDNS
|
#DynDNS
|
||||||
('DDNS_ACTIVE', 'Enable DynDNS', '', 'boolean', '', '' , str(DDNS_ACTIVE) , 'DynDNS'),
|
('DDNS_ACTIVE', 'Enable DynDNS', '', 'boolean', '', '' , str(DDNS_ACTIVE) , 'DynDNS'),
|
||||||
@@ -2310,7 +2342,7 @@ def openDB ():
|
|||||||
print_log ('Opening DB...')
|
print_log ('Opening DB...')
|
||||||
|
|
||||||
# Open DB and Cursor
|
# Open DB and Cursor
|
||||||
sql_connection = sqlite3.connect (dbPath, isolation_level=None)
|
sql_connection = sqlite3.connect (fullDbPath, isolation_level=None)
|
||||||
sql_connection.execute('pragma journal_mode=wal') #
|
sql_connection.execute('pragma journal_mode=wal') #
|
||||||
sql_connection.text_factory = str
|
sql_connection.text_factory = str
|
||||||
sql_connection.row_factory = sqlite3.Row
|
sql_connection.row_factory = sqlite3.Row
|
||||||
@@ -2359,16 +2391,7 @@ def to_binary_sensor(input):
|
|||||||
#===============================================================================
|
#===============================================================================
|
||||||
# UTIL
|
# UTIL
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
def file_print(*args):
|
|
||||||
|
|
||||||
result = ''
|
|
||||||
|
|
||||||
file = open(logPath + "/pialert.log", "a")
|
|
||||||
for arg in args:
|
|
||||||
result += str(arg)
|
|
||||||
print(result)
|
|
||||||
file.write(result + '\n')
|
|
||||||
file.close()
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
def print_log (pText):
|
def print_log (pText):
|
||||||
global log_timestamp
|
global log_timestamp
|
||||||
|
|||||||
@@ -583,9 +583,18 @@ height: 50px;
|
|||||||
width:30%;
|
width:30%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.setting_input input
|
.center
|
||||||
{
|
{
|
||||||
width:300px;
|
margin: 0;
|
||||||
|
position: relative;
|
||||||
|
left: 50%;
|
||||||
|
-ms-transform: translate(-50%, -50%);
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.top-margin
|
||||||
|
{
|
||||||
|
margin-top: 50px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.settings_content {
|
.settings_content {
|
||||||
|
|||||||
@@ -381,7 +381,7 @@ if ($_REQUEST['tab'] == '1') {
|
|||||||
pialert.log
|
pialert.log
|
||||||
</div>
|
</div>
|
||||||
<div class="db_tools_table_cell_b">
|
<div class="db_tools_table_cell_b">
|
||||||
<textarea class="logs" cols="70" rows="10" ><?php echo file_get_contents( "./log/pialert.log" ); ?>
|
<textarea id="pialert_log" class="logs" cols="70" rows="10" ><?php echo file_get_contents( "./log/pialert.log" ); ?>
|
||||||
</textarea>
|
</textarea>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -390,7 +390,7 @@ if ($_REQUEST['tab'] == '1') {
|
|||||||
IP_changes.log
|
IP_changes.log
|
||||||
</div>
|
</div>
|
||||||
<div class="db_tools_table_cell_b">
|
<div class="db_tools_table_cell_b">
|
||||||
<textarea class="logs" cols="70" rows="10" ><?php echo file_get_contents( "./log/IP_changes.log" ); ?>
|
<textarea id="IP_changes_log" class="logs" cols="70" rows="10" ><?php echo file_get_contents( "./log/IP_changes.log" ); ?>
|
||||||
</textarea>
|
</textarea>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -399,7 +399,7 @@ if ($_REQUEST['tab'] == '1') {
|
|||||||
stdout.log
|
stdout.log
|
||||||
</div>
|
</div>
|
||||||
<div class="db_tools_table_cell_b">
|
<div class="db_tools_table_cell_b">
|
||||||
<textarea class="logs" cols="70" rows="10" ><?php echo file_get_contents( "./log/stdout.log" ); ?>
|
<textarea id="stdout_log" class="logs" cols="70" rows="10" ><?php echo file_get_contents( "./log/stdout.log" ); ?>
|
||||||
</textarea>
|
</textarea>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -408,7 +408,7 @@ if ($_REQUEST['tab'] == '1') {
|
|||||||
stderr.log
|
stderr.log
|
||||||
</div>
|
</div>
|
||||||
<div class="db_tools_table_cell_b">
|
<div class="db_tools_table_cell_b">
|
||||||
<textarea class="logs" cols="70" rows="10" ><?php echo file_get_contents( "./log/stderr.log" ); ?>
|
<textarea id="stderr_log" class="logs" cols="70" rows="10" ><?php echo file_get_contents( "./log/stderr.log" ); ?>
|
||||||
</textarea>
|
</textarea>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -450,6 +450,21 @@ if ($_REQUEST['tab'] == '1') {
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
|
function scrollDown()
|
||||||
|
{
|
||||||
|
temp = $('#pialert_log');
|
||||||
|
$temp.scrollTop($text[0].scrollHeight);
|
||||||
|
|
||||||
|
temp = $('#IP_changes_log');
|
||||||
|
$temp.scrollTop($text[0].scrollHeight);
|
||||||
|
|
||||||
|
temp = $('#stdout_log');
|
||||||
|
$temp.scrollTop($text[0].scrollHeight);
|
||||||
|
|
||||||
|
temp = $('#stderr_log');
|
||||||
|
$temp.scrollTop($text[0].scrollHeight);
|
||||||
|
}
|
||||||
|
|
||||||
// delete devices with emty macs
|
// delete devices with emty macs
|
||||||
function askDeleteDevicesWithEmptyMACs () {
|
function askDeleteDevicesWithEmptyMACs () {
|
||||||
// Ask
|
// Ask
|
||||||
@@ -630,9 +645,12 @@ function PiaToggleArpScan()
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// laod footer asynchronously not to block the page load/other sections
|
// load footer asynchronously not to block the page load/other sections
|
||||||
window.onload = function asyncFooter()
|
window.onload = function asyncFooter()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// scrollDown();
|
||||||
|
|
||||||
$("#lastCommit").append('<img alt="GitHub last commit" src="https://img.shields.io/github/last-commit/jokob-sk/pi.alert/main?logo=github">');
|
$("#lastCommit").append('<img alt="GitHub last commit" src="https://img.shields.io/github/last-commit/jokob-sk/pi.alert/main?logo=github">');
|
||||||
|
|
||||||
$("#lastDockerUpdate").append(
|
$("#lastDockerUpdate").append(
|
||||||
|
|||||||
@@ -8,32 +8,56 @@
|
|||||||
// Puche 2021 pi.alert.application@gmail.com GNU GPLv3
|
// Puche 2021 pi.alert.application@gmail.com GNU GPLv3
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
// ## TimeZone processing
|
## TimeZone processing
|
||||||
$config_file = "../../../config/pialert.conf";
|
$basePath = "../../../config/";
|
||||||
$config_file_lines = file($config_file);
|
$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));
|
$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);
|
|
||||||
|
|
||||||
$FUNCTION = $_REQUEST['function'];
|
$FUNCTION = $_REQUEST['function'];
|
||||||
|
$SETTINGS = $_REQUEST['settings'];
|
||||||
|
|
||||||
|
|
||||||
if ($FUNCTION == 'savesettings') {
|
if ($FUNCTION == 'savesettings') {
|
||||||
saveSettings();
|
saveSettings();
|
||||||
} elseif ($PIA_SCAN_MODE == 'test') {
|
|
||||||
// other function
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Formatting data functions
|
// Formatting data functions
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
// Creates a PHP array from a string representing a python array (input format ['...','...'])
|
||||||
function createArray($input){
|
function createArray($input){
|
||||||
$pattern = '/(^\s*\[)|(\]\s*$)/';
|
|
||||||
$replacement = '';
|
|
||||||
$noBrackets = preg_replace($pattern, $replacement, $input);
|
|
||||||
|
|
||||||
return $options = explode(",", $noBrackets);
|
// regex patterns
|
||||||
|
$patternBrackets = '/(^\s*\[)|(\]\s*$)/';
|
||||||
|
$patternQuotes = '/(^\s*\')|(\'\s*$)/';
|
||||||
|
$replacement = '';
|
||||||
|
|
||||||
|
// remove brackets
|
||||||
|
$noBrackets = preg_replace($patternBrackets, $replacement, $input);
|
||||||
|
|
||||||
|
$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) {
|
function formatDate ($date1) {
|
||||||
@@ -75,7 +99,8 @@ function checkPermissions($files)
|
|||||||
// check access to database
|
// check access to database
|
||||||
if(file_exists($file) != 1)
|
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()
|
function saveSettings()
|
||||||
{
|
{
|
||||||
$config_file = "../../../config/pialert.conf";
|
global $SETTINGS, $FUNCTION, $fullConfPath, $basePath, $config_file_lines_timezone, $config_file_lines;
|
||||||
// save in the file
|
|
||||||
$new_location = $config_file.'_'.strtotime("now").'.backup';
|
|
||||||
|
|
||||||
if(file_exists( $config_file) == 1)
|
$timeZone = "";
|
||||||
|
|
||||||
|
foreach ($config_file_lines as $line)
|
||||||
{
|
{
|
||||||
// create a backup copy
|
if( preg_match('/TIMEZONE(.*?)/', $line, $match) == 1 )
|
||||||
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.";
|
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) {
|
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
|
//General
|
||||||
$pia_lang['SCAN_SUBNETS_name'] = 'Subnets to scan';
|
$pia_lang['SCAN_SUBNETS_name'] = 'Subnets to scan';
|
||||||
$pia_lang['SCAN_SUBNETS_description'] = '
|
$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>
|
<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>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>Run <code>iwconfig</code> in your ocntainer 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):
|
|
||||||
</ol>
|
</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_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['PRINT_LOG_description'] = 'This setting will enable more verbose logging. Useful for debugging events writing into the database.';
|
||||||
$pia_lang['TIMEZONE_name'] = 'Time zone';
|
$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_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_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_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_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['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';
|
$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>
|
</span><br>
|
||||||
If the database is still read-only, try reinstalling or restoring a database backup from the maintenance page.';
|
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_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">
|
$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 href="https://github.com/jokob-sk/Pi.Alert/blob/main/db/pialert.db">original DB from GitHub</a>.</li>
|
<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 href="https://github.com/jokob-sk/Pi.Alert/tree/main/dockerfiles#-examples">Examples</a> for details).</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="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="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>
|
<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
|
//General
|
||||||
$pia_lang['SCAN_SUBNETS_name'] = 'Subnets to scan';
|
$pia_lang['SCAN_SUBNETS_name'] = 'Subnets to scan';
|
||||||
$pia_lang['SCAN_SUBNETS_description'] = '
|
$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>
|
<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>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>Run <code>iwconfig</code> in your container 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):
|
|
||||||
</ol>
|
</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_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['PRINT_LOG_description'] = 'This setting will enable more verbose logging. Useful for debugging events writing into the database.';
|
||||||
$pia_lang['TIMEZONE_name'] = 'Time zone';
|
$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_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_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_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_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['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';
|
$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
|
//General
|
||||||
$pia_lang['SCAN_SUBNETS_name'] = 'Subnets to scan';
|
$pia_lang['SCAN_SUBNETS_name'] = 'Subnets to scan';
|
||||||
$pia_lang['SCAN_SUBNETS_description'] = '
|
$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>
|
<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>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>Run <code>iwconfig</code> in your container 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):
|
|
||||||
</ol>
|
</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_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['PRINT_LOG_description'] = 'This setting will enable more verbose logging. Useful for debugging events writing into the database.';
|
||||||
$pia_lang['TIMEZONE_name'] = 'Time zone';
|
$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_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_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_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_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['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';
|
$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_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.';
|
$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-dialog">
|
||||||
<div class="modal-content">
|
<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>
|
<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>
|
<h4 id="modal-default-title" class="modal-title"> Modal Default Title </h4>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ $db->close();
|
|||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
$resultHTML = "";
|
$html = "";
|
||||||
$groups = [];
|
$groups = [];
|
||||||
|
|
||||||
// collect all groups
|
// collect all groups
|
||||||
@@ -87,70 +87,85 @@ $db->close();
|
|||||||
|
|
||||||
// create settings groups
|
// create settings groups
|
||||||
foreach ($groups as $group) {
|
foreach ($groups as $group) {
|
||||||
$resultHTML = $resultHTML.'<section class="settings_content">
|
$html = $html.'<section class="settings_content">
|
||||||
<h4>'.$group.'</h4>';
|
<h4>'.$group.'</h4>';
|
||||||
|
|
||||||
// populate settings for each group
|
// populate settings for each group
|
||||||
foreach ($settings as $setting) {
|
foreach ($settings as $set) {
|
||||||
if($setting["Group"] == $group)
|
if($set["Group"] == $group)
|
||||||
{
|
{
|
||||||
$resultHTML = $resultHTML.
|
$html = $html.
|
||||||
'<div class="table_row" >
|
'<div class="table_row" >
|
||||||
<div class="table_cell setting_name" >';
|
<div class="table_cell setting_name" >';
|
||||||
|
|
||||||
$resultHTML = $resultHTML.getString ($setting['Code_Name'].'_name', $setting['Display_Name'], $pia_lang);
|
$html = $html.getString ($set['Code_Name'].'_name', $set['Display_Name'], $pia_lang);
|
||||||
|
|
||||||
$resultHTML = $resultHTML.
|
$html = $html.
|
||||||
'</div>
|
'</div>
|
||||||
<div class="table_cell setting_description" >';
|
<div class="table_cell setting_description" >';
|
||||||
|
|
||||||
$resultHTML = $resultHTML.getString ($setting['Code_Name'].'_description', $setting['Description'], $pia_lang);
|
$html = $html.getString ($set['Code_Name'].'_description', $set['Description'], $pia_lang);
|
||||||
|
|
||||||
$resultHTML = $resultHTML.
|
$html = $html.
|
||||||
'</div>
|
'</div>
|
||||||
<div class="table_cell setting_input" >';
|
<div class="table_cell setting_input" >';
|
||||||
|
|
||||||
// render different input types based on the setting type
|
// render different input types based on the set type
|
||||||
$inputType = "";
|
$input = "";
|
||||||
|
|
||||||
// text - textbox
|
// text - textbox
|
||||||
if($setting['Type'] == 'text')
|
if($set['Type'] == 'text' )
|
||||||
{
|
{
|
||||||
$inputType = '<input value="'.$setting['Value'].'"/>';
|
$input = '<input class="form-control input" id="'.$set['Code_Name'].'" value="'.$set['Value'].'"/>';
|
||||||
}
|
}
|
||||||
// password - hidden text
|
// password - hidden text
|
||||||
elseif ($setting['Type'] == 'password')
|
elseif ($set['Type'] == 'password')
|
||||||
{
|
{
|
||||||
$inputType = '<input type="password" value="'.$setting['Value'].'"/>';
|
$input = '<input class="form-control input" id="'.$set['Code_Name'].'" type="password" value="'.$set['Value'].'"/>';
|
||||||
|
}
|
||||||
|
// readonly
|
||||||
|
elseif ($set['Type'] == 'readonly')
|
||||||
|
{
|
||||||
|
$input = '<input class="form-control input" id="'.$set['Code_Name'].'" value="'.$set['Value'].'" readonly/>';
|
||||||
}
|
}
|
||||||
// boolean - checkbox
|
// boolean - checkbox
|
||||||
elseif ($setting['Type'] == 'boolean')
|
elseif ($set['Type'] == 'boolean')
|
||||||
{
|
{
|
||||||
$checked = "";
|
$checked = "";
|
||||||
if ($setting['Value'] == "True") { $checked = "checked";};
|
if ($set['Value'] == "True") { $checked = "checked";};
|
||||||
$inputType = '<input type="checkbox" value="'.$setting['Value'].'" '.$checked.' />';
|
$input = '<input class="checkbox" id="'.$set['Code_Name'].'" type="checkbox" value="'.$set['Value'].'" '.$checked.' />';
|
||||||
}
|
}
|
||||||
// integer - number input
|
// integer - number input
|
||||||
elseif ($setting['Type'] == 'integer')
|
elseif ($set['Type'] == 'integer')
|
||||||
{
|
{
|
||||||
$inputType = '<input type="number" value="'.$setting['Value'].'"/>';
|
$input = '<input class="form-control" id="'.$set['Code_Name'].'" type="number" value="'.$set['Value'].'"/>';
|
||||||
}
|
}
|
||||||
// select - dropdown
|
// selecttext - dropdown
|
||||||
elseif ($setting['Type'] == 'select')
|
elseif ($set['Type'] == 'selecttext')
|
||||||
{
|
{
|
||||||
$inputType = '<select name="'.$setting['Code_Name'].'" id="'.$setting['Code_Name'].'">';
|
$input = '<select class="form-control" name="'.$set['Code_Name'].'" id="'.$set['Code_Name'].'">';
|
||||||
$options = createArray($setting['Options']);
|
$options = createArray($set['Options']);
|
||||||
foreach ($options as $option) {
|
foreach ($options as $option) {
|
||||||
$inputType = $inputType.'<option value="'.$option.'">'.$option.'</option>';
|
$input = $input.'<option value="'.$option.'">'.$option.'</option>';
|
||||||
|
|
||||||
}
|
}
|
||||||
$inputType = $inputType.'</select>';
|
$input = $input.'</select>';
|
||||||
|
}
|
||||||
|
// selectinteger - dropdown
|
||||||
|
elseif ($set['Type'] == 'selectinteger')
|
||||||
|
{
|
||||||
|
$input = '<select class="form-control" name="'.$set['Code_Name'].'" id="'.$set['Code_Name'].'">';
|
||||||
|
$options = createArray($set['Options']);
|
||||||
|
foreach ($options as $option) {
|
||||||
|
$input = $input.'<option value="'.$option.'">'.$option.'</option>';
|
||||||
|
}
|
||||||
|
$input = $input.'</select>';
|
||||||
}
|
}
|
||||||
// multiselect
|
// multiselect
|
||||||
elseif ($setting['Type'] == 'multiselect')
|
elseif ($set['Type'] == 'multiselect')
|
||||||
{
|
{
|
||||||
$inputType = '<select name="'.$setting['Code_Name'].'" id="'.$setting['Code_Name'].'" multiple>';
|
$input = '<select class="form-control" name="'.$set['Code_Name'].'" id="'.$set['Code_Name'].'" multiple>';
|
||||||
$values = createArray($setting['Value']);
|
$values = createArray($set['Value']);
|
||||||
$options = createArray($setting['Options']);
|
$options = createArray($set['Options']);
|
||||||
|
|
||||||
foreach ($options as $option) {
|
foreach ($options as $option) {
|
||||||
$selected = "";
|
$selected = "";
|
||||||
@@ -159,27 +174,57 @@ $db->close();
|
|||||||
$selected = "selected";
|
$selected = "selected";
|
||||||
}
|
}
|
||||||
|
|
||||||
$inputType = $inputType.'<option value="'.$option.'" '.$selected.'>'.$option.'</option>';
|
$input = $input.'<option value="'.$option.'" '.$selected.'>'.$option.'</option>';
|
||||||
}
|
}
|
||||||
$inputType = $inputType.'</select>';
|
$input = $input.'</select>';
|
||||||
|
}
|
||||||
|
// multiselect
|
||||||
|
elseif ($set['Type'] == 'subnets')
|
||||||
|
{
|
||||||
|
$input = $input.
|
||||||
|
'<div class="row form-group">
|
||||||
|
<div class="col-xs-6">
|
||||||
|
<input class="form-control " id="ipMask" type="text" placeholder="192.168.1.0/24"/>
|
||||||
|
</div>';
|
||||||
|
$input = $input.
|
||||||
|
'<div class="col-xs-3">
|
||||||
|
<input class="form-control " id="ipInterface" type="text" placeholder="eth0" />
|
||||||
|
</div>
|
||||||
|
<div class="col-xs-3"><button class="btn btn-primary" onclick="addInterface()" >Add</button></div>
|
||||||
|
</div>';
|
||||||
|
|
||||||
|
$input = $input.'<div class="form-group">
|
||||||
|
<select class="form-control" name="'.$set['Code_Name'].'" id="'.$set['Code_Name'].'" multiple readonly>';
|
||||||
|
$options = createArray($set['Value']);
|
||||||
|
|
||||||
|
|
||||||
|
foreach ($options as $option) {
|
||||||
|
|
||||||
|
$input = $input.'<option value="'.$option.'" disabled>'.$option.'</option>';
|
||||||
|
}
|
||||||
|
$input = $input.'</select></div>';
|
||||||
|
$input = $input.'<div><button class="btn btn-primary" onclick="removeInterfaces()">Remove all</button></div>';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$resultHTML = $resultHTML.$inputType;
|
$html = $html.$input;
|
||||||
|
|
||||||
$resultHTML = $resultHTML.'</div>
|
$html = $html.'</div>
|
||||||
</div>';
|
</div>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$resultHTML = $resultHTML.'</section>';
|
$html = $html.'</section>';
|
||||||
}
|
}
|
||||||
|
|
||||||
echo $resultHTML;
|
echo $html;
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<!-- /.content -->
|
<!-- /.content -->
|
||||||
<div class="table_row" >
|
<div class="row" >
|
||||||
<button type="button" class="btn btn-default pa-btn bg-green dbtools-button" id="save" onclick="saveSettings()"><?php echo $pia_lang['DevDetail_button_Save'];?></button>
|
<div class="row">
|
||||||
|
<button type="button" class="center top-margin btn btn-primary btn-default pa-btn bg-green dbtools-button" id="save" onclick="saveSettings()"><?php echo $pia_lang['DevDetail_button_Save'];?></button>
|
||||||
|
</div>
|
||||||
<div id="result"></div>
|
<div id="result"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -193,13 +238,77 @@ $db->close();
|
|||||||
?>
|
?>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
function addInterface()
|
||||||
|
{
|
||||||
|
ipMask = $('#ipMask').val();
|
||||||
|
ipInterface = $('#ipInterface').val();
|
||||||
|
|
||||||
|
full = ipMask + " --interface=" + ipInterface;
|
||||||
|
|
||||||
|
if(ipMask == "" || ipInterface == "")
|
||||||
|
{
|
||||||
|
showModalDefault ('Validation error', 'Specify both, the network mask and the interface');
|
||||||
|
} else {
|
||||||
|
$('#SCAN_SUBNETS').append($('<option disabled></option>').attr('value', full).text(full));
|
||||||
|
|
||||||
|
$('#ipMask').val('');
|
||||||
|
$('#ipInterface').val('');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeInterfaces()
|
||||||
|
{
|
||||||
|
$('#SCAN_SUBNETS').empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
function collectSettings()
|
||||||
|
{
|
||||||
|
var settingsArray = [];
|
||||||
|
|
||||||
|
// generate javascript to collect values
|
||||||
|
// multiselect, select, password
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$noConversion = array('text', 'integer', 'password', 'readonly', 'selecttext', 'selectinteger', "multiselect");
|
||||||
|
|
||||||
|
foreach ($settings as $set) {
|
||||||
|
if(in_array($set['Type'] , $noConversion))
|
||||||
|
{
|
||||||
|
echo 'settingsArray.push(["'.$set["Group"].'", "'.$set["Code_Name"].'", $("#'.$set["Code_Name"].'").val(), "'.$set["Type"].'" ]);';
|
||||||
|
}
|
||||||
|
elseif ($set['Type'] == "boolean")
|
||||||
|
{
|
||||||
|
echo 'temp = $("#'.$set["Code_Name"].'").is(":checked") ;';
|
||||||
|
echo 'settingsArray.push(["'.$set["Group"].'", "'.$set["Code_Name"].'", temp, "'.$set["Type"].'" ]);';
|
||||||
|
}
|
||||||
|
elseif ($set["Code_Name"] == "SCAN_SUBNETS")
|
||||||
|
{
|
||||||
|
echo "var temps = [];
|
||||||
|
|
||||||
|
$( '#SCAN_SUBNETS option' ).each( function( i, selected ) {
|
||||||
|
temps.push($( selected ).val());
|
||||||
|
});
|
||||||
|
|
||||||
|
";
|
||||||
|
echo 'settingsArray.push(["'.$set["Group"].'", "'.$set["Code_Name"].'", temps, "'.$set["Type"].'" ]);';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
console.log(settingsArray);
|
||||||
|
return settingsArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function saveSettings() {
|
function saveSettings() {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
url: "../php/server/util.php",
|
url: "../php/server/util.php",
|
||||||
data: { function: 'savesettings' },
|
data: { function: 'savesettings', settings: collectSettings() },
|
||||||
success: function(data, textStatus) {
|
success: function(data, textStatus) {
|
||||||
$("#result").html(data);
|
// $("#result").html(data);
|
||||||
|
console.log(data);
|
||||||
|
showModalDefault ('Result', data + "<br/><b>Restart the container for the chanegs to take effect.</b>");
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user