Merge remote-tracking branch 'origin/leiweibau-merge-2022-07-31' into pr/55
This commit is contained in:
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
@@ -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
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@@ -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) .
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user