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

@@ -149,7 +149,10 @@
<div class="form-group">
<label class="col-sm-3 control-label"><?php echo lang('DevDetail_MainInfo_Name');?></label>
<div class="col-sm-9">
<input class="form-control" id="txtName" type="text" value="--">
<div class="input-group">
<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>
@@ -1388,37 +1391,10 @@ function recordSwitch(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)
{
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!
// mac = params.mac;
mac = devicesList[pos].mac.toString();
// Save Changes
// if ( ! document.getElementById('btnSave').hasAttribute('disabled') ) {
// setDeviceData (direction, recordSwitch);
// }
getDeviceData (true);
// reload current tab
@@ -1681,8 +1652,8 @@ function loadNmap()
listData.forEach(function (item, index) {
tableRows += '<tr class="deviceSpecific"><td>'
+item.Index+'</td><td>'
+item.Time+'</td><td>'
+item.Port+'</td><td>'
+item.Time+'</td><td><a href="http://'+item.IP+':'+item.Port.split('/')[0]+'" target="_blank">'
+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.Service+'</td><td>'
+'<div class="input-group">\
@@ -1790,6 +1761,7 @@ function loadPholus()
// });
// }
//-----------------------------------------------------------------------------------
function initTable(tableId, mac){
@@ -1821,30 +1793,32 @@ function initTable(tableId, mac){
// Processing
'processing' : true,
'language' : {
processing: '<table><td width="130px" align="middle">Loading...</td>'+
'<td><i class="ion ion-ios-loop-strong fa-spin fa-2x fa-fw">'+
'</td></table>',
emptyTable: 'No data',
"lengthMenu": "<?php echo lang('Events_Tablelenght');?>",
"search": "<?php echo lang('Events_Searchbox');?>: ",
"paginate": {
"next": "<?php echo lang('Events_Table_nav_next');?>",
"previous": "<?php echo lang('Events_Table_nav_prev');?>"
},
"info": "<?php echo lang('Events_Table_info');?>",
}
});
processing: '<table><td width="130px" align="middle">Loading...</td>'+
'<td><i class="ion ion-ios-loop-strong fa-spin fa-2x fa-fw">'+
'</td></table>',
emptyTable: 'No data',
"lengthMenu": "<?php echo lang('Events_Tablelenght');?>",
"search": "<?php echo lang('Events_Searchbox');?>: ",
"paginate": {
"next": "<?php echo lang('Events_Table_nav_next');?>",
"previous": "<?php echo lang('Events_Table_nav_prev');?>"
},
"info": "<?php echo lang('Events_Table_info');?>",
}
});
$("#"+tableId).attr("data-mac", mac)
$("#"+tableId).attr("data-mac", mac)
// Save Parameters rows & order when changed
$('#'+tableId).on( 'length.dt', function ( e, settings, len ) {
setParameter (parSessionsRows, len);
// Save Parameters rows & order when changed
$('#'+tableId).on( 'length.dt', function ( e, settings, len ) {
setParameter (parSessionsRows, len);
} );
} );
}
//-----------------------------------------------------------------------------------
window.onload = function async()
{
initializeTabsNew();
@@ -1852,6 +1826,8 @@ window.onload = function async()
reloadTab();
}
//-----------------------------------------------------------------------------------
function reloadTab()
{
// tab loaded without switching
@@ -1866,9 +1842,11 @@ function reloadTab()
}
}
//-----------------------------------------------------------------------------------
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)
{
return data.replace(/(\r\n|\n|\r)/gm,"").replace(/[^\x00-\x7F]/g, "")
@@ -205,12 +205,12 @@ function setParameter (parameter, value) {
sleep (200);
$.get('php/server/parameters.php?action=set&parameter=' + parameter +
'&value='+ value,
function(data) {
if (data != "OK") {
// alert (data);
} else {
// alert ("OK. Second attempt");
};
function(data) {
if (data != "OK") {
// alert (data);
} else {
// alert ("OK. Second attempt");
};
} );
};
} );
@@ -219,18 +219,22 @@ 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 },
method: "GET",
url: "php/server/devices.php",
data: { action: 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;
if(sanitize(data) == 'OK')
{
showMessage("Saved")
// Remove navigation prompt "Are you sure you want to leave..."
window.onbeforeunload = null;
} else
{
showMessage("ERROR")
}
}
});

View File

