version check 0.3
This commit is contained in:
@@ -376,12 +376,10 @@ def importConfig ():
|
|||||||
NMAP_ARGS = ccd('NMAP_ARGS', '-p -10000' , c_d, 'Nmap custom arguments', 'text', '', 'Nmap')
|
NMAP_ARGS = ccd('NMAP_ARGS', '-p -10000' , c_d, 'Nmap custom arguments', 'text', '', 'Nmap')
|
||||||
|
|
||||||
# Insert into DB
|
# Insert into DB
|
||||||
sql.execute ("DELETE FROM Settings")
|
sql.execute ("DELETE FROM Settings")
|
||||||
|
|
||||||
sql.executemany ("""INSERT INTO Settings ("Code_Name", "Display_Name", "Description", "Type", "Options",
|
sql.executemany ("""INSERT INTO Settings ("Code_Name", "Display_Name", "Description", "Type", "Options",
|
||||||
"RegEx", "Value", "Group" ) VALUES (?, ?, ?, ?, ?, ?, ?, ?)""", mySettings)
|
"RegEx", "Value", "Group" ) VALUES (?, ?, ?, ?, ?, ?, ?, ?)""", mySettings)
|
||||||
|
|
||||||
|
|
||||||
# Used to determine the next import
|
# Used to determine the next import
|
||||||
lastTimeImported = time.time()
|
lastTimeImported = time.time()
|
||||||
|
|
||||||
@@ -411,11 +409,6 @@ def importConfig ():
|
|||||||
updateSubnets()
|
updateSubnets()
|
||||||
|
|
||||||
file_print('[', timeNow(), '] Config: Imported new config')
|
file_print('[', timeNow(), '] Config: Imported new config')
|
||||||
#-------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#===============================================================================
|
|
||||||
# USER CONFIG VARIABLES - END
|
|
||||||
#===============================================================================
|
|
||||||
|
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
# MAIN
|
# MAIN
|
||||||
@@ -433,6 +426,8 @@ last_run = now_minus_24h
|
|||||||
last_cleanup = now_minus_24h
|
last_cleanup = now_minus_24h
|
||||||
last_update_vendors = time_started - datetime.timedelta(days = 6) # update vendors 24h after first run and than once a week
|
last_update_vendors = time_started - datetime.timedelta(days = 6) # update vendors 24h after first run and than once a week
|
||||||
|
|
||||||
|
# indicates, if a new version is available
|
||||||
|
newVersionAvailable = False
|
||||||
|
|
||||||
def main ():
|
def main ():
|
||||||
# Initialize global variables
|
# Initialize global variables
|
||||||
@@ -474,6 +469,8 @@ def main ():
|
|||||||
startTime = startTime.replace (microsecond=0)
|
startTime = startTime.replace (microsecond=0)
|
||||||
|
|
||||||
# determine run/scan type based on passed time
|
# determine run/scan type based on passed time
|
||||||
|
|
||||||
|
# check for changes in Internet IP
|
||||||
if last_internet_IP_scan + datetime.timedelta(minutes=3) < time_started:
|
if last_internet_IP_scan + datetime.timedelta(minutes=3) < time_started:
|
||||||
cycle = 'internet_IP'
|
cycle = 'internet_IP'
|
||||||
last_internet_IP_scan = time_started
|
last_internet_IP_scan = time_started
|
||||||
@@ -521,7 +518,7 @@ def main ():
|
|||||||
nmapSchedule.last_run = datetime.datetime.now(tz).replace(microsecond=0)
|
nmapSchedule.last_run = datetime.datetime.now(tz).replace(microsecond=0)
|
||||||
performNmapScan(get_all_devices())
|
performNmapScan(get_all_devices())
|
||||||
|
|
||||||
# Perform an arp-scan if not disabled with a file
|
# Perform a network scan via arp-scan or pihole
|
||||||
if last_network_scan + datetime.timedelta(minutes=SCAN_CYCLE_MINUTES) < time_started:
|
if last_network_scan + datetime.timedelta(minutes=SCAN_CYCLE_MINUTES) < time_started:
|
||||||
last_network_scan = time_started
|
last_network_scan = time_started
|
||||||
cycle = 1 # network scan
|
cycle = 1 # network scan
|
||||||
@@ -1026,14 +1023,6 @@ def execute_arpscan ():
|
|||||||
unique_mac.append(device['mac'])
|
unique_mac.append(device['mac'])
|
||||||
unique_devices.append(device)
|
unique_devices.append(device)
|
||||||
|
|
||||||
# DEBUG
|
|
||||||
# file_print(devices_list)
|
|
||||||
# file_print(unique_mac)
|
|
||||||
# file_print(unique_devices)
|
|
||||||
# file_print(len(devices_list))
|
|
||||||
# file_print(len(unique_mac))
|
|
||||||
# file_print(len(unique_devices))
|
|
||||||
|
|
||||||
# return list
|
# return list
|
||||||
return unique_devices
|
return unique_devices
|
||||||
|
|
||||||
@@ -2692,8 +2681,6 @@ def mqtt_start():
|
|||||||
#===============================================================================
|
#===============================================================================
|
||||||
# DB
|
# DB
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
def upgradeDB ():
|
def upgradeDB ():
|
||||||
|
|
||||||
@@ -2776,7 +2763,8 @@ def upgradeDB ():
|
|||||||
('Front_Devices_Rows', '100'),
|
('Front_Devices_Rows', '100'),
|
||||||
('Front_Details_Tab', 'tabDetails'),
|
('Front_Details_Tab', 'tabDetails'),
|
||||||
('Back_Settings_Imported', round(time.time() * 1000)),
|
('Back_Settings_Imported', round(time.time() * 1000)),
|
||||||
('Back_App_State', 'Initializing')
|
('Back_App_State', 'Initializing'),
|
||||||
|
('Back_New_Version_Available', False)
|
||||||
]
|
]
|
||||||
|
|
||||||
sql.executemany ("""INSERT INTO Parameters ("par_ID", "par_Value") VALUES (?, ?)""", params)
|
sql.executemany ("""INSERT INTO Parameters ("par_ID", "par_Value") VALUES (?, ?)""", params)
|
||||||
@@ -3000,7 +2988,6 @@ def get_device_stats():
|
|||||||
""")
|
""")
|
||||||
|
|
||||||
row = sql.fetchone()
|
row = sql.fetchone()
|
||||||
|
|
||||||
commitDB()
|
commitDB()
|
||||||
|
|
||||||
return row
|
return row
|
||||||
@@ -3027,32 +3014,34 @@ def hide_email(email):
|
|||||||
return email
|
return email
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
def isNewVersion():
|
def isNewVersion():
|
||||||
|
global newVersionAvailable
|
||||||
|
|
||||||
f = open(pialertPath + '/front/buildtimestamp.txt', 'r')
|
if newVersionAvailable == False:
|
||||||
buildTimestamp = int(f.read().strip())
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
url = requests.get("https://api.github.com/repos/jokob-sk/Pi.Alert/releases")
|
f = open(pialertPath + '/front/buildtimestamp.txt', 'r')
|
||||||
text = url.text
|
buildTimestamp = int(f.read().strip())
|
||||||
|
f.close()
|
||||||
|
|
||||||
data = json.loads(text)
|
url = requests.get("https://api.github.com/repos/jokob-sk/Pi.Alert/releases")
|
||||||
|
text = url.text
|
||||||
# Debug
|
|
||||||
write_file (logPath + '/pialert_version_new.json', json.dumps(data))
|
|
||||||
|
|
||||||
# make sure we received a valid response and not an API rate limit exceeded message
|
data = json.loads(text)
|
||||||
if len(data) > 0 and "published_at" in data:
|
|
||||||
|
|
||||||
dateTimeStr = data[0]["published_at"]
|
|
||||||
|
|
||||||
realeaseTimestamp = int(datetime.datetime.strptime(dateTimeStr, '%Y-%m-%dT%H:%M:%SZ').strftime('%s'))
|
# make sure we received a valid response and not an API rate limit exceeded message
|
||||||
|
if len(data) > 0 and "published_at" in data[0]:
|
||||||
|
|
||||||
|
dateTimeStr = data[0]["published_at"]
|
||||||
|
|
||||||
if realeaseTimestamp > buildTimestamp + 600:
|
realeaseTimestamp = int(datetime.datetime.strptime(dateTimeStr, '%Y-%m-%dT%H:%M:%SZ').strftime('%s'))
|
||||||
file_print("here")
|
|
||||||
return True
|
if realeaseTimestamp > buildTimestamp + 600:
|
||||||
|
file_print(" New version of the container available!")
|
||||||
|
newVersionAvailable = True
|
||||||
|
sql.execute ("UPDATE Parameters SET par_Value='"+ str(newVersionAvailable) +"' WHERE par_ID='Back_New_Version_Available'")
|
||||||
|
|
||||||
|
return newVersionAvailable
|
||||||
|
|
||||||
return False
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
# Cron-like Scheduling
|
# Cron-like Scheduling
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ function handleVersion(){
|
|||||||
release_timestamp = new Date(release_datetime).getTime() / 1000;
|
release_timestamp = new Date(release_datetime).getTime() / 1000;
|
||||||
|
|
||||||
// cache value
|
// cache value
|
||||||
setCookie("release_timestamp", release_timestamp, 5);
|
setCookie("release_timestamp", release_timestamp, 30);
|
||||||
|
|
||||||
handleVersion();
|
handleVersion();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user