diff --git a/back/pialert.py b/back/pialert.py
index 5c9de76b..4db13c82 100755
--- a/back/pialert.py
+++ b/back/pialert.py
@@ -253,7 +253,7 @@ def importConfig ():
# Specify globals so they can be overwritten with the new config
global lastTimeImported, mySettings
# General
- global ENABLE_ARPSCAN, SCAN_SUBNETS, PRINT_LOG, TIMEZONE, PIALERT_WEB_PROTECTION, PIALERT_WEB_PASSWORD, INCLUDED_SECTIONS, SCAN_CYCLE_MINUTES, DAYS_TO_KEEP_EVENTS, REPORT_DASHBOARD_URL
+ global ENABLE_ARPSCAN, SCAN_SUBNETS, PRINT_LOG, TIMEZONE, PIALERT_WEB_PROTECTION, PIALERT_WEB_PASSWORD, INCLUDED_SECTIONS, SCAN_CYCLE_MINUTES, DAYS_TO_KEEP_EVENTS, REPORT_DASHBOARD_URL, DIG_GET_IP_ARG
# Email
global REPORT_MAIL, SMTP_SERVER, SMTP_PORT, REPORT_TO, REPORT_FROM, SMTP_SKIP_LOGIN, SMTP_USER, SMTP_PASS, SMTP_SKIP_TLS
# Webhooks
@@ -300,6 +300,7 @@ def importConfig ():
SCAN_CYCLE_MINUTES = ccd('SCAN_CYCLE_MINUTES', 5 , c_d, 'Scan cycle delay (m)', 'integer', '', 'General')
DAYS_TO_KEEP_EVENTS = ccd('DAYS_TO_KEEP_EVENTS', 90 , c_d, 'Delete events days', 'integer', '', 'General')
REPORT_DASHBOARD_URL = ccd('REPORT_DASHBOARD_URL', 'http://pi.alert/' , c_d, 'PiAlert URL', 'text', '', 'General')
+ DIG_GET_IP_ARG = ccd('DIG_GET_IP_ARG', '-4 myip.opendns.com @resolver1.opendns.com' , c_d, 'DIG arguments', 'text', '', 'General')
# Email
REPORT_MAIL = ccd('REPORT_MAIL', False , c_d, 'Enable email', 'boolean', '', 'Email', ['test'])
@@ -629,19 +630,12 @@ def check_internet_IP ():
def get_internet_IP ():
# BUGFIX #46 - curl http://ipv4.icanhazip.com repeatedly is very slow
# Using 'dig'
- dig_args = ['dig', '+short', '-4', 'myip.opendns.com', '@resolver1.opendns.com']
+ dig_args = ['dig', '+short'] + DIG_GET_IP_ARG.strip().split()
try:
cmd_output = subprocess.check_output (dig_args, universal_newlines=True)
except subprocess.CalledProcessError as e:
file_print(e.output)
cmd_output = '' # no internet
-
-
- ## BUGFIX #12 - Query IPv4 address (not IPv6)
- ## Using 'curl' instead of 'dig'
- ## curl_args = ['curl', '-s', 'https://diagnostic.opendns.com/myip']
- #curl_args = ['curl', '-s', QUERY_MYIP_SERVER]
- #cmd_output = subprocess.check_output (curl_args, universal_newlines=True)
# Check result is an IP
IP = check_IP_format (cmd_output)
diff --git a/front/deviceDetails.php b/front/deviceDetails.php
index e9823909..001a479a 100755
--- a/front/deviceDetails.php
+++ b/front/deviceDetails.php
@@ -766,7 +766,7 @@ function main () {
initializeCalendar();
// Read Cookies
- devicesList = getCookie('devicesList');
+ devicesList = getCache('devicesList');
if (devicesList != '') {
devicesList = JSON.parse (devicesList);
} else {
@@ -923,22 +923,22 @@ function writeDropdownHtml(dropdownId, dropdownHtmlContent)
HTMLelement.innerHTML += dropdownHtmlContent;
}
// -----------------------------------------------------------------------------
-function getCache(key)
-{
- // check cache
- if(sessionStorage.getItem(key))
- {
- return sessionStorage.getItem(key);
- } else
- {
- return "";
- }
-}
-// -----------------------------------------------------------------------------
-function setCache(key, data)
-{
- sessionStorage.setItem(key, data);
-}
+// function getCache(key)
+// {
+// // check cache
+// if(sessionStorage.getItem(key))
+// {
+// return sessionStorage.getItem(key);
+// } else
+// {
+// return "";
+// }
+// }
+// // -----------------------------------------------------------------------------
+// function setCache(key, data)
+// {
+// sessionStorage.setItem(key, data);
+// }
// -----------------------------------------------------------------------------
function initializeComboSkipRepeated () {
diff --git a/front/devices.php b/front/devices.php
index 811a6fb7..14ebdcfe 100755
--- a/front/devices.php
+++ b/front/devices.php
@@ -341,11 +341,11 @@ function initializeDatatable () {
$('#tableDevices').on( 'order.dt', function () {
setParameter (parTableOrder, JSON.stringify (table.order()) );
- setCookie ('devicesList', getDevicesFromTable(table) );
+ setCache ('devicesList', getDevicesFromTable(table) );
} );
$('#tableDevices').on( 'search.dt', function () {
- setCookie ('devicesList', getDevicesFromTable(table) );
+ setCache ('devicesList', getDevicesFromTable(table) );
} );
};
diff --git a/front/js/pialert_common.js b/front/js/pialert_common.js
index c989916b..8ff73acb 100755
--- a/front/js/pialert_common.js
+++ b/front/js/pialert_common.js
@@ -16,21 +16,30 @@ var emptyArr = ['undefined', "", undefined, null];
// get: (searchParams, prop) => searchParams.get(prop.toString()),
// });
+
+// -----------------------------------------------------------------------------
+// Simple session cache withe expiration managed via cookies
+// -----------------------------------------------------------------------------
function getCache(key)
{
// check cache
if(sessionStorage.getItem(key))
{
- return sessionStorage.getItem(key);
- } else
- {
- return "";
+ // check if not expired
+ if(getCookie(key + '_session_expiry') != "")
+ {
+ return sessionStorage.getItem(key);
+ }
}
+
+ return "";
}
-function setCache(key, data)
+// -----------------------------------------------------------------------------
+function setCache(key, data, expirationMinutes='')
{
sessionStorage.setItem(key, data);
+ setCookie (key + '_session_expiry', 'OK', expirationMinutes='')
}
@@ -40,7 +49,7 @@ function setCookie (cookie, value, expirationMinutes='') {
var expires = '';
if (typeof expirationMinutes === 'number') {
expires = ';expires=' + new Date(Date.now() + expirationMinutes *60*1000).toUTCString();
- }
+ }
// Save Cookie
document.cookie = cookie + "=" + value + expires;
@@ -87,7 +96,8 @@ function deleteAllCookies() {
}
-
+// -----------------------------------------------------------------------------
+// Modal dialog handling
// -----------------------------------------------------------------------------
function showModalOk (title, message, callbackFunction = null) {
// set captions
@@ -170,13 +180,6 @@ function modalWarningOK () {
}, 100);
}
-// -----------------------------------------------------------------------------
-// remove unnecessary lines from the result
-function sanitize(data)
-{
- return data.replace(/(\r\n|\n|\r)/gm,"").replace(/[^\x00-\x7F]/g, "")
-}
-
// -----------------------------------------------------------------------------
function showMessage (textMessage="") {
if (textMessage.toLowerCase().includes("error") ) {
@@ -194,6 +197,15 @@ function showMessage (textMessage="") {
}
+// -----------------------------------------------------------------------------
+// General utilities
+// -----------------------------------------------------------------------------
+// remove unnecessary lines from the result
+function sanitize(data)
+{
+ return data.replace(/(\r\n|\n|\r)/gm,"").replace(/[^\x00-\x7F]/g, "")
+}
+
// -----------------------------------------------------------------------------
function setParameter (parameter, value) {
// Retry
diff --git a/front/php/templates/language/en_us.php b/front/php/templates/language/en_us.php
index 0b6c988d..7e745f75 100755
--- a/front/php/templates/language/en_us.php
+++ b/front/php/templates/language/en_us.php
@@ -485,6 +485,8 @@ the arp-scan will take hours to complete instead of seconds.
'DAYS_TO_KEEP_EVENTS_description' => 'This is a maintenance setting. This specifies the number of days worth of event entries that will be kept. All older events will be deleted periodically.',
'REPORT_DASHBOARD_URL_name' => 'Pi.Alert URL',
'REPORT_DASHBOARD_URL_description' => 'This URL is used as the base for generating links in the emails. Enter full URL starting with http:// including the port number (no trailig slash /).',
+'DIG_GET_IP_ARG_name' => 'Internet IP discovery',
+'DIG_GET_IP_ARG_description' => 'Change the dig utility arguments if you have issues resolving your Internet IP. Arguments are added at the end of the following command: dig +short .',
//Email
'REPORT_MAIL_name' => 'Enable email',
diff --git a/front/settings.php b/front/settings.php
index 6e7a6b37..61983379 100644
--- a/front/settings.php
+++ b/front/settings.php
@@ -286,7 +286,7 @@ CommitDB();