@@ -56,7 +56,8 @@
case 'getGroups': getGroups(); break;
case 'getLocations': getLocations(); break;
case 'getPholus': getPholus(); break;
case 'getNmap': getNmap(); break;
case 'getNmap': getNmap(); break;
case 'saveNmapPort': saveNmapPort(); break;
default: logServerConsole ('Action: '. $action); break;
}
@@ -145,7 +146,6 @@ function getDeviceData() {
//------------------------------------------------------------------------------
function setDeviceData() {
global $db;
global $pia_lang;
// sql
$sql = 'UPDATE Devices SET
@@ -184,7 +184,6 @@ function setDeviceData() {
//------------------------------------------------------------------------------
function deleteDevice() {
global $db;
global $pia_lang;
// sql
$sql = 'DELETE FROM Devices WHERE dev_MAC="' . $_REQUEST['mac'] .'"';
@@ -203,8 +202,7 @@ function deleteDevice() {
// Delete all devices with empty MAC addresses
//------------------------------------------------------------------------------
function deleteAllWithEmptyMACs() {
global $db;
global $pia_lang;
global $db;
// sql
$sql = 'DELETE FROM Devices WHERE dev_MAC=""';
@@ -223,8 +221,7 @@ function deleteAllWithEmptyMACs() {
// Delete all devices with empty MAC addresses
//------------------------------------------------------------------------------
function deleteUnknownDevices() {
global $db;
global $pia_lang;
global $db;
// sql
$sql = 'DELETE FROM Devices WHERE dev_Name="(unknown)"';
@@ -244,7 +241,6 @@ function deleteUnknownDevices() {
//------------------------------------------------------------------------------
function deleteDeviceEvents() {
global $db;
global $pia_lang;
// sql
$sql = 'DELETE FROM Events WHERE eve_MAC="' . $_REQUEST['mac'] .'"';
@@ -264,7 +260,6 @@ function deleteDeviceEvents() {
//------------------------------------------------------------------------------
function deleteAllDevices() {
global $db;
global $pia_lang;
// sql
$sql = 'DELETE FROM Devices';
@@ -284,8 +279,6 @@ function deleteAllDevices() {
//------------------------------------------------------------------------------
function deleteEvents() {
global $db;
global $pia_lang;
// sql
$sql = 'DELETE FROM Events';
// execute sql
@@ -304,7 +297,6 @@ function deleteEvents() {
//------------------------------------------------------------------------------
function deleteEvents30() {
global $db;
global $pia_lang;
// sql
$sql = "DELETE FROM Events WHERE eve_DateTime <= date('now', '-30 day')";
@@ -324,7 +316,6 @@ function deleteEvents30() {
//------------------------------------------------------------------------------
function deleteActHistory() {
global $db;
global $pia_lang;
// sql
$sql = 'DELETE FROM Online_History';
@@ -346,8 +337,7 @@ function PiaBackupDBtoArchive() {
// prepare fast Backup
$file = '../../../db/pialert.db';
$newfile = '../../../db/pialert.db.latestbackup';
global $pia_lang;
// copy files as a fast Backup
if (!copy($file, $newfile)) {
echo lang('BackDevices_Backup_CopError');
@@ -374,8 +364,7 @@ function PiaBackupDBtoArchive() {
function PiaRestoreDBfromArchive() {
// prepare fast Backup
$file = '../../../db/pialert.db';
$oldfile = '../../../db/pialert.db.prerestore';
global $pia_lang;
$oldfile = '../../../db/pialert.db.prerestore';
// copy files as a fast Backup
if (!copy($file, $oldfile)) {
@@ -399,8 +388,7 @@ function PiaRestoreDBfromArchive() {
//------------------------------------------------------------------------------
// Purge Backups
//------------------------------------------------------------------------------
function PiaPurgeDBBackups() {
global $pia_lang;
function PiaPurgeDBBackups() {
$Pia_Archive_Path = '../../../db';
$Pia_Backupfiles = array();
@@ -485,8 +473,7 @@ function ImportCSV() {
if (file_exists($file)) {
global $db;
global $pia_lang;
global $db;
$error = "";
@@ -545,8 +532,7 @@ function ImportCSV() {
// Toggle Dark/Light Themes
//------------------------------------------------------------------------------
function PiaEnableDarkmode() {
$file = '../../../db/setting_darkmode';
global $pia_lang;
$file = '../../../db/setting_darkmode';
if (file_exists($file)) {
echo lang('BackDevices_darkmode_disabled');
@@ -948,7 +934,8 @@ function getNmap() {
throw new Exception('Invalid mac address');
}
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
$tableData = array();
@@ -963,6 +950,7 @@ function getNmap() {
'Time' => $row['Time'],
'State' => $row['State'],
'Service' => $row['Service'],
'IP' => $row['dev_LastIP'],
'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
//------------------------------------------------------------------------------

View File

@@ -10,16 +10,28 @@
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/language/lang.php';
// require '/home/pi/pialert/front/php/server/db.php';
$FUNCTION = [];
$SETTINGS = [];
// displayMessage($_REQUEST);
// echo 'hereeeeeeeeeeeeeeeeeeeeee1';
// init request params
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'];
displayMessage($FUNCTION);
}
if(array_key_exists('settings', $_REQUEST) != FALSE)
@@ -36,10 +48,7 @@ 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
@@ -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) {