Merge remote-tracking branch 'origin/terorero-merge' into pr/74

This commit is contained in:
jokob-sk
2022-08-06 19:47:26 +10:00
44 changed files with 2305 additions and 613 deletions

View File

@@ -594,7 +594,42 @@ input[type="password"]::-webkit-caps-lock-indicator {
}
/*** Additional fixes For Pi.Alert UI ***/
.small-box {
border-radius: 10px;
border-top: 0px;
}
.pa-small-box-aqua .inner {
background-color: rgb(45,108,133);
border-top-left-radius: 10px;
border-top-right-radius: 10px;
}
.pa-small-box-green .inner {
background-color: rgb(31,76,46);
border-top-left-radius: 10px;
border-top-right-radius: 10px;
}
.pa-small-box-yellow .inner {
background-color: rgb(151,104,37);
border-top-left-radius: 10px;
border-top-right-radius: 10px;
}
.pa-small-box-red .inner {
background-color: rgb(120,50,38);
border-top-left-radius: 10px;
border-top-right-radius: 10px;
}
.pa-small-box-gray .inner {
background-color: #777;
/* color: rgba(20,20,20,30%); */
border-top-left-radius: 10px;
border-top-right-radius: 10px;
}
.pa-small-box-gray .inner h3 {
color: #bbb;
}
.text-gray-20 {
color: rgba(220,220,220,30%);
}
.bg-gray {
background-color: #888888 !important;
}
@@ -670,4 +705,21 @@ input[type="password"]::-webkit-caps-lock-indicator {
.login-box-body {
color: #bec5cb;
background-color: #272c30;
}
}
/* Add border radius to bottom of the status boxes*/
.pa-small-box-footer {
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
}
.small-box > .inner h3, .small-box > .inner p {
margin-bottom: 0px;
margin-left: 0px;
}
.small-box:hover .icon {
font-size: 3.74em;
}
.small-box .icon {
top: 0.01em;
font-size: 3.25em;
}

View File

