Pi.Alert 3.00

This commit is contained in:
pucherot
2021-04-21 19:23:35 +02:00
parent 10757f0717
commit 4072bbf406
15 changed files with 756 additions and 286 deletions

View File

@@ -216,7 +216,8 @@ def get_previous_internet_IP ():
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
def save_new_internet_IP (pNewIP): def save_new_internet_IP (pNewIP):
# Log new IP into logfile # Log new IP into logfile
append_line_to_file (LOG_PATH + '/IP_changes.log', str(startTime) +'\t'+ pNewIP +'\n') append_line_to_file (LOG_PATH + '/IP_changes.log',
str(startTime) +'\t'+ pNewIP +'\n')
# Save event # Save event
sql.execute ("""INSERT INTO Events (eve_MAC, eve_IP, eve_DateTime, sql.execute ("""INSERT INTO Events (eve_MAC, eve_IP, eve_DateTime,
@@ -295,7 +296,8 @@ def update_devices_MAC_vendors (pArg = ''):
# print (recordsToUpdate) # print (recordsToUpdate)
# update devices # update devices
sql.executemany ("UPDATE Devices SET dev_Vendor = ? WHERE dev_MAC = ? ", recordsToUpdate ) sql.executemany ("UPDATE Devices SET dev_Vendor = ? WHERE dev_MAC = ? ",
recordsToUpdate )
# DEBUG - print number of rows updated # DEBUG - print number of rows updated
# print (sql.rowcount) # print (sql.rowcount)
@@ -443,8 +445,13 @@ def query_ScanCycle_Data (pOpenCloseDB = False):
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
def execute_arpscan (pRetries): def execute_arpscan (pRetries):
# Prepara command arguments
arpscan_args = ['sudo', 'arp-scan', '--localnet', '--ignoredups', '--retry=' + str(pRetries)] # #101 - arp-scan subnet configuration
# Prepare command arguments
subnets = SCAN_SUBNETS.strip().split()
arpscan_args = ['sudo', 'arp-scan', '--ignoredups', '--retry=' + str(pRetries)] + subnets
# arpscan_args = ['sudo', 'arp-scan', SCAN_SUBNETS, '--ignoredups', '--retry=' + str(pRetries)]
# print (arpscan_args)
# TESTING - Fast Scan # TESTING - Fast Scan
# arpscan_args = ['sudo', 'arp-scan', '--localnet', '--ignoredups', '--retry=1'] # arpscan_args = ['sudo', 'arp-scan', '--localnet', '--ignoredups', '--retry=1']
@@ -570,6 +577,25 @@ def save_scanned_devices (p_arpscan_devices, p_cycle_interval):
(int(startTime.strftime('%s')) - 60 * p_cycle_interval), (int(startTime.strftime('%s')) - 60 * p_cycle_interval),
cycle) ) cycle) )
# Check Internet connectivity
internet_IP = get_internet_IP()
# TESTING - Force IP
# internet_IP = ""
if internet_IP != "" :
sql.execute ("""INSERT INTO CurrentScan (cur_ScanCycle, cur_MAC, cur_IP, cur_Vendor, cur_ScanMethod)
VALUES (?, 'Internet', ?, Null, 'queryDNS') """, (cycle, internet_IP) )
# #76 Add Local MAC of default local interface
local_mac_cmd = ["ifconfig `ip route list default | awk {'print $5'}` | grep ether | awk '{print $2}'"]
local_mac = subprocess.Popen (local_mac_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT).communicate()[0].strip()
local_ip_cmd = ["ip route list default | awk {'print $7'}"]
local_ip = subprocess.Popen (local_ip_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT).communicate()[0].strip()
sql.execute ("INSERT INTO CurrentScan (cur_ScanCycle, cur_MAC, cur_IP, cur_Vendor, cur_ScanMethod) "+
"VALUES ( ?, ?, ?, Null, 'local_MAC') ", (cycle, local_mac, local_ip) )
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
def print_scan_stats (): def print_scan_stats ():
# Devices Detected # Devices Detected
@@ -672,9 +698,9 @@ def create_new_devices ():
sql.execute ("""INSERT INTO Devices (dev_MAC, dev_name, dev_Vendor, sql.execute ("""INSERT INTO Devices (dev_MAC, dev_name, dev_Vendor,
dev_LastIP, dev_FirstConnection, dev_LastConnection, dev_LastIP, dev_FirstConnection, dev_LastConnection,
dev_ScanCycle, dev_AlertEvents, dev_AlertDeviceDown, dev_ScanCycle, dev_AlertEvents, dev_AlertDeviceDown,
dev_PresentLastScan, dev_NewDevice) dev_PresentLastScan)
SELECT cur_MAC, '(unknown)', cur_Vendor, cur_IP, ?, ?, SELECT cur_MAC, '(unknown)', cur_Vendor, cur_IP, ?, ?,
1, 1, 0, 1, 1 1, 1, 0, 1
FROM CurrentScan FROM CurrentScan
WHERE cur_ScanCycle = ? WHERE cur_ScanCycle = ?
AND NOT EXISTS (SELECT 1 FROM Devices AND NOT EXISTS (SELECT 1 FROM Devices
@@ -701,9 +727,9 @@ def create_new_devices ():
sql.execute ("""INSERT INTO Devices (dev_MAC, dev_name, dev_Vendor, sql.execute ("""INSERT INTO Devices (dev_MAC, dev_name, dev_Vendor,
dev_LastIP, dev_FirstConnection, dev_LastConnection, dev_LastIP, dev_FirstConnection, dev_LastConnection,
dev_ScanCycle, dev_AlertEvents, dev_AlertDeviceDown, dev_ScanCycle, dev_AlertEvents, dev_AlertDeviceDown,
dev_PresentLastScan, dev_NewDevice) dev_PresentLastScan)
SELECT PH_MAC, PH_Name, PH_Vendor, IFNULL (PH_IP,'-'), SELECT PH_MAC, PH_Name, PH_Vendor, IFNULL (PH_IP,'-'),
?, ?, 1, 1, 0, 1, 1 ?, ?, 1, 1, 0, 1
FROM PiHole_Network FROM PiHole_Network
WHERE NOT EXISTS (SELECT 1 FROM Devices WHERE NOT EXISTS (SELECT 1 FROM Devices
WHERE dev_MAC = PH_MAC) """, WHERE dev_MAC = PH_MAC) """,
@@ -731,7 +757,7 @@ def create_new_devices ():
sql.execute ("""INSERT INTO Devices (dev_MAC, dev_name, dev_LastIP, sql.execute ("""INSERT INTO Devices (dev_MAC, dev_name, dev_LastIP,
dev_Vendor, dev_FirstConnection, dev_LastConnection, dev_Vendor, dev_FirstConnection, dev_LastConnection,
dev_ScanCycle, dev_AlertEvents, dev_AlertDeviceDown, dev_ScanCycle, dev_AlertEvents, dev_AlertDeviceDown,
dev_PresentLastScan, dev_NewDevice) dev_PresentLastScan)
SELECT DISTINCT DHCP_MAC, SELECT DISTINCT DHCP_MAC,
(SELECT DHCP_Name FROM DHCP_Leases AS D2 (SELECT DHCP_Name FROM DHCP_Leases AS D2
WHERE D2.DHCP_MAC = D1.DHCP_MAC WHERE D2.DHCP_MAC = D1.DHCP_MAC
@@ -739,7 +765,7 @@ def create_new_devices ():
(SELECT DHCP_IP FROM DHCP_Leases AS D2 (SELECT DHCP_IP FROM DHCP_Leases AS D2
WHERE D2.DHCP_MAC = D1.DHCP_MAC WHERE D2.DHCP_MAC = D1.DHCP_MAC
ORDER BY DHCP_DateTime DESC LIMIT 1), ORDER BY DHCP_DateTime DESC LIMIT 1),
'(unknown)', ?, ?, 1, 1, 0, 1, 1 '(unknown)', ?, ?, 1, 1, 0, 1
FROM DHCP_Leases AS D1 FROM DHCP_Leases AS D1
WHERE NOT EXISTS (SELECT 1 FROM Devices WHERE NOT EXISTS (SELECT 1 FROM Devices
WHERE dev_MAC = DHCP_MAC) """, WHERE dev_MAC = DHCP_MAC) """,
@@ -913,7 +939,8 @@ def update_devices_names ():
# Devices without name # Devices without name
print (' Trying to resolve devices without name...', end='') print (' Trying to resolve devices without name...', end='')
for device in sql.execute ("SELECT * FROM Devices WHERE dev_Name IN ('(unknown)','') ") : # BUGFIX #97 - Updating name of Devices w/o IP
for device in sql.execute ("SELECT * FROM Devices WHERE dev_Name IN ('(unknown)','') AND dev_LastIP <> '-'") :
# Resolve device name # Resolve device name
newName = resolve_device_name (device['dev_MAC'], device['dev_LastIP']) newName = resolve_device_name (device['dev_MAC'], device['dev_LastIP'])
@@ -949,11 +976,14 @@ def resolve_device_name (pMAC, pIP):
if len(pMACstr) != 17 or len(mac) != 12 : if len(pMACstr) != 17 or len(mac) != 12 :
return -2 return -2
# DEBUG
# print (pMAC, pIP)
# Resolve name with DIG # Resolve name with DIG
dig_args = ['dig', '+short', '-x', pIP] dig_args = ['dig', '+short', '-x', pIP]
newName = subprocess.check_output (dig_args, universal_newlines=True) newName = subprocess.check_output (dig_args, universal_newlines=True)
# Check if Eliminate local domain # Check returns
newName = newName.strip() newName = newName.strip()
if len(newName) == 0 : if len(newName) == 0 :
return -2 return -2
@@ -981,7 +1011,8 @@ def void_ghost_disconnections ():
print_log ('Void - 1 Connect ghost events') print_log ('Void - 1 Connect ghost events')
sql.execute ("""UPDATE Events SET eve_PairEventRowid = Null, sql.execute ("""UPDATE Events SET eve_PairEventRowid = Null,
eve_EventType ='VOIDED - ' || eve_EventType eve_EventType ='VOIDED - ' || eve_EventType
WHERE eve_EventType = 'Connected' WHERE eve_MAC != 'Internet'
AND eve_EventType = 'Connected'
AND eve_DateTime = ? AND eve_DateTime = ?
AND eve_MAC IN ( AND eve_MAC IN (
SELECT Events.eve_MAC SELECT Events.eve_MAC
@@ -1000,7 +1031,8 @@ def void_ghost_disconnections ():
# Void connect paired events # Void connect paired events
print_log ('Void - 2 Paired events') print_log ('Void - 2 Paired events')
sql.execute ("""UPDATE Events SET eve_PairEventRowid = Null sql.execute ("""UPDATE Events SET eve_PairEventRowid = Null
WHERE eve_PairEventRowid IN ( WHERE eve_MAC != 'Internet'
AND eve_PairEventRowid IN (
SELECT Events.RowID SELECT Events.RowID
FROM CurrentScan, Devices, ScanCycles, Events FROM CurrentScan, Devices, ScanCycles, Events
WHERE cur_ScanCycle = ? WHERE cur_ScanCycle = ?
@@ -1018,7 +1050,8 @@ def void_ghost_disconnections ():
print_log ('Void - 3 Disconnect ghost events') print_log ('Void - 3 Disconnect ghost events')
sql.execute ("""UPDATE Events SET eve_PairEventRowid = Null, sql.execute ("""UPDATE Events SET eve_PairEventRowid = Null,
eve_EventType = 'VOIDED - '|| eve_EventType eve_EventType = 'VOIDED - '|| eve_EventType
WHERE ROWID IN ( WHERE eve_MAC != 'Internet'
AND ROWID IN (
SELECT Events.RowID SELECT Events.RowID
FROM CurrentScan, Devices, ScanCycles, Events FROM CurrentScan, Devices, ScanCycles, Events
WHERE cur_ScanCycle = ? WHERE cur_ScanCycle = ?
@@ -1180,7 +1213,8 @@ def email_reporting ():
eventAlert['eve_EventType'], eventAlert['eve_DateTime'], eventAlert['eve_EventType'], eventAlert['eve_DateTime'],
eventAlert['eve_IP'], eventAlert['eve_AdditionalInfo']) eventAlert['eve_IP'], eventAlert['eve_AdditionalInfo'])
format_report_section (mail_section_Internet, 'SECTION_INTERNET', 'TABLE_INTERNET', mail_text_Internet, mail_html_Internet) format_report_section (mail_section_Internet, 'SECTION_INTERNET',
'TABLE_INTERNET', mail_text_Internet, mail_html_Internet)
# Compose New Devices Section # Compose New Devices Section
mail_section_new_devices = False mail_section_new_devices = False
@@ -1207,7 +1241,8 @@ def email_reporting ():
eventAlert['eve_DateTime'], eventAlert['eve_IP'], eventAlert['eve_DateTime'], eventAlert['eve_IP'],
eventAlert['dev_Name'], eventAlert['eve_AdditionalInfo']) eventAlert['dev_Name'], eventAlert['eve_AdditionalInfo'])
format_report_section (mail_section_new_devices, 'SECTION_NEW_DEVICES', 'TABLE_NEW_DEVICES', mail_text_new_devices, mail_html_new_devices) format_report_section (mail_section_new_devices, 'SECTION_NEW_DEVICES',
'TABLE_NEW_DEVICES', mail_text_new_devices, mail_html_new_devices)
# Compose Devices Down Section # Compose Devices Down Section
mail_section_devices_down = False mail_section_devices_down = False
@@ -1233,7 +1268,8 @@ def email_reporting ():
eventAlert['eve_DateTime'], eventAlert['eve_IP'], eventAlert['eve_DateTime'], eventAlert['eve_IP'],
eventAlert['dev_Name']) eventAlert['dev_Name'])
format_report_section (mail_section_devices_down, 'SECTION_DEVICES_DOWN', 'TABLE_DEVICES_DOWN', mail_text_devices_down, mail_html_devices_down) format_report_section (mail_section_devices_down, 'SECTION_DEVICES_DOWN',
'TABLE_DEVICES_DOWN', mail_text_devices_down, mail_html_devices_down)
# Compose Events Section # Compose Events Section
mail_section_events = False mail_section_events = False
@@ -1263,7 +1299,8 @@ def email_reporting ():
eventAlert['eve_EventType'], eventAlert['dev_Name'], eventAlert['eve_EventType'], eventAlert['dev_Name'],
eventAlert['eve_AdditionalInfo']) eventAlert['eve_AdditionalInfo'])
format_report_section (mail_section_events, 'SECTION_EVENTS', 'TABLE_EVENTS', mail_text_events, mail_html_events) format_report_section (mail_section_events, 'SECTION_EVENTS',
'TABLE_EVENTS', mail_text_events, mail_html_events)
# DEBUG - Write output emails for testing # DEBUG - Write output emails for testing
if True : if True :
@@ -1319,7 +1356,8 @@ def remove_section (pText, pSection):
if pText.find ('<'+ pSection +'>') >=0 \ if pText.find ('<'+ pSection +'>') >=0 \
and pText.find ('</'+ pSection +'>') >=0 : and pText.find ('</'+ pSection +'>') >=0 :
# return text without the section # return text without the section
return pText[:pText.find ('<'+ pSection+'>')] + pText[pText.find ('</'+ pSection +'>') + len (pSection) +3:] return pText[:pText.find ('<'+ pSection+'>')] + \
pText[pText.find ('</'+ pSection +'>') + len (pSection) +3:]
else : else :
# return all text # return all text
return pText return pText

View File

@@ -35,3 +35,16 @@ PIHOLE_ACTIVE = False
PIHOLE_DB = '/etc/pihole/pihole-FTL.db' PIHOLE_DB = '/etc/pihole/pihole-FTL.db'
DHCP_ACTIVE = False DHCP_ACTIVE = False
DHCP_LEASES = '/etc/pihole/dhcp.leases' DHCP_LEASES = '/etc/pihole/dhcp.leases'
# arp-scan options & samples
#
# Scan local network (default)
# SCAN_SUBNETS = '--localnet'
#
# Scan two subnets
# SCAN_SUBNETS = '192.168.11.0/24 192.168.144.0/24'
#
# Scan using interface eth0
# SCAN_SUBNETS = '--localnet --interface=eth0'
SCAN_SUBNETS = '--localnet'

View File

@@ -1,3 +1,3 @@
VERSION = '2.70' VERSION = '3.00'
VERSION_YEAR = '2021' VERSION_YEAR = '2021'
VERSION_DATE = '2021-02-01' VERSION_DATE = '2021-04-21'

Binary file not shown.

View File

@@ -37,6 +37,10 @@
color: #808080; color: #808080;
} }
.text-gray-20 {
color: rgba(192,192,192,20%);
}
.text-aqua-20 { .text-aqua-20 {
color: rgba(0,192,239,20%); color: rgba(0,192,239,20%);
} }
@@ -151,6 +155,13 @@
margin-bottom: 1.3em; margin-bottom: 1.3em;
} }
.pa-small-box-footer {
color: white !important;
font-size: 18px;
}
/* -------------------------------------------------------------------------- */
.pa-small-box-aqua { .pa-small-box-aqua {
border-top: 3px solid #00c0ef; border-top: 3px solid #00c0ef;
box-shadow: 0 5px 5px rgba(0, 0, 0, 0.1); box-shadow: 0 5px 5px rgba(0, 0, 0, 0.1);
@@ -169,8 +180,6 @@
color: #00c0ef; color: #00c0ef;
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
.pa-small-box-green { .pa-small-box-green {
border-top: 3px solid #00a65a; border-top: 3px solid #00a65a;
@@ -228,7 +237,26 @@
color: #dd4b39; color: #dd4b39;
} }
/* -------------------------------------------------------------------------- */
.pa-small-box-gray {
border-top: 3px solid #a0a0a0;
box-shadow: 0 5px 5px rgba(0, 0, 0, 0.1);
}
.pa-small-box-gray .inner {
color: #a0a0a0;
background-color:#FFFFFF;
}
.pa-small-box-gray .inner h3 {
margin-left: 0.5em;
}
.pa-small-box-gray .icon {
color: #a0a0a0;
}
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
Customized Box Borders Customized Box Borders
----------------------------------------------------------------------------- */ ----------------------------------------------------------------------------- */
@@ -304,6 +332,29 @@
color: #B0B0B0; color: #B0B0B0;
} }
/* -----------------------------------------------------------------------------
Customized buttons
----------------------------------------------------------------------------- */
.pa-btn {
padding: 10px;
min-width: 90px;
}
.pa-btn-delete {
border-color:#ffb060;
background-color:#ffd080;
}
.pa-btn-delete:hover {
border-color:#ffb060;
background-color:#ffb060;
}
.pa-btn-records, .pa-btn-records:hover, .pa-btn-records:focus, .pa-btn-records:active {
border-color:#ddd;
background-color:#f4f4f4;
cursor: default;
}
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------

View File

@@ -42,15 +42,10 @@
<div class="col-lg-3 col-sm-6 col-xs-6"> <div class="col-lg-3 col-sm-6 col-xs-6">
<a href="#" onclick="javascript: $('#tabDetails').trigger('click')"> <a href="#" onclick="javascript: $('#tabDetails').trigger('click')">
<div class="small-box bg-aqua pa-small-box-aqua"> <div class="small-box bg-aqua pa-small-box-aqua pa-small-box-2">
<div class="inner"> <h3 id="deviceStatus" style="margin-left: 0em"> -- </h3> </div>
<div class="inner">
<h4>Current Status</h4>
<h3 id="deviceStatus" style="margin-left: 0em"> -- </h3>
</div>
<div class="icon"> <i id="deviceStatusIcon" class=""></i> </div> <div class="icon"> <i id="deviceStatusIcon" class=""></i> </div>
<div class="small-box-footer"> Details <i class="fa fa-arrow-circle-right"></i> </div> <div class="small-box-footer pa-small-box-footer"> Current Status <i class="fa fa-arrow-circle-right"></i> </div>
</div> </div>
</a> </a>
</div> </div>
@@ -58,15 +53,10 @@
<!-- top small box 2 ------------------------------------------------------- --> <!-- top small box 2 ------------------------------------------------------- -->
<div class="col-lg-3 col-sm-6 col-xs-6"> <div class="col-lg-3 col-sm-6 col-xs-6">
<a href="#" onclick="javascript: $('#tabSessions').trigger('click');"> <a href="#" onclick="javascript: $('#tabSessions').trigger('click');">
<div class="small-box bg-green pa-small-box-green"> <div class="small-box bg-green pa-small-box-green pa-small-box-2">
<div class="inner"> <h3 id="deviceSessions"> -- </h3> </div>
<div class="inner">
<h4>Sessions</h4>
<h3 id="deviceSessions"> -- </h3>
</div>
<div class="icon"> <i class="fa fa-plug"></i> </div> <div class="icon"> <i class="fa fa-plug"></i> </div>
<div class="small-box-footer"> Details <i class="fa fa-arrow-circle-right"></i> </div> <div class="small-box-footer pa-small-box-footer"> Sesions <i class="fa fa-arrow-circle-right"></i> </div>
</div> </div>
</a> </a>
</div> </div>
@@ -74,15 +64,10 @@
<!-- top small box 3 ------------------------------------------------------- --> <!-- top small box 3 ------------------------------------------------------- -->
<div class="col-lg-3 col-sm-6 col-xs-6"> <div class="col-lg-3 col-sm-6 col-xs-6">
<a href="#" onclick="javascript: $('#tabPresence').trigger('click')"> <a href="#" onclick="javascript: $('#tabPresence').trigger('click')">
<div class="small-box bg-yellow pa-small-box-yellow"> <div class="small-box bg-yellow pa-small-box-yellow pa-small-box-2">
<div class="inner"> <h3 id="deviceEvents" style="margin-left: 0em"> -- </h3> </div>
<div class="inner">
<h4 id="deviceEventsTitle"> Presence </h4>
<h3 id="deviceEvents" style="margin-left: 0em"> -- </h3>
</div>
<div id="deviceEventsIcon" class="icon"> <i class="fa fa-calendar"></i> </div> <div id="deviceEventsIcon" class="icon"> <i class="fa fa-calendar"></i> </div>
<div class="small-box-footer"> Details <i class="fa fa-arrow-circle-right"></i> </div> <div class="small-box-footer pa-small-box-footer"> Presence <i class="fa fa-arrow-circle-right"></i> </div>
</div> </div>
</a> </a>
</div> </div>
@@ -90,15 +75,10 @@
<!-- top small box 4 ------------------------------------------------------ --> <!-- top small box 4 ------------------------------------------------------ -->
<div class="col-lg-3 col-sm-6 col-xs-6"> <div class="col-lg-3 col-sm-6 col-xs-6">
<a href="#" onclick="javascript: $('#tabEvents').trigger('click');"> <a href="#" onclick="javascript: $('#tabEvents').trigger('click');">
<div class="small-box bg-red pa-small-box-red"> <div class="small-box bg-red pa-small-box-red pa-small-box-2">
<div class="inner"> <h3 id="deviceDownAlerts"> -- </h3> </div>
<div class="inner">
<h4>Down Alerts</h4>
<h3 id="deviceDownAlerts"> -- </h3>
</div>
<div class="icon"> <i class="fa fa-warning"></i> </div> <div class="icon"> <i class="fa fa-warning"></i> </div>
<div class="small-box-footer"> Details <i class="fa fa-arrow-circle-right"></i> </div> <div class="small-box-footer pa-small-box-footer"> Down Alerts <i class="fa fa-arrow-circle-right"></i> </div>
</div> </div>
</a> </a>
</div> </div>
@@ -111,13 +91,28 @@
<div class="col-lg-12 col-sm-12 col-xs-12"> <div class="col-lg-12 col-sm-12 col-xs-12">
<!-- <div class="box-transparent"> --> <!-- <div class="box-transparent"> -->
<div id="navDevice" class="nav-tabs-custom"> <div id="navDevice" class="nav-tabs-custom">
<ul class="nav nav-tabs" style="fon t-size:16px;"> <ul class="nav nav-tabs" style="fon t-size:16px;">
<li> <a id="tabDetails" href="#panDetails" data-toggle="tab"> Details </a></li> <li> <a id="tabDetails" href="#panDetails" data-toggle="tab"> Details </a></li>
<li> <a id="tabSessions" href="#panSessions" data-toggle="tab"> Sessions </a></li> <li> <a id="tabSessions" href="#panSessions" data-toggle="tab"> Sessions </a></li>
<li> <a id="tabPresence" href="#panPresence" data-toggle="tab"> Presence </a></li> <li> <a id="tabPresence" href="#panPresence" data-toggle="tab"> Presence </a></li>
<li> <a id="tabEvents" href="#panEvents" data-toggle="tab"> Events </a></li> <li> <a id="tabEvents" href="#panEvents" data-toggle="tab"> Events </a></li>
<div class="btn-group pull-right">
<button type="button" class="btn btn-default" style="padding: 10px; min-width: 30px;"
id="btnPrevious" onclick="previousRecord()"> <i class="fa fa-chevron-left"></i> </button>
<div class="btn pa-btn-records" style="padding: 10px; min-width: 30px; margin-left: 1px;"
id="txtRecord" > 0 / 0 </div>
<button type="button" class="btn btn-default" style="padding: 10px; min-width: 30px; margin-left: 1px;"
id="btnNext" onclick="nextRecord()"> <i class="fa fa-chevron-right"></i> </button>
</div>
</ul> </ul>
<div class="tab-content" style="min-height: 430px"> <div class="tab-content" style="min-height: 430px">
<!-- tab page 1 ------------------------------------------------------------ --> <!-- tab page 1 ------------------------------------------------------------ -->
@@ -318,8 +313,8 @@
<button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown" aria-expanded="false" id="dropdownButtonScanCycle"> <button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown" aria-expanded="false" id="dropdownButtonScanCycle">
<span class="fa fa-caret-down"></span></button> <span class="fa fa-caret-down"></span></button>
<ul id="dropdownScanCycle" class="dropdown-menu dropdown-menu-right"> <ul id="dropdownScanCycle" class="dropdown-menu dropdown-menu-right">
<li><a href="javascript:void(0)" onclick="setTextValue('txtScanCycle','1 min')"> Scan 1' every 5'</a></li> <li><a href="javascript:void(0)" onclick="setTextValue('txtScanCycle','1 min')"> Scan 1 min every 5 min</a></li>
<li><a href="javascript:void(0)" onclick="setTextValue('txtScanCycle','15 min');"> Scan 12' every 15'</a></li> <li><a href="javascript:void(0)" onclick="setTextValue('txtScanCycle','15 min');"> Scan 12 min every 15 min</a></li>
<li><a href="javascript:void(0)" onclick="setTextValue('txtScanCycle','0 min');"> Don't Scan</a></li> <li><a href="javascript:void(0)" onclick="setTextValue('txtScanCycle','0 min');"> Don't Scan</a></li>
</ul> </ul>
</div> </div>
@@ -372,14 +367,42 @@
</div> </div>
</div> </div>
<!-- Archived -->
<div class="form-group">
<label class="col-sm-5 control-label">Archived:</label>
<div class="col-sm-7" style="padding-top:6px;">
<input class="checkbox blue hidden" id="chkArchived" type="checkbox">
</div>
</div>
<!-- Randomized MAC -->
<div class="form-group" >
<label class="col-sm-5 control-label">Random MAC:</label>
<div class="col-sm-7" style="padding-top:6px;">
<span id="iconRandomMACinactive" data-toggle="tooltip" data-placement="right" title="Random MAC is Inactive">
<i style="font-size: 24px;" class="text-gray glyphicon glyphicon-random"></i> &nbsp &nbsp </span>
<span id="iconRandomMACactive" data-toggle="tooltip" data-placement="right" title="Random MAC is Active" class="hidden">
<i style="font-size: 24px;" class="text-yellow glyphicon glyphicon-random"></i> &nbsp &nbsp </span>
<a href="https://github.com/pucherot/Pi.Alert/blob/main/docs/RAMDOM_MAC.md" target="_blank" style="color: #777;">
<i class="fa fa-info-circle"></i> </a>
</div>
</div>
</div> </div>
</div> </div>
<!-- Buttons --> <!-- Buttons -->
<div class="col-xs-12"> <div class="col-xs-12">
<button type="button" class="btn btn-primary pull-right" style="padding: 10px; min-width: 90px;" id="btnSave" onclick="setDeviceData()"> Save </button> <div class="pull-right">
<button type="button" class="btn btn-default pull-right" style="padding: 10px; min-width: 90px; margin-right:10px;" id="btnRestore" onclick="getDeviceData(true)"> Reset Changes </button> <button type="button" class="btn btn-default pa-btn pa-btn-delete" style="margin-left:0px;"
<button type="button" class="btn bg-default pull-right" style="padding: 10px; min-width: 90px; margin-right:10px; background-color:#ffd080;" id="btnDelete" onclick="askDeleteDevice()"> Delete Device </button> id="btnDelete" onclick="askDeleteDevice()"> Delete Device </button>
<button type="button" class="btn btn-default pa-btn" style="margin-left:6px;"
id="btnRestore" onclick="getDeviceData(true)"> Reset Changes </button>
<button type="button" disabled class="btn btn-primary pa-btn" style="margin-left:6px; "
id="btnSave" onclick="setDeviceData()" > Save </button>
</div>
</div> </div>
</div> </div>
@@ -488,13 +511,15 @@
<script> <script>
var mac = ''; var mac = '';
var devicesList = [];
var pos = -1;
var parPeriod = 'Front_Details_Period'; var parPeriod = 'Front_Details_Period';
var parTab = 'Front_Details_Tab'; var parTab = 'Front_Details_Tab';
var parSessionsRows = 'Front_Details_Sessions_Rows'; var parSessionsRows = 'Front_Details_Sessions_Rows';
var parEventsRows = 'Front_Details_Events_Rows'; var parEventsRows = 'Front_Details_Events_Rows';
var parEventsHide = 'Front_Details_Events_Hide'; var parEventsHide = 'Front_Details_Events_Hide';
var period = '1 month'; var period = '1 month';
var tab = 'tabDetails' var tab = '#panDetails'
var sessionsRows = 10; var sessionsRows = 10;
var eventsRows = 10; var eventsRows = 10;
var eventsHide = true; var eventsHide = true;
@@ -558,10 +583,20 @@ function main () {
initializeDatatables(); initializeDatatables();
initializeCalendar(); initializeCalendar();
// Read Cookies
devicesList = getCookie('devicesList');
deleteCookie ('devicesList');
if (devicesList != '') {
devicesList = JSON.parse (devicesList);
} else {
devicesList = [];
}
// query data // query data
getDeviceData(true); getDeviceData(true);
getSessionsPresenceEvents(); getSessionsPresenceEvents();
// Force re-render calendar on tab change // Force re-render calendar on tab change
// (bugfix for render error at left panel) // (bugfix for render error at left panel)
$(document).on('shown.bs.tab', 'a[data-toggle="tab"]', function (nav) { $(document).on('shown.bs.tab', 'a[data-toggle="tab"]', function (nav) {
@@ -570,6 +605,13 @@ function main () {
} }
}); });
// Ask before exit without saving data
window.onbeforeunload = function(){
if ( ! document.getElementById('btnSave').hasAttribute('disabled') ) {
return 'Are you sure you want to discard unsaved changes?';
}
};
}); });
}); });
}); });
@@ -578,6 +620,7 @@ function main () {
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
function initializeTabs () { function initializeTabs () {
// Activate panel // Activate panel
@@ -619,7 +662,7 @@ function initializeiCheck () {
radioClass: 'iradio_flat-red', radioClass: 'iradio_flat-red',
increaseArea: '20%' increaseArea: '20%'
}); });
// When toggle iCheck // When toggle iCheck
$('input').on('ifToggled', function(event){ $('input').on('ifToggled', function(event){
// Hide / Show Events // Hide / Show Events
@@ -629,6 +672,11 @@ function initializeiCheck () {
} else { } else {
// Activate save & restore // Activate save & restore
activateSaveRestoreData(); activateSaveRestoreData();
// Ask skip notifications
if (event.currentTarget.id == 'chkArchived' ) {
askSkipNotifications();
}
} }
}); });
} }
@@ -896,7 +944,7 @@ function periodChanged () {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
function getDeviceData (updatePanelData=false) { function getDeviceData (readAllData=false) {
// stop timer // stop timer
stopTimerRefreshData(); stopTimerRefreshData();
@@ -905,6 +953,15 @@ function getDeviceData (updatePanelData=false) {
return; return;
} }
// Deactivate next previous buttons
if (readAllData) {
$('#btnPrevious').attr ('disabled','');
$('#btnPrevious').addClass ('text-gray50');
$('#btnNext').attr ('disabled','');
$('#btnNext').addClass ('text-gray50');
$("body").css ("cursor", "progress");
}
// get data from server // get data from server
$.get('php/server/devices.php?action=getDeviceData&mac='+ mac + '&period='+ period, function(data) { $.get('php/server/devices.php?action=getDeviceData&mac='+ mac + '&period='+ period, function(data) {
@@ -912,8 +969,15 @@ function getDeviceData (updatePanelData=false) {
// check device exists // check device exists
if (deviceData['dev_MAC'] == null) { if (deviceData['dev_MAC'] == null) {
$('#pageTitle').html ('Device not found: <small>'+ mac +'</small>'); // Status
$('#deviceStatus').html ('--');
$('#deviceStatus')[0].className = 'text-gray';
$('#deviceStatusIcon')[0].className = '';
$('#deviceSessions').html ('--');
$('#deviceDownAlerts').html ('--');
$('#deviceEvents').html ('--');
$('#txtMAC').val ('--'); $('#txtMAC').val ('--');
$('#txtName').val ('--'); $('#txtName').val ('--');
$('#txtOwner').val ('--'); $('#txtOwner').val ('--');
@@ -935,11 +999,23 @@ function getDeviceData (updatePanelData=false) {
$('#chkAlertEvents').iCheck ('uncheck') $('#chkAlertEvents').iCheck ('uncheck')
$('#chkAlertDown').iCheck ('uncheck') $('#chkAlertDown').iCheck ('uncheck')
$('#txtSkipRepeated').val ('--'); $('#txtSkipRepeated').val ('--');
$('#chkNewDevice').iCheck ('uncheck') $('#chkNewDevice').iCheck ('uncheck');
$('#chkArchived').iCheck ('uncheck');
$('#iconRandomMACactive').addClass ('hidden');
$('#iconRandomMACinactive').removeClass ('hidden');
// Deactivate controls // Deactivate controls
$('#panDetails :input').attr('disabled', true); $('#panDetails :input').attr('disabled', true);
// Check if device is deleted o no exists in this session
if (pos == -1) {
devicesList = [];
$('#pageTitle').html ('Device not found: <small>'+ mac +'</small>');
} else {
$('#pageTitle').html ('Device deleted');
}
} else { } else {
// Name // Name
@@ -949,7 +1025,7 @@ function getDeviceData (updatePanelData=false) {
} else { } else {
$('#pageTitle').html (deviceData['dev_Name'] + ' ('+ deviceData['dev_Owner'] +')'); $('#pageTitle').html (deviceData['dev_Name'] + ' ('+ deviceData['dev_Owner'] +')');
} }
// Status // Status
$('#deviceStatus').html (deviceData['dev_Status']); $('#deviceStatus').html (deviceData['dev_Status']);
switch (deviceData['dev_Status']) { switch (deviceData['dev_Status']) {
@@ -976,7 +1052,12 @@ function getDeviceData (updatePanelData=false) {
} }
// Device info // Device info
if (updatePanelData) { if (readAllData) {
// Activate controls
$('#panDetails :input').attr('disabled', false);
mac =deviceData['dev_MAC'];
$('#txtMAC').val (deviceData['dev_MAC']); $('#txtMAC').val (deviceData['dev_MAC']);
$('#txtName').val (deviceData['dev_Name']); $('#txtName').val (deviceData['dev_Name']);
$('#txtOwner').val (deviceData['dev_Owner']); $('#txtOwner').val (deviceData['dev_Owner']);
@@ -999,20 +1080,87 @@ function getDeviceData (updatePanelData=false) {
if (deviceData['dev_AlertDeviceDown'] == 1) {$('#chkAlertDown').iCheck('check');} if (deviceData['dev_AlertDeviceDown'] == 1) {$('#chkAlertDown').iCheck('check');}
$('#txtSkipRepeated').val (findSkipRepeated (deviceData['dev_SkipRepeated'])); $('#txtSkipRepeated').val (findSkipRepeated (deviceData['dev_SkipRepeated']));
if (deviceData['dev_NewDevice'] == 1) {$('#chkNewDevice').iCheck('check');} if (deviceData['dev_NewDevice'] == 1) {$('#chkNewDevice').iCheck('check');}
if (deviceData['dev_Archived'] == 1) {$('#chkArchived').iCheck('check');}
if (deviceData['dev_RandomMAC'] == 1) {$('#iconRandomMACactive').removeClass ('hidden');
$('#iconRandomMACinactive').addClass ('hidden'); }
else {$('#iconRandomMACactive').addClass ('hidden');
$('#iconRandomMACinactive').removeClass ('hidden'); };
deactivateSaveRestoreData (); deactivateSaveRestoreData ();
} }
// Check if device is part of the devicesList
pos = devicesList.indexOf (deviceData['rowid']);
if (pos == -1) {
devicesList =[deviceData['rowid']];
pos=0;
}
}
// Record number
$('#txtRecord').html (pos+1 +' / '+ devicesList.length);
// Deactivate previous button
if (pos <= 0) {
$('#btnPrevious').attr ('disabled','');
$('#btnPrevious').addClass ('text-gray50');
} else {
$('#btnPrevious').removeAttr ('disabled');
$('#btnPrevious').removeClass ('text-gray50');
}
// Deactivate next button
if (pos >= (devicesList.length-1)) {
$('#btnNext').attr ('disabled','');
$('#btnNext').addClass ('text-gray50');
} else {
$('#btnNext').removeAttr ('disabled');
$('#btnNext').removeClass ('text-gray50');
} }
// Timer for refresh data // Timer for refresh data
$("body").css("cursor", "default");
newTimerRefreshData (getDeviceData); newTimerRefreshData (getDeviceData);
}); });
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
function setDeviceData () { function previousRecord () {
// Save Changes
if ( ! document.getElementById('btnSave').hasAttribute('disabled') ) {
setDeviceData (previousRecord);
return;
}
// Previous Record
if (pos > 0) {
pos--;
mac = devicesList[pos].toString();
getDeviceData (true);
}
}
// -----------------------------------------------------------------------------
function nextRecord () {
// Save Changes
if ( ! document.getElementById('btnSave').hasAttribute('disabled') ) {
setDeviceData (nextRecord);
return;
}
// Next Record
if (pos < (devicesList.length-1) ) {
pos++;
mac = devicesList[pos].toString();
getDeviceData (true);
}
}
// -----------------------------------------------------------------------------
function setDeviceData (refreshCallback='') {
// Check MAC // Check MAC
if (mac == '') { if (mac == '') {
return; return;
@@ -1034,14 +1182,48 @@ function setDeviceData () {
+ '&alertdown=' + ($('#chkAlertDown')[0].checked * 1) + '&alertdown=' + ($('#chkAlertDown')[0].checked * 1)
+ '&skiprepeated=' + $('#txtSkipRepeated').val().split(' ')[0] + '&skiprepeated=' + $('#txtSkipRepeated').val().split(' ')[0]
+ '&newdevice=' + ($('#chkNewDevice')[0].checked * 1) + '&newdevice=' + ($('#chkNewDevice')[0].checked * 1)
+ '&archived=' + ($('#chkArchived')[0].checked * 1)
, function(msg) { , function(msg) {
// deactivate button
deactivateSaveRestoreData (); deactivateSaveRestoreData ();
showMessage (msg); showMessage (msg);
// Callback fuction
if (typeof refreshCallback == 'function') {
refreshCallback();
}
}); });
} }
// -----------------------------------------------------------------------------
function askSkipNotifications () {
// Check MAC
if (mac == '') {
return;
}
// When Archived
if ($('#chkArchived')[0].checked && $('#txtScanCycle').val().split(' ')[0] != "0") {
// Ask skip notifications
showModalDefault ('Device Archived', 'Do you want to skip all notifications for this device?',
'Cancel', 'Ok', 'skipNotifications');
}
}
// -----------------------------------------------------------------------------
function skipNotifications () {
// Check MAC
if (mac == '') {
return;
}
// Set cycle 0
$('#txtScanCycle').val ('0 min');
activateSaveRestoreData();
}
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
function askDeleteDevice () { function askDeleteDevice () {
// Check MAC // Check MAC
@@ -1050,7 +1232,7 @@ function askDeleteDevice () {
} }
// Ask delete device // Ask delete device
showModal ('Delete Device', 'Are you sure you want to delete this device?', showModalWarning ('Delete Device', 'Are you sure you want to delete this device?<br>(maybe you prefer to archive it)',
'Cancel', 'Delete', 'deleteDevice'); 'Cancel', 'Delete', 'deleteDevice');
} }

View File

@@ -27,65 +27,67 @@
<!-- top small box 1 ------------------------------------------------------- --> <!-- top small box 1 ------------------------------------------------------- -->
<div class="row"> <div class="row">
<div class="col-lg-3 col-sm-6 col-xs-6"> <div class="col-lg-2 col-sm-4 col-xs-6">
<a href="#" onclick="javascript: getDevicesList('all');"> <a href="#" onclick="javascript: getDevicesList('all');">
<div class="small-box bg-aqua pa-small-box-aqua"> <div class="small-box bg-aqua pa-small-box-aqua pa-small-box-2">
<div class="inner"> <h3 id="devicesAll"> -- </h3> </div>
<div class="inner"> <div class="icon"> <i class="fa fa-laptop text-aqua-20"></i> </div>
<h4>Total Devices</h4> <div class="small-box-footer pa-small-box-footer"> All Devices <i class="fa fa-arrow-circle-right"></i> </div>
<h3 id="devicesAll"> -- </h3>
</div>
<div class="icon"> <i class="fa fa-laptop"></i> </div>
<div class="small-box-footer"> Details <i class="fa fa-arrow-circle-right"></i> </div>
</div> </div>
</a> </a>
</div> </div>
<!-- top small box 2 ------------------------------------------------------- --> <!-- top small box 2 ------------------------------------------------------- -->
<div class="col-lg-3 col-sm-6 col-xs-6"> <div class="col-lg-2 col-sm-4 col-xs-6">
<a href="#" onclick="javascript: getDevicesList('connected');"> <a href="#" onclick="javascript: getDevicesList('connected');">
<div class="small-box bg-green pa-small-box-green"> <div class="small-box bg-green pa-small-box-green pa-small-box-2">
<div class="inner"> <h3 id="devicesConnected"> -- </h3> </div>
<div class="inner"> <div class="icon"> <i class="fa fa-plug text-green-20"></i> </div>
<h4>Connected</h4> <div class="small-box-footer pa-small-box-footer"> Connected <i class="fa fa-arrow-circle-right"></i> </div>
<h3 id="devicesConnected"> -- </h3>
</div>
<div class="icon"> <i class="fa fa-plug"></i> </div>
<div class="small-box-footer"> Details <i class="fa fa-arrow-circle-right"></i> </div>
</div> </div>
</a> </a>
</div> </div>
<!-- top small box 3 ------------------------------------------------------- --> <!-- top small box 3 ------------------------------------------------------- -->
<div class="col-lg-3 col-sm-6 col-xs-6"> <div class="col-lg-2 col-sm-4 col-xs-6">
<a href="#" onclick="javascript: getDevicesList('new');"> <a href="#" onclick="javascript: getDevicesList('favorites');">
<div class="small-box bg-yellow pa-small-box-yellow"> <div class="small-box bg-yellow pa-small-box-yellow pa-small-box-2">
<div class="inner"> <h3 id="devicesFavorites"> -- </h3> </div>
<div class="inner"> <div class="icon"> <i class="fa fa-star text-yellow-20"></i> </div>
<h4>New Devices</h4> <div class="small-box-footer pa-small-box-footer"> Favorites <i class="fa fa-arrow-circle-right"></i> </div>
<h3 id="devicesNew"> -- </h3>
</div>
<div class="icon"> <i class="ion ion-plus-round"></i> </div>
<div class="small-box-footer"> Details <i class="fa fa-arrow-circle-right"></i> </div>
</div> </div>
</a> </a>
</div> </div>
<!-- top small box 4 ------------------------------------------------------- --> <!-- top small box 4 ------------------------------------------------------- -->
<div class="col-lg-3 col-sm-6 col-xs-6"> <div class="col-lg-2 col-sm-4 col-xs-6">
<a href="#" onclick="javascript: getDevicesList('new');">
<div class="small-box bg-yellow pa-small-box-yellow pa-small-box-2">
<div class="inner"> <h3 id="devicesNew"> -- </h3> </div>
<div class="icon"> <i class="ion ion-plus-round text-yellow-20"></i> </div>
<div class="small-box-footer pa-small-box-footer"> New Devices <i class="fa fa-arrow-circle-right"></i> </div>
</div>
</a>
</div>
<!-- top small box 5 ------------------------------------------------------- -->
<div class="col-lg-2 col-sm-4 col-xs-6">
<a href="#" onclick="javascript: getDevicesList('down');"> <a href="#" onclick="javascript: getDevicesList('down');">
<div class="small-box bg-red pa-small-box-red"> <div class="small-box bg-red pa-small-box-red pa-small-box-2">
<div class="inner"> <h3 id="devicesDown"> -- </h3> </div>
<div class="icon"> <i class="fa fa-warning text-red-20"></i> </div>
<div class="small-box-footer pa-small-box-footer"> Down Alerts <i class="fa fa-arrow-circle-right"></i> </div>
</div>
</a>
</div>
<div class="inner"> <!-- top small box 6 ------------------------------------------------------- -->
<h4>Down Alerts</h4> <div class="col-lg-2 col-sm-4 col-xs-6">
<h3 id="devicesDown"> -- </h3> <a href="#" onclick="javascript: getDevicesList('archived');">
</div> <div class="small-box bg-gray pa-small-box-gray pa-small-box-2">
<div class="inner"> <h3 id="devicesArchived"> -- </h3> </div>
<div class="icon"> <i class="fa fa-warning"></i> </div> <div class="icon"> <i class="fa fa-eye-slash text-gray-20"></i> </div>
<div class="small-box-footer"> Details <i class="fa fa-arrow-circle-right"></i> </div> <div class="small-box-footer pa-small-box-footer"> Archived <i class="fa fa-arrow-circle-right"></i> </div>
</div> </div>
</a> </a>
</div> </div>
@@ -110,15 +112,17 @@
<tr> <tr>
<th>Name</th> <th>Name</th>
<th>Owner</th> <th>Owner</th>
<th>Device type</th> <th>Type</th>
<th>Favorite</th> <th>Favorite</th>
<th>Group</th> <th>Group</th>
<th>First Session</th> <th>First Session</th>
<th>Last Session</th> <th>Last Session</th>
<th>Last IP</th> <th>Last IP</th>
<th>MAC</th>
<th>Status</th> <th>Status</th>
<th>MAC</th> <th>MAC</th>
<th>Last IP Order</th> <th>Last IP Order</th>
<th>Rowid</th>
</tr> </tr>
</thead> </thead>
</table> </table>
@@ -187,8 +191,8 @@ function main () {
// query data // query data
getDevicesTotals(); getDevicesTotals();
getDevicesList (deviceStatus); getDevicesList (deviceStatus);
}); });
}); });
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@@ -209,15 +213,16 @@ function initializeDatatable () {
// 'order' : [[3,'desc'], [0,'asc']], // 'order' : [[3,'desc'], [0,'asc']],
'columnDefs' : [ 'columnDefs' : [
{visible: false, targets: [9, 10] }, {visible: false, targets: [10, 11, 12] },
{className: 'text-center', targets: [3, 8] }, {className: 'text-center', targets: [3, 8, 9] },
{width: '0px', targets: 8 }, {width: '80px', targets: [5, 6] },
{orderData: [10], targets: 7 }, {width: '0px', targets: 9 },
{orderData: [11], targets: 7 },
// Device Name // Device Name
{targets: [0], {targets: [0],
'createdCell': function (td, cellData, rowData, row, col) { 'createdCell': function (td, cellData, rowData, row, col) {
$(td).html ('<b><a href="deviceDetails.php?mac='+ rowData[9] +'" class="">'+ cellData +'</a></b>'); $(td).html ('<b><a href="deviceDetails.php?mac='+ rowData[10] +'" class="">'+ cellData +'</a></b>');
} }, } },
// Favorite // Favorite
@@ -236,18 +241,29 @@ function initializeDatatable () {
$(td).html (translateHTMLcodes (cellData)); $(td).html (translateHTMLcodes (cellData));
} }, } },
// Status color // Random MAC
{targets: [8], {targets: [8],
'createdCell': function (td, cellData, rowData, row, col) {
if (cellData == 1){
$(td).html ('<i data-toggle="tooltip" data-placement="right" title="Random MAC" style="font-size: 16px;" class="text-yellow glyphicon glyphicon-random"></i>');
} else {
$(td).html ('');
}
} },
// Status color
{targets: [9],
'createdCell': function (td, cellData, rowData, row, col) { 'createdCell': function (td, cellData, rowData, row, col) {
switch (cellData) { switch (cellData) {
case 'Down': color='red'; break; case 'Down': color='red'; break;
case 'New': color='yellow'; break; case 'New': color='yellow'; break;
case 'On-line': color='green'; break; case 'On-line': color='green'; break;
case 'Off-line': color='gray text-white'; break; case 'Off-line': color='gray text-white'; break;
case 'Archived': color='gray text-white'; break;
default: color='aqua'; break; default: color='aqua'; break;
}; };
$(td).html ('<a href="deviceDetails.php?mac='+ rowData[9] +'" class="badge bg-'+ color +'">'+ cellData +'</a>'); $(td).html ('<a href="deviceDetails.php?mac='+ rowData[10] +'" class="badge bg-'+ color +'">'+ cellData +'</a>');
} }, } },
], ],
@@ -259,13 +275,18 @@ function initializeDatatable () {
} }
}); });
// Save Parameters rows & order when changed // Save cookie Rows displayed, and Parameters rows & order
$('#tableDevices').on( 'length.dt', function ( e, settings, len ) { $('#tableDevices').on( 'length.dt', function ( e, settings, len ) {
setParameter (parTableRows, len); setParameter (parTableRows, len);
} ); } );
$('#tableDevices').on( 'order.dt', function () { $('#tableDevices').on( 'order.dt', function () {
setParameter (parTableOrder, JSON.stringify (table.order()) ); setParameter (parTableOrder, JSON.stringify (table.order()) );
setCookie ('devicesList',JSON.stringify (table.column(12, { 'search': 'applied' }).data().toArray()) );
} );
$('#tableDevices').on( 'search.dt', function () {
setCookie ('devicesList', JSON.stringify (table.column(12, { 'search': 'applied' }).data().toArray()) );
} ); } );
}; };
@@ -281,8 +302,10 @@ function getDevicesTotals () {
$('#devicesAll').html (totalsDevices[0].toLocaleString()); $('#devicesAll').html (totalsDevices[0].toLocaleString());
$('#devicesConnected').html (totalsDevices[1].toLocaleString()); $('#devicesConnected').html (totalsDevices[1].toLocaleString());
$('#devicesNew').html (totalsDevices[2].toLocaleString()); $('#devicesFavorites').html (totalsDevices[2].toLocaleString());
$('#devicesDown').html (totalsDevices[3].toLocaleString()); $('#devicesNew').html (totalsDevices[3].toLocaleString());
$('#devicesDown').html (totalsDevices[4].toLocaleString());
$('#devicesArchived').html (totalsDevices[5].toLocaleString());
// Timer for refresh data // Timer for refresh data
newTimerRefreshData (getDevicesTotals); newTimerRefreshData (getDevicesTotals);
@@ -297,12 +320,13 @@ function getDevicesList (status) {
// Define color & title for the status selected // Define color & title for the status selected
switch (deviceStatus) { switch (deviceStatus) {
case 'all': tableTitle = 'Total Devices'; color = 'aqua'; break; case 'all': tableTitle = 'All Devices'; color = 'aqua'; break;
case 'connected': tableTitle = 'Connected Devices'; color = 'green'; break; case 'connected': tableTitle = 'Connected Devices'; color = 'green'; break;
case 'new': tableTitle = 'New Devices'; color = 'yellow'; break; case 'favorites': tableTitle = 'Favorites'; color = 'yellow'; break;
case 'down': tableTitle = 'Down Alerts'; color = 'red'; break; case 'new': tableTitle = 'New Devices'; color = 'yellow'; break;
case 'favorites': tableTitle = 'Favorites'; color = 'yellow'; break; case 'down': tableTitle = 'Down Alerts'; color = 'red'; break;
default: tableTitle = 'Devices'; boxClass = ''; break; case 'archived': tableTitle = 'Archived Devices'; color = 'gray'; break;
default: tableTitle = 'Devices'; color = 'gray'; break;
} }
// Set title and color // Set title and color

View File

@@ -43,8 +43,7 @@
<div class="small-box bg-aqua pa-small-box-aqua pa-small-box-2"> <div class="small-box bg-aqua pa-small-box-aqua pa-small-box-2">
<div class="inner"> <h3 id="eventsAll"> -- </h3> </div> <div class="inner"> <h3 id="eventsAll"> -- </h3> </div>
<div class="icon"> <i class="fa fa-bolt text-aqua-20"></i> </div> <div class="icon"> <i class="fa fa-bolt text-aqua-20"></i> </div>
<div class="small-box-footer pa-small-box-footer"> All events <i class="fa fa-arrow-circle-right"></i> </div>
<div class="small-box-footer"> All events <i class="fa fa-arrow-circle-right"></i> </div>
</div> </div>
</a> </a>
</div> </div>
@@ -55,8 +54,7 @@
<div class="small-box bg-green pa-small-box-green pa-small-box-2"> <div class="small-box bg-green pa-small-box-green pa-small-box-2">
<div class="inner"> <h3 id="eventsSessions"> -- </h3> </div> <div class="inner"> <h3 id="eventsSessions"> -- </h3> </div>
<div class="icon"> <i class="fa fa-plug text-green-20"></i> </div> <div class="icon"> <i class="fa fa-plug text-green-20"></i> </div>
<div class="small-box-footer pa-small-box-footer"> Sessions <i class="fa fa-arrow-circle-right"></i> </div>
<div class="small-box-footer"> Sessions <i class="fa fa-arrow-circle-right"></i> </div>
</div> </div>
</a> </a>
</div> </div>
@@ -67,8 +65,7 @@
<div class="small-box bg-yellow pa-small-box-yellow pa-small-box-2"> <div class="small-box bg-yellow pa-small-box-yellow pa-small-box-2">
<div class="inner"> <h3 id="eventsMissing"> -- </h3> </div> <div class="inner"> <h3 id="eventsMissing"> -- </h3> </div>
<div class="icon"> <i class="fa fa-exchange text-yellow-20"></i> </div> <div class="icon"> <i class="fa fa-exchange text-yellow-20"></i> </div>
<div class="small-box-footer pa-small-box-footer"> Missing Sessions <i class="fa fa-arrow-circle-right"></i> </div>
<div class="small-box-footer"> Missing Sessions <i class="fa fa-arrow-circle-right"></i> </div>
</div> </div>
</a> </a>
</div> </div>
@@ -79,8 +76,7 @@
<div class="small-box bg-yellow pa-small-box-yellow pa-small-box-2"> <div class="small-box bg-yellow pa-small-box-yellow pa-small-box-2">
<div class="inner"> <h3 id="eventsVoided"> -- </h3> </div> <div class="inner"> <h3 id="eventsVoided"> -- </h3> </div>
<div class="icon text-aqua-20"> <i class="fa fa-exclamation-circle text-yellow-20"></i> </div> <div class="icon text-aqua-20"> <i class="fa fa-exclamation-circle text-yellow-20"></i> </div>
<div class="small-box-footer pa-small-box-footer"> Voided Sessions <i class="fa fa-arrow-circle-right"></i> </div>
<div class="small-box-footer"> Voided Sessions <i class="fa fa-arrow-circle-right"></i> </div>
</div> </div>
</a> </a>
</div> </div>
@@ -91,8 +87,7 @@
<div class="small-box bg-yellow pa-small-box-yellow pa-small-box-2"> <div class="small-box bg-yellow pa-small-box-yellow pa-small-box-2">
<div class="inner"> <h3 id="eventsNewDevices"> -- </h3> </div> <div class="inner"> <h3 id="eventsNewDevices"> -- </h3> </div>
<div class="icon"> <i class="ion ion-plus-round text-yellow-20"></i> </div> <div class="icon"> <i class="ion ion-plus-round text-yellow-20"></i> </div>
<div class="small-box-footer pa-small-box-footer"> New Devices <i class="fa fa-arrow-circle-right"></i> </div>
<div class="small-box-footer"> New Devices <i class="fa fa-arrow-circle-right"></i> </div>
</div> </div>
</a> </a>
</div> </div>
@@ -103,8 +98,7 @@
<div class="small-box bg-red pa-small-box-red pa-small-box-2"> <div class="small-box bg-red pa-small-box-red pa-small-box-2">
<div class="inner"> <h3 id="eventsDown"> -- </h3> </div> <div class="inner"> <h3 id="eventsDown"> -- </h3> </div>
<div class="icon"> <i class="fa fa-warning text-red-20"></i> </div> <div class="icon"> <i class="fa fa-warning text-red-20"></i> </div>
<div class="small-box-footer pa-small-box-footer"> Down Alerts <i class="fa fa-arrow-circle-right"></i> </div>
<div class="small-box-footer"> Down Alerts <i class="fa fa-arrow-circle-right"></i> </div>
</div> </div>
</a> </a>
</div> </div>

View File

@@ -27,65 +27,67 @@
<!-- top small box 1 ------------------------------------------------------- --> <!-- top small box 1 ------------------------------------------------------- -->
<div class="row"> <div class="row">
<div class="col-lg-3 col-sm-6 col-xs-6"> <div class="col-lg-2 col-sm-4 col-xs-6">
<a href="#" onclick="javascript: getDevicesList('all');"> <a href="#" onclick="javascript: getDevicesList('all');">
<div class="small-box bg-aqua pa-small-box-aqua"> <div class="small-box bg-aqua pa-small-box-aqua pa-small-box-2">
<div class="inner"> <h3 id="devicesAll"> -- </h3> </div>
<div class="inner"> <div class="icon"> <i class="fa fa-laptop text-aqua-20"></i> </div>
<h4>Total Devices</h4> <div class="small-box-footer pa-small-box-footer"> All Devices <i class="fa fa-arrow-circle-right"></i> </div>
<h3 id="devicesAll"> -- </h3>
</div>
<div class="icon"> <i class="fa fa-laptop"></i> </div>
<div class="small-box-footer"> Details <i class="fa fa-arrow-circle-right"></i> </div>
</div> </div>
</a> </a>
</div> </div>
<!-- top small box 2 ------------------------------------------------------- --> <!-- top small box 2 ------------------------------------------------------- -->
<div class="col-lg-3 col-sm-6 col-xs-6"> <div class="col-lg-2 col-sm-4 col-xs-6">
<a href="#" onclick="javascript: getDevicesList('connected');"> <a href="#" onclick="javascript: getDevicesList('connected');">
<div class="small-box bg-green pa-small-box-green"> <div class="small-box bg-green pa-small-box-green pa-small-box-2">
<div class="inner"> <h3 id="devicesConnected"> -- </h3> </div>
<div class="inner"> <div class="icon"> <i class="fa fa-plug text-green-20"></i> </div>
<h4>Connected</h4> <div class="small-box-footer pa-small-box-footer"> Connected <i class="fa fa-arrow-circle-right"></i> </div>
<h3 id="devicesConnected"> -- </h3>
</div>
<div class="icon"> <i class="fa fa-plug"></i> </div>
<div class="small-box-footer"> Details <i class="fa fa-arrow-circle-right"></i> </div>
</div> </div>
</a> </a>
</div> </div>
<!-- top small box 3 ------------------------------------------------------- --> <!-- top small box 3 ------------------------------------------------------- -->
<div class="col-lg-3 col-sm-6 col-xs-6"> <div class="col-lg-2 col-sm-4 col-xs-6">
<a href="#" onclick="javascript: getDevicesList('new');"> <a href="#" onclick="javascript: getDevicesList('favorites');">
<div class="small-box bg-yellow pa-small-box-yellow"> <div class="small-box bg-yellow pa-small-box-yellow pa-small-box-2">
<div class="inner"> <h3 id="devicesFavorites"> -- </h3> </div>
<div class="inner"> <div class="icon"> <i class="fa fa-star text-yellow-20"></i> </div>
<h4>New Devices</h4> <div class="small-box-footer pa-small-box-footer"> Favorites <i class="fa fa-arrow-circle-right"></i> </div>
<h3 id="devicesNew"> -- </h3>
</div>
<div class="icon"> <i class="ion ion-plus-round"></i> </div>
<div class="small-box-footer"> Details <i class="fa fa-arrow-circle-right"></i> </div>
</div> </div>
</a> </a>
</div> </div>
<!-- top small box 4 ------------------------------------------------------- --> <!-- top small box 4 ------------------------------------------------------- -->
<div class="col-lg-3 col-sm-6 col-xs-6"> <div class="col-lg-2 col-sm-4 col-xs-6">
<a href="#" onclick="javascript: getDevicesList('new');">
<div class="small-box bg-yellow pa-small-box-yellow pa-small-box-2">
<div class="inner"> <h3 id="devicesNew"> -- </h3> </div>
<div class="icon"> <i class="ion ion-plus-round text-yellow-20"></i> </div>
<div class="small-box-footer pa-small-box-footer"> New Devices <i class="fa fa-arrow-circle-right"></i> </div>
</div>
</a>
</div>
<!-- top small box 5 ------------------------------------------------------- -->
<div class="col-lg-2 col-sm-4 col-xs-6">
<a href="#" onclick="javascript: getDevicesList('down');"> <a href="#" onclick="javascript: getDevicesList('down');">
<div class="small-box bg-red pa-small-box-red"> <div class="small-box bg-red pa-small-box-red pa-small-box-2">
<div class="inner"> <h3 id="devicesDown"> -- </h3> </div>
<div class="icon"> <i class="fa fa-warning text-red-20"></i> </div>
<div class="small-box-footer pa-small-box-footer"> Down Alerts <i class="fa fa-arrow-circle-right"></i> </div>
</div>
</a>
</div>
<div class="inner"> <!-- top small box 6 ------------------------------------------------------- -->
<h4>Down Alerts</h4> <div class="col-lg-2 col-sm-4 col-xs-6">
<h3 id="devicesDown"> -- </h3> <a href="#" onclick="javascript: getDevicesList('archived');">
</div> <div class="small-box bg-gray pa-small-box-gray pa-small-box-2">
<div class="inner"> <h3 id="devicesArchived"> -- </h3> </div>
<div class="icon"> <i class="fa fa-warning"></i> </div> <div class="icon"> <i class="fa fa-eye-slash text-gray-20"></i> </div>
<div class="small-box-footer"> Details <i class="fa fa-arrow-circle-right"></i> </div> <div class="small-box-footer pa-small-box-footer"> Archived <i class="fa fa-arrow-circle-right"></i> </div>
</div> </div>
</a> </a>
</div> </div>
@@ -110,15 +112,17 @@
<tr> <tr>
<th>Name</th> <th>Name</th>
<th>Owner</th> <th>Owner</th>
<th>Device type</th> <th>Type</th>
<th>Favorite</th> <th>Favorite</th>
<th>Group</th> <th>Group</th>
<th>First Session</th> <th>First Session</th>
<th>Last Session</th> <th>Last Session</th>
<th>Last IP</th> <th>Last IP</th>
<th>MAC</th>
<th>Status</th> <th>Status</th>
<th>MAC</th> <th>MAC</th>
<th>Last IP Order</th> <th>Last IP Order</th>
<th>Rowid</th>
</tr> </tr>
</thead> </thead>
</table> </table>
@@ -187,8 +191,8 @@ function main () {
// query data // query data
getDevicesTotals(); getDevicesTotals();
getDevicesList (deviceStatus); getDevicesList (deviceStatus);
}); });
}); });
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@@ -209,15 +213,16 @@ function initializeDatatable () {
// 'order' : [[3,'desc'], [0,'asc']], // 'order' : [[3,'desc'], [0,'asc']],
'columnDefs' : [ 'columnDefs' : [
{visible: false, targets: [9, 10] }, {visible: false, targets: [10, 11, 12] },
{className: 'text-center', targets: [3, 8] }, {className: 'text-center', targets: [3, 8, 9] },
{width: '0px', targets: 8 }, {width: '80px', targets: [5, 6] },
{orderData: [10], targets: 7 }, {width: '0px', targets: 9 },
{orderData: [11], targets: 7 },
// Device Name // Device Name
{targets: [0], {targets: [0],
'createdCell': function (td, cellData, rowData, row, col) { 'createdCell': function (td, cellData, rowData, row, col) {
$(td).html ('<b><a href="deviceDetails.php?mac='+ rowData[9] +'" class="">'+ cellData +'</a></b>'); $(td).html ('<b><a href="deviceDetails.php?mac='+ rowData[10] +'" class="">'+ cellData +'</a></b>');
} }, } },
// Favorite // Favorite
@@ -236,18 +241,29 @@ function initializeDatatable () {
$(td).html (translateHTMLcodes (cellData)); $(td).html (translateHTMLcodes (cellData));
} }, } },
// Status color // Random MAC
{targets: [8], {targets: [8],
'createdCell': function (td, cellData, rowData, row, col) {
if (cellData == 1){
$(td).html ('<i data-toggle="tooltip" data-placement="right" title="Random MAC" style="font-size: 16px;" class="text-yellow glyphicon glyphicon-random"></i>');
} else {
$(td).html ('');
}
} },
// Status color
{targets: [9],
'createdCell': function (td, cellData, rowData, row, col) { 'createdCell': function (td, cellData, rowData, row, col) {
switch (cellData) { switch (cellData) {
case 'Down': color='red'; break; case 'Down': color='red'; break;
case 'New': color='yellow'; break; case 'New': color='yellow'; break;
case 'On-line': color='green'; break; case 'On-line': color='green'; break;
case 'Off-line': color='gray text-white'; break; case 'Off-line': color='gray text-white'; break;
case 'Archived': color='gray text-white'; break;
default: color='aqua'; break; default: color='aqua'; break;
}; };
$(td).html ('<a href="deviceDetails.php?mac='+ rowData[9] +'" class="badge bg-'+ color +'">'+ cellData +'</a>'); $(td).html ('<a href="deviceDetails.php?mac='+ rowData[10] +'" class="badge bg-'+ color +'">'+ cellData +'</a>');
} }, } },
], ],
@@ -259,13 +275,18 @@ function initializeDatatable () {
} }
}); });
// Save Parameters rows & order when changed // Save cookie Rows displayed, and Parameters rows & order
$('#tableDevices').on( 'length.dt', function ( e, settings, len ) { $('#tableDevices').on( 'length.dt', function ( e, settings, len ) {
setParameter (parTableRows, len); setParameter (parTableRows, len);
} ); } );
$('#tableDevices').on( 'order.dt', function () { $('#tableDevices').on( 'order.dt', function () {
setParameter (parTableOrder, JSON.stringify (table.order()) ); setParameter (parTableOrder, JSON.stringify (table.order()) );
setCookie ('devicesList',JSON.stringify (table.column(12, { 'search': 'applied' }).data().toArray()) );
} );
$('#tableDevices').on( 'search.dt', function () {
setCookie ('devicesList', JSON.stringify (table.column(12, { 'search': 'applied' }).data().toArray()) );
} ); } );
}; };
@@ -281,8 +302,10 @@ function getDevicesTotals () {
$('#devicesAll').html (totalsDevices[0].toLocaleString()); $('#devicesAll').html (totalsDevices[0].toLocaleString());
$('#devicesConnected').html (totalsDevices[1].toLocaleString()); $('#devicesConnected').html (totalsDevices[1].toLocaleString());
$('#devicesNew').html (totalsDevices[2].toLocaleString()); $('#devicesFavorites').html (totalsDevices[2].toLocaleString());
$('#devicesDown').html (totalsDevices[3].toLocaleString()); $('#devicesNew').html (totalsDevices[3].toLocaleString());
$('#devicesDown').html (totalsDevices[4].toLocaleString());
$('#devicesArchived').html (totalsDevices[5].toLocaleString());
// Timer for refresh data // Timer for refresh data
newTimerRefreshData (getDevicesTotals); newTimerRefreshData (getDevicesTotals);
@@ -297,12 +320,13 @@ function getDevicesList (status) {
// Define color & title for the status selected // Define color & title for the status selected
switch (deviceStatus) { switch (deviceStatus) {
case 'all': tableTitle = 'Total Devices'; color = 'aqua'; break; case 'all': tableTitle = 'All Devices'; color = 'aqua'; break;
case 'connected': tableTitle = 'Connected Devices'; color = 'green'; break; case 'connected': tableTitle = 'Connected Devices'; color = 'green'; break;
case 'new': tableTitle = 'New Devices'; color = 'yellow'; break; case 'favorites': tableTitle = 'Favorites'; color = 'yellow'; break;
case 'down': tableTitle = 'Down Alerts'; color = 'red'; break; case 'new': tableTitle = 'New Devices'; color = 'yellow'; break;
case 'favorites': tableTitle = 'Favorites'; color = 'yellow'; break; case 'down': tableTitle = 'Down Alerts'; color = 'red'; break;
default: tableTitle = 'Devices'; boxClass = ''; break; case 'archived': tableTitle = 'Archived Devices'; color = 'gray'; break;
default: tableTitle = 'Devices'; color = 'gray'; break;
} }
// Set title and color // Set title and color

View File

@@ -13,20 +13,98 @@ var modalCallbackFunction = '';
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
function showModal (title, message, btnCancel, btnOK, callbackFunction) { function setCookie (cookie, value, expirationHours='') {
// Calc expiration date
var expires = '';
if (typeof expirationHours === 'number') {
expires = ';expires=' + new Date(Date.now() + expirationHours *60*60*1000).toUTCString();
}
// Save Cookie
document.cookie = cookie + "=" + value + expires;
}
// -----------------------------------------------------------------------------
function getCookie (cookie) {
// Array of cookies
var allCookies = document.cookie.split(';');
// For each cookie
for (var i = 0; i < allCookies.length; i++) {
var currentCookie = allCookies[i].trim();
// If the current cookie is the correct cookie
if (currentCookie.indexOf (cookie +'=') == 0) {
// Return value
return currentCookie.substring (cookie.length+1);
}
}
// Return empty (not found)
return "";
}
// -----------------------------------------------------------------------------
function deleteCookie (cookie) {
document.cookie = cookie + '=;expires=Thu, 01 Jan 1970 00:00:00 UTC';
}
// -----------------------------------------------------------------------------
function deleteAllCookies() {
// Array of cookies
var allCookies = document.cookie.split(";");
// For each cookie
for (var i = 0; i < allCookies.length; i++) {
var cookie = allCookies[i].trim();
var eqPos = cookie.indexOf("=");
var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 UTC";
}
}
// -----------------------------------------------------------------------------
function showModalDefault (title, message, btnCancel, btnOK, callbackFunction) {
// set captions // set captions
$('#modal-title').html (title); $('#modal-default-title').html (title);
$('#modal-message').html (message); $('#modal-default-message').html (message);
$('#modal-cancel').html (btnCancel); $('#modal-default-cancel').html (btnCancel);
$('#modal-OK').html (btnOK); $('#modal-default-OK').html (btnOK);
modalCallbackFunction = callbackFunction; modalCallbackFunction = callbackFunction;
// Show modal
$('#modal-default').modal('show');
}
// -----------------------------------------------------------------------------
function showModalWarning (title, message, btnCancel, btnOK, callbackFunction) {
// set captions
$('#modal-warning-title').html (title);
$('#modal-warning-message').html (message);
$('#modal-warning-cancel').html (btnCancel);
$('#modal-warning-OK').html (btnOK);
modalCallbackFunction = callbackFunction;
// Show modal // Show modal
$('#modal-warning').modal('show'); $('#modal-warning').modal('show');
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
function modalOK () { function modalDefaultOK () {
// Hide modal
$('#modal-default').modal('hide');
// timer to execute function
window.setTimeout( function() {
window[modalCallbackFunction]();
}, 100);
}
// -----------------------------------------------------------------------------
function modalWarningOK () {
// Hide modal // Hide modal
$('#modal-warning').modal('hide'); $('#modal-warning').modal('hide');

View File

@@ -57,19 +57,22 @@ function getDeviceData() {
$mac = $_REQUEST['mac']; $mac = $_REQUEST['mac'];
// Device Data // Device Data
$sql = 'SELECT *, $sql = 'SELECT rowid, *,
CASE WHEN dev_AlertDeviceDown=1 AND dev_PresentLastScan=0 THEN "Down" CASE WHEN dev_AlertDeviceDown=1 AND dev_PresentLastScan=0 THEN "Down"
WHEN dev_PresentLastScan=1 THEN "On-line" WHEN dev_PresentLastScan=1 THEN "On-line"
ELSE "Off-line" END as dev_Status ELSE "Off-line" END as dev_Status
FROM Devices FROM Devices
WHERE dev_MAC="'. $mac .'"'; WHERE dev_MAC="'. $mac .'" or cast(rowid as text)="'. $mac. '"';
$result = $db->query($sql); $result = $db->query($sql);
$row = $result -> fetchArray (SQLITE3_ASSOC); $row = $result -> fetchArray (SQLITE3_ASSOC);
$deviceData = $row; $deviceData = $row;
$mac = $deviceData['dev_MAC'];
$deviceData['dev_FirstConnection'] = formatDate ($row['dev_FirstConnection']); // Date formated $deviceData['dev_FirstConnection'] = formatDate ($row['dev_FirstConnection']); // Date formated
$deviceData['dev_LastConnection'] = formatDate ($row['dev_LastConnection']); // Date formated $deviceData['dev_LastConnection'] = formatDate ($row['dev_LastConnection']); // Date formated
$deviceData['dev_RandomMAC'] = ( in_array($mac[1], array("2","6","A","E","a","e")) ? 1 : 0);
// Count Totals // Count Totals
$condition = ' WHERE eve_MAC="'. $mac .'" AND eve_DateTime >= '. $periodDate; $condition = ' WHERE eve_MAC="'. $mac .'" AND eve_DateTime >= '. $periodDate;
@@ -89,16 +92,16 @@ function getDeviceData() {
$row = $result -> fetchArray (SQLITE3_NUM); $row = $result -> fetchArray (SQLITE3_NUM);
$deviceData['dev_Events'] = $row[0]; $deviceData['dev_Events'] = $row[0];
// Donw Alerts // Down Alerts
$sql = 'SELECT COUNT(*) FROM Events '. $condition .' AND eve_EventType = "Device Down"'; $sql = 'SELECT COUNT(*) FROM Events '. $condition .' AND eve_EventType = "Device Down"';
$result = $db->query($sql); $result = $db->query($sql);
$row = $result -> fetchArray (SQLITE3_NUM); $row = $result -> fetchArray (SQLITE3_NUM);
$deviceData['dev_DownAlerts'] = $row[0]; $deviceData['dev_DownAlerts'] = $row[0];
// Presence hours // Presence hours
$sql = 'SELECT SUM (julianday (IFNULL (ses_DateTimeDisconnection, DATETIME("now"))) $sql = 'SELECT CAST(( MAX (0, SUM (julianday (IFNULL (ses_DateTimeDisconnection, DATETIME("now","localtime")))
- julianday (CASE WHEN ses_DateTimeConnection < '. $periodDate .' THEN '. $periodDate .' - julianday (CASE WHEN ses_DateTimeConnection < '. $periodDate .' THEN '. $periodDate .'
ELSE ses_DateTimeConnection END)) *24 ELSE ses_DateTimeConnection END)) *24 )) AS INT)
FROM Sessions FROM Sessions
WHERE ses_MAC="'. $mac .'" WHERE ses_MAC="'. $mac .'"
AND ses_DateTimeConnection IS NOT NULL AND ses_DateTimeConnection IS NOT NULL
@@ -136,7 +139,8 @@ function setDeviceData() {
dev_AlertEvents = "'. quotes($_REQUEST['alertevents']) .'", dev_AlertEvents = "'. quotes($_REQUEST['alertevents']) .'",
dev_AlertDeviceDown = "'. quotes($_REQUEST['alertdown']) .'", dev_AlertDeviceDown = "'. quotes($_REQUEST['alertdown']) .'",
dev_SkipRepeated = "'. quotes($_REQUEST['skiprepeated']) .'", dev_SkipRepeated = "'. quotes($_REQUEST['skiprepeated']) .'",
dev_NewDevice = "'. quotes($_REQUEST['newdevice']) .'" dev_NewDevice = "'. quotes($_REQUEST['newdevice']) .'",
dev_Archived = "'. quotes($_REQUEST['archived']) .'"
WHERE dev_MAC="' . $_REQUEST['mac'] .'"'; WHERE dev_MAC="' . $_REQUEST['mac'] .'"';
// update Data // update Data
$result = $db->query($sql); $result = $db->query($sql);
@@ -177,15 +181,20 @@ function getDevicesTotals() {
global $db; global $db;
// All // All
$result = $db->query('SELECT COUNT(*) FROM Devices '); $result = $db->query('SELECT COUNT(*) FROM Devices '. getDeviceCondition ('all'));
$row = $result -> fetchArray (SQLITE3_NUM); $row = $result -> fetchArray (SQLITE3_NUM);
$devices = $row[0]; $devices = $row[0];
// Connected // On-Line
$result = $db->query('SELECT COUNT(*) FROM Devices '. getDeviceCondition ('connected') ); $result = $db->query('SELECT COUNT(*) FROM Devices '. getDeviceCondition ('connected') );
$row = $result -> fetchArray (SQLITE3_NUM); $row = $result -> fetchArray (SQLITE3_NUM);
$connected = $row[0]; $connected = $row[0];
// Favorites
$result = $db->query('SELECT COUNT(*) FROM Devices '. getDeviceCondition ('favorites') );
$row = $result -> fetchArray (SQLITE3_NUM);
$favorites = $row[0];
// New // New
$result = $db->query('SELECT COUNT(*) FROM Devices '. getDeviceCondition ('new') ); $result = $db->query('SELECT COUNT(*) FROM Devices '. getDeviceCondition ('new') );
$row = $result -> fetchArray (SQLITE3_NUM); $row = $result -> fetchArray (SQLITE3_NUM);
@@ -194,10 +203,14 @@ function getDevicesTotals() {
// Down Alerts // Down Alerts
$result = $db->query('SELECT COUNT(*) FROM Devices '. getDeviceCondition ('down')); $result = $db->query('SELECT COUNT(*) FROM Devices '. getDeviceCondition ('down'));
$row = $result -> fetchArray (SQLITE3_NUM); $row = $result -> fetchArray (SQLITE3_NUM);
$devicesDownAlert = $row[0]; $downAlert = $row[0];
echo (json_encode (array ($devices, $connected, $newDevices, // Archived
$devicesDownAlert))); $result = $db->query('SELECT COUNT(*) FROM Devices '. getDeviceCondition ('archived'));
$row = $result -> fetchArray (SQLITE3_NUM);
$archived = $row[0];
echo (json_encode (array ($devices, $connected, $favorites, $newDevices, $downAlert, $archived)));
} }
@@ -210,7 +223,7 @@ function getDevicesList() {
// SQL // SQL
$condition = getDeviceCondition ($_REQUEST['status']); $condition = getDeviceCondition ($_REQUEST['status']);
$sql = 'SELECT *, CASE $sql = 'SELECT rowid, *, CASE
WHEN dev_AlertDeviceDown=1 AND dev_PresentLastScan=0 THEN "Down" WHEN dev_AlertDeviceDown=1 AND dev_PresentLastScan=0 THEN "Down"
WHEN dev_NewDevice=1 THEN "New" WHEN dev_NewDevice=1 THEN "New"
WHEN dev_PresentLastScan=1 THEN "On-line" WHEN dev_PresentLastScan=1 THEN "On-line"
@@ -230,9 +243,11 @@ function getDevicesList() {
formatDate ($row['dev_FirstConnection']), formatDate ($row['dev_FirstConnection']),
formatDate ($row['dev_LastConnection']), formatDate ($row['dev_LastConnection']),
$row['dev_LastIP'], $row['dev_LastIP'],
( in_array($row['dev_MAC'][1], array("2","6","A","E","a","e")) ? 1 : 0),
$row['dev_Status'], $row['dev_Status'],
$row['dev_MAC'], // MAC (hidden) $row['dev_MAC'], // MAC (hidden)
formatIPlong ($row['dev_LastIP']) // IP orderable formatIPlong ($row['dev_LastIP']), // IP orderable
$row['rowid'] // Rowid (hidden)
); );
} }
@@ -332,6 +347,7 @@ function getDeviceTypes() {
UNION SELECT 2 as dev_Order, "Server" UNION SELECT 2 as dev_Order, "Server"
UNION SELECT 2 as dev_Order, "Singleboard Computer (SBC)" UNION SELECT 2 as dev_Order, "Singleboard Computer (SBC)"
UNION SELECT 3 as dev_Order, "Domotic"
UNION SELECT 3 as dev_Order, "Game Console" UNION SELECT 3 as dev_Order, "Game Console"
UNION SELECT 3 as dev_Order, "SmartTV" UNION SELECT 3 as dev_Order, "SmartTV"
UNION SELECT 3 as dev_Order, "TV Decoder" UNION SELECT 3 as dev_Order, "TV Decoder"
@@ -346,6 +362,8 @@ function getDeviceTypes() {
UNION SELECT 5 as dev_Order, "NAS" UNION SELECT 5 as dev_Order, "NAS"
UNION SELECT 5 as dev_Order, "PLC" UNION SELECT 5 as dev_Order, "PLC"
UNION SELECT 5 as dev_Order, "Router" UNION SELECT 5 as dev_Order, "Router"
UNION SELECT 5 as dev_Order, "USB LAN Adapter"
UNION SELECT 5 as dev_Order, "USB WIFI Adapter"
UNION SELECT 10 as dev_Order, "Other" UNION SELECT 10 as dev_Order, "Other"
@@ -451,12 +469,13 @@ function getLocations() {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
function getDeviceCondition ($deviceStatus) { function getDeviceCondition ($deviceStatus) {
switch ($deviceStatus) { switch ($deviceStatus) {
case 'all': return ''; break; case 'all': return 'WHERE dev_Archived=0'; break;
case 'connected': return 'WHERE dev_PresentLastScan=1'; break; case 'connected': return 'WHERE dev_Archived=0 AND dev_PresentLastScan=1'; break;
case 'new': return 'WHERE dev_NewDevice=1'; break; case 'favorites': return 'WHERE dev_Archived=0 AND dev_Favorite=1'; break;
case 'down': return 'WHERE dev_AlertDeviceDown=1 AND dev_PresentLastScan=0'; break; case 'new': return 'WHERE dev_Archived=0 AND dev_NewDevice=1'; break;
case 'favorites': return 'WHERE dev_Favorite=1'; break; case 'down': return 'WHERE dev_Archived=0 AND dev_AlertDeviceDown=1 AND dev_PresentLastScan=0'; break;
default: return 'WHERE 1=0'; break; case 'archived': return 'WHERE dev_Archived=1'; break;
default: return 'WHERE 1=0'; break;
} }
} }

View File

@@ -64,7 +64,7 @@
<!-- ----------------------------------------------------------------------- --> <!-- ----------------------------------------------------------------------- -->
<!-- Logo --> <!-- Logo -->
<a href="/" class="logo"> <a href="." class="logo">
<!-- mini logo for sidebar mini 50x50 pixels --> <!-- mini logo for sidebar mini 50x50 pixels -->
<span class="logo-mini">P<b>a</b></span> <span class="logo-mini">P<b>a</b></span>
<!-- logo for regular state and mobile devices --> <!-- logo for regular state and mobile devices -->
@@ -140,7 +140,7 @@
<!-- Sidebar user panel (optional) --> <!-- Sidebar user panel (optional) -->
<div class="user-panel"> <div class="user-panel">
<a href="/" class="logo"> <a href="." class="logo">
<img src="img/pialertLogoGray80.png" class="img-responsive" alt="Pi.Alert Logo"/> <img src="img/pialertLogoGray80.png" class="img-responsive" alt="Pi.Alert Logo"/>
</a> </a>
</div> </div>
@@ -154,7 +154,6 @@
<li class="header">MAIN MENU</li> <li class="header">MAIN MENU</li>
--> -->
<!-- Optionally, you can add icons to the links -->
<li class=" <?php if (in_array (basename($_SERVER['SCRIPT_NAME']), array('devices.php', 'deviceDetails.php') ) ){ echo 'active'; } ?>"> <li class=" <?php if (in_array (basename($_SERVER['SCRIPT_NAME']), array('devices.php', 'deviceDetails.php') ) ){ echo 'active'; } ?>">
<a href="devices.php"><i class="fa fa-laptop"></i> <span>Devices</span></a> <a href="devices.php"><i class="fa fa-laptop"></i> <span>Devices</span></a>
</li> </li>
@@ -177,14 +176,18 @@
<i class="fa fa-angle-left pull-right"></i> <i class="fa fa-angle-left pull-right"></i>
</span> </span>
</a> </a>
<ul class="treeview-menu"> <ul class="treeview-menu">
<li><a href="#">Scan Cycles</a></li> <li class=" <?php if (in_array (basename($_SERVER['SCRIPT_NAME']), array('scancycles.php', 'scancyclesDetails.php') ) ){ echo 'active'; } ?>">
<a href="scancycles.php"><i class="fa fa-link"></i> <span>Scan Cycles</span></a>
</li>
<li><a href="#">Cron Status</a></li> <li><a href="#">Cron Status</a></li>
<li><a href="#">Current IP</a></li> <li><a href="#">Current IP</a></li>
</ul> </ul>
</li> </li>
--> -->
</ul> </ul>
<!-- /.sidebar-menu --> <!-- /.sidebar-menu -->
</section> </section>
<!-- /.sidebar --> <!-- /.sidebar -->

View File

@@ -7,6 +7,30 @@
# Puche 2021 pi.alert.application@gmail.com GNU GPLv3 # Puche 2021 pi.alert.application@gmail.com GNU GPLv3
#--------------------------------------------------------------------------- --> #--------------------------------------------------------------------------- -->
<!-- Modal Default -->
<div class="modal fade" id="modal-default" style="display: none;">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header" style="background-color: #d0d0d0;">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 id="modal-default-title" class="modal-title"> Modal Default Title </h4>
</div>
<div id="modal-default-message" class="modal-body"> Modal Default message </div>
<div class="modal-footer">
<button id="modal-default-cancel" type="button" class="btn btn-default pull-left" style="min-width: 80px;" data-dismiss="modal"> Cancel </button>
<button id="modal-default-OK" type="button" class="btn btn-primary" style="min-width: 80px;" onclick="modalDefaultOK()"> OK </button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
<!-- Modal warning --> <!-- Modal warning -->
<div class="modal modal-warning fade" id="modal-warning" style="display: none;"> <div class="modal modal-warning fade" id="modal-warning" style="display: none;">
<div class="modal-dialog"> <div class="modal-dialog">
@@ -14,22 +38,24 @@
<div class="modal-header"> <div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 id="modal-title" class="modal-title"> Modal Title </h4> <h4 id="modal-warning-title" class="modal-title"> Modal Title </h4>
</div> </div>
<div id="modal-message" class="modal-body"> Modal message </div> <div id="modal-warning-message" class="modal-body"> Modal message </div>
<div class="modal-footer"> <div class="modal-footer">
<button id="modal-cancel" type="button" class="btn btn-outline pull-left" data-dismiss="modal"> Cancel </button> <button id="modal-warning-cancel" type="button" class="btn btn-outline pull-left" style="min-width: 80px;" data-dismiss="modal"> Cancel </button>
<button id="modal-OK" type="button" class="btn btn-outline" onclick="modalOK()"> OK </button> <button id="modal-warning-OK" type="button" class="btn btn-outline" style="min-width: 80px;" onclick="modalWarningOK()"> OK </button>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<!-- Alert float --> <!-- Alert float -->
<div id="notification" class="alert alert-dimissible pa_alert_notification"> <div id="notification" class="alert alert-dimissible pa_alert_notification">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button> <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<div id="alert-message"> Alert message </div> <div id="alert-message"> Alert message </div>
</div> </div>

View File

@@ -17,7 +17,7 @@
<!-- Content header--------------------------------------------------------- --> <!-- Content header--------------------------------------------------------- -->
<section class="content-header"> <section class="content-header">
<h1 id="pageTitle"> <h1 id="pageTitle">
Presence by Devices Presence by Device
</h1> </h1>
</section> </section>
@@ -27,66 +27,67 @@
<!-- top small box 1 ------------------------------------------------------- --> <!-- top small box 1 ------------------------------------------------------- -->
<div class="row"> <div class="row">
<div class="col-lg-3 col-sm-6 col-xs-6"> <div class="col-lg-2 col-sm-4 col-xs-6">
<a href="#" onclick="javascript: getDevicesPresence('all');"> <a href="#" onclick="javascript: getDevicesPresence('all');">
<div class="small-box bg-aqua pa-small-box-aqua"> <div class="small-box bg-aqua pa-small-box-aqua pa-small-box-2">
<div class="inner"> <h3 id="devicesAll"> -- </h3> </div>
<div class="inner"> <div class="icon"> <i class="fa fa-laptop text-aqua-20"></i> </div>
<h4>All Devices</h4> <div class="small-box-footer pa-small-box-footer"> All Devices <i class="fa fa-arrow-circle-right"></i> </div>
<h3 id="devicesAll"> -- </h3>
</div>
<div class="icon"> <i class="fa fa-laptop"></i> </div>
<div class="small-box-footer"> Details <i class="fa fa-arrow-circle-right"></i> </div>
</div> </div>
</a> </a>
</div> </div>
<!-- top small box 2 ------------------------------------------------------- --> <!-- top small box 2 ------------------------------------------------------- -->
<div class="col-lg-3 col-sm-6 col-xs-6"> <div class="col-lg-2 col-sm-4 col-xs-6">
<a href="#" onclick="javascript: getDevicesPresence('connected');"> <a href="#" onclick="javascript: getDevicesPresence('connected');">
<div class="small-box bg-green pa-small-box-green"> <div class="small-box bg-green pa-small-box-green pa-small-box-2">
<div class="inner"> <h3 id="devicesConnected"> -- </h3> </div>
<div class="inner"> <div class="icon"> <i class="fa fa-plug text-green-20"></i> </div>
<h4>Connected</h4> <div class="small-box-footer pa-small-box-footer"> Connected <i class="fa fa-arrow-circle-right"></i> </div>
<h3 id="devicesConnected"> -- </h3>
</div>
<div class="icon"> <i class="fa fa-plug"></i> </div>
<div class="small-box-footer"> Details <i class="fa fa-arrow-circle-right"></i> </div>
</div> </div>
</a> </a>
</div> </div>
<!-- top small box 3 ------------------------------------------------------- --> <!-- top small box 3 ------------------------------------------------------- -->
<div class="col-lg-3 col-sm-6 col-xs-6"> <div class="col-lg-2 col-sm-4 col-xs-6">
<a href="#" onclick="javascript: getDevicesPresence('new');"> <a href="#" onclick="javascript: getDevicesPresence('favorites');">
<div class="small-box bg-yellow pa-small-box-yellow"> <div class="small-box bg-yellow pa-small-box-yellow pa-small-box-2">
<div class="inner"> <h3 id="devicesFavorites"> -- </h3> </div>
<div class="inner"> <div class="icon"> <i class="fa fa-star text-yellow-20"></i> </div>
<h4>New Devices</h4> <div class="small-box-footer pa-small-box-footer"> Favorites <i class="fa fa-arrow-circle-right"></i> </div>
<h3 id="devicesNew"> -- </h3>
</div>
<div class="icon"> <i class="ion ion-plus-round"></i> </div>
<div class="small-box-footer"> Details <i class="fa fa-arrow-circle-right"></i> </div>
</div> </div>
</a> </a>
</div> </div>
<!-- top small box 4 ------------------------------------------------------- --> <!-- top small box 4 ------------------------------------------------------- -->
<div class="col-lg-3 col-sm-6 col-xs-6"> <div class="col-lg-2 col-sm-4 col-xs-6">
<a href="#" onclick="javascript: getDevicesPresence('new');">
<div class="small-box bg-yellow pa-small-box-yellow pa-small-box-2">
<div class="inner"> <h3 id="devicesNew"> -- </h3> </div>
<div class="icon"> <i class="ion ion-plus-round text-yellow-20"></i> </div>
<div class="small-box-footer pa-small-box-footer"> New Devices <i class="fa fa-arrow-circle-right"></i> </div>
</div>
</a>
</div>
<!-- top small box 5 ------------------------------------------------------- -->
<div class="col-lg-2 col-sm-4 col-xs-6">
<a href="#" onclick="javascript: getDevicesPresence('down');"> <a href="#" onclick="javascript: getDevicesPresence('down');">
<div class="small-box bg-red pa-small-box-red"> <div class="small-box bg-red pa-small-box-red pa-small-box-2">
<div class="inner"> <h3 id="devicesDown"> -- </h3> </div>
<div class="icon"> <i class="fa fa-warning text-red-20"></i> </div>
<div class="small-box-footer pa-small-box-footer"> Down Alerts <i class="fa fa-arrow-circle-right"></i> </div>
</div>
</a>
</div>
<div class="inner"> <!-- top small box 6 ------------------------------------------------------- -->
<h4>Down Alerts</h4> <div class="col-lg-2 col-sm-4 col-xs-6">
<h3 id="devicesDown"> -- </h3> <a href="#" onclick="javascript: getDevicesPresence('hidden');">
</div> <div class="small-box bg-gray pa-small-box-gray pa-small-box-2">
<div class="inner"> <h3 id="devicesHidden"> -- </h3> </div>
<div class="icon"> <i class="fa fa-warning"></i> </div> <div class="icon"> <i class="fa fa-eye-slash text-gray-20"></i> </div>
<div class="small-box-footer"> Details <i class="fa fa-arrow-circle-right"></i> </div> <div class="small-box-footer pa-small-box-footer"> Hidden <i class="fa fa-arrow-circle-right"></i> </div>
</div> </div>
</a> </a>
</div> </div>
@@ -295,8 +296,10 @@ function getDevicesTotals () {
$('#devicesAll').html (totalsDevices[0].toLocaleString()); $('#devicesAll').html (totalsDevices[0].toLocaleString());
$('#devicesConnected').html (totalsDevices[1].toLocaleString()); $('#devicesConnected').html (totalsDevices[1].toLocaleString());
$('#devicesNew').html (totalsDevices[2].toLocaleString()); $('#devicesFavorites').html (totalsDevices[2].toLocaleString());
$('#devicesDown').html (totalsDevices[3].toLocaleString()); $('#devicesNew').html (totalsDevices[3].toLocaleString());
$('#devicesDown').html (totalsDevices[4].toLocaleString());
$('#devicesHidden').html (totalsDevices[5].toLocaleString());
// Timer for refresh data // Timer for refresh data
newTimerRefreshData (getDevicesTotals); newTimerRefreshData (getDevicesTotals);
@@ -313,10 +316,11 @@ function getDevicesPresence (status) {
switch (deviceStatus) { switch (deviceStatus) {
case 'all': tableTitle = 'Total Devices'; color = 'aqua'; break; case 'all': tableTitle = 'Total Devices'; color = 'aqua'; break;
case 'connected': tableTitle = 'Connected Devices'; color = 'green'; break; case 'connected': tableTitle = 'Connected Devices'; color = 'green'; break;
case 'favorites': tableTitle = 'Favorites'; color = 'yellow'; break;
case 'new': tableTitle = 'New Devices'; color = 'yellow'; break; case 'new': tableTitle = 'New Devices'; color = 'yellow'; break;
case 'down': tableTitle = 'Down Alerts'; color = 'red'; break; case 'down': tableTitle = 'Down Alerts'; color = 'red'; break;
case 'favorites': tableTitle = 'Favorites'; color = 'yellow'; break; case 'hidden': tableTitle = 'Hidden Devices'; color = 'gray'; break;
default: tableTitle = 'Devices'; boxClass = ''; break; default: tableTitle = 'Devices'; color = 'gray'; break;
} }
// Set title and color // Set title and color

View File

@@ -129,6 +129,10 @@ update_config() {
if ! grep -Fq QUERY_MYIP_SERVER "$PIALERT_HOME/config/pialert.conf" ; then if ! grep -Fq QUERY_MYIP_SERVER "$PIALERT_HOME/config/pialert.conf" ; then
echo "QUERY_MYIP_SERVER = 'http://ipv4.icanhazip.com'" >> "$PIALERT_HOME/config/pialert.conf" echo "QUERY_MYIP_SERVER = 'http://ipv4.icanhazip.com'" >> "$PIALERT_HOME/config/pialert.conf"
fi fi
if ! grep -Fq SCAN_SUBNETS "$PIALERT_HOME/config/pialert.conf" ; then
echo "SCAN_SUBNETS = '--localnet'" >> "$PIALERT_HOME/config/pialert.conf"
fi
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@@ -163,6 +167,16 @@ update_db() {
print_msg " - Adding column 'Location' to 'Devices'..." print_msg " - Adding column 'Location' to 'Devices'..."
sqlite3 $PIALERT_HOME/db/pialert.db "ALTER TABLE Devices ADD COLUMN dev_Location STRING(250) COLLATE NOCASE;" 2>&1 >> "$LOG" sqlite3 $PIALERT_HOME/db/pialert.db "ALTER TABLE Devices ADD COLUMN dev_Location STRING(250) COLLATE NOCASE;" 2>&1 >> "$LOG"
fi fi
COL=`sqlite3 $PIALERT_HOME/db/pialert.db "SELECT COUNT(*) FROM PRAGMA_TABLE_INFO ('Devices') WHERE name='dev_Hidden' COLLATE NOCASE";` 2>&1 >> "$LOG"
if [ "$COL" == "0" ] ; then
print_msg " - Adding column 'Archived / Hidden' to 'Devices'..."
sqlite3 $PIALERT_HOME/db/pialert.db "ALTER TABLE Devices ADD COLUMN dev_Archived BOOLEAN NOT NULL DEFAULT (0) CHECK (dev_Archived IN (0, 1) );" 2>&1 >> "$LOG"
sqlite3 $PIALERT_HOME/db/pialert.db "CREATE INDEX IDX_dev_Archived ON Devices (dev_Archived);" 2>&1 >> "$LOG"
fi
print_msg "- Cheking Internet scancycle..."
sqlite3 $PIALERT_HOME/db/pialert.db "UPDATE Devices set dev_ScanCycle=1, dev_AlertEvents=1, dev_AlertDeviceDown=1 WHERE dev_MAC='Internet' AND dev_ScanCycle=0;" 2>&1 >> "$LOG"
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------