version check

This commit is contained in:
Jokob-sk
2023-01-03 23:58:35 +11:00
parent 2aabae6faa
commit 8490540384
12 changed files with 333 additions and 27 deletions

View File

@@ -641,6 +641,8 @@ def main ():
# re-load user configuration
importConfig()
isNewVersion()
# proceed if 1 minute passed
if last_run + datetime.timedelta(minutes=1) < time_started :
@@ -2224,6 +2226,9 @@ def send_notifications ():
# Open html Template
template_file = open(PIALERT_BACK_PATH + '/report_template.html', 'r')
if isNewVersion():
template_file = open(PIALERT_BACK_PATH + '/report_template_new_version.html', 'r')
mail_html = template_file.read()
template_file.close()
@@ -2235,6 +2240,8 @@ def send_notifications ():
mail_text = mail_text.replace ('<SERVER_NAME>', socket.gethostname() )
mail_html = mail_html.replace ('<SERVER_NAME>', socket.gethostname() )
if 'internet' in INCLUDED_SECTIONS:
# Compose Internet Section
mail_section_Internet = False
@@ -3218,6 +3225,34 @@ def hide_email(email):
return email
#-------------------------------------------------------------------------------
def isNewVersion():
f = open(pialertPath + '/front/buildtimestamp.txt', 'r')
buildTimestamp = int(f.read().strip())
f.close()
url = requests.get("https://api.github.com/repos/jokob-sk/Pi.Alert/releases")
text = url.text
data = json.loads(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
if len(data) > 0:
dateTimeStr = data[0]["published_at"]
realeaseTimestamp = int(datetime.datetime.strptime(dateTimeStr, '%Y-%m-%dT%H:%M:%SZ').strftime('%s'))
if realeaseTimestamp > buildTimestamp + 600:
file_print("here")
return True
return False
#-------------------------------------------------------------------------------
# Cron-like Scheduling
#-------------------------------------------------------------------------------

View File

@@ -20,7 +20,7 @@
Pi.Alert Report
</td>
</tr>
<tr>
<td>
<table width=100% border=0 bgcolor=#FFD966 cellpadding=5px cellspacing=0 style="border-collapse: collapse; font-size: 15px; text-align:center; color:#404040"> <tr>
@@ -36,7 +36,7 @@
<p style="font-size: 24px; font-weight: bold; color:#C04040"> Internet: </p>
<table width=100% border=1 bordercolor=#C0C0C0 cellpadding=3px cellspacing=0 style="border-collapse: collapse; font-size: 12px; color:#707070">
<tr bgcolor=#909090 style="color:#F0F0F0">
<tr bgcolor=#909090 style="color:#f0f0f0">
<th width=140> Event Type </th>
<th width=130> Datetime </th>
<th width=100> IP </th>

View File

@@ -0,0 +1,120 @@
<!-- ---------------------------------------------------------------------------
# Pi.Alert
# Open Source Network Guard / WIFI & LAN intrusion detector
#
# repot_template.html - Back module. Template to email reporting in HTML format
#-------------------------------------------------------------------------------
# Puche 2021 pi.alert.application@gmail.com GNU GPLv3
#--------------------------------------------------------------------------- -->
<html>
<head>
</head>
<body>
<font face=sans-serif>
<table align=center width=100% cellpadding=0 cellspacing=0 style="border-radius: 5px;">
<tr>
<td bgcolor=#EFB956 align=center style="padding: 20px 10px 10px 10px; font-size: 30px; font-weight: bold; color:#000000; border-top-right-radius: 5px; border-top-left-radius: 5px; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2)">
Pi.Alert Report
</td>
</tr>
<tr>
<td bgcolor=#2656f1 width=100% align=center style="padding: 20px 10px 10px 10px; font-size: 20px; font-weight: bold; color:#ffffff; border-top-right-radius: 5px; border-top-left-radius: 5px; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2)">🆕 New <a style="color:#ffffff" href="https://github.com/jokob-sk/Pi.Alert/releases">version</a> available 🆕</td>
</tr>
<tr>
<td>
<table width=100% border=0 bgcolor=#FFD966 cellpadding=5px cellspacing=0 style="border-collapse: collapse; font-size: 15px; text-align:center; color:#404040"> <tr>
<td width=100%> Report Date: <b><REPORT_DATE></b> </td>
</tr>
</table>
</td>
</tr>
<tr>
<td bgcolor=#F5F5F5 height=200 valign=top style="padding: 10px">
<SECTION_INTERNET>
<p style="font-size: 24px; font-weight: bold; color:#C04040"> Internet: </p>
<table width=100% border=1 bordercolor=#C0C0C0 cellpadding=3px cellspacing=0 style="border-collapse: collapse; font-size: 12px; color:#707070">
<tr bgcolor=#909090 style="color:#f0f0f0">
<th width=140> Event Type </th>
<th width=130> Datetime </th>
<th width=100> IP </th>
<th> Additional Info </th>
</tr>
<TABLE_INTERNET>
</table>
<br>
</SECTION_INTERNET>
<SECTION_NEW_DEVICES>
<p style="font-size: 14px; font-weight: bold; color:#C04040"> New Devices: </p>
<table width=100% border=1 bordercolor=#C0C0C0 cellpadding=3px cellspacing=0 style="border-collapse: collapse; font-size: 12px; color:#707070">
<tr bgcolor=#909090 style="color:#F0F0F0">
<th width=150> MAC </th>
<th width=130> Datetime </th>
<th width=100> IP </th>
<th width=140> Device Name </th>
<th> Vendor </th>
</tr>
<TABLE_NEW_DEVICES>
</table>
<br>
</SECTION_NEW_DEVICES>
<SECTION_DEVICES_DOWN>
<p style="font-size: 14px; font-weight: bold; color:#C04040"> Devices Down: </p>
<table width=100% border=1 bordercolor=#C0C0C0 cellpadding=3px cellspacing=0 style="border-collapse: collapse; font-size: 12px; color:#707070">
<tr bgcolor=#909090 style="color:#F0F0F0">
<th width=140> MAC </th>
<th width=130> Datetime </th>
<th width=100> IP </th>
<th> Device Name </th>
</tr>
<TABLE_DEVICES_DOWN>
</table>
<br>
</SECTION_DEVICES_DOWN>
<SECTION_EVENTS>
<p style="font-size: 14px; font-weight: bold; color:#409040"> Events: </p>
<table width=100% border=1 bordercolor=#C0C0C0 cellpadding=3px cellspacing=0 style="border-collapse: collapse; font-size: 12px; color:#707070">
<tr bgcolor=#909090 style="color:#F0F0F0">
<th width=140> MAC </th>
<th width=130> Datetime </th>
<th width=100> IP </th>
<th width=100> Event Type </th>
<th width=140> Device Name </th>
<th> Additional Info </th>
</tr>
<TABLE_EVENTS>
</table>
</SECTION_EVENTS>
</td>
</tr>
<tr>
<td>
<table width=100% bgcolor=#46802e cellpadding=5px cellspacing=0 style="font-size: 13px; font-weight: bold; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px;">
<tr>
<td width=50% style="text-align:center"> Pi.Alert - <SERVER_NAME></td>
</tr>
</table>
</td>
</tr>
</table>
</font>
</body>
</html>