@@ -12,7 +12,7 @@ session_start();
if ($_SESSION["login"] != 1)
{
header('Location: /pialert/index.php');
header('Location: index.php');
exit;
}
@@ -263,7 +263,8 @@ if ($_REQUEST['mac'] == 'Internet') { $DevDetail_Tap_temp = "Tools"; } else { $D
<textarea class="form-control" rows="3" id="txtComments"></textarea>
</div>
</div>
<!-- Network -->
<h4 class="bottom-border-aqua"><?php echo $pia_lang['DevDetail_MainInfo_Network_Title'];?></h4>
<div class="form-group">
<label class="col-sm-6 control-label"><?php echo $pia_lang['DevDetail_MainInfo_Network'];?></label>
<div class="col-sm-6">
@@ -814,44 +815,85 @@ function initializeiCheck () {
// -----------------------------------------------------------------------------
function initializeCombos () {
// Initialize combos with queries
initializeCombo ( $('#dropdownOwner')[0], 'getOwners', 'txtOwner');
initializeCombo ( $('#dropdownDeviceType')[0], 'getDeviceTypes', 'txtDeviceType');
initializeCombo ( $('#dropdownGroup')[0], 'getGroups', 'txtGroup');
initializeCombo ( $('#dropdownLocation')[0], 'getLocations', 'txtLocation');
initializeCombo ( $('#dropdownNetworkNodeMac')[0], 'getNetworkNodes', 'txtNetworkNodeMac');
initializeCombo ( '#dropdownOwner', 'getOwners', 'txtOwner', true);
initializeCombo ( '#dropdownDeviceType', 'getDeviceTypes', 'txtDeviceType', true);
initializeCombo ( '#dropdownGroup', 'getGroups', 'txtGroup', true);
initializeCombo ( '#dropdownLocation', 'getLocations', 'txtLocation', true);
initializeCombo ( '#dropdownNetworkNodeMac', 'getNetworkNodes', 'txtNetworkNodeMac', false);
// Initialize static combos
initializeComboSkipRepeated ();
}
function initializeCombo (HTMLelement, queryAction, txtDataField) {
// get data from server
$.get('php/server/devices.php?action='+queryAction, function(data) {
var listData = JSON.parse(data);
var order = 1;
function initializeCombo (dropdownId, queryAction, txtDataField, useCache) {
HTMLelement.innerHTML = ''
// for each item
listData.forEach(function (item, index) {
// insert line divisor
if (order != item['order']) {
HTMLelement.innerHTML += '<li class="divider"></li>';
order = item['order'];
}
// check if we have the value cached already
var dropdownHtmlContent = useCache ? getCache(dropdownId) : "";
id = item['name'];
// use explicitly specified id (value) if avaliable
if(item['id'])
{
id = item['id'];
}
if(dropdownHtmlContent == "")
{
// get data from server
$.get('php/server/devices.php?action='+queryAction, function(data) {
var listData = JSON.parse(data);
var order = 1;
// add dropdown item
HTMLelement.innerHTML +=
'<li><a href="javascript:void(0)" onclick="setTextValue(\''+
txtDataField +'\',\''+ id +'\')">'+ item['name'] + '</a></li>'
// for each item
listData.forEach(function (item, index) {
// insert line divisor
if (order != item['order']) {
dropdownHtmlContent += '<li class="divider"></li>';
order = item['order'];
}
id = item['name'];
// use explicitly specified id (value) if avaliable
if(item['id'])
{
id = item['id'];
}
// add dropdown item
dropdownHtmlContent +=
'<li><a href="javascript:void(0)" onclick="setTextValue(\''+
txtDataField +'\',\''+ id +'\')">'+ item['name'] + '</a></li>'
});
writeDropdownHtml(dropdownId, dropdownHtmlContent)
});
});
} else
{
writeDropdownHtml(dropdownId, dropdownHtmlContent)
}
}
// write out the HTML for the dropdown
function writeDropdownHtml(dropdownId, dropdownHtmlContent)
{
// cache
setCache(dropdownId, dropdownHtmlContent);
// write HTML for the dropdown
var HTMLelement = $(dropdownId)[0];
HTMLelement.innerHTML = ''
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);
}
@@ -1139,7 +1181,7 @@ function getDeviceData (readAllData=false) {
$('#txtGroup').val ('--');
$('#txtLocation').val ('--');
$('#txtComments').val ('--');
$('#txtNetworkNodeMac').val ('--');
$('#txtNetworkNodeMac').val ('--');
$('#txtNetworkPort').val ('--');
$('#txtFirstConnection').val ('--');
@@ -1228,7 +1270,7 @@ function getDeviceData (readAllData=false) {
$('#txtGroup').val (deviceData['dev_Group']);
$('#txtLocation').val (deviceData['dev_Location']);
$('#txtComments').val (deviceData['dev_Comments']);
$('#txtNetworkNodeMac').val (deviceData['dev_Network_Node_MAC']);
$('#txtNetworkNodeMac').val (deviceData['dev_Network_Node_MAC_ADDR']);
$('#txtNetworkPort').val (deviceData['dev_Network_Node_port']);
$('#txtFirstConnection').val (deviceData['dev_FirstConnection']);

View File

@@ -12,7 +12,7 @@ session_start();
if ($_SESSION["login"] != 1)
{
header('Location: /pialert/index.php');
header('Location: index.php');
exit;
}
@@ -114,7 +114,7 @@ if ($_SESSION["login"] != 1)
<div class="col-md-12">
<div class="box" id="clients">
<div class="box-header with-border">
<h3 class="box-title"><?php echo $pia_lang['Device_Shortcut_OnlineChart_a'];?> <span class="maxlogage-interval">12</span> <?php echo $pia_lang['Device_Shortcut_OnlineChart_b'];?></h3>
<h3 class="box-title"><?php echo $pia_lang['Device_Shortcut_OnlineChart'];?> </h3>
</div>
<div class="box-body">
<div class="chart">
@@ -237,6 +237,12 @@ function main () {
// -----------------------------------------------------------------------------
function initializeDatatable () {
// If the device has a small width (mobile) only show name, ip, and status columns.
if (window.screen.width < 400) {
var tableColumnShow = [10,11,12,1,2,3,4,5,6,8];
} else {
var tableColumnShow = [10, 11, 12];
};
var table=
$('#tableDevices').DataTable({
'paging' : true,
@@ -254,7 +260,7 @@ function initializeDatatable () {
// 'order' : [[3,'desc'], [0,'asc']],
'columnDefs' : [
{visible: false, targets: [10, 11, 12] },
{visible: false, targets: tableColumnShow },
{className: 'text-center', targets: [3, 8, 9] },
{width: '80px', targets: [5, 6] },
{width: '0px', targets: 9 },

View File

@@ -1,6 +1,6 @@
<!-- ---------------------------------------------------------------------------
# Pi.Alert
# Open Source Network Guard / WIFI & LAN intrusion detector
# Open Source Network Guard / WIFI & LAN intrusion detector
#
# events.php - Front module. Events page
#-------------------------------------------------------------------------------
@@ -12,7 +12,7 @@ session_start();
if ($_SESSION["login"] != 1)
{
header('Location: /pialert/index.php');
header('Location: index.php');
exit;
}

View File

@@ -4,13 +4,30 @@ session_start();
if ($_REQUEST['action'] == 'logout') {
session_destroy();
setcookie("PiAler_SaveLogin", "", time() - 3600);
header('Location: /pialert/index.php');
header('Location: index.php');
}
// ##################################################
// ## Login Processing start
// ##################################################
$config_file = "../config/pialert.conf";
$config_file_lines = file($config_file);
// ###################################
// ## Login language settings
// ###################################
if (file_exists('../db/setting_darkmode')) {
$ENABLED_DARKMODE = True;
}
foreach (glob("../db/setting_skin*") as $filename) {
$pia_skin_selected = str_replace('setting_','',basename($filename));
}
if (strlen($pia_skin_selected) == 0) {$pia_skin_selected = 'skin-blue';}
foreach (glob("../db/setting_language*") as $filename) {
$pia_lang_selected = str_replace('setting_language_','',basename($filename));
}
if (strlen($pia_lang_selected) == 0) {$pia_lang_selected = 'en_us';}
require 'php/templates/language/'.$pia_lang_selected.'.php';
// ###################################
// ## Login language settings
@@ -31,7 +48,7 @@ $Pia_WebProtection = strtolower(trim($protection_line[1]));
if ($Pia_WebProtection != 'true')
{
header('Location: /pialert/devices.php');
header('Location: devices.php');
$_SESSION["login"] = 1;
exit;
}
@@ -47,7 +64,15 @@ $Pia_Password = $password_line[1];
// Password without Cookie check -> pass and set initial cookie
if ($Pia_Password == hash('sha256',$_POST["loginpassword"]))
{
header('Location: /pialert/devices.php');
header('Location: devices.php');
$_SESSION["login"] = 1;
if (isset($_POST['PWRemember'])) {setcookie("PiAler_SaveLogin", hash('sha256',$_POST["loginpassword"]), time()+604800);}
}
// active Session or valid cookie (cookie not extends)
if (($_SESSION["login"] == 1) || ($Pia_Password == $_COOKIE["PiAler_SaveLogin"]))
{
header('Location: devices.php');
$_SESSION["login"] = 1;
if (isset($_POST['PWRemember'])) {setcookie("PiAler_SaveLogin", hash('sha256',$_POST["loginpassword"]), time()+604800);}
}
@@ -116,12 +141,12 @@ if ($ENABLED_DARKMODE === True) {
<body class="hold-transition login-page">
<div class="login-box">
<div class="login-logo">
<a href="/pialert/index.php">Pi.<b>Alert</b></a>
<a href="/index2.php">Pi.<b>Alert</b></a>
</div>
<!-- /.login-logo -->
<div class="login-box-body">
<p class="login-box-msg"><?php echo $pia_lang['Login_Box'];?></p>
<form action="/pialert/index.php" method="post">
<form action="index.php" method="post">
<div class="form-group has-feedback">
<input type="password" class="form-control" placeholder="<?php echo $pia_lang['Login_Psw-box'];?>" name="loginpassword">
<span class="glyphicon glyphicon-lock form-control-feedback"></span>

View File

@@ -197,3 +197,10 @@ function debugTimer () {
}
// -----------------------------------------------------------------------------
function openInNewTab (url) {
window.open(url, "_blank");
}

View File

@@ -3,7 +3,7 @@ session_start();
if ($_SESSION["login"] != 1)
{
header('Location: /pialert/index.php');
header('Location: index.php');
exit;
}
@@ -310,6 +310,12 @@ if (submit && isset($_POST['langselector_set'])) {
</div>
<div class="db_tools_table_cell_b"><?php echo $pia_lang['Maintenance_Tool_del_allevents_text'];?></div>
</div>
<div class="db_info_table_row">
<div class="db_tools_table_cell_a" style="">
<button type="button" class="btn btn-default pa-btn pa-btn-delete bg-red dbtools-button" id="btnDeleteEvents30" onclick="askDeleteEvents30()"><?php echo $pia_lang['Maintenance_Tool_del_allevents30'];?></button>
</div>
<div class="db_tools_table_cell_b"><?php echo $pia_lang['Maintenance_Tool_del_allevents30_text'];?></div>
</div>
<div class="db_info_table_row">
<div class="db_tools_table_cell_a" style="">
<button type="button" class="btn btn-default pa-btn pa-btn-delete bg-red dbtools-button" id="btnDeleteActHistory" onclick="askDeleteActHistory()"><?php echo $pia_lang['Maintenance_Tool_del_ActHistory'];?></button>
@@ -338,9 +344,21 @@ if (submit && isset($_POST['langselector_set'])) {
</div>
<div class="db_tools_table_cell_b"><?php echo $pia_lang['Maintenance_Tool_purgebackup_text'];?></div>
</div>
</div>
</div>
</div>
<div class="db_info_table_row">
<div class="db_tools_table_cell_a" style="">
<button type="button" class="btn btn-default pa-btn bg-green dbtools-button" id="btnExportCSV" onclick="askExportCSV()"><?php echo $pia_lang['Maintenance_Tool_ExportCSV'];?></button>
</div>
<div class="db_tools_table_cell_b"><?php echo $pia_lang['Maintenance_Tool_ExportCSV_text'];?></div>
</div>
<div class="db_info_table_row">
<div class="db_tools_table_cell_a" style="">
<button type="button" class="btn btn-default pa-btn pa-btn-delete bg-red dbtools-button" id="btnImportCSV" onclick="askImportCSV()"><?php echo $pia_lang['Maintenance_Tool_ImportCSV'];?></button>
</div>
<div class="db_tools_table_cell_b"><?php echo $pia_lang['Maintenance_Tool_ImportCSV_text'];?></div>
</div>
</div>
</div>
</div>
</div>
<div style="width: 100%; height: 20px;"></div>
@@ -415,6 +433,20 @@ function deleteEvents()
});
}
// delete all Events older than 30 days
function askDeleteEvents30 () {
// Ask
showModalWarning('<?php echo $pia_lang['Maintenance_Tool_del_allevents30_noti'];?>', '<?php echo $pia_lang['Maintenance_Tool_del_allevents30_noti_text'];?>',
'<?php echo $pia_lang['Gen_Cancel'];?>', '<?php echo $pia_lang['Gen_Delete'];?>', 'deleteEvents30');
}
function deleteEvents30()
{
// Execute
$.get('php/server/devices.php?action=deleteEvents30', function(msg) {
showMessage (msg);
});
}
// delete Hostory
function askDeleteActHistory () {
// Ask
@@ -471,6 +503,32 @@ function PiaPurgeDBBackups()
});
}
// Export CSV
function askExportCSV() {
// Ask
showModalWarning('<?php echo $pia_lang['Maintenance_Tool_ExportCSV_noti'];?>', '<?php echo $pia_lang['Maintenance_Tool_ExportCSV_noti_text'];?>',
'<?php echo $pia_lang['Gen_Cancel'];?>', '<?php echo $pia_lang['Gen_Okay'];?>', 'ExportCSV');
}
function ExportCSV()
{
// Execute
openInNewTab(window.location.origin + "/php/server/devices.php?action=ExportCSV")
}
// Import CSV
function askImportCSV() {
// Ask
showModalWarning('<?php echo $pia_lang['Maintenance_Tool_ImportCSV_noti'];?>', '<?php echo $pia_lang['Maintenance_Tool_ImportCSV_noti_text'];?>',
'<?php echo $pia_lang['Gen_Cancel'];?>', '<?php echo $pia_lang['Gen_Okay'];?>', 'ImportCSV');
}
function ImportCSV()
{
// Execute
$.get('/php/server/devices.php?action=ImportCSV', function(msg) {
showMessage (msg);
});
}
// Switch Darkmode
function askPiaEnableDarkmode() {
// Ask

View File

@@ -1,368 +1,430 @@
<?php
session_start();
if ($_SESSION["login"] != 1)
session_start();
if ($_SESSION["login"] != 1)
{
header('Location: /pialert/index.php');
header('Location: index.php');
exit;
}
require 'php/templates/header.php';
require 'php/server/db.php';
require 'php/templates/header.php';
require 'php/server/db.php';
require 'php/server/util.php';
$DBFILE = '../db/pialert.db';
OpenDB();
// #####################################
// ## Create Table if not exists'
// #####################################
$sql = 'CREATE TABLE IF NOT EXISTS "network_infrastructure" (
"device_id" INTEGER,
"net_device_name" TEXT NOT NULL,
"net_device_typ" TEXT NOT NULL,
"net_device_port" INTEGER,
PRIMARY KEY("device_id" AUTOINCREMENT)
)';
$result = $db->query($sql);
// #####################################
// ## Expand Devices Table
// #####################################
$sql = 'ALTER TABLE "Devices" ADD "dev_Infrastructure" INTEGER';
$result = $db->query($sql);
$sql = 'ALTER TABLE "Devices" ADD "dev_Infrastructure_port" INTEGER';
$result = $db->query($sql);
// #####################################
// Add New Network Devices
// #####################################
if ($_REQUEST['Networkinsert'] == "yes") {
if (isset($_REQUEST['NetworkDeviceName']) && isset($_REQUEST['NetworkDeviceTyp']))
{
$sql = 'INSERT INTO "network_infrastructure" ("net_device_name", "net_device_typ", "net_device_port") VALUES("'.$_REQUEST['NetworkDeviceName'].'", "'.$_REQUEST['NetworkDeviceTyp'].'", "'.$_REQUEST['NetworkDevicePort'].'")';
$result = $db->query($sql);
}
}
// #####################################
// Add New Network Devices
// #####################################
if ($_REQUEST['Networkedit'] == "yes") {
if (isset($_REQUEST['NewNetworkDeviceName']) && isset($_REQUEST['NewNetworkDeviceTyp']))
{
$sql = 'UPDATE "network_infrastructure" SET "net_device_name" = "'.$_REQUEST['NewNetworkDeviceName'].'", "net_device_typ" = "'.$_REQUEST['NewNetworkDeviceTyp'].'", "net_device_port" = "'.$_REQUEST['NewNetworkDevicePort'].'" WHERE "device_id"="'.$_REQUEST['NetworkDeviceID'].'"';
//$sql = 'INSERT INTO "network_infrastructure" ("net_device_name", "net_device_typ", "net_device_port") VALUES("'.$_REQUEST['NetworkDeviceName'].'", "'.$_REQUEST['NetworkDeviceTyp'].'", "'.$_REQUEST['NetworkDevicePort'].'")';
$result = $db->query($sql);
}
}
// #####################################
// remove Network Devices
// #####################################
if ($_REQUEST['Networkdelete'] == "yes") {
if (isset($_REQUEST['NetworkDeviceID']))
{
$sql = 'DELETE FROM "network_infrastructure" WHERE "device_id"="'.$_REQUEST['NetworkDeviceID'].'"';
$result = $db->query($sql);
}
}
// online / offline badges HTML snippets
define('badge_online', '<div class="badge bg-green text-white" style="width: 60px;">Online</div>');
define('badge_offline', '<div class="badge bg-red text-white" style="width: 60px;">Offline</div>');
define('circle_online', '<div class="badge bg-green text-white" style="width: 10px; height: 10px; padding:2px; margin-top: -25px;">&nbsp;</div>');
define('circle_offline', '<div class="badge bg-red text-white" style="width: 10px; height: 10px; padding:2px; margin-top: -25px;">&nbsp;</div>');
$DBFILE = '../db/pialert.db';
$NETWORKTYPES = getNetworkTypes();
OpenDB();
?>
<!-- Page ------------------------------------------------------------------ -->
<div class="content-wrapper">
<!-- Content header--------------------------------------------------------- -->
<section class="content-header">
<?php require 'php/templates/notification.php'; ?>
<h1 id="pageTitle">
<?php echo $pia_lang['Network_Title'];?>
</h1>
</section>
<!-- Content header--------------------------------------------------------- -->
<section class="content-header">
<?php require 'php/templates/notification.php'; ?>
<h1 id="pageTitle">
<?php echo $pia_lang['Network_Title'];?>
</h1>
</section>
<?php
echo $_REQUEST['device_id'];
?>
<!-- Main content ---------------------------------------------------------- -->
<section class="content">
<div class="box box-default collapsed-box"> <!-- collapsed-box -->
<div class="box-header with-border" data-widget="collapse">
<h3 class="box-title"><?php echo $pia_lang['Network_ManageDevices'];?></h3>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-plus"></i></button>
</div>
</div>
<!-- /.box-header -->
<div class="box-body" style="">
<div class="row">
<div class="col-md-4">
<h4 class="box-title"><?php echo $pia_lang['Network_ManageAdd'];?></h4>
<form role="form" method="post" action="./network.php">
<div class="form-group">
<label for="NetworkDeviceName"><?php echo $pia_lang['Network_ManageAdd_Name'];?>:</label>
<input type="text" class="form-control" id="NetworkDeviceName" name="NetworkDeviceName" placeholder="<?php echo $pia_lang['Network_ManageAdd_Name_text'];?>">
</div>
<!-- /.form-group -->
<div class="form-group">
<label><?php echo $pia_lang['Network_ManageAdd_Type'];?>:</label>
<select class="form-control" name="NetworkDeviceTyp">
<option value=""><?php echo $pia_lang['Network_ManageAdd_Type_text'];?></option>
<option value="Router">Router</option>
<option value="Switch">Switch</option>
<option value="WLAN">WLAN</option>
<option value="Powerline">Powerline</option>
</select>
</div>
<div class="form-group">
<label for="NetworkDevicePort"><?php echo $pia_lang['Network_ManageAdd_Port'];?>:</label>
<input type="text" class="form-control" id="NetworkDevicePort" name="NetworkDevicePort" placeholder="<?php echo $pia_lang['Network_ManageAdd_Port_text'];?>">
</div>
<div class="form-group">
<button type="submit" class="btn btn-success" name="Networkinsert" value="yes"><?php echo $pia_lang['Network_ManageAdd_Submit'];?></button>
</div>
</form>
<!-- /.form-group -->
</div>
<!-- /.col -->
<div class="col-md-4">
<h4 class="box-title"><?php echo $pia_lang['Network_ManageEdit'];?></h4>
<form role="form" method="post" action="./network.php">
<div class="form-group">
<label><?php echo $pia_lang['Network_ManageEdit_ID'];?>:</label>
<select class="form-control" name="NetworkDeviceID">
<option value=""><?php echo $pia_lang['Network_ManageEdit_ID_text'];?></option>
<?php
$sql = 'SELECT "device_id", "net_device_name", "net_device_typ" FROM "network_infrastructure"';
$result = $db->query($sql);//->fetchArray(SQLITE3_ASSOC);
while($res = $result->fetchArray(SQLITE3_ASSOC)){
if(!isset($res['device_id'])) continue;
echo '<option value="'.$res['device_id'].'">'.$res['net_device_name'].' / '.$res['net_device_typ'].'</option>';
}
?>
</select>
</div>
<div class="form-group">
<label for="NetworkDeviceName"><?php echo $pia_lang['Network_ManageEdit_Name'];?>:</label>
<input type="text" class="form-control" id="NewNetworkDeviceName" name="NewNetworkDeviceName" placeholder="<?php echo $pia_lang['Network_ManageEdit_Name_text'];?>">
</div>
<div class="form-group">
<label><?php echo $pia_lang['Network_ManageEdit_Type'];?>:</label>
<select class="form-control" name="NewNetworkDeviceTyp">
<option value=""><?php echo $pia_lang['Network_ManageEdit_Type_text'];?></option>
<option value="Router">Router</option>
<option value="Switch">Switch</option>
<option value="WLAN">WLAN</option>
<option value="Powerline">Powerline</option>
</select>
</div>
<div class="form-group">
<label for="NetworkDevicePort"><?php echo $pia_lang['Network_ManageEdit_Port'];?>:</label>
<input type="text" class="form-control" id="NewNetworkDevicePort" name="NewNetworkDevicePort" placeholder="<?php echo $pia_lang['Network_ManageEdit_Port_text'];?>">
</div>
<!-- /.form-group -->
<div class="form-group">
<button type="submit" class="btn btn-primary" name="Networkedit" value="yes"><?php echo $pia_lang['Network_ManageEdit_Submit'];?></button>
</div>
</form>
<!-- /.form-group -->
</div>
<!-- /.col -->
<div class="col-md-4">
<h4 class="box-title"><?php echo $pia_lang['Network_ManageDel'];?></h4>
<form role="form" method="post" action="./network.php">
<div class="form-group">
<label><?php echo $pia_lang['Network_ManageDel_Name'];?>:</label>
<select class="form-control" name="NetworkDeviceID">
<option value=""><?php echo $pia_lang['Network_ManageDel_Name_text'];?></option>
<?php
$sql = 'SELECT "device_id", "net_device_name", "net_device_typ" FROM "network_infrastructure"';
$result = $db->query($sql);//->fetchArray(SQLITE3_ASSOC);
while($res = $result->fetchArray(SQLITE3_ASSOC)){
if(!isset($res['device_id'])) continue;
echo '<option value="'.$res['device_id'].'">'.$res['net_device_name'].' / '.$res['net_device_typ'].'</option>';
}
?>
</select>
</div>
<!-- /.form-group -->
<div class="form-group">
<button type="submit" class="btn btn-danger" name="Networkdelete" value="yes"><?php echo $pia_lang['Network_ManageDel_Submit'];?></button>
</div>
</form>
<!-- /.form-group -->
</div>
</div>
<!-- /.row -->
</div>
<!-- /.box-body -->
</div>
<?php
echo $_REQUEST['net_MAC'];
?>
<?php
// #####################################
// ## Start Function Setup
// #####################################
function createnetworktab($pia_func_netdevid, $pia_func_netdevname, $pia_func_netdevtyp, $pia_func_netdevport, $activetab) {
echo '<li class="'.$activetab.'"><a href="#'.$pia_func_netdevid.'" data-toggle="tab">'.$pia_func_netdevname.' / '.$pia_func_netdevtyp;
if ($pia_func_netdevport != "") {echo ' ('.$pia_func_netdevport.')';}
echo '</a></li>';
}
function createnetworktabcontent($pia_func_netdevid, $pia_func_netdevname, $pia_func_netdevtyp, $pia_func_netdevport, $activetab) {
global $pia_lang;
echo '<div class="tab-pane '.$activetab.'" id="'.$pia_func_netdevid.'">
<h4>'.$pia_func_netdevname.' (ID: '.$pia_func_netdevid.')</h4><br>';
echo '<div class="box-body no-padding">
<table class="table table-striped">
<tbody><tr>
<th style="width: 40px">Port</th>
<th style="width: 100px">'.$pia_lang['Network_Table_State'].'</th>
<th>'.$pia_lang['Network_Table_Hostname'].'</th>
<th>'.$pia_lang['Network_Table_IP'].'</th>
</tr>';
// Prepare Array for Devices with Port value
// If no Port is set, the Port number is set to 1
if ($pia_func_netdevport == "") {$pia_func_netdevport = 1;}
// Create Array with specific length
$network_device_portname = array();
$network_device_portmac = array();
$network_device_portip = array();
$network_device_portstate = array();
// make sql query for Network Hardware ID
global $db;
$func_sql = 'SELECT * FROM "Devices" WHERE "dev_Infrastructure" = "'.$pia_func_netdevid.'"';
$func_result = $db->query($func_sql);//->fetchArray(SQLITE3_ASSOC);
while($func_res = $func_result->fetchArray(SQLITE3_ASSOC)) {
//if(!isset($func_res['dev_Name'])) continue;
if ($func_res['dev_PresentLastScan'] == 1) {$port_state = '<div class="badge bg-green text-white" style="width: 60px;">Online</div>';} else {$port_state = '<div class="badge bg-red text-white" style="width: 60px;">Offline</div>';}
// Prepare Table with Port > push values in array
if ($pia_func_netdevport > 1)
{
if (stristr($func_res['dev_Infrastructure_port'], ',') == '') {
if ($network_device_portname[$func_res['dev_Infrastructure_port']] != '') {$network_device_portname[$func_res['dev_Infrastructure_port']] = $network_device_portname[$func_res['dev_Infrastructure_port']].','.$func_res['dev_Name'];} else {$network_device_portname[$func_res['dev_Infrastructure_port']] = $func_res['dev_Name'];}
if ($network_device_portmac[$func_res['dev_Infrastructure_port']] != '') {$network_device_portmac[$func_res['dev_Infrastructure_port']] = $network_device_portmac[$func_res['dev_Infrastructure_port']].','.$func_res['dev_MAC'];} else {$network_device_portmac[$func_res['dev_Infrastructure_port']] = $func_res['dev_MAC'];}
if ($network_device_portip[$func_res['dev_Infrastructure_port']] != '') {$network_device_portip[$func_res['dev_Infrastructure_port']] = $network_device_portip[$func_res['dev_Infrastructure_port']].','.$func_res['dev_LastIP'];} else {$network_device_portip[$func_res['dev_Infrastructure_port']] = $func_res['dev_LastIP'];}
if (isset($network_device_portstate[$func_res['dev_Infrastructure_port']])) {$network_device_portstate[$func_res['dev_Infrastructure_port']] = $network_device_portstate[$func_res['dev_Infrastructure_port']].','.$func_res['dev_PresentLastScan'];} else {$network_device_portstate[$func_res['dev_Infrastructure_port']] = $func_res['dev_PresentLastScan'];}
} else {
$multiport = array();
$multiport = explode(',',$func_res['dev_Infrastructure_port']);
foreach($multiport as $row) {
$network_device_portname[trim($row)] = $func_res['dev_Name'];
$network_device_portmac[trim($row)] = $func_res['dev_MAC'];
$network_device_portip[trim($row)] = $func_res['dev_LastIP'];
$network_device_portstate[trim($row)] = $func_res['dev_PresentLastScan'];
}
unset($multiport);
<!-- Main content ---------------------------------------------------------- -->
<section class="content">
<?php
// Create top-level node (network devices) tabs
function createDeviceTabs($node_mac, $node_name, $node_status, $node_type, $node_ports_count, $activetab) {
global $pia_lang; //language strings
// prepare string with port number in brackets if available
$str_port = "";
if ($node_ports_count != "") {
$str_port = ' ('.$node_ports_count.')';
}
} else {
// Table without Port > echo values
// Specific icon for devicetype
if ($pia_func_netdevtyp == "WLAN") {$dev_port_icon = 'fa-wifi';}
if ($pia_func_netdevtyp == "Powerline") {$dev_port_icon = 'fa-flash';}
echo '<tr><td style="text-align: center;"><i class="fa '.$dev_port_icon.'"></i></td><td>'.$port_state.'</td><td style="padding-left: 10px;"><a href="./deviceDetails.php?mac='.$func_res['dev_MAC'].'"><b>'.$func_res['dev_Name'].'</b></a></td><td>'.$func_res['dev_LastIP'].'</td></tr>';
}
}
// Create table with Port
if ($pia_func_netdevport > 1)
{
for ($x=1; $x<=$pia_func_netdevport; $x++)
// online/offline status circle (red/green)
$node_badge = "";
if($node_status == 1) // 1 means online, 0 offline
{
// Prepare online/offline badge for later functions
$online_badge = '<div class="badge bg-green text-white" style="width: 60px;">Online</div>';
$offline_badge = '<div class="badge bg-red text-white" style="width: 60px;">Offline</div>';
// Set online/offline badge
echo '<tr>';
echo '<td style="text-align: right; padding-right:16px;">'.$x.'</td>';
// Set online/offline badge
// Check if multiple badges necessary
if (stristr($network_device_portstate[$x],',') == '') {
// Set single online/offline badge
if ($network_device_portstate[$x] == 1) {$port_state = $online_badge;} else {$port_state = $offline_badge;}
echo '<td>'.$port_state.'</td>';
} else {
// Set multiple online/offline badges
$multistate = array();
$multistate = explode(',',$network_device_portstate[$x]);
echo '<td>';
foreach($multistate as $key => $value) {
if ($value == 1) {$port_state = $online_badge;} else {$port_state = $offline_badge;}
echo $port_state.'<br>';
}
echo '</td>';
unset($multistate);
}
// Check if multiple Hostnames are set
// print single hostname
if (stristr($network_device_portmac[$x],',') == '') {
echo '<td style="padding-left: 10px;"><a href="./deviceDetails.php?mac='.$network_device_portmac[$x].'"><b>'.$network_device_portname[$x].'</b></a></td>';
} else {
// print multiple hostnames with separate links
$multimac = array();
$multimac = explode(',',$network_device_portmac[$x]);
$multiname = array();
$multiname = explode(',',$network_device_portname[$x]);
echo '<td style="padding-left: 10px;">';
foreach($multiname as $key => $value) {
echo '<a href="./deviceDetails.php?mac='.$multimac[$key].'"><b>'.$value.'</b></a><br>';
}
echo '</td>';
unset($multiname, $multimac);
}
// Check if multiple IP are set
// print single IP
if (stristr($network_device_portip[$x],',') == '') {
echo '<td style="padding-left: 10px;">'.$network_device_portip[$x].'</td>';
} else {
// print multiple IPs
$multiip = array();
$multiip = explode(',',$network_device_portip[$x]);
echo '<td style="padding-left: 10px;">';
foreach($multiip as $key => $value) {
echo $value.'<br>';
}
echo '</td>';
unset($multiip);
}
echo '</tr>';
$node_badge = circle_online;
} else
{
$node_badge = circle_offline;
}
}
echo ' </tbody></table>
</div>';
echo '</div> ';
}
// #####################################
// ## End Function Setup
// #####################################
// #####################################
// ## Create Tabs
// #####################################
$sql = 'SELECT "device_id", "net_device_name", "net_device_typ", "net_device_port" FROM "network_infrastructure"';
$result = $db->query($sql);//->fetchArray(SQLITE3_ASSOC);
?>
<div class="nav-tabs-custom" style="margin-bottom: 0px;">
<ul class="nav nav-tabs">
<?php
$i = 0;
while($res = $result->fetchArray(SQLITE3_ASSOC)){
if(!isset($res['device_id'])) continue;
if ($i == 0) {$active = 'active';} else {$active = '';}
createnetworktab($res['device_id'], $res['net_device_name'], $res['net_device_typ'], $res['net_device_port'], $active);
$i++;
}
?>
</ul>
<div class="tab-content">
<?php
// #####################################
// ## Ctreate Tab Content
// #####################################
$i = 0;
while($res = $result->fetchArray(SQLITE3_ASSOC)){
if(!isset($res['device_id'])) continue;
if ($i == 0) {$active = 'active';} else {$active = '';}
createnetworktabcontent($res['device_id'], $res['net_device_name'], $res['net_device_typ'], $res['net_device_port'], $active);
$i++;
}
unset($i);
?>
<!-- /.tab-pane -->
</div>
<!-- /.tab-content -->
</div>
<div style="width: 100%; height: 20px;"></div>
</section>
$str_tab_header = '<li class="'.$activetab.'">
<a href="#'.str_replace(":", "_", $node_mac).'" data-toggle="tab">'
.$node_name.' ' .$str_port.$node_badge.
'</a>
</li>';
echo $str_tab_header;
}
// Create pane content (displayed inside of the tabs)
function createPane($node_mac, $node_name, $node_status, $node_type, $node_ports_count, $node_parent_mac, $activetab){
global $pia_lang; //language strings
// online/offline status circle (red/green)
$node_badge = "";
if($node_status == 1) // 1 means online, 0 offline
{
$node_badge = badge_online;
} else
{
$node_badge = badge_offline;
}
$str_tab_pane = '<div class="tab-pane '.$activetab.'" id="'.str_replace(":", "_", $node_mac).'">
<a href="./deviceDetails.php?mac='.$node_mac.'">
<h4>'.$node_name.'</h4>
</a>
<table class="table table-striped" style="width:200px;">
<tbody>
<tr>
<td>
<b>MAC:</b>
</td>
<td>'
.$node_mac.
'</td>
</tr>
<tr>
<td>
<b>'.$pia_lang['Device_TableHead_Type'].'</b>
</td>
<td>
' .$node_type. '
</td>
</tr>
<tr>
<td>
<b>'.$pia_lang['Network_Table_State'].':</b>
</td>
<td> '
.$node_badge.
'</td>
</tr>
<tr>
<td>
<b>'.$pia_lang['DevDetail_MainInfo_Network'].'</b>
</td>
<td>
<a href="./deviceDetails.php?mac='.$node_parent_mac.'">
<b>'.$node_parent_mac.'</b>
</a>
</td>
</tr>
</tbody>
</table>
<br>
<div class="box-body no-padding">';
$str_table = ' <h4>
'.$pia_lang['Device_Title'].'
</h4>
<table class="table table-striped">
<tbody>
<tr>
<th style="width: 40px">Port</th>
<th style="width: 100px">'.$pia_lang['Network_Table_State'].'</th>
<th>'.$pia_lang['Network_Table_Hostname'].'</th>
<th>'.$pia_lang['Network_Table_IP'].'</th>
</tr>';
// Prepare Array for Devices with Port value
// If no Port is set, the Port number is set to 0
if ($node_ports_count == "") {
$node_ports_count = 0;
}
// Get all leafs connected to a node based on the node_mac
$func_sql = 'SELECT dev_Network_Node_port as port,
dev_MAC as mac,
dev_PresentLastScan as online,
dev_Name as name,
dev_DeviceType as type,
dev_LastIP as last_ip,
(select dev_DeviceType from Devices a where dev_MAC = "'.$node_mac.'") as node_type
FROM Devices WHERE dev_Network_Node_MAC_ADDR = "'.$node_mac.'" order by port asc';
global $db;
$func_result = $db->query($func_sql);
// array
$tableData = array();
while ($row = $func_result -> fetchArray (SQLITE3_ASSOC)) {
// Push row data
$tableData[] = array( 'port' => $row['port'],
'mac' => $row['mac'],
'online' => $row['online'],
'name' => $row['name'],
'type' => $row['type'],
'last_ip' => $row['last_ip'],
'node_type' => $row['node_type']);
}
// Control no rows
if (empty($tableData)) {
$tableData = [];
}
$str_table_rows = "";
foreach ($tableData as $row) {
if ($row['online'] == 1) {
$port_state = badge_online;
} else {
$port_state = badge_offline;
}
// prepare HTML for the port table column cell
$port_content = "N/A";
if ($row['node_type'] == "WLAN" || $row['node_type'] == "AP" ) {
$port_content = '<i class="fa fa-wifi"></i>';
} elseif ($row['node_type'] == "Powerline")
{
$port_content = '<i class="fa fa-flash"></i>';
} elseif ($row['port'] != NULL && $row['port'] != "")
{
$port_content = $row['port'];
}
$str_table_rows = $str_table_rows.
'<tr>
<td style="text-align: center;">
'.$port_content.'
</td>
<td>'
.$port_state.
'</td>
<td style="padding-left: 10px;">
<a href="./deviceDetails.php?mac='.$row['mac'].'">
<b>'.$row['name'].'</b>
</a>
</td>
<td>'
.$row['last_ip'].
'</td>
</tr>';
}
$str_table_close = '</tbody>
</table>';
// no connected device - don't render table, just display some info
if($str_table_rows == "")
{
$str_table = "<div>
<h4>
".$pia_lang['Device_Title']."
</h4>
<div>
This network device (node) doesn't have any assigned devices (leaf nodes).
Go to <a href='devices.php'><b>".$pia_lang['Device_Title']."</b></a>, select a device you want to attach to this node and assign it in the <b>Details</b> tab by selecting it in the <b>".$pia_lang['DevDetail_MainInfo_Network'] ."</b> dropdown.
</div>
</div>";
$str_table_close = "";
}
$str_close_pane = '</div>
</div>';
// write the HTML
echo ''.$str_tab_header.
$str_tab_pane.
$str_table.
$str_table_rows.
$str_table_close.
$str_close_pane;
}
// Create Top level tabs (List of network devices), explanation of the terminology below:
//
// Switch 1 (node)
// /(p1) \ (p2) <----- port numbers
// / \
// Smart TV (leaf) Switch 2 (node (for the PC) and leaf (for Switch 1))
// \
// PC (leaf)
$sql = "SELECT node_name, node_mac, online, node_type, node_ports_count, parent_mac
FROM
(
SELECT a.dev_Name as node_name,
a.dev_MAC as node_mac,
a.dev_PresentLastScan as online,
a.dev_DeviceType as node_type,
a.dev_Network_Node_MAC_ADDR as parent_mac
FROM Devices a
WHERE a.dev_DeviceType in ('AP', 'Gateway', 'Powerline', 'Switch', 'WLAN', 'PLC', 'Router','USB LAN Adapter', 'USB WIFI Adapter', 'Internet')
) t1
LEFT JOIN
(
SELECT b.dev_Network_Node_MAC_ADDR as node_mac_2,
count() as node_ports_count
FROM Devices b
WHERE b.dev_Network_Node_MAC_ADDR NOT NULL group by b.dev_Network_Node_MAC_ADDR
) t2
ON (t1.node_mac = t2.node_mac_2);
";
$result = $db->query($sql);
// array
$tableData = array();
while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
// Push row data
$tableData[] = array( 'node_mac' => $row['node_mac'],
'node_name' => $row['node_name'],
'online' => $row['online'],
'node_type' => $row['node_type'],
'parent_mac' => $row['parent_mac'],
'node_ports_count' => $row['node_ports_count']);
}
// Control no rows
if (empty($tableData)) {
$tableData = [];
}
echo '<div class="nav-tabs-custom" style="margin-bottom: 0px;">
<ul class="nav nav-tabs">';
$activetab='active';
foreach ($tableData as $row) {
createDeviceTabs( $row['node_mac'],
$row['node_name'],
$row['online'],
$row['node_type'],
$row['node_ports_count'],
$activetab);
$activetab = ""; // reset active tab indicator, only the first tab is active
}
echo ' </ul> <div class="tab-content">';
$activetab='active';
foreach ($tableData as $row) {
createPane($row['node_mac'],
$row['node_name'],
$row['online'],
$row['node_type'],
$row['node_ports_count'],
$row['parent_mac'],
$activetab);
$activetab = ""; // reset active tab indicator, only the first tab is active
}
$db->close();
?>
<!-- /.tab-pane -->
</div>
</section>
<!-- Unassigned devices -->
<?php
global $pia_lang; //language strings
OpenDB();
// Get all Unassigned / unconnected nodes
$func_sql = 'SELECT dev_MAC as mac,
dev_PresentLastScan as online,
dev_Name as name,
dev_LastIP as last_ip,
dev_Network_Node_MAC_ADDR
FROM Devices WHERE (dev_Network_Node_MAC_ADDR is null or dev_Network_Node_MAC_ADDR = "" or dev_Network_Node_MAC_ADDR = " " ) and dev_MAC not like "%internet%" order by name asc';
global $db;
$func_result = $db->query($func_sql);
// array
$tableData = array();
while ($row = $func_result -> fetchArray (SQLITE3_ASSOC)) {
// Push row data
$tableData[] = array( 'mac' => $row['mac'],
'online' => $row['online'],
'name' => $row['name'],
'last_ip' => $row['last_ip']);
}
// Don't do anything if empty
if (!(empty($tableData))) {
$str_table_header = '
<div class="content">
<div class="box box-aqua box-body">
<section>
<h4>
'.$pia_lang['Network_UnassignedDevices'].'
</h4>
<table class="table table-striped">
<tbody>
<tr>
<th style="width: 100px">'.$pia_lang['Network_Table_State'].'</th>
<th>'.$pia_lang['Network_Table_Hostname'].'</th>
<th>'.$pia_lang['Network_Table_IP'].'</th>
</tr>';
$str_table_rows = "";
foreach ($tableData as $row) {
if ($row['online'] == 1) {
$state = badge_online;
} else {
$state = badge_offline;
}
$str_table_rows = $str_table_rows.
'<tr>
<td>'
.$state.
'</td>
<td style="padding-left: 10px;">
<a href="./deviceDetails.php?mac='.$row['mac'].'">
<b>'.$row['name'].'</b>
</a>
</td>
<td>'
.$row['last_ip'].
'</td>
</tr>';
}
$str_table_close = '</tbody>
</table>
</section>
</div>
</div>';
// write the html
echo $str_table_header.$str_table_rows.$str_table_close;
}
$db->close();
?>
<!-- /.content -->
</div>
@@ -371,4 +433,4 @@ unset($i);
<!-- ----------------------------------------------------------------------- -->
<?php
require 'php/templates/footer.php';
?>
?>

View File

@@ -0,0 +1,7 @@
<?php
// Cache the contents to a cache file
$cached = fopen($cachefile, 'w');
fwrite($cached, ob_get_contents());
fclose($cached);
ob_end_flush(); // Send the output to the browser
?>

View File

@@ -0,0 +1,15 @@
<?php
$url = $_SERVER["SCRIPT_NAME"];
$break = Explode('/', $url);
$file = $break[count($break) - 1];
$cachefile = 'cached-'.substr_replace($file ,"",-4).'.html';
$cachetime = 18000;
// Serve from the cache if it is younger than $cachetime
if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile)) {
echo "<!-- Cached copy, generated ".date('H:i', filemtime($cachefile))." -->\n";
readfile($cachefile);
exit;
}
ob_start(); // Start the output buffer
?>

View File

@@ -8,6 +8,13 @@
// Puche 2021 pi.alert.application@gmail.com GNU GPLv3
//------------------------------------------------------------------------------
// ## TimeZone processing
$config_file = "../../../config/pialert.conf";
$config_file_lines = file($config_file);
$config_file_lines_timezone = array_values(preg_grep('/^TIMEZONE\s.*/', $config_file_lines));
$timezone_line = explode("'", $config_file_lines_timezone[0]);
$Pia_TimeZone = $timezone_line[1];
date_default_timezone_set($Pia_TimeZone);
//------------------------------------------------------------------------------
// DB File Path
@@ -51,10 +58,11 @@ function OpenDB () {
}
$db = SQLite3_connect(true);
$db->exec('PRAGMA journal_mode = wal;');
if(!$db)
{
die ('Error connecting to database');
}
}
?>
?>

View File

@@ -7,6 +7,13 @@
//------------------------------------------------------------------------------
// Puche 2021 pi.alert.application@gmail.com GNU GPLv3
//------------------------------------------------------------------------------
// ## TimeZone processing
$config_file = "../../../config/pialert.conf";
$config_file_lines = file($config_file);
$config_file_lines_timezone = array_values(preg_grep('/^TIMEZONE\s.*/', $config_file_lines));
$timezone_line = explode("'", $config_file_lines_timezone[0]);
$Pia_TimeZone = $timezone_line[1];
date_default_timezone_set($Pia_TimeZone);
foreach (glob("../../../db/setting_language*") as $filename) {
$pia_lang_selected = str_replace('setting_language_','',basename($filename));
@@ -34,9 +41,9 @@ if (strlen($pia_lang_selected) == 0) {$pia_lang_selected = 'en_us';}
switch ($action) {
case 'getDeviceData': getDeviceData(); break;
case 'setDeviceData': setDeviceData(); break;
case 'deleteDevice': deleteDevice(); break;
case 'getNetworkNodes': getNetworkNodes(); break;
case 'deleteAllWithEmptyMACs': deleteAllWithEmptyMACs(); break;
case 'deleteDevice': deleteDevice(); break;
case 'deleteAllWithEmptyMACs': deleteAllWithEmptyMACs(); break;
case 'createBackupDB': createBackupDB(); break;
case 'restoreBackupDB': restoreBackupDB(); break;
case 'deleteAllDevices': deleteAllDevices(); break;
@@ -44,13 +51,16 @@ if (strlen($pia_lang_selected) == 0) {$pia_lang_selected = 'en_us';}
case 'runScan1min': runScan1min(); break;
case 'deleteUnknownDevices': deleteUnknownDevices(); break;
case 'deleteEvents': deleteEvents(); break;
case 'deleteEvents30': deleteEvents30(); break;
case 'deleteActHistory': deleteActHistory(); break;
case 'deleteDeviceEvents': deleteDeviceEvents(); break;
case 'PiaBackupDBtoArchive': PiaBackupDBtoArchive(); break;
case 'PiaRestoreDBfromArchive': PiaRestoreDBfromArchive(); break;
case 'PiaPurgeDBBackups': PiaPurgeDBBackups(); break;
case 'PiaEnableDarkmode': PiaEnableDarkmode(); break;
case 'PiaToggleArpScan': PiaToggleArpScan(); break;
case 'PiaToggleArpScan': PiaToggleArpScan(); break;
case 'ExportCSV': ExportCSV(); break;
case 'ImportCSV': ImportCSV(); break;
case 'getDevicesTotals': getDevicesTotals(); break;
case 'getDevicesList': getDevicesList(); break;
@@ -88,8 +98,8 @@ function getDeviceData() {
$deviceData = $row;
$mac = $deviceData['dev_MAC'];
$deviceData['dev_Network_Node_MAC'] = $row['dev_Infrastructure'];
$deviceData['dev_Network_Node_port'] = $row['dev_Infrastructure_port'];
$deviceData['dev_Network_Node_MAC_ADDR'] = $row['dev_Network_Node_MAC_ADDR'];
$deviceData['dev_Network_Node_port'] = $row['dev_Network_Node_port'];
$deviceData['dev_FirstConnection'] = formatDate ($row['dev_FirstConnection']); // Date formated
$deviceData['dev_LastConnection'] = formatDate ($row['dev_LastConnection']); // Date formated
@@ -120,8 +130,10 @@ function getDeviceData() {
$row = $result -> fetchArray (SQLITE3_NUM);
$deviceData['dev_DownAlerts'] = $row[0];
// Get current date using php, sql datetime does not return time respective to timezone.
$currentdate = date("Y-m-d H:i:s");
// Presence hours
$sql = 'SELECT CAST(( MAX (0, SUM (julianday (IFNULL (ses_DateTimeDisconnection, DATETIME("now","localtime")))
$sql = 'SELECT CAST(( MAX (0, SUM (julianday (IFNULL (ses_DateTimeDisconnection,"'. $currentdate .'" ))
- julianday (CASE WHEN ses_DateTimeConnection < '. $periodDate .' THEN '. $periodDate .'
ELSE ses_DateTimeConnection END)) *24 )) AS INT)
FROM Sessions
@@ -149,23 +161,23 @@ function setDeviceData() {
// sql
$sql = 'UPDATE Devices SET
dev_Name = "'. quotes($_REQUEST['name']) .'",
dev_Owner = "'. quotes($_REQUEST['owner']) .'",
dev_DeviceType = "'. quotes($_REQUEST['type']) .'",
dev_Vendor = "'. quotes($_REQUEST['vendor']) .'",
dev_Favorite = "'. quotes($_REQUEST['favorite']) .'",
dev_Group = "'. quotes($_REQUEST['group']) .'",
dev_Location = "'. quotes($_REQUEST['location']) .'",
dev_Comments = "'. quotes($_REQUEST['comments']) .'",
dev_Infrastructure = "'. quotes($_REQUEST['networknode']).'",
dev_Infrastructure_port = "'. quotes($_REQUEST['networknodeport']).'",
dev_StaticIP = "'. quotes($_REQUEST['staticIP']) .'",
dev_ScanCycle = "'. quotes($_REQUEST['scancycle']) .'",
dev_AlertEvents = "'. quotes($_REQUEST['alertevents']) .'",
dev_AlertDeviceDown = "'. quotes($_REQUEST['alertdown']) .'",
dev_SkipRepeated = "'. quotes($_REQUEST['skiprepeated']) .'",
dev_NewDevice = "'. quotes($_REQUEST['newdevice']) .'",
dev_Archived = "'. quotes($_REQUEST['archived']) .'"
dev_Name = "'. quotes($_REQUEST['name']) .'",
dev_Owner = "'. quotes($_REQUEST['owner']) .'",
dev_DeviceType = "'. quotes($_REQUEST['type']) .'",
dev_Vendor = "'. quotes($_REQUEST['vendor']) .'",
dev_Favorite = "'. quotes($_REQUEST['favorite']) .'",
dev_Group = "'. quotes($_REQUEST['group']) .'",
dev_Location = "'. quotes($_REQUEST['location']) .'",
dev_Comments = "'. quotes($_REQUEST['comments']) .'",
dev_Network_Node_MAC_ADDR = "'. quotes($_REQUEST['networknode']).'",
dev_Network_Node_port = "'. quotes($_REQUEST['networknodeport']).'",
dev_StaticIP = "'. quotes($_REQUEST['staticIP']) .'",
dev_ScanCycle = "'. quotes($_REQUEST['scancycle']) .'",
dev_AlertEvents = "'. quotes($_REQUEST['alertevents']) .'",
dev_AlertDeviceDown = "'. quotes($_REQUEST['alertdown']) .'",
dev_SkipRepeated = "'. quotes($_REQUEST['skiprepeated']) .'",
dev_NewDevice = "'. quotes($_REQUEST['newdevice']) .'",
dev_Archived = "'. quotes($_REQUEST['archived']) .'"
WHERE dev_MAC="' . $_REQUEST['mac'] .'"';
// update Data
$result = $db->query($sql);
@@ -299,6 +311,26 @@ function deleteEvents() {
}
}
//------------------------------------------------------------------------------
// Delete all Events older than 30 days
//------------------------------------------------------------------------------
function deleteEvents30() {
global $db;
global $pia_lang;
// sql
$sql = "DELETE FROM Events WHERE eve_DateTime <= date('now', '-30 day')";
// execute sql
$result = $db->query($sql);
// check result
if ($result == TRUE) {
echo $pia_lang['BackDevices_DBTools_DelEvents'];
} else {
echo $pia_lang['BackDevices_DBTools_DelEventsError']."\n\n$sql \n\n". $db->lastErrorMsg();
}
}
//------------------------------------------------------------------------------
// Delete History
//------------------------------------------------------------------------------
@@ -407,6 +439,120 @@ function PiaPurgeDBBackups() {
}
//------------------------------------------------------------------------------
// Export CSV of devices
//------------------------------------------------------------------------------
function ExportCSV() {
header("Content-Type: application/octet-stream");
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=\"devices.csv\"");
global $db;
$func_result = $db->query("SELECT * FROM Devices");
// prepare CSV header row
// header array with column names
$columns = getDevicesColumns();
// wrap the headers with " (quotes)
$resultCSV = '"'.implode('","', $columns).'"';
//and append a new line
$resultCSV = $resultCSV."\n";
// retrieve the devices from the DB
while ($row = $func_result -> fetchArray (SQLITE3_ASSOC)) {
// loop through columns and add values to the string
$index = 0;
foreach ($columns as $columnName) {
// add quotes around the value to prevent issues with commas in fields
$resultCSV = $resultCSV.'"'.$row[$columnName].'"';
// detect last loop - skip as no comma needed
if ($index != count($columns) - 1 )
{
$resultCSV = $resultCSV.',';
}
$index++;
}
//$resultCSV = $resultCSV.implode(",", [$row["dev_MAC"], $row["dev_Name"]]);
$resultCSV = $resultCSV."\n";
}
//write the built CSV string
echo $resultCSV;
}
//------------------------------------------------------------------------------
// Import CSV of devices
//------------------------------------------------------------------------------
function ImportCSV() {
$file = '../../../config/devices.csv';
if (file_exists($file)) {
global $db;
global $pia_lang;
$error = "";
// sql
$sql = 'DELETE FROM Devices';
// execute sql
$result = $db->query($sql);
// Open the CSV file with read-only mode
$csvFile = fopen($file, 'r');
// Skip the first line
fgetcsv($csvFile);
$columns = getDevicesColumns();
// Parse data from CSV file line by line (max 10000 lines)
while (($row = fgetcsv($csvFile, 10000, ",")) !== FALSE)
{
$sql = 'INSERT INTO Devices ('.implode(',', $columns).') VALUES ("' .implode('","', $row).'")';
$result = $db->query($sql);
// check result
if ($result != TRUE) {
$error = $db->lastErrorMsg();
// break the while loop on error
break;
}
}
// Close opened CSV file
fclose($csvFile);
if($error == "")
{
// import succesful
echo $pia_lang['BackDevices_DBTools_ImportCSV'];
}
else{
// an error occurred while writing to the DB, display the last error message
echo $pia_lang['BackDevices_DBTools_ImportCSVError']."\n\n$sql \n\n".$error;
}
} else {
echo $pia_lang['BackDevices_DBTools_ImportCSVMissing'];
}
$db->close();
}
//------------------------------------------------------------------------------
// Toggle Dark/Light Themes
//------------------------------------------------------------------------------
@@ -448,22 +594,35 @@ function PiaToggleArpScan() {
// Query total numbers of Devices by status
//------------------------------------------------------------------------------
function getDevicesTotals() {
global $db;
// combined query
$result = $db->query(
'SELECT
(SELECT COUNT(*) FROM Devices '. getDeviceCondition ('all').') as devices,
(SELECT COUNT(*) FROM Devices '. getDeviceCondition ('connected').') as connected,
(SELECT COUNT(*) FROM Devices '. getDeviceCondition ('favorites').') as favorites,
(SELECT COUNT(*) FROM Devices '. getDeviceCondition ('new').') as new,
(SELECT COUNT(*) FROM Devices '. getDeviceCondition ('down').') as down,
(SELECT COUNT(*) FROM Devices '. getDeviceCondition ('archived').') as archived
');
$resultJSON = "";
$row = $result -> fetchArray (SQLITE3_NUM);
if(getCache("getDevicesTotals") != "")
{
$resultJSON = getCache("getDevicesTotals");
} else
{
global $db;
echo (json_encode (array ($row[0], $row[1], $row[2], $row[3], $row[4], $row[5])));
// combined query
$result = $db->query(
'SELECT
(SELECT COUNT(*) FROM Devices '. getDeviceCondition ('all').') as devices,
(SELECT COUNT(*) FROM Devices '. getDeviceCondition ('connected').') as connected,
(SELECT COUNT(*) FROM Devices '. getDeviceCondition ('favorites').') as favorites,
(SELECT COUNT(*) FROM Devices '. getDeviceCondition ('new').') as new,
(SELECT COUNT(*) FROM Devices '. getDeviceCondition ('down').') as down,
(SELECT COUNT(*) FROM Devices '. getDeviceCondition ('archived').') as archived
');
$row = $result -> fetchArray (SQLITE3_NUM);
$resultJSON = json_encode (array ($row[0], $row[1], $row[2], $row[3], $row[4], $row[5]));
// save to cache
setCache("getDevicesTotals", $resultJSON );
}
echo ($resultJSON);
}
@@ -574,12 +733,43 @@ function getOwners() {
}
//------------------------------------------------------------------------------
// Query Device Data
//------------------------------------------------------------------------------
function getNetworkNodes() {
global $db;
// Device Data
$sql = 'SELECT * FROM Devices WHERE dev_DeviceType in ( "AP", "Gateway", "Powerline", "Switch", "WLAN", "PLC", "Router","USB LAN Adapter", "USB WIFI Adapter")';
$result = $db->query($sql);
// arrays of rows
$tableData = array();
while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
// Push row data
$tableData[] = array('id' => $row['dev_MAC'],
'name' => $row['dev_Name'] );
}
// Control no rows
if (empty($tableData)) {
$tableData = [];
}
// Return json
echo (json_encode ($tableData));
}
//------------------------------------------------------------------------------
// Query the List of types
//------------------------------------------------------------------------------
function getDeviceTypes() {
global $db;
$networkTypes = getNetworkTypes();
// SQL
$sql = 'SELECT DISTINCT 9 as dev_Order, dev_DeviceType
FROM Devices
@@ -588,7 +778,7 @@ function getDeviceTypes() {
"Laptop", "Mini PC", "PC", "Printer", "Server", "Singleboard Computer (SBC)",
"Game Console", "SmartTV", "TV Decoder", "Virtual Assistance",
"Clock", "House Appliance", "Phone", "Radio",
"AP", "NAS", "PLC", "Router")
"AP", "Gateway", "Powerline", "Switch", "WLAN", "PLC", "Router","USB LAN Adapter", "USB WIFI Adapter" )
UNION SELECT 1 as dev_Order, "Smartphone"
UNION SELECT 1 as dev_Order, "Tablet"
@@ -599,6 +789,7 @@ function getDeviceTypes() {
UNION SELECT 2 as dev_Order, "Printer"
UNION SELECT 2 as dev_Order, "Server"
UNION SELECT 2 as dev_Order, "Singleboard Computer (SBC)"
UNION SELECT 2 as dev_Order, "NAS"
UNION SELECT 3 as dev_Order, "Domotic"
UNION SELECT 3 as dev_Order, "Game Console"
@@ -611,8 +802,12 @@ function getDeviceTypes() {
UNION SELECT 4 as dev_Order, "Phone"
UNION SELECT 4 as dev_Order, "Radio"
-- network devices
UNION SELECT 5 as dev_Order, "AP"
UNION SELECT 5 as dev_Order, "NAS"
UNION SELECT 5 as dev_Order, "Gateway"
UNION SELECT 5 as dev_Order, "Powerline"
UNION SELECT 5 as dev_Order, "Switch"
UNION SELECT 5 as dev_Order, "WLAN"
UNION SELECT 5 as dev_Order, "PLC"
UNION SELECT 5 as dev_Order, "Router"
UNION SELECT 5 as dev_Order, "USB LAN Adapter"
@@ -621,6 +816,8 @@ function getDeviceTypes() {
UNION SELECT 10 as dev_Order, "Other"
ORDER BY 1,2';
$result = $db->query($sql);
// arrays of rows
@@ -633,8 +830,6 @@ function getDeviceTypes() {
// Return json
echo (json_encode ($tableData));
}
//------------------------------------------------------------------------------
// Query the List of groups
//------------------------------------------------------------------------------
@@ -761,4 +956,5 @@ function getDeviceCondition ($deviceStatus) {
}
}
?>

View File

@@ -7,7 +7,13 @@
//------------------------------------------------------------------------------
// Puche 2021 pi.alert.application@gmail.com GNU GPLv3
//------------------------------------------------------------------------------
// ## TimeZone processing
$config_file = "../../../config/pialert.conf";
$config_file_lines = file($config_file);
$config_file_lines_timezone = array_values(preg_grep('/^TIMEZONE\s.*/', $config_file_lines));
$timezone_line = explode("'", $config_file_lines_timezone[0]);
$Pia_TimeZone = $timezone_line[1];
date_default_timezone_set($Pia_TimeZone);
//------------------------------------------------------------------------------
// External files
@@ -46,51 +52,57 @@ function getEventsTotals() {
global $db;
// Request Parameters
$periodDate = getDateFromPeriod();
$periodDate = $_REQUEST['period'];
// SQL
$SQL1 = 'SELECT Count(*)
FROM Events
WHERE eve_DateTime >= '. $periodDate;
$SQL2 = 'SELECT Count(*)
FROM Sessions ';
$periodDateSQL = "";
$days = "";
// All
$result = $db->query($SQL1);
$row = $result -> fetchArray (SQLITE3_NUM);
$eventsAll = $row[0];
switch ($periodDate) {
case '7 days':
$days = "7";
break;
case '1 month':
$days = "30";
break;
case '1 year':
$days = "365";
break;
case '100 years':
$days = "3650"; //10 years
break;
default:
$days = "1";
}
// Sessions
$result = $db->query($SQL2. ' WHERE ( ses_DateTimeConnection >= '. $periodDate .'
OR ses_DateTimeDisconnection >= '. $periodDate .'
OR ses_StillConnected = 1 ) ');
$row = $result -> fetchArray (SQLITE3_NUM);
$eventsSessions = $row[0];
$periodDateSQL = "-".$days." day";
// Missing
$result = $db->query($SQL2. ' WHERE (ses_DateTimeConnection IS NULL AND ses_DateTimeDisconnection >= '. $periodDate .' )
OR (ses_DateTimeDisconnection IS NULL AND ses_StillConnected = 0 AND ses_DateTimeConnection >= '. $periodDate .' )' );
$row = $result -> fetchArray (SQLITE3_NUM);
$eventsMissing = $row[0];
$resultJSON = "";
// Voided
$result = $db->query($SQL1. ' AND eve_EventType LIKE "VOIDED%" ');
$row = $result -> fetchArray (SQLITE3_NUM);
$eventsVoided = $row[0];
// check cache if JSON available in a cookie
if(getCache("getEventsTotals".$days) != "")
{
$resultJSON = getCache("getEventsTotals".$days);
} else
{
// one query to get all numbers, whcih is quicker than multiple queries
$sql = "select
(SELECT Count(*) FROM Events WHERE eve_DateTime >= date('now', '".$periodDateSQL."')) as all_events,
(SELECT Count(*) FROM Sessions as sessions WHERE ( ses_DateTimeConnection >= date('now', '".$periodDateSQL."') OR ses_DateTimeDisconnection >= date('now', '".$periodDateSQL."') OR ses_StillConnected = 1 )) as sessions,
(SELECT Count(*) FROM Sessions WHERE ((ses_DateTimeConnection IS NULL AND ses_DateTimeDisconnection >= date('now', '".$periodDateSQL."' )) OR (ses_DateTimeDisconnection IS NULL AND ses_StillConnected = 0 AND ses_DateTimeConnection >= date('now', '".$periodDateSQL."' )))) as missing,
(SELECT Count(*) FROM Events WHERE eve_DateTime >= date('now', '".$periodDateSQL."') AND eve_EventType LIKE 'VOIDED%' ) as voided,
(SELECT Count(*) FROM Events WHERE eve_DateTime >= date('now', '".$periodDateSQL."') AND eve_EventType LIKE 'New Device' ) as new,
(SELECT Count(*) FROM Events WHERE eve_DateTime >= date('now', '".$periodDateSQL."') AND eve_EventType LIKE 'Device Down' ) as down";
// New
$result = $db->query($SQL1. ' AND eve_EventType LIKE "New Device" ');
$row = $result -> fetchArray (SQLITE3_NUM);
$eventsNew = $row[0];
$result = $db->query($sql);
$row = $result -> fetchArray (SQLITE3_NUM);
$resultJSON = json_encode (array ($row[0], $row[1], $row[2], $row[3], $row[4], $row[5]));
// Down
$result = $db->query($SQL1. ' AND eve_EventType LIKE "Device Down" ');
$row = $result -> fetchArray (SQLITE3_NUM);
$eventsDown = $row[0];
// Return json
echo (json_encode (array ($eventsAll, $eventsSessions, $eventsMissing, $eventsVoided, $eventsNew, $eventsDown)));
// save JSON result to cache
setCache("getEventsTotals".$days, $resultJSON );
}
// Return json
echo ($resultJSON);
}
@@ -217,15 +229,15 @@ function getDeviceSessions() {
// Disconnection DateTime
if ($row['ses_StillConnected'] == true) {
$end = '...';
$end = '...';
} elseif ($row['ses_EventTypeDisconnection'] == '<missing event>') {
$end = $row['ses_EventTypeDisconnection'];
$end = $row['ses_EventTypeDisconnection'];
} else {
$end = formatDate ($row['ses_DateTimeDisconnection']);
}
// Duration
if ($row['ses_EventTypeConnection'] == '<missing event>' || $row['ses_EventTypeDisconnection'] == '<missing event>') {
if ($row['ses_EventTypeConnection'] == '<missing event>' || $row['ses_EventTypeConnection'] == NULL || $row['ses_EventTypeDisconnection'] == '<missing event>' || $row['ses_EventTypeDisconnection'] == NULL) {
$dur = '...';
} elseif ($row['ses_StillConnected'] == true) {
$dur = formatDateDiff ($row['ses_DateTimeConnection'], ''); //***********
@@ -261,7 +273,6 @@ function getDevicePresence() {
// Request Parameters
$mac = $_REQUEST['mac'];
$periodDate = getDateFromPeriod();
$startDate = '"'. formatDateISO ($_REQUEST ['start']) .'"';
$endDate = '"'. formatDateISO ($_REQUEST ['end']) .'"';
@@ -276,7 +287,7 @@ function getDevicePresence() {
END AS ses_DateTimeConnectionCorrected,
CASE
WHEN ses_EventTypeDisconnection = "<missing event>" THEN
WHEN ses_EventTypeDisconnection = "<missing event>" OR ses_EventTypeDisconnection = NULL THEN
(SELECT MIN(ses_DateTimeConnection) FROM Sessions AS SES2 WHERE SES2.ses_MAC = SES1.ses_MAC AND SES2.ses_DateTimeConnection > SES1.ses_DateTimeConnection)
ELSE ses_DateTimeDisconnection
END AS ses_DateTimeDisconnectionCorrected
@@ -290,13 +301,14 @@ function getDevicePresence() {
// arrays of rows
while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
// Event color
if ($row['ses_EventTypeConnection'] == '<missing event>' || $row['ses_EventTypeDisconnection'] == '<missing event>') {
$color = '#f39c12';
} elseif ($row['ses_StillConnected'] == 1 ) {
$color = '#00a659';
} else {
$color = '#0073b7';
}
if ($row['ses_EventTypeConnection'] == '<missing event>' || $row['ses_EventTypeDisconnection'] == '<missing event>') {
$color = '#f39c12';
} elseif ($row['ses_StillConnected'] == 1 ) {
$color = '#00a659';
} else {
$color = '#0073b7';
}
// tooltip
$tooltip = 'Connection: ' . formatEventDate ($row['ses_DateTimeConnection'], $row['ses_EventTypeConnection']) . chr(13) .
@@ -333,7 +345,7 @@ function getEventsCalendar() {
$startDate = '"'. $_REQUEST ['start'] .'"';
$endDate = '"'. $_REQUEST ['end'] .'"';
// SQL
// SQL
$SQL = 'SELECT ses_MAC, ses_EventTypeConnection, ses_DateTimeConnection,
ses_EventTypeDisconnection, ses_DateTimeDisconnection, ses_IP, ses_AdditionalInfo, ses_StillConnected,
@@ -358,12 +370,12 @@ function getEventsCalendar() {
while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
// Event color
if ($row['ses_EventTypeConnection'] == '<missing event>' || $row['ses_EventTypeDisconnection'] == '<missing event>') {
$color = '#f39c12';
} elseif ($row['ses_StillConnected'] == 1 ) {
$color = '#00a659';
} else {
$color = '#0073b7';
}
$color = '#f39c12';
} elseif ($row['ses_StillConnected'] == 1 ) {
$color = '#00a659';
} else {
$color = '#0073b7';
}
// tooltip
$tooltip = 'Connection: ' . formatEventDate ($row['ses_DateTimeConnection'], $row['ses_EventTypeConnection']) . chr(13) .

View File

@@ -8,6 +8,13 @@
// Puche 2021 pi.alert.application@gmail.com GNU GPLv3
//------------------------------------------------------------------------------
// ## TimeZone processing
$config_file = "../../../config/pialert.conf";
$config_file_lines = file($config_file);
$config_file_lines_timezone = array_values(preg_grep('/^TIMEZONE\s.*/', $config_file_lines));
$timezone_line = explode("'", $config_file_lines_timezone[0]);
$Pia_TimeZone = $timezone_line[1];
date_default_timezone_set($Pia_TimeZone);
//------------------------------------------------------------------------------
// Formatting data functions
@@ -58,4 +65,62 @@ function logServerConsole ($text) {
$y = $x['__________'. $text .'__________'];
}
function getNetworkTypes(){
$array = array(
"AP", "Gateway", "Powerline", "Switch", "WLAN", "PLC", "Router","USB LAN Adapter", "USB WIFI Adapter"
);
return $array;
}
function getDevicesColumns(){
$columns = ["dev_MAC",
"dev_Name",
"dev_Owner",
"dev_DeviceType",
"dev_Vendor",
"dev_Favorite",
"dev_Group",
"dev_Comments",
"dev_FirstConnection",
"dev_LastConnection",
"dev_LastIP",
"dev_StaticIP",
"dev_ScanCycle",
"dev_LogEvents",
"dev_AlertEvents",
"dev_AlertDeviceDown",
"dev_SkipRepeated",
"dev_LastNotification",
"dev_PresentLastScan",
"dev_NewDevice",
"dev_Location",
"dev_Archived",
"dev_Network_Node_port",
"dev_Network_Node_MAC_ADDR"];
return $columns;
}
//------------------------------------------------------------------------------
// Simple cookie cache
//------------------------------------------------------------------------------
function getCache($key) {
if( isset($_COOKIE[$key]))
{
return $_COOKIE[$key];
}else
{
return "";
}
}
function setCache($key, $value) {
setcookie($key, $value, time()+300, "/","", 0); // 5min cache
}
?>

View File

@@ -1,10 +1,16 @@
<?php
require 'php/server/db.php';
$DBFILE = '../db/pialert.db';
OpenDB();
$Pia_Graph_Device_Time = array();
$Pia_Graph_Device_All = array();
$Pia_Graph_Device_Online = array();
$Pia_Graph_Device_Down = array();
$Pia_Graph_Device_Arch = array();
$db = new SQLite3('../db/pialert.db');
//$db = new SQLite3('../db/pialert.db');
$results = $db->query('SELECT * FROM Online_History ORDER BY Scan_Date DESC LIMIT 144');
while ($row = $results->fetchArray()) {
$time_raw = explode(' ', $row['Scan_Date']);
@@ -23,4 +29,5 @@ function pia_graph_devices_data($Pia_Graph_Array) {
}
}
$db->close();
?>

View File

@@ -88,6 +88,7 @@ if ($ENABLED_DARKMODE === True) {
?>
<!-- Servertime to the right of the hostname -->
<script>
var pia_servertime = new Date(<?php echo date("Y, n, j, G, i, s") ?>);
function show_pia_servertime() {
@@ -118,7 +119,7 @@ function show_pia_servertime() {
<!-- ----------------------------------------------------------------------- -->
<!-- Logo -->
<a href="." class="logo">
<a href="devices.php" class="logo">
<!-- mini logo for sidebar mini 50x50 pixels -->
<span class="logo-mini">P<b>a</b></span>
<!-- logo for regular state and mobile devices -->
@@ -162,7 +163,7 @@ function show_pia_servertime() {
<li class="user-footer">
<div class="pull-right">
<a href="/pialert/index.php?action=logout" class="btn btn-danger">Sign out</a>
<a href="index.php?action=logout" class="btn btn-danger">Sign out</a>
</div>
</li>
</ul>
@@ -218,11 +219,6 @@ function show_pia_servertime() {
<li class=" <?php if (in_array (basename($_SERVER['SCRIPT_NAME']), array('maintenance.php') ) ){ echo 'active'; } ?>">
<a href="maintenance.php"><i class="fa fa-cog"></i> <span><?php echo $pia_lang['Navigation_Maintenance'];?></span></a>
</li>
<li class=" <?php if (in_array (basename($_SERVER['SCRIPT_NAME']), array('help_faq.php') ) ){ echo 'active'; } ?>">
<a href="help_faq.php"><i class="fa fa-question"></i> <span><?php echo $pia_lang['Navigation_HelpFAQ'];?></span></a>
</li>
<!--
<li class="treeview">
<a href="#"><i class="fa fa-link"></i> <span>Config</span>

View File

@@ -44,8 +44,7 @@ $pia_lang['Device_Shortcut_NewDevices'] = 'Neue Geräte';
$pia_lang['Device_Shortcut_DownAlerts'] = 'Down Meldungen';
$pia_lang['Device_Shortcut_Archived'] = 'Archiviert';
$pia_lang['Device_Shortcut_Devices'] = 'Geräte';
$pia_lang['Device_Shortcut_OnlineChart_a'] = 'Netzwerkaktivität über die letzten';
$pia_lang['Device_Shortcut_OnlineChart_b'] = 'Stunden';
$pia_lang['Device_Shortcut_OnlineChart'] = 'Gerätepräsenz im Laufe der Zeit';
$pia_lang['Device_TableHead_Name'] = 'Name';
$pia_lang['Device_TableHead_Owner'] = 'Eigentümer';
$pia_lang['Device_TableHead_Type'] = 'Typ';

View File

@@ -251,11 +251,11 @@ $pia_lang['Maintenance_Tool_del_allevents30_noti_text'] = 'Are you sure you want
$pia_lang['Maintenance_Tool_backup'] = 'DB Backup';
$pia_lang['Maintenance_Tool_backup_text'] = 'The database backups are located in the database directory as a zip-archive, named with the creation date. There is no maximum number of backups.';
$pia_lang['Maintenance_Tool_backup_noti'] = 'DB Backup';
$pia_lang['Maintenance_Tool_backup_noti_text'] = 'Are you sure you want to exectute the the DB Backup? Be sure that no scan is currently running.';
$pia_lang['Maintenance_Tool_backup_noti_text'] = 'Are you sure you want to execute the the DB Backup? Be sure that no scan is currently running.';
$pia_lang['Maintenance_Tool_restore'] = 'DB Restore';
$pia_lang['Maintenance_Tool_restore_text'] = 'The latest backup can be restored via the button, but older backups can only be restored manually. After the restore, make an integrity check on the database for safety, in case the db was currently in write access when the backup was created.';
$pia_lang['Maintenance_Tool_restore_noti'] = 'DB Restore';
$pia_lang['Maintenance_Tool_restore_noti_text'] = 'Are you sure you want to exectute the the DB Restore? Be sure that no scan is currently running.';
$pia_lang['Maintenance_Tool_restore_noti_text'] = 'Are you sure you want to execute the the DB Restore? Be sure that no scan is currently running.';
$pia_lang['Maintenance_Tool_purgebackup'] = 'Purge Backups';
$pia_lang['Maintenance_Tool_purgebackup_text'] = 'All other backups will be deleted except for the last 3 backups.';
$pia_lang['Maintenance_Tool_purgebackup_noti'] = 'Purge Backups';
@@ -264,6 +264,14 @@ $pia_lang['Maintenance_Tool_del_ActHistory'] = 'Deleting the network activity';
$pia_lang['Maintenance_Tool_del_ActHistory_text'] = 'The network activity graph is reset. This does not affect the events.';
$pia_lang['Maintenance_Tool_del_ActHistory_noti'] = 'Delete network activity';
$pia_lang['Maintenance_Tool_del_ActHistory_noti_text'] = 'Are you sure you want to reset the network activity?';
$pia_lang['Maintenance_Tool_ExportCSV'] = 'CSV Export';
$pia_lang['Maintenance_Tool_ExportCSV_text'] = 'Generate a CSV (comma separated value) file containing the list of Devices including the Network relationships between Network Nodes and connected devices.';
$pia_lang['Maintenance_Tool_ExportCSV_noti'] = 'CSV Export';
$pia_lang['Maintenance_Tool_ExportCSV_noti_text'] = 'Are you sure you want to generate a CSV file?';
$pia_lang['Maintenance_Tool_ImportCSV'] = 'CSV Import';
$pia_lang['Maintenance_Tool_ImportCSV_text'] = 'Before using this function, please make a backup. Import a CSV (comma separated value) file containing the list of Devices including the Network relationships between Network Nodes and connected devices. To do that place the CSV file named <b>devices.csv</b> into your <b>/config</b> folder.';
$pia_lang['Maintenance_Tool_ImportCSV_noti'] = 'CSV Import';
$pia_lang['Maintenance_Tool_ImportCSV_noti_text'] = 'Are you sure you want to import the CSV file? This will completely overwrite the devices in your database.';
//////////////////////////////////////////////////////////////////
// Maintenance Page
@@ -290,6 +298,10 @@ $pia_lang['BackDevices_DBTools_UpdDevError'] = 'Error updating device';
$pia_lang['BackDevices_DBTools_Upgrade'] = 'Database upgraded successfully';
$pia_lang['BackDevices_DBTools_UpgradeError'] = 'Database upgrade failed';
$pia_lang['BackDevices_DBTools_Purge'] = 'The oldest backups were deleted';
$pia_lang['BackDevices_DBTools_ImportCSV'] = 'The devices from the CSV file were imported successfully.';
$pia_lang['BackDevices_DBTools_ImportCSVError'] = 'The CSV file couldn\'t be imported. Make sure the format is correct.';
$pia_lang['BackDevices_DBTools_ImportCSVMissing'] = 'The CSV file couldn\'t be found under <b>/config/devices.csv.</b>';
//////////////////////////////////////////////////////////////////
// Network Page
@@ -322,5 +334,6 @@ $pia_lang['Network_ManageDel_Submit'] = 'Delete';
$pia_lang['Network_Table_State'] = 'State';
$pia_lang['Network_Table_Hostname'] = 'Hostname';
$pia_lang['Network_Table_IP'] = 'IP';
$pia_lang['Network_UnassignedDevices'] = 'Unassigned devices';
?>

View File

@@ -12,7 +12,7 @@ session_start();
if ($_SESSION["login"] != 1)
{
header('Location: /pialert/index.php');
header('Location: index.php');
exit;
}
@@ -114,7 +114,7 @@ if ($_SESSION["login"] != 1)
<div class="col-md-12">
<div class="box" id="clients">
<div class="box-header with-border">
<h3 class="box-title"><?php echo $pia_lang['Device_Shortcut_OnlineChart_a'];?> <span class="maxlogage-interval">12</span> <?php echo $pia_lang['Device_Shortcut_OnlineChart_b'];?></h3>
<h3 class="box-title"><?php echo $pia_lang['Device_Shortcut_OnlineChart'];?></h3>
</div>
<div class="box-body">
<div class="chart">