saving port info + links

This commit is contained in:
Jokob-sk
2023-01-06 21:16:01 +11:00
parent 09d9491354
commit c20b239351
5 changed files with 113 additions and 127 deletions

View File

@@ -695,11 +695,11 @@ def get_previous_internet_IP ():
sql.execute ("SELECT dev_LastIP FROM Devices WHERE dev_MAC = 'Internet' ") sql.execute ("SELECT dev_LastIP FROM Devices WHERE dev_MAC = 'Internet' ")
result = sql.fetchone() result = sql.fetchone()
if len(result) > 0 and type(result) is not None:
previous_IP = result[0]
commitDB() commitDB()
if result is not None and len(result) > 0 :
previous_IP = result[0]
# return previous IP # return previous IP
return previous_IP return previous_IP

View File

@@ -149,7 +149,10 @@
<div class="form-group"> <div class="form-group">
<label class="col-sm-3 control-label"><?php echo lang('DevDetail_MainInfo_Name');?></label> <label class="col-sm-3 control-label"><?php echo lang('DevDetail_MainInfo_Name');?></label>
<div class="col-sm-9"> <div class="col-sm-9">
<div class="input-group">
<input class="form-control" id="txtName" type="text" value="--"> <input class="form-control" id="txtName" type="text" value="--">
<span class="input-group-addon"><i class="fa fa-pencil drp-edit" onclick="editDrp('txtName');"></i></span>
</div>
</div> </div>
</div> </div>
@@ -1388,37 +1391,10 @@ function recordSwitch(direction) {
{ {
performSwitch(direction) 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) function performSwitch(direction)
{ {
somethingChanged = false; somethingChanged = false;
@@ -1437,17 +1413,12 @@ function performSwitch(direction)
} }
} }
console.log('here ' + pos) // 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! // 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 = params.mac;
mac = devicesList[pos].mac.toString(); mac = devicesList[pos].mac.toString();
// Save Changes
// if ( ! document.getElementById('btnSave').hasAttribute('disabled') ) {
// setDeviceData (direction, recordSwitch);
// }
getDeviceData (true); getDeviceData (true);
// reload current tab // reload current tab
@@ -1681,8 +1652,8 @@ function loadNmap()
listData.forEach(function (item, index) { listData.forEach(function (item, index) {
tableRows += '<tr class="deviceSpecific"><td>' tableRows += '<tr class="deviceSpecific"><td>'
+item.Index+'</td><td>' +item.Index+'</td><td>'
+item.Time+'</td><td>' +item.Time+'</td><td><a href="http://'+item.IP+':'+item.Port.split('/')[0]+'" target="_blank">'
+item.Port+'</td><td>' +item.Port+'</a><a href="https://'+item.IP+':'+item.Port.split('/')[0]+'" target="_blank"><span style="padding-left:5px"><i class="fa fa-lock "></i></a></span></td><td>'
+item.State+'</td><td>' +item.State+'</td><td>'
+item.Service+'</td><td>' +item.Service+'</td><td>'
+'<div class="input-group">\ +'<div class="input-group">\
@@ -1790,6 +1761,7 @@ function loadPholus()
// }); // });
// } // }
//-----------------------------------------------------------------------------------
function initTable(tableId, mac){ function initTable(tableId, mac){
@@ -1845,6 +1817,8 @@ $('#'+tableId).on( 'length.dt', function ( e, settings, len ) {
} }
//-----------------------------------------------------------------------------------
window.onload = function async() window.onload = function async()
{ {
initializeTabsNew(); initializeTabsNew();
@@ -1852,6 +1826,8 @@ window.onload = function async()
reloadTab(); reloadTab();
} }
//-----------------------------------------------------------------------------------
function reloadTab() function reloadTab()
{ {
// tab loaded without switching // tab loaded without switching
@@ -1866,6 +1842,8 @@ function reloadTab()
} }
} }
//-----------------------------------------------------------------------------------
function saveNmapPort(index) function saveNmapPort(index)
{ {
saveData('saveNmapPort', index, $('#port_'+index).val()) saveData('saveNmapPort', index, $('#port_'+index).val())

View File

@@ -171,7 +171,7 @@ function modalWarningOK () {
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// remove unnecessary lines from the result
function sanitize(data) function sanitize(data)
{ {
return data.replace(/(\r\n|\n|\r)/gm,"").replace(/[^\x00-\x7F]/g, "") return data.replace(/(\r\n|\n|\r)/gm,"").replace(/[^\x00-\x7F]/g, "")
@@ -219,18 +219,22 @@ function setParameter (parameter, value) {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
function saveData(functionName, index, value) { function saveData(functionName, index, value) {
console.log(functionName + ' ' + index +' ' + value)
$.ajax({ $.ajax({
method: "POST", method: "GET",
url: "/home/pi/pialert/front/php/server/util.php", url: "php/server/devices.php",
data: { function: functionName, index: index, value:value }, data: { action: functionName, index: index, value:value },
success: function(data) { success: function(data) {
// console.log(data);
showModalOk ('Result', data ); if(sanitize(data) == 'OK')
{
showMessage("Saved")
// Remove navigation prompt "Are you sure you want to leave..." // Remove navigation prompt "Are you sure you want to leave..."
window.onbeforeunload = null; window.onbeforeunload = null;
} else
{
showMessage("ERROR")
}
} }
}); });

View File

@@ -57,6 +57,7 @@
case 'getLocations': getLocations(); break; case 'getLocations': getLocations(); break;
case 'getPholus': getPholus(); break; case 'getPholus': getPholus(); break;
case 'getNmap': getNmap(); break; case 'getNmap': getNmap(); break;
case 'saveNmapPort': saveNmapPort(); break;
default: logServerConsole ('Action: '. $action); break; default: logServerConsole ('Action: '. $action); break;
} }
@@ -145,7 +146,6 @@ function getDeviceData() {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
function setDeviceData() { function setDeviceData() {
global $db; global $db;
global $pia_lang;
// sql // sql
$sql = 'UPDATE Devices SET $sql = 'UPDATE Devices SET
@@ -184,7 +184,6 @@ function setDeviceData() {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
function deleteDevice() { function deleteDevice() {
global $db; global $db;
global $pia_lang;
// sql // sql
$sql = 'DELETE FROM Devices WHERE dev_MAC="' . $_REQUEST['mac'] .'"'; $sql = 'DELETE FROM Devices WHERE dev_MAC="' . $_REQUEST['mac'] .'"';
@@ -204,7 +203,6 @@ function deleteDevice() {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
function deleteAllWithEmptyMACs() { function deleteAllWithEmptyMACs() {
global $db; global $db;
global $pia_lang;
// sql // sql
$sql = 'DELETE FROM Devices WHERE dev_MAC=""'; $sql = 'DELETE FROM Devices WHERE dev_MAC=""';
@@ -224,7 +222,6 @@ function deleteAllWithEmptyMACs() {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
function deleteUnknownDevices() { function deleteUnknownDevices() {
global $db; global $db;
global $pia_lang;
// sql // sql
$sql = 'DELETE FROM Devices WHERE dev_Name="(unknown)"'; $sql = 'DELETE FROM Devices WHERE dev_Name="(unknown)"';
@@ -244,7 +241,6 @@ function deleteUnknownDevices() {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
function deleteDeviceEvents() { function deleteDeviceEvents() {
global $db; global $db;
global $pia_lang;
// sql // sql
$sql = 'DELETE FROM Events WHERE eve_MAC="' . $_REQUEST['mac'] .'"'; $sql = 'DELETE FROM Events WHERE eve_MAC="' . $_REQUEST['mac'] .'"';
@@ -264,7 +260,6 @@ function deleteDeviceEvents() {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
function deleteAllDevices() { function deleteAllDevices() {
global $db; global $db;
global $pia_lang;
// sql // sql
$sql = 'DELETE FROM Devices'; $sql = 'DELETE FROM Devices';
@@ -284,8 +279,6 @@ function deleteAllDevices() {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
function deleteEvents() { function deleteEvents() {
global $db; global $db;
global $pia_lang;
// sql // sql
$sql = 'DELETE FROM Events'; $sql = 'DELETE FROM Events';
// execute sql // execute sql
@@ -304,7 +297,6 @@ function deleteEvents() {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
function deleteEvents30() { function deleteEvents30() {
global $db; global $db;
global $pia_lang;
// sql // sql
$sql = "DELETE FROM Events WHERE eve_DateTime <= date('now', '-30 day')"; $sql = "DELETE FROM Events WHERE eve_DateTime <= date('now', '-30 day')";
@@ -324,7 +316,6 @@ function deleteEvents30() {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
function deleteActHistory() { function deleteActHistory() {
global $db; global $db;
global $pia_lang;
// sql // sql
$sql = 'DELETE FROM Online_History'; $sql = 'DELETE FROM Online_History';
@@ -346,7 +337,6 @@ function PiaBackupDBtoArchive() {
// prepare fast Backup // prepare fast Backup
$file = '../../../db/pialert.db'; $file = '../../../db/pialert.db';
$newfile = '../../../db/pialert.db.latestbackup'; $newfile = '../../../db/pialert.db.latestbackup';
global $pia_lang;
// copy files as a fast Backup // copy files as a fast Backup
if (!copy($file, $newfile)) { if (!copy($file, $newfile)) {
@@ -375,7 +365,6 @@ function PiaRestoreDBfromArchive() {
// prepare fast Backup // prepare fast Backup
$file = '../../../db/pialert.db'; $file = '../../../db/pialert.db';
$oldfile = '../../../db/pialert.db.prerestore'; $oldfile = '../../../db/pialert.db.prerestore';
global $pia_lang;
// copy files as a fast Backup // copy files as a fast Backup
if (!copy($file, $oldfile)) { if (!copy($file, $oldfile)) {
@@ -400,7 +389,6 @@ function PiaRestoreDBfromArchive() {
// Purge Backups // Purge Backups
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
function PiaPurgeDBBackups() { function PiaPurgeDBBackups() {
global $pia_lang;
$Pia_Archive_Path = '../../../db'; $Pia_Archive_Path = '../../../db';
$Pia_Backupfiles = array(); $Pia_Backupfiles = array();
@@ -486,7 +474,6 @@ function ImportCSV() {
if (file_exists($file)) { if (file_exists($file)) {
global $db; global $db;
global $pia_lang;
$error = ""; $error = "";
@@ -546,7 +533,6 @@ function ImportCSV() {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
function PiaEnableDarkmode() { function PiaEnableDarkmode() {
$file = '../../../db/setting_darkmode'; $file = '../../../db/setting_darkmode';
global $pia_lang;
if (file_exists($file)) { if (file_exists($file)) {
echo lang('BackDevices_darkmode_disabled'); echo lang('BackDevices_darkmode_disabled');
@@ -948,7 +934,8 @@ function getNmap() {
throw new Exception('Invalid mac address'); throw new Exception('Invalid mac address');
} }
else{ else{
$sql = 'SELECT * from Nmap_Scan where MAC ="'.$mac.'" '; // $sql = 'SELECT * from Nmap_Scan where MAC ="'.$mac.'" ';
$sql = 'select * from (select * from Nmap_Scan INNER JOIN Devices on Nmap_Scan.MAC = Devices.dev_MAC) where MAC = "'.$mac.'" ';
// array // array
$tableData = array(); $tableData = array();
@@ -963,6 +950,7 @@ function getNmap() {
'Time' => $row['Time'], 'Time' => $row['Time'],
'State' => $row['State'], 'State' => $row['State'],
'Service' => $row['Service'], 'Service' => $row['Service'],
'IP' => $row['dev_LastIP'],
'Extra' => $row['Extra']); 'Extra' => $row['Extra']);
} }
@@ -976,6 +964,33 @@ function getNmap() {
} }
} }
// -------------------------------------------------------------------------------------------
function saveNmapPort()
{
$portIndex = $_REQUEST['index'];
$value = $_REQUEST['value'];
if(is_integer((int)$portIndex))
{
global $db;
// sql
$sql = 'UPDATE Nmap_Scan SET "Extra" = "'. $value .'" WHERE "Index"=' . $portIndex ;
// update Data
$result = $db->query($sql);
// check result
if ($result == TRUE) {
echo 'OK';
} else {
echo 'KO';
}
}
// echo "asdasdasasd";
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Status Where conditions // Status Where conditions
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------

View File

@@ -10,16 +10,28 @@
require '/home/pi/pialert/front/php/templates/timezone.php'; require '/home/pi/pialert/front/php/templates/timezone.php';
require '/home/pi/pialert/front/php/templates/skinUI.php'; require '/home/pi/pialert/front/php/templates/skinUI.php';
// require '/home/pi/pialert/front/php/templates/language/lang.php';
// require '/home/pi/pialert/front/php/server/db.php';
$FUNCTION = []; $FUNCTION = [];
$SETTINGS = []; $SETTINGS = [];
// displayMessage($_REQUEST);
// echo 'hereeeeeeeeeeeeeeeeeeeeee1';
// init request params // init request params
if(array_key_exists('function', $_REQUEST) != FALSE) if(array_key_exists('function', $_REQUEST) != FALSE)
{ {
displayMessage(array_key_exists('function', $_REQUEST));
displayMessage(array_key_exists('index', $_REQUEST));
displayMessage(array_key_exists('value', $_REQUEST));
$FUNCTION = $_REQUEST['function']; $FUNCTION = $_REQUEST['function'];
displayMessage($FUNCTION);
} }
if(array_key_exists('settings', $_REQUEST) != FALSE) if(array_key_exists('settings', $_REQUEST) != FALSE)
@@ -36,10 +48,7 @@ elseif ($FUNCTION == 'cleanLog')
{ {
cleanLog($SETTINGS); cleanLog($SETTINGS);
} }
elseif ($FUNCTION == 'saveNmapPort' && array_key_exists('index', $_REQUEST) && array_key_exists('value', $_REQUEST) )
{
saveNmapPort($_REQUEST['index'], $_REQUEST['value']);
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Formatting data functions // Formatting data functions
@@ -287,27 +296,7 @@ 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) { function getString ($codeName, $default) {