tar update
This commit is contained in:
@@ -167,8 +167,7 @@ def check_internet_IP ():
|
|||||||
def get_internet_IP ():
|
def get_internet_IP ():
|
||||||
# BUGFIX #46 - curl http://ipv4.icanhazip.com repeatedly is very slow
|
# BUGFIX #46 - curl http://ipv4.icanhazip.com repeatedly is very slow
|
||||||
# Using 'dig'
|
# Using 'dig'
|
||||||
dig_args = ['dig', '+short', '-4', 'myip.opendns.com',
|
dig_args = ['dig', '+short', '-4', 'myip.opendns.com', '@resolver1.opendns.com']
|
||||||
'@resolver1.opendns.com']
|
|
||||||
cmd_output = subprocess.check_output (dig_args, universal_newlines=True)
|
cmd_output = subprocess.check_output (dig_args, universal_newlines=True)
|
||||||
|
|
||||||
## BUGFIX #12 - Query IPv4 address (not IPv6)
|
## BUGFIX #12 - Query IPv4 address (not IPv6)
|
||||||
@@ -217,8 +216,7 @@ 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',
|
append_line_to_file (LOG_PATH + '/IP_changes.log', str(startTime) +'\t'+ pNewIP +'\n')
|
||||||
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,
|
||||||
@@ -297,8 +295,7 @@ def update_devices_MAC_vendors (pArg = ''):
|
|||||||
# print (recordsToUpdate)
|
# print (recordsToUpdate)
|
||||||
|
|
||||||
# update devices
|
# update devices
|
||||||
sql.executemany ("UPDATE Devices SET dev_Vendor = ? WHERE dev_MAC = ? ",
|
sql.executemany ("UPDATE Devices SET dev_Vendor = ? WHERE dev_MAC = ? ", recordsToUpdate )
|
||||||
recordsToUpdate )
|
|
||||||
|
|
||||||
# DEBUG - print number of rows updated
|
# DEBUG - print number of rows updated
|
||||||
# print (sql.rowcount)
|
# print (sql.rowcount)
|
||||||
@@ -447,19 +444,16 @@ def query_ScanCycle_Data (pOpenCloseDB = False):
|
|||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
def execute_arpscan (pRetries):
|
def execute_arpscan (pRetries):
|
||||||
# Prepara command arguments
|
# Prepara command arguments
|
||||||
arpscan_args = ['sudo', 'arp-scan', '--localnet', '--ignoredups',
|
arpscan_args = ['sudo', 'arp-scan', '--localnet', '--ignoredups', '--retry=' + str(pRetries)]
|
||||||
'--retry=' + str(pRetries)]
|
|
||||||
|
|
||||||
# TESTING - Fast Scan
|
# TESTING - Fast Scan
|
||||||
# arpscan_args = ['sudo', 'arp-scan', '--localnet', '--ignoredups',
|
# arpscan_args = ['sudo', 'arp-scan', '--localnet', '--ignoredups', '--retry=1']
|
||||||
# '--retry=1']
|
|
||||||
|
|
||||||
# DEBUG - arp-scan command
|
# DEBUG - arp-scan command
|
||||||
# print (" ".join (arpscan_args))
|
# print (" ".join (arpscan_args))
|
||||||
|
|
||||||
# Execute command
|
# Execute command
|
||||||
arpscan_output = subprocess.check_output (arpscan_args,
|
arpscan_output = subprocess.check_output (arpscan_args, universal_newlines=True)
|
||||||
universal_newlines=True)
|
|
||||||
|
|
||||||
# Search IP + MAC + Vendor as regular expresion
|
# Search IP + MAC + Vendor as regular expresion
|
||||||
re_ip = r'(?P<ip>((2[0-5]|1[0-9]|[0-9])?[0-9]\.){3}((2[0-5]|1[0-9]|[0-9])?[0-9]))'
|
re_ip = r'(?P<ip>((2[0-5]|1[0-9]|[0-9])?[0-9]\.){3}((2[0-5]|1[0-9]|[0-9])?[0-9]))'
|
||||||
@@ -678,9 +672,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_PresentLastScan, dev_NewDevice)
|
||||||
SELECT cur_MAC, '(unknown)', cur_Vendor, cur_IP, ?, ?,
|
SELECT cur_MAC, '(unknown)', cur_Vendor, cur_IP, ?, ?,
|
||||||
1, 1, 0, 1
|
1, 1, 0, 1, 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
|
||||||
@@ -707,9 +701,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_PresentLastScan, dev_NewDevice)
|
||||||
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, 0, 1, 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) """,
|
||||||
@@ -737,7 +731,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_PresentLastScan, dev_NewDevice)
|
||||||
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
|
||||||
@@ -745,7 +739,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
|
'(unknown)', ?, ?, 1, 1, 0, 1, 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) """,
|
||||||
@@ -1186,8 +1180,7 @@ 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',
|
format_report_section (mail_section_Internet, 'SECTION_INTERNET', 'TABLE_INTERNET', mail_text_Internet, mail_html_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
|
||||||
@@ -1214,8 +1207,7 @@ 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',
|
format_report_section (mail_section_new_devices, 'SECTION_NEW_DEVICES', 'TABLE_NEW_DEVICES', mail_text_new_devices, mail_html_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
|
||||||
@@ -1241,8 +1233,7 @@ 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',
|
format_report_section (mail_section_devices_down, 'SECTION_DEVICES_DOWN', 'TABLE_DEVICES_DOWN', mail_text_devices_down, mail_html_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
|
||||||
@@ -1272,8 +1263,7 @@ 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',
|
format_report_section (mail_section_events, 'SECTION_EVENTS', 'TABLE_EVENTS', mail_text_events, mail_html_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 :
|
||||||
@@ -1329,8 +1319,7 @@ 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+'>')] + \
|
return pText[:pText.find ('<'+ pSection+'>')] + pText[pText.find ('</'+ pSection +'>') + len (pSection) +3:]
|
||||||
pText[pText.find ('</'+ pSection +'>') + len (pSection) +3:]
|
|
||||||
else :
|
else :
|
||||||
# return all text
|
# return all text
|
||||||
return pText
|
return pText
|
||||||
|
|||||||
BIN
db/pialert.db
BIN
db/pialert.db
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user