mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
Fix Network scaling, DeviceDetials link, missing lang string, incorrectly mapped columns, default device values
This commit is contained in:
@@ -383,7 +383,7 @@ def importConfig ():
|
||||
lastTimeImported = time.time()
|
||||
|
||||
# Used to display a message in the UI when old (outdated) settings are loaded
|
||||
sql.execute ("""UPDATE Parameters set "par_Value" = ? where "par_ID" = "Back_Settings_Imported" """, (round(time.time() * 1000),))
|
||||
initOrSetParam("Back_Settings_Imported",(round(time.time() * 1000),) )
|
||||
|
||||
commitDB()
|
||||
|
||||
@@ -2840,6 +2840,9 @@ def upgradeDB ():
|
||||
AND name='Nmap_Scan';
|
||||
""").fetchone() == None
|
||||
|
||||
# Initialize Parameters if unavailable
|
||||
initOrSetParam('Back_App_State','Initializing')
|
||||
|
||||
# if nmapScanMissing == False:
|
||||
# # Re-creating Nmap_Scan table
|
||||
# sql.execute("DROP TABLE Nmap_Scan;")
|
||||
@@ -2860,7 +2863,13 @@ def upgradeDB ():
|
||||
);
|
||||
""")
|
||||
|
||||
# don't hog DB access
|
||||
commitDB ()
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
def initOrSetParam(parID, parValue):
|
||||
|
||||
sql.execute ("INSERT INTO Parameters(par_ID, par_Value) VALUES('"+str(parID)+"', '"+str(parValue)+"') ON CONFLICT(par_ID) DO UPDATE SET par_Value='"+str(parValue)+"' where par_ID='"+str(parID)+"'")
|
||||
|
||||
commitDB ()
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
@@ -2868,7 +2877,6 @@ def updateState(newState):
|
||||
|
||||
sql.execute ("UPDATE Parameters SET par_Value='"+ newState +"' WHERE par_ID='Back_App_State'")
|
||||
|
||||
# don't hog DB access
|
||||
commitDB ()
|
||||
|
||||
|
||||
@@ -3112,7 +3120,7 @@ def isNewVersion():
|
||||
if realeaseTimestamp > buildTimestamp + 600:
|
||||
file_print(" New version of the container available!")
|
||||
newVersionAvailable = True
|
||||
sql.execute ("UPDATE Parameters SET par_Value='"+ str(newVersionAvailable) +"' WHERE par_ID='Back_New_Version_Available'")
|
||||
initOrSetParam('Back_New_Version_Available', str(newVersionAvailable))
|
||||
|
||||
return newVersionAvailable
|
||||
|
||||
|
||||
@@ -192,9 +192,9 @@
|
||||
var parTableOrder = 'Front_Devices_Order';
|
||||
var tableRows = 10;
|
||||
var tableOrder = [[3,'desc'], [0,'asc']];
|
||||
var tableColumnVisible = [0,1,2,3,4,5,6,7,8,9,10,12,13,14];
|
||||
var columnsStr = '[0,1,2,3,4,5,6,7,8,9,10,12,13,14]';
|
||||
var tableColumnOrder = [0,1,2,3,4,5,6,7,8,9,10,12,13,14] ;
|
||||
var tableColumnVisible = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14];
|
||||
var columnsStr = '[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14]';
|
||||
var tableColumnOrder = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14] ;
|
||||
|
||||
// Read parameters & Initialize components
|
||||
main();
|
||||
@@ -461,7 +461,7 @@ function getDevicesFromTable(table)
|
||||
rowIDs.map(function(rowID, index){
|
||||
result.push({
|
||||
"rowid": rowID,
|
||||
"mac":rowMACs[index],
|
||||
"mac" : rowMACs[index],
|
||||
"name" : rowNames[index],
|
||||
"type" : rowTypes[index],
|
||||
"icon" : rowIcons[index],
|
||||
|
||||
@@ -454,7 +454,7 @@
|
||||
<script src="js/pialert_common.js"></script>
|
||||
|
||||
|
||||
<script>
|
||||
<script defer>
|
||||
// ---------------------------------------------------------------------------
|
||||
// Tree functionality
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -580,7 +580,11 @@
|
||||
renderNode: nodeData => {
|
||||
|
||||
// calculate the font size of the leaf nodes to fit everything into the tree area
|
||||
var fontSize = (nodeData.data.hasChildren) ? "" : "font-size:"+((600/(20*leafNodesCount)).toFixed(2))+"em;";
|
||||
leafNodesCount == 0 ? 1 : leafNodesCount;
|
||||
emSize = ((600/(20*leafNodesCount)).toFixed(2));
|
||||
emSize = emSize > 1 ? 1 : emSize;
|
||||
|
||||
var fontSize = (nodeData.data.hasChildren) ? "" : "font-size:"+emSize+"em;";
|
||||
|
||||
deviceIcon = (!emptyArr.includes(nodeData.data.icon )) ? "<div class='netIcon '><i class='fa fa-"+nodeData.data.icon +"'></i></div>" : "";
|
||||
collapseExpandIcon = nodeData.data.hiddenChildren ? "square-plus" :"square-minus";
|
||||
@@ -637,25 +641,7 @@
|
||||
|
||||
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
|
||||
|
||||
// init parent node
|
||||
var currentNodeMac = $(".tab-content .active td[data-mynodemac]").attr('data-mynodemac');
|
||||
|
||||
initButtons(currentNodeMac);
|
||||
|
||||
// change highlighted node in the tree
|
||||
selNode = $("#networkTree .highlightedNode")[0]
|
||||
|
||||
// console.log(selNode)
|
||||
|
||||
if(selNode)
|
||||
{
|
||||
$(selNode).attr('class', $(selNode).attr('class').replace('highlightedNode'))
|
||||
}
|
||||
|
||||
newSelNode = $("#networkTree div[data-mytreemacmain='"+currentNodeMac+"']")[0]
|
||||
|
||||
$(newSelNode).attr('class', $(newSelNode).attr('class') + ' highlightedNode')
|
||||
|
||||
initButtons()
|
||||
|
||||
});
|
||||
|
||||
@@ -696,8 +682,26 @@
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
function initButtons(currentNodeMac)
|
||||
function initButtons()
|
||||
{
|
||||
|
||||
var currentNodeMac = $(".tab-content .active td[data-mynodemac]").attr('data-mynodemac');
|
||||
|
||||
// change highlighted node in the tree
|
||||
selNode = $("#networkTree .highlightedNode")[0]
|
||||
|
||||
// console.log(selNode)
|
||||
|
||||
if(selNode)
|
||||
{
|
||||
$(selNode).attr('class', $(selNode).attr('class').replace('highlightedNode'))
|
||||
}
|
||||
|
||||
newSelNode = $("#networkTree div[data-mytreemacmain='"+currentNodeMac+"']")[0]
|
||||
|
||||
$(newSelNode).attr('class', $(newSelNode).attr('class') + ' highlightedNode')
|
||||
|
||||
|
||||
// init the Assign buttons
|
||||
$('#unassignedDevices button[data-myleafmac]').each(function(){
|
||||
$(this).attr('onclick', 'updateLeaf("'+$(this).attr('data-myleafmac')+'","'+currentNodeMac+'")')
|
||||
@@ -712,6 +716,8 @@
|
||||
// ---------------------------------------------------------------------------
|
||||
function updateLeaf(leafMac,nodeMac)
|
||||
{
|
||||
console.log(leafMac)
|
||||
console.log(nodeMac)
|
||||
saveData('updateNetworkLeaf', leafMac, nodeMac);
|
||||
setTimeout("location.reload();", 1000); // refresh page after 1s
|
||||
}
|
||||
@@ -726,6 +732,9 @@
|
||||
// attach on-click events
|
||||
attachTreeEvents();
|
||||
|
||||
// init Assign/Unassign buttons
|
||||
initButtons()
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
@@ -622,8 +622,8 @@ function getDevicesList() {
|
||||
|
||||
$defaultOrder = array ($row['dev_Name'],
|
||||
$row['dev_Owner'],
|
||||
$row['dev_DeviceType'],
|
||||
$row['dev_Icon'],
|
||||
handleNull($row['dev_DeviceType']),
|
||||
handleNull($row['dev_Icon'], "laptop"),
|
||||
$row['dev_Favorite'],
|
||||
$row['dev_Group'],
|
||||
formatDate ($row['dev_FirstConnection']),
|
||||
@@ -634,12 +634,12 @@ function getDevicesList() {
|
||||
$row['dev_MAC'], // MAC (hidden)
|
||||
formatIPlong ($row['dev_LastIP']), // IP orderable
|
||||
$row['rowid'], // Rowid (hidden)
|
||||
$row['dev_Network_Node_MAC_ADDR'] //
|
||||
handleNull($row['dev_Network_Node_MAC_ADDR']) //
|
||||
);
|
||||
|
||||
$newOrder = array();
|
||||
|
||||
|
||||
// reorder columns based on user settings
|
||||
for($index = 0; $index < count($columnOrderMapping); $index++)
|
||||
{
|
||||
array_push($newOrder, $defaultOrder[$columnOrderMapping[$index][2]]);
|
||||
@@ -758,9 +758,10 @@ function getIcons() {
|
||||
// arrays of rows
|
||||
$tableData = array();
|
||||
while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
|
||||
$icon = handleNull($row['dev_Icon'], "laptop");
|
||||
// Push row data
|
||||
$tableData[] = array('id' => $row['dev_Icon'],
|
||||
'name' => '<i class="fa fa-'.$row['dev_Icon'].'"></i> - '.$row['dev_Icon'] );
|
||||
$tableData[] = array('id' => $icon,
|
||||
'name' => '<i class="fa fa-'.$icon.'"></i> - '.$icon );
|
||||
}
|
||||
|
||||
// Control no rows
|
||||
|
||||
@@ -80,6 +80,9 @@ function getParameter($skipCache, $defaultValue, $expireMinutes) {
|
||||
$value = $row[0];
|
||||
} else{
|
||||
$value = $defaultValue;
|
||||
|
||||
// Nothing found in the DB, Insert new value
|
||||
insertNew($parameter, $value);
|
||||
}
|
||||
|
||||
// update cache
|
||||
@@ -113,15 +116,7 @@ function setParameter($expireMinutes) {
|
||||
$changes = $db->changes();
|
||||
if ($changes == 0) {
|
||||
// Insert new value
|
||||
$sql = 'INSERT INTO Parameters (par_ID, par_Value)
|
||||
VALUES ("'. quotes($parameter) .'",
|
||||
"'. quotes($value) .'")';
|
||||
$result = $db->query($sql);
|
||||
|
||||
if (! $result == TRUE) {
|
||||
echo "Error creating parameter\n\n$sql \n\n". $db->lastErrorMsg();
|
||||
return;
|
||||
}
|
||||
insertNew($parameter, $value);
|
||||
}
|
||||
|
||||
// update cache
|
||||
@@ -130,4 +125,21 @@ function setParameter($expireMinutes) {
|
||||
echo 'OK';
|
||||
}
|
||||
|
||||
function insertNew($parameter, $value)
|
||||
{
|
||||
global $db;
|
||||
|
||||
// Insert new value
|
||||
$sql = 'INSERT INTO Parameters (par_ID, par_Value)
|
||||
VALUES ("'. quotes($parameter) .'",
|
||||
"'. quotes($value) .'")';
|
||||
$result = $db->query($sql);
|
||||
|
||||
if (! $result == TRUE) {
|
||||
echo "Error creating parameter\n\n$sql \n\n". $db->lastErrorMsg();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
||||
@@ -354,6 +354,18 @@ function logServerConsole ($text) {
|
||||
$y = $x['__________'. $text .'__________'];
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------
|
||||
function handleNull ($text, $default = "") {
|
||||
if($text == NULL || $text == 'NULL')
|
||||
{
|
||||
return $default;
|
||||
} else
|
||||
{
|
||||
return $text;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------
|
||||
|
||||
function getNetworkTypes(){
|
||||
|
||||
Reference in New Issue
Block a user