Merge remote-tracking branch 'origin/leiweibau-merge-2022-07-31' into pr/55

This commit is contained in:
jokob-sk
2022-07-31 10:09:27 +10:00
39 changed files with 1284 additions and 160 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

@@ -704,7 +704,6 @@ function main () {
// Read Cookies
devicesList = getCookie('devicesList');
deleteCookie ('devicesList');
if (devicesList != '') {
devicesList = JSON.parse (devicesList);
} else {
@@ -1193,6 +1192,13 @@ function getDeviceData (readAllData=false) {
mac =deviceData['dev_MAC'];
// update the mac parameter in the URL, this makes the selected device persistent when the page is reloaded
var searchParams = new URLSearchParams(window.location.search);
searchParams.set("mac", mac);
var newRelativePathQuery = window.location.pathname + '?' + searchParams.toString();
history.pushState(null, '', newRelativePathQuery);
getSessionsPresenceEvents();
$('#txtMAC').val (deviceData['dev_MAC']);
$('#txtName').val (deviceData['dev_Name']);
$('#txtOwner').val (deviceData['dev_Owner']);
@@ -1254,7 +1260,7 @@ function getDeviceData (readAllData=false) {
$('#btnNext').removeAttr ('disabled');
$('#btnNext').removeClass ('text-gray50');
}
// Timer for refresh data
$("body").css("cursor", "default");
newTimerRefreshData (getDeviceData);
@@ -1422,13 +1428,16 @@ function deleteDevice () {
// -----------------------------------------------------------------------------
function getSessionsPresenceEvents () {
// Check MAC in url
var urlParams = new URLSearchParams(window.location.search);
mac = urlParams.get ('mac');
// Define Sessions datasource and query dada
$('#tableSessions').DataTable().ajax.url('php/server/events.php?action=getDeviceSessions&mac=' + mac +'&period='+ period).load();
// Define Presence datasource and query data
$('#calendar').fullCalendar('removeEventSources');
$('#calendar').fullCalendar('addEventSource',
{ url: 'php/server/events.php?action=getDevicePresence&mac=' + mac +'&period='+ period });
{ url: 'php/server/events.php?action=getDevicePresence&mac=' + mac});
// Query events
getDeviceEvents();

View File

@@ -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

@@ -338,9 +338,9 @@ 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>
</div>
</div>
</div>
<div style="width: 100%; height: 20px;"></div>

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));
@@ -35,7 +42,8 @@ if (strlen($pia_lang_selected) == 0) {$pia_lang_selected = 'en_us';}
case 'getDeviceData': getDeviceData(); break;
case 'setDeviceData': setDeviceData(); break;
case 'deleteDevice': deleteDevice(); break;
case 'deleteAllWithEmptyMACs': deleteAllWithEmptyMACs(); break;
case 'deleteDeviceEvents': deleteDeviceEvents(); break;
case 'deleteAllWithEmptyMACs': deleteAllWithEmptyMACs(); break;
case 'createBackupDB': createBackupDB(); break;
case 'restoreBackupDB': restoreBackupDB(); break;
case 'deleteAllDevices': deleteAllDevices(); break;
@@ -49,7 +57,7 @@ if (strlen($pia_lang_selected) == 0) {$pia_lang_selected = 'en_us';}
case 'PiaRestoreDBfromArchive': PiaRestoreDBfromArchive(); break;
case 'PiaPurgeDBBackups': PiaPurgeDBBackups(); break;
case 'PiaEnableDarkmode': PiaEnableDarkmode(); break;
case 'PiaToggleArpScan': PiaToggleArpScan(); break;
case 'PiaToggleArpScan': PiaToggleArpScan(); break;
case 'getDevicesTotals': getDevicesTotals(); break;
case 'getDevicesList': getDevicesList(); break;
@@ -119,8 +127,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
@@ -198,6 +208,26 @@ function deleteDevice() {
}
}
//------------------------------------------------------------------------------
// Delete Device Events
//------------------------------------------------------------------------------
function deleteDeviceEvents() {
global $db;
global $pia_lang;
// sql
$sql = 'DELETE FROM Events WHERE eve_MAC="' . $_REQUEST['mac'] .'"';
// 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 all devices with empty MAC addresses
//------------------------------------------------------------------------------

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
@@ -217,15 +223,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 +267,6 @@ function getDevicePresence() {
// Request Parameters
$mac = $_REQUEST['mac'];
$periodDate = getDateFromPeriod();
$startDate = '"'. formatDateISO ($_REQUEST ['start']) .'"';
$endDate = '"'. formatDateISO ($_REQUEST ['end']) .'"';
@@ -276,7 +281,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 +295,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 +339,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 +364,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

View File

@@ -102,6 +102,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() {
@@ -232,7 +233,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="treeview">
<a href="#"><i class="fa fa-link"></i> <span>Config</span>

View File

@@ -27,8 +27,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

@@ -10,6 +10,7 @@ $pia_lang['Gen_Backup'] = 'Run Backup';
$pia_lang['Gen_Restore'] = 'Run Restore';
$pia_lang['Gen_Switch'] = 'Switch';
//////////////////////////////////////////////////////////////////
// Device Page
//////////////////////////////////////////////////////////////////
@@ -27,8 +28,7 @@ $pia_lang['Device_Shortcut_NewDevices'] = 'New Devices';
$pia_lang['Device_Shortcut_DownAlerts'] = 'Down Alerts';
$pia_lang['Device_Shortcut_Archived'] = 'Archived';
$pia_lang['Device_Shortcut_Devices'] = 'Devices';
$pia_lang['Device_Shortcut_OnlineChart_a'] = 'Network activity over last';
$pia_lang['Device_Shortcut_OnlineChart_b'] = 'hours';
$pia_lang['Device_Shortcut_OnlineChart'] = 'Device presence over time';
$pia_lang['Device_TableHead_Name'] = 'Name';
$pia_lang['Device_TableHead_Owner'] = 'Owner';
$pia_lang['Device_TableHead_Type'] = 'Type';
@@ -152,6 +152,8 @@ $pia_lang['DevDetail_EveandAl_RandomMAC'] = 'Random MAC';
$pia_lang['DevDetail_EveandAl_ScanCycle_a'] = 'Scan Device (1 min)';
$pia_lang['DevDetail_EveandAl_ScanCycle_z'] = 'Don&#39;t Scan Device (0 min)';
$pia_lang['DevDetail_button_Delete'] = 'Delete Device';
$pia_lang['DevDetail_button_DeleteEvents'] = 'Delete Events';
$pia_lang['DevDetail_button_DeleteEvents_Warning'] = 'Are you sure you want to delete all Events of this device?<br><br>(this will clear the <b>Events history</b> and the <b>Sessions</b> and might help with constant (persistent) notifications)';
$pia_lang['DevDetail_button_Reset'] = 'Reset Changes';
$pia_lang['DevDetail_button_Save'] = 'Save';
$pia_lang['DevDetail_button_DeleteEvents'] = 'Delete Events';

View File

@@ -26,8 +26,7 @@ $pia_lang['Device_Shortcut_NewDevices'] = 'Nuevo(s)';
$pia_lang['Device_Shortcut_DownAlerts'] = 'Alerta(s) de caída(s)';
$pia_lang['Device_Shortcut_Archived'] = 'Archivado(s)';
$pia_lang['Device_Shortcut_Devices'] = 'Dispositivos';
$pia_lang['Device_Shortcut_OnlineChart_a'] = 'Actividad de la red durante las últimas';
$pia_lang['Device_Shortcut_OnlineChart_b'] = 'horas';
$pia_lang['Device_Shortcut_OnlineChart'] = 'Presencia del dispositivo a lo largo del tiempo';
$pia_lang['Device_TableHead_Name'] = 'Nombre';
$pia_lang['Device_TableHead_Owner'] = 'Propietario';
$pia_lang['Device_TableHead_Type'] = 'Tipo';

View File

@@ -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">