code cleanup

This commit is contained in:
Jokob-sk
2022-12-26 21:30:28 +11:00
parent 31d7c5173f
commit ca8042c2e9
7 changed files with 51 additions and 32 deletions

View File

@@ -163,10 +163,8 @@ PRINT_LOG = False
TIMEZONE = 'Europe/Berlin' TIMEZONE = 'Europe/Berlin'
PIALERT_WEB_PROTECTION = False PIALERT_WEB_PROTECTION = False
PIALERT_WEB_PASSWORD = '8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92' PIALERT_WEB_PASSWORD = '8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92'
INCLUDED_SECTIONS = ['internet', 'new_devices', 'down_devices', 'events'] # Specifies which events trigger notifications. INCLUDED_SECTIONS = ['internet', 'new_devices', 'down_devices', 'events']
# Remove the event type(s) you don't want to get notified on SCAN_CYCLE_MINUTES = 5
# Overrides device-specific settings in the UI.
SCAN_CYCLE_MINUTES = 5 # delay between scans
SCAN_SUBNETS = ['192.168.1.0/24 --interface=eth1', '192.168.1.0/24 --interface=eth0'] SCAN_SUBNETS = ['192.168.1.0/24 --interface=eth1', '192.168.1.0/24 --interface=eth0']
@@ -188,11 +186,8 @@ REPORT_DASHBOARD_URL = 'http://pi.alert/'
# ---------------------- # ----------------------
REPORT_WEBHOOK = False REPORT_WEBHOOK = False
WEBHOOK_URL = '' WEBHOOK_URL = ''
WEBHOOK_PAYLOAD = 'json' # webhook payload data format for the "body > attachements > text" attribute WEBHOOK_PAYLOAD = 'json'
# in https://github.com/jokob-sk/Pi.Alert/blob/main/docs/webhook_json_sample.json WEBHOOK_REQUEST_METHOD = 'GET'
# supported values: 'json', 'html' or 'text'
# e.g.: for discord use 'html'
WEBHOOK_REQUEST_METHOD = 'GET' # POST, GET...
# Apprise settings # Apprise settings
#----------------------- #-----------------------
@@ -234,8 +229,8 @@ DDNS_UPDATE_URL = 'https://api.dynu.com/nic/update?'
# PIHOLE settings # PIHOLE settings
# ---------------------- # ----------------------
PIHOLE_ACTIVE = False # if enabled you need to map '/etc/pihole/pihole-FTL.db' in docker-compose.yml PIHOLE_ACTIVE = False
DHCP_ACTIVE = False # if enabled you need to map '/etc/pihole/dhcp.leases' in docker-compose.yml DHCP_ACTIVE = False
# keep 90 days of network activity if not specified how many days to keep # keep 90 days of network activity if not specified how many days to keep
DAYS_TO_KEEP_EVENTS = 90 DAYS_TO_KEEP_EVENTS = 90

View File

