diff --git a/docker-compose.yml b/docker-compose.yml index 082c5fac..74d02ec6 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,9 +6,9 @@ services: network_mode: "host" restart: unless-stopped volumes: - - ${APP_DATA_LOCATION}/pialert/config:/home/pi/pialert/config + - ${APP_DATA_LOCATION}/pialert/config2:/home/pi/pialert/config # - ${APP_DATA_LOCATION}/pialert/db/pialert.db:/home/pi/pialert/db/pialert.db - - ${APP_DATA_LOCATION}/pialert/db:/home/pi/pialert/db + - ${APP_DATA_LOCATION}/pialert/db2:/home/pi/pialert/db # (optional) map an empty file with the name 'setting_darkmode' if you want to force the dark mode on container rebuilt - ${APP_DATA_LOCATION}/pialert/db/setting_darkmode:/home/pi/pialert/db/setting_darkmode # (optional) useful for debugging if you have issues setting up the container diff --git a/front/deviceDetails.php b/front/deviceDetails.php index e5e8e822..103b9409 100755 --- a/front/deviceDetails.php +++ b/front/deviceDetails.php @@ -686,7 +686,7 @@ if ($ENABLED_DARKMODE === True) { mac = getMac() // can also be rowID!! not only mac var devicesList = []; // this will contain a list the database row IDs of the devices ordered by the position displayed in the UI - var pos = -1; + var pos = -1; var parPeriod = 'Front_Details_Period'; var parTab = 'Front_Details_Tab'; var parSessionsRows = 'Front_Details_Sessions_Rows'; @@ -783,13 +783,6 @@ function main () { } }); - // Ask before exit without saving data - window.onbeforeunload = function(){ - if ( ! document.getElementById('btnSave').hasAttribute('disabled') ) { - return 'Are you sure you want to discard unsaved changes?'; - } - }; - }); }); @@ -841,7 +834,7 @@ function initializeiCheck () { setParameter (parEventsHide, event.currentTarget.checked); } else { // Activate save & restore - activateSaveRestoreData(); + // activateSaveRestoreData(); // Ask skip notifications // if (event.currentTarget.id == 'chkArchived' ) { @@ -1342,8 +1335,7 @@ function getDeviceData (readAllData=false) { if (deviceData['dev_RandomMAC'] == 1) {$('#iconRandomMACactive').removeClass ('hidden'); $('#iconRandomMACinactive').addClass ('hidden'); } else {$('#iconRandomMACactive').addClass ('hidden'); - $('#iconRandomMACinactive').removeClass ('hidden'); }; - deactivateSaveRestoreData (); + $('#iconRandomMACinactive').removeClass ('hidden'); }; } // Check if device is part of the devicesList @@ -1388,8 +1380,49 @@ function getDeviceData (readAllData=false) { // cycle between devices function recordSwitch(direction) { - var recordToSave = null; + if(somethingChanged) + { + showModalDefaultStrParam ('Unsaved changes', 'Do you want to discard your changes?', + '', '', performSwitch, direction); + } else + { + performSwitch(direction) + } + // // update the global position in the devices list variable 'pos' + // if(direction == "next") + // { + // // Next Record + // if (pos < (devicesList.length-1) ) { + // pos++; + // } + // }else if (direction == "prev") + // { + // if (pos > 0) { + // pos--; + // } + // } + + // // get new mac from the devicesList. Don't change to the commented out line below, the mac query string in the URL isn't updated yet! + // // mac = params.mac; + // mac = devicesList[pos].mac.toString(); + + // // Save Changes + // // if ( ! document.getElementById('btnSave').hasAttribute('disabled') ) { + // // setDeviceData (direction, recordSwitch); + // // } + + // getDeviceData (true); + + // // reload current tab + // reloadTab() + +} + +function performSwitch(direction) +{ + somethingChanged = false; + // update the global position in the devices list variable 'pos' if(direction == "next") { @@ -1404,20 +1437,21 @@ function recordSwitch(direction) { } } + console.log('here ' + pos) + // get new mac from the devicesList. Don't change to the commented out line below, the mac query string in the URL isn't updated yet! // mac = params.mac; mac = devicesList[pos].mac.toString(); // Save Changes - if ( ! document.getElementById('btnSave').hasAttribute('disabled') ) { - setDeviceData (direction, recordSwitch); - } + // if ( ! document.getElementById('btnSave').hasAttribute('disabled') ) { + // setDeviceData (direction, recordSwitch); + // } getDeviceData (true); // reload current tab reloadTab() - } // ----------------------------------------------------------------------------- @@ -1447,9 +1481,7 @@ function setDeviceData (direction='', refreshCallback='') { + '&newdevice=' + ($('#chkNewDevice')[0].checked * 1) + '&archived=' + ($('#chkArchived')[0].checked * 1) , function(msg) { - - // deactivate button - deactivateSaveRestoreData (); + showMessage (msg); // clear session storage @@ -1459,6 +1491,10 @@ function setDeviceData (direction='', refreshCallback='') { setCache("#dropdownLocation",""); setCache("#dropdownNetworkNodeMac",""); + // Remove navigation prompt "Are you sure you want to leave..." + window.onbeforeunload = null; + somethingChanged = false; + // Callback fuction if (typeof refreshCallback == 'function') { refreshCallback(direction); @@ -1491,8 +1527,7 @@ function skipNotifications () { } // Set cycle 0 - $('#txtScanCycle').val ('no'); - activateSaveRestoreData(); + $('#txtScanCycle').val ('no'); } // ----------------------------------------------------------------------------- @@ -1581,32 +1616,13 @@ function getDeviceEvents () { // ----------------------------------------------------------------------------- // Activate save & restore on any value change -$(document).on('input', 'input:text', function() { - activateSaveRestoreData(); +$(document).on('input', 'input:text', function() { + settingsChanged(); }); -$(document).on('input', 'textarea', function() { - activateSaveRestoreData(); -}); - - -// ----------------------------------------------------------------------------- -function activateSaveRestoreData () { - $('#btnRestore').removeAttr ('disabled'); - $('#btnSave').removeAttr ('disabled'); -} - - -function deactivateSaveRestoreData () { - //$('#btnRestore').attr ('disabled',''); - $('#btnSave').attr ('disabled',''); -} - - // ----------------------------------------------------------------------------- function setTextValue (textElement, textValue) { - $('#'+textElement).val (textValue); - activateSaveRestoreData (); + $('#'+textElement).val (textValue); } // ----------------------------------------------------------------------------- @@ -1647,10 +1663,7 @@ function initializeTabsNew () { function loadNmap() { - // console.log(mac) - // console.log('php/server/devices.php?action=getPholus&mac='+ mac) - - $(".deviceSpecific").remove(); + $(".deviceSpecific").remove(); // remove any previous data listed in teh table $.get('php/server/devices.php?action=getNmap&mac='+ mac, function(data) { @@ -1660,20 +1673,26 @@ function loadNmap() { var listData = JSON.parse(data); var order = 1; - - // console.log(listData) - // console.log(listData[0].MAC) tableRows = ""; // for each item listData.forEach(function (item, index) { - tableRows += ''+item.Index+''+item.Time+''+item.Port+''+item.State+''+item.Service+''+item.Extra+''; + tableRows += '' + +item.Index+'' + +item.Time+'' + +item.Port+'' + +item.State+'' + +item.Service+'' + +'
\ + \ + \ +
\ + '; }); - $("#tableNmapBody").html($("#tableNmapBody").html()+tableRows); - // $("#tablePholusPlc").attr("style", "display:none"); + $("#tableNmapBody").html($("#tableNmapBody").html()+tableRows); $("#tableNmapPlc").hide(); } else @@ -1689,10 +1708,7 @@ function loadNmap() function loadPholus() { - // console.log(mac) - // console.log('php/server/devices.php?action=getPholus&mac='+ mac) - - $(".deviceSpecific").remove(); + $(".deviceSpecific").remove(); // remove any previous data listed in teh table $.get('php/server/devices.php?action=getPholus&mac='+ mac, function(data) { @@ -1702,20 +1718,15 @@ function loadPholus() { var listData = JSON.parse(data); var order = 1; - - // console.log(listData) - - // console.log(listData[0].MAC) tableRows = ""; // for each item listData.forEach(function (item, index) { - tableRows += ''+item.Index+''+item.Info+''+item.Time+''+item.IP_v4_or_v6+''+item.Record_Type+''+item.Value+''+item.Extra+''; + tableRows += ''+item.Index+''+item.Info+''+item.Time+''+item.IP_v4_or_v6+''+item.Record_Type+''+item.Value+''+ item.Extra +''; }); - $("#tablePholusBody").html($("#tablePholusBody").html()+tableRows); - // $("#tablePholusPlc").attr("style", "display:none"); + $("#tablePholusBody").html($("#tablePholusBody").html()+tableRows); $("#tablePholusPlc").hide(); } else @@ -1775,8 +1786,6 @@ function loadPholus() // // $(".deviceSpecific").remove(); // } - - // }); // } @@ -1857,5 +1866,10 @@ function reloadTab() } } +function saveNmapPort(index) +{ + saveData('saveNmapPort',index , $('#port_'+index).val()) +} + diff --git a/front/js/pialert_common.js b/front/js/pialert_common.js index 644cdde1..3c97787d 100755 --- a/front/js/pialert_common.js +++ b/front/js/pialert_common.js @@ -117,6 +117,24 @@ function showModalDefault (title, message, btnCancel, btnOK, callbackFunction) { $('#modal-default').modal('show'); } +// ----------------------------------------------------------------------------- + +function showModalDefaultStrParam (title, message, btnCancel, btnOK, callbackFunction, param='') { + // set captions + $('#modal-str-title').html (title); + $('#modal-str-message').html (message); + $('#modal-str-cancel').html (btnCancel); + $('#modal-str-OK').html (btnOK); + $("#modal-str-OK").off("click"); //remove existing handlers + $('#modal-str-OK').on('click', function (){ + $('#modal-str').modal('hide'); + callbackFunction(param) + }) + + // Show modal + $('#modal-str').modal('show'); +} + // ----------------------------------------------------------------------------- function showModalWarning (title, message, btnCancel, btnOK, callbackFunction) { // set captions @@ -199,6 +217,25 @@ function setParameter (parameter, value) { } +// ----------------------------------------------------------------------------- +function saveData(functionName, index, value) { + + console.log(functionName + ' ' + index +' ' + value) + + $.ajax({ + method: "POST", + url: "/home/pi/pialert/front/php/server/util.php", + data: { function: functionName, index: index, value:value }, + success: function(data) { + // console.log(data); + showModalOk ('Result', data ); + // Remove navigation prompt "Are you sure you want to leave..." + window.onbeforeunload = null; + } + }); + +} + // ----------------------------------------------------------------------------- function sleep(milliseconds) { const date = Date.now(); @@ -208,6 +245,16 @@ function sleep(milliseconds) { } while (currentDate - date < milliseconds); } +// --------------------------------------------------------- +somethingChanged = false; +function settingsChanged() +{ + somethingChanged = true; + // Enable navigation prompt ... "Are you sure you want to leave..." + window.onbeforeunload = function() { + return true; + }; +} // ----------------------------------------------------------------------------- function translateHTMLcodes (text) { diff --git a/front/php/server/util.php b/front/php/server/util.php index 8c7f25f4..8aaf4d91 100755 --- a/front/php/server/util.php +++ b/front/php/server/util.php @@ -12,6 +12,7 @@ require '/home/pi/pialert/front/php/templates/timezone.php'; require '/home/pi/pialert/front/php/templates/skinUI.php'; + $FUNCTION = []; $SETTINGS = []; @@ -35,6 +36,10 @@ elseif ($FUNCTION == 'cleanLog') { cleanLog($SETTINGS); } +elseif ($FUNCTION == 'saveNmapPort' && array_key_exists('index', $_REQUEST) && array_key_exists('value', $_REQUEST) ) +{ + saveNmapPort($_REQUEST['index'], $_REQUEST['value']); +} //------------------------------------------------------------------------------ // Formatting data functions @@ -281,6 +286,29 @@ function saveSettings() } +// ------------------------------------------------------------------------------------------- +function saveNmapPort($portIndex, $value) +{ + if(is_integer($portIndex)) + { + $value = escapeString($value); + + // sql + $sql = 'UPDATE Nmap_Scan SET Extra = "'. quotes($value) .'" WHERE Index="' . $portIndex .'"'; + // update Data + $result = $db->query($sql); + + // check result + if ($result == TRUE) { + echo lang('Gen_Upd'); + } else { + echo lang('Gen_Upd_Fail')."\n\n$sql \n\n". $db->lastErrorMsg(); + } + } + echo "asdasdasasd"; +} +// ------------------------------------------------------------------------------------------- + function getString ($codeName, $default) { $result = lang($codeName); diff --git a/front/php/templates/language/en_us.php b/front/php/templates/language/en_us.php index 7881b00a..f6b2d5ac 100755 --- a/front/php/templates/language/en_us.php +++ b/front/php/templates/language/en_us.php @@ -20,6 +20,8 @@ $lang['en_us'] = array( 'Gen_Restore' => 'Run Restore', 'Gen_Switch' => 'Switch', 'Gen_AreYouSure' => 'Are you sure?', +'Gen_Upd' => 'Updated successfully', +'Gen_Upd_Fail' => 'Update failed', ////////////////////////////////////////////////////////////////// // Login Page - Update by @TeroRERO 03ago2022 diff --git a/front/php/templates/notification.php b/front/php/templates/notification.php index e7e757e5..9728287d 100755 --- a/front/php/templates/notification.php +++ b/front/php/templates/notification.php @@ -49,6 +49,28 @@ + + + diff --git a/front/settings.php b/front/settings.php index a3e2ecaf..0748ce0d 100644 --- a/front/settings.php +++ b/front/settings.php @@ -383,16 +383,6 @@ CommitDB(); }); } - // --------------------------------------------------------- - - function settingsChanged() - { - // Enable navigation prompt ... "Are you sure you want to leave..." - window.onbeforeunload = function() { - return true; - }; - } -