@@ -220,7 +220,8 @@ if ($_REQUEST['mac'] == 'Internet') { $DevDetail_Tap_temp = "Tools"; } else { $D
<input class="form-control" id="txtGroup" type="text" value="--"> <input class="form-control" id="txtGroup" type="text" value="--">
<div class="input-group-btn"> <div class="input-group-btn">
<button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown" aria-expanded="false"> <button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
<span class="fa fa-caret-down"></span></button> <span class="fa fa-caret-down"></span>
</button>
<ul id="dropdownGroup" class="dropdown-menu dropdown-menu-right"> <ul id="dropdownGroup" class="dropdown-menu dropdown-menu-right">
<li><a href="javascript:void(0)" onclick="setTextValue('txtGroup','Always On')"> Always On </a></li> <li><a href="javascript:void(0)" onclick="setTextValue('txtGroup','Always On')"> Always On </a></li>
<li><a href="javascript:void(0)" onclick="setTextValue('txtGroup','Friends')"> Friends </a></li> <li><a href="javascript:void(0)" onclick="setTextValue('txtGroup','Friends')"> Friends </a></li>

View File

@@ -84,10 +84,18 @@ function deleteAllCookies() {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
function showModalOk (title, message) { function showModalOk (title, message, callbackFunction = null) {
// set captions // set captions
$('#modal-ok-title').html (title); $('#modal-ok-title').html (title);
$('#modal-ok-message').html (message); $('#modal-ok-message').html (message);
if(callbackFunction!= null)
{
$("#modal-ok-OK").click(function()
{
callbackFunction()
});
}
// Show modal // Show modal
$('#modal-ok').modal('show'); $('#modal-ok').modal('show');

View File

@@ -708,10 +708,10 @@ window.onload = function asyncFooter()
{ {
scrollDown(); 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('<a href="https://github.com/jokob-sk/Pi.Alert/commits" target="_blank"><img alt="GitHub last commit" src="https://img.shields.io/github/last-commit/jokob-sk/pi.alert/main?logo=github"></a>');
$("#lastDockerUpdate").append( $("#lastDockerUpdate").append(
'<img alt="Docker last pushed" src="https://img.shields.io/badge/dynamic/json?color=blue&label=Last%20pushed&query=last_updated&url=https%3A%2F%2Fhub.docker.com%2Fv2%2Frepositories%2Fjokobsk%2Fpi.alert%2F&logo=docker&?link=http://left&link=https://hub.docker.com/repository/docker/jokobsk/pi.alert">'); '<a href="https://hub.docker.com/r/jokobsk/pi.alert/tags" target="_blank"><img alt="Docker last pushed" src="https://img.shields.io/badge/dynamic/json?color=blue&label=Last%20pushed&query=last_updated&url=https%3A%2F%2Fhub.docker.com%2Fv2%2Frepositories%2Fjokobsk%2Fpi.alert%2F&logo=docker&?link=http://left&link=https://hub.docker.com/repository/docker/jokobsk/pi.alert"></a>');
} }

View File

@@ -29,7 +29,7 @@ $lang['en_us'] = array(
'Login_Remember' => 'Remember', 'Login_Remember' => 'Remember',
'Login_Remember_small' => '(valid for 7 days)', 'Login_Remember_small' => '(valid for 7 days)',
'Login_Submit' => 'Log in', 'Login_Submit' => 'Log in',
'Login_Psw_run' => 'To change password run:', 'Login_Psw_run' => 'To change the password run:',
'Login_Psw_new' => 'new_password', 'Login_Psw_new' => 'new_password',
'Login_Psw_folder' => 'in the config folder.', 'Login_Psw_folder' => 'in the config folder.',
'Login_Psw_alert' => 'Password Alert!', 'Login_Psw_alert' => 'Password Alert!',
@@ -446,7 +446,7 @@ the scan will take hours to complete instead of seconds.
'PIALERT_WEB_PROTECTION_name' => 'Enable login', 'PIALERT_WEB_PROTECTION_name' => 'Enable login',
'PIALERT_WEB_PROTECTION_description' => 'When enabled a login dialog is displayed. Read below carefully if you get locked out of your instance.', 'PIALERT_WEB_PROTECTION_description' => 'When enabled a login dialog is displayed. Read below carefully if you get locked out of your instance.',
'PIALERT_WEB_PASSWORD_name' => 'Login password', 'PIALERT_WEB_PASSWORD_name' => 'Login password',
'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', 'PIALERT_WEB_PASSWORD_description' => 'The default password is <code>123456</code>. To change the password run <code>/home/pi/pialert/back/pialert-cli</code> in the container',
'INCLUDED_SECTIONS_name' => 'Notify on', 'INCLUDED_SECTIONS_name' => 'Notify on',
'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).', '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).',
'SCAN_CYCLE_MINUTES_name' => 'Scan cycle delay', 'SCAN_CYCLE_MINUTES_name' => 'Scan cycle delay',
@@ -482,7 +482,7 @@ the scan will take hours to complete instead of seconds.
'WEBHOOK_URL_name' => 'Target URL', 'WEBHOOK_URL_name' => 'Target URL',
'WEBHOOK_URL_description' => 'Target URL starting with <code>http://</code> or <code>https://</code>.', 'WEBHOOK_URL_description' => 'Target URL starting with <code>http://</code> or <code>https://</code>.',
'WEBHOOK_PAYLOAD_name' => 'Payload type', 'WEBHOOK_PAYLOAD_name' => 'Payload type',
'WEBHOOK_PAYLOAD_description' => 'The Webhook payload data format for the "body > attachements > text" attribute in the payload json. See an example of the payload <a target="_blank" href="https://github.com/jokob-sk/Pi.Alert/blob/main/docs/webhook_json_sample.json">here</a>. (e.g.: for discord use <code>\'html\'</code>)', 'WEBHOOK_PAYLOAD_description' => 'The Webhook payload data format for the <code>body</code> > <code>attachments</code> > <code>text</code> attribute in the payload json. See an example of the payload <a target="_blank" href="https://github.com/jokob-sk/Pi.Alert/blob/main/docs/webhook_json_sample.json">here</a>. (e.g.: for discord use <code>html</code>)',
'WEBHOOK_REQUEST_METHOD_name' => 'Request method', 'WEBHOOK_REQUEST_METHOD_name' => 'Request method',
'WEBHOOK_REQUEST_METHOD_description' => 'The HTTP request method to be used for the webhook call.', 'WEBHOOK_REQUEST_METHOD_description' => 'The HTTP request method to be used for the webhook call.',
@@ -525,9 +525,9 @@ the scan will take hours to complete instead of seconds.
'MQTT_PASSWORD_name' => 'MQTT password', 'MQTT_PASSWORD_name' => 'MQTT password',
'MQTT_PASSWORD_description' => 'Password used to login into your MQTT broker instance.', 'MQTT_PASSWORD_description' => 'Password used to login into your MQTT broker instance.',
'MQTT_QOS_name' => 'MQTT Quality of Service', 'MQTT_QOS_name' => 'MQTT Quality of Service',
'MQTT_QOS_description' => 'Quality of service setting for MQTT message sending. 0 - Low quality to 2 - High quality. The higher the quality the longer the delay.', 'MQTT_QOS_description' => 'Quality of service setting for MQTT message sending. <code>0</code> - Low quality to <code>2</code> - High quality. The higher the quality the longer the delay.',
'MQTT_DELAY_SEC_name' => 'MQTT delay per device', 'MQTT_DELAY_SEC_name' => 'MQTT delay per device',
'MQTT_DELAY_SEC_description' => 'A little hack - delay adding to the queue in case the process is restarted and previous publish processes aborted (it takes ~2s to update a sensor config on the broker). Tested with 2-3 seconds of delay. This delay is only applied when devices are created (during the first notification loop). It doesn\'t affect subsequent scans or notifications.', 'MQTT_DELAY_SEC_description' => 'A little hack - delay adding to the queue in case the process is restarted and previous publish processes aborted (it takes ~<code>2</code>s to update a sensor config on the broker). Tested with <code>2</code>-<code>3</code> seconds of delay. This delay is only applied when devices are created (during the first notification loop). It doesn\'t affect subsequent scans or notifications.',
//DynDNS //DynDNS
'DDNS_ACTIVE_name' => 'Enable DynDNS', 'DDNS_ACTIVE_name' => 'Enable DynDNS',

View File

@@ -517,7 +517,7 @@ the scan will take hours to complete instead of seconds.
'MQTT_QOS_name' => 'MQTT Quality of Service', 'MQTT_QOS_name' => 'MQTT Quality of Service',
'MQTT_QOS_description' => 'Quality of service setting for MQTT message sending. 0 - Low quality to 2 - High quality. The higher the quality the longer the delay.', 'MQTT_QOS_description' => 'Quality of service setting for MQTT message sending. 0 - Low quality to 2 - High quality. The higher the quality the longer the delay.',
'MQTT_DELAY_SEC_name' => 'MQTT delay per device', 'MQTT_DELAY_SEC_name' => 'MQTT delay per device',
'MQTT_DELAY_SEC_description' => 'A little hack - delay adding to the queue in case the process is restarted and previous publish processes aborted (it takes ~2s to update a sensor config on the broker). Tested with 2-3 seconds of delay. This delay is only applied when devices are created (during the first notification loop). It doesn\'t affect subsequent scans or notifications.', 'MQTT_DELAY_SEC_description' => 'A little hack - delay adding to the queue in case the process is restarted and previous publish processes aborted (it takes ~<code>2</code>s to update a sensor config on the broker). Tested with <code>2</code>-<code>3</code> seconds of delay. This delay is only applied when devices are created (during the first notification loop). It doesn\'t affect subsequent scans or notifications.',
//DynDNS //DynDNS
'DDNS_ACTIVE_name' => 'Enable DynDNS', 'DDNS_ACTIVE_name' => 'Enable DynDNS',

View File

@@ -57,8 +57,6 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
$db->close(); $db->close();
echo "<script>if(".count($settings)." != 46)alert('".lang("settings_missing")."')</script>";
?> ?>
<!-- Page ------------------------------------------------------------------ --> <!-- Page ------------------------------------------------------------------ -->
<div class="content-wrapper"> <div class="content-wrapper">
@@ -71,7 +69,7 @@ echo "<script>if(".count($settings)." != 46)alert('".lang("settings_missing")."'
</h1> </h1>
</section> </section>
<div class="content"> <div class="content">
<?php <?php
$html = ""; $html = "";
$groups = []; $groups = [];
@@ -242,6 +240,15 @@ echo "<script>if(".count($settings)." != 46)alert('".lang("settings_missing")."'
?> ?>
<script> <script>
// number of settings has to be equal to
var settingsNumber = 46;
if(<?php echo count($settings)?> != settingsNumber)
{
showModalOk('WARNING', '<?php echo lang("settings_missing")?>');
}
function addInterface() function addInterface()
{ {
ipMask = $('#ipMask').val(); ipMask = $('#ipMask').val();
@@ -249,9 +256,11 @@ echo "<script>if(".count($settings)." != 46)alert('".lang("settings_missing")."'
full = ipMask + " --interface=" + ipInterface; full = ipMask + " --interface=" + ipInterface;
console.log(full)
if(ipMask == "" || ipInterface == "") if(ipMask == "" || ipInterface == "")
{ {
modalDefaultOK ('Validation error', 'Specify both, the network mask and the interface'); showModalOk ('Validation error', 'Specify both, the network mask and the interface');
} else { } else {
$('#SCAN_SUBNETS').append($('<option disabled></option>').attr('value', full).text(full)); $('#SCAN_SUBNETS').append($('<option disabled></option>').attr('value', full).text(full));
@@ -300,11 +309,15 @@ echo "<script>if(".count($settings)." != 46)alert('".lang("settings_missing")."'
?> ?>
console.log(settingsArray); console.log(settingsArray);
return settingsArray; return settingsArray;
} }
function saveSettings() {
function saveSettings() { if(<?php echo count($settings)?> != settingsNumber)
$.ajax({ {
showModalOk('WARNING', '<?php echo lang("settings_missing")?>');
} else
{
$.ajax({
method: "POST", method: "POST",
url: "../php/server/util.php", url: "../php/server/util.php",
data: { function: 'savesettings', settings: collectSettings() }, data: { function: 'savesettings', settings: collectSettings() },
@@ -312,7 +325,9 @@ echo "<script>if(".count($settings)." != 46)alert('".lang("settings_missing")."'
// $("#result").html(data); // $("#result").html(data);
// console.log(data); // console.log(data);
showModalOk ('Result', data ); showModalOk ('Result', data );
} }
}) });
}
} }
</script> </script>