mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
added Logs in maintenance + cleanup
This commit is contained in:
@@ -31,7 +31,11 @@ COPY . /home/pi/pialert
|
||||
# Pi.Alert
|
||||
RUN rm /etc/nginx/sites-available/default \
|
||||
&& ln -s /home/pi/pialert/install/default /etc/nginx/sites-available/default \
|
||||
&& sed -ie 's/listen 80/listen '${PORT}'/g' /etc/nginx/sites-available/default
|
||||
&& sed -ie 's/listen 80/listen '${PORT}'/g' /etc/nginx/sites-available/default \
|
||||
# make the logs accessible in the old location
|
||||
&& ln -s /home/pi/pialert/front/log /home/pi/pialert/log \
|
||||
# run the hardware vendors update
|
||||
&& /home/pi/pialert/back/update_vendors.sh
|
||||
|
||||
# it's easy for permissions set in Git to be overridden, so doing it manually
|
||||
RUN chmod -R a+rxw /home/pi/pialert/
|
||||
|
||||
281
back/pialert.py
281
back/pialert.py
@@ -40,123 +40,71 @@ import threading
|
||||
# sys.stderr = sys.stdout
|
||||
|
||||
#===============================================================================
|
||||
# CONFIG CONSTANTS
|
||||
# CONFIG VARIABLES
|
||||
#===============================================================================
|
||||
PIALERT_BACK_PATH = os.path.dirname(os.path.abspath(__file__))
|
||||
PIALERT_PATH = PIALERT_BACK_PATH + "/.."
|
||||
STOPARPSCAN = PIALERT_PATH + "/db/setting_stoparpscan"
|
||||
|
||||
# INITIALIZE VARIABLES from pialert.conf
|
||||
|
||||
# GENERAL
|
||||
PRINT_LOG = False
|
||||
LOG_PATH = PIALERT_PATH + '/front/log'
|
||||
|
||||
# keep 90 days of network activity if not specified how many days to keep
|
||||
DAYS_TO_KEEP_EVENTS = 90
|
||||
|
||||
# Scan loop delay
|
||||
SCAN_CYCLE_MINUTES = 5
|
||||
|
||||
# Email reporting defaults
|
||||
SMTP_SERVER = ''
|
||||
SMTP_PORT = 587
|
||||
SMTP_USER = ''
|
||||
SMTP_PASS = ''
|
||||
SMTP_SKIP_TLS = False
|
||||
SMTP_SKIP_LOGIN = False
|
||||
|
||||
# Which sections to include in the reports. Include everything by default
|
||||
INCLUDED_SECTIONS = ['internet', 'new_devices', 'down_devices', 'events']
|
||||
|
||||
# WEBHOOKS
|
||||
WEBHOOK_REQUEST_METHOD = 'GET'
|
||||
|
||||
# payload type for the webhook request
|
||||
WEBHOOK_PAYLOAD = 'json'
|
||||
|
||||
# NTFY default values
|
||||
NTFY_USER = ''
|
||||
NTFY_PASSWORD = ''
|
||||
NTFY_TOPIC = ''
|
||||
NTFY_HOST = 'https://ntfy.sh'
|
||||
|
||||
# MQTT default values
|
||||
REPORT_MQTT = False
|
||||
MQTT_BROKER = ''
|
||||
MQTT_PORT = ''
|
||||
MQTT_CLIENT_ID = 'PiAlert'
|
||||
MQTT_USER = ''
|
||||
MQTT_PASSWORD = ''
|
||||
MQTT_QOS = 0
|
||||
MQTT_DELAY_SEC = 2
|
||||
|
||||
# Apprise
|
||||
APPRISE_URL = ''
|
||||
APPRISE_HOST = ''
|
||||
|
||||
# Pushsafer
|
||||
PUSHSAFER_TOKEN = 'ApiKey'
|
||||
|
||||
# load user configuration
|
||||
|
||||
if (sys.version_info > (3,0)):
|
||||
exec(open(PIALERT_PATH + "/config/pialert.conf").read())
|
||||
else:
|
||||
execfile (PIALERT_PATH + "/config/pialert.conf")
|
||||
|
||||
# INITIALIZE ALL CONSTANTS from pialert.conf
|
||||
|
||||
# GENERAL
|
||||
# keep 90 days of network activity if not specified how many days to keep
|
||||
try:
|
||||
strdaystokeepEV = str(DAYS_TO_KEEP_EVENTS)
|
||||
except NameError: # variable not defined, use a default
|
||||
strdaystokeepEV = str(90)
|
||||
|
||||
try:
|
||||
network_scan_minutes = SCAN_CYCLE_MINUTES
|
||||
except NameError:
|
||||
network_scan_minutes = 5
|
||||
|
||||
# Which sections to include in the reports. Include everything by default
|
||||
try:
|
||||
includedSections = INCLUDED_SECTIONS
|
||||
except NameError:
|
||||
includedSections = ['internet', 'new_devices', 'down_devices', 'events']
|
||||
|
||||
|
||||
# WEBHOOKS
|
||||
# HTTP request method for the webhook (GET, POST...)
|
||||
try:
|
||||
webhookRequestMethod = WEBHOOK_REQUEST_METHOD
|
||||
except NameError:
|
||||
webhookRequestMethod = 'GET'
|
||||
|
||||
# payload type for the webhook request
|
||||
try:
|
||||
webhookPayload = WEBHOOK_PAYLOAD
|
||||
except NameError:
|
||||
webhookPayload = 'json'
|
||||
|
||||
|
||||
# NTFY
|
||||
try:
|
||||
ntfyUser = NTFY_USER
|
||||
except NameError:
|
||||
ntfyUser = ''
|
||||
|
||||
try:
|
||||
ntfyPassword = NTFY_PASSWORD
|
||||
except NameError:
|
||||
ntfyPassword = ''
|
||||
|
||||
try:
|
||||
ntfyTopic = NTFY_TOPIC
|
||||
except NameError:
|
||||
ntfyTopic = ''
|
||||
|
||||
try:
|
||||
ntfyHost = NTFY_HOST
|
||||
except NameError:
|
||||
ntfyHost = 'https://ntfy.sh'
|
||||
|
||||
|
||||
# MQTT
|
||||
try:
|
||||
reportMQTT = REPORT_MQTT
|
||||
except NameError:
|
||||
reportMQTT = False
|
||||
|
||||
try:
|
||||
mqttBroker = MQTT_BROKER
|
||||
except NameError:
|
||||
mqttBroker = ''
|
||||
|
||||
try:
|
||||
mqttPort = MQTT_PORT
|
||||
except NameError:
|
||||
mqttPort = ''
|
||||
|
||||
try:
|
||||
mqttTopic = MQTT_TOPIC
|
||||
except NameError:
|
||||
mqttTopic = ''
|
||||
|
||||
try:
|
||||
mqttClientId = MQTT_CLIENT_ID
|
||||
except NameError:
|
||||
mqttClientId = 'PiAlert'
|
||||
|
||||
try:
|
||||
mqttUser = MQTT_USER
|
||||
except NameError:
|
||||
mqttUser = ''
|
||||
|
||||
try:
|
||||
mqttPassword = MQTT_PASSWORD
|
||||
except NameError:
|
||||
mqttPassword = ''
|
||||
|
||||
try:
|
||||
mqttQoS = MQTT_QOS
|
||||
except NameError:
|
||||
mqttQoS = 0
|
||||
|
||||
try:
|
||||
mqttDelay = MQTT_DELAY_SEC
|
||||
except NameError:
|
||||
mqttDelay = 2
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
# MAIN
|
||||
#===============================================================================
|
||||
@@ -172,18 +120,25 @@ last_network_scan = now_minus_24h
|
||||
last_internet_IP_scan = now_minus_24h
|
||||
last_run = now_minus_24h
|
||||
last_cleanup = now_minus_24h
|
||||
last_update_vendors = time_now - timedelta(days = 7)
|
||||
last_update_vendors = time_now - timedelta(days = 6) # update vendors 24h after first run
|
||||
|
||||
def main ():
|
||||
# Initialize global variables
|
||||
global time_now, cycle, last_network_scan, last_internet_IP_scan, last_run, last_cleanup, last_update_vendors, network_scan_minutes, mqtt_thread_up
|
||||
global time_now, cycle, last_network_scan, last_internet_IP_scan, last_run, last_cleanup, last_update_vendors, mqtt_thread_up
|
||||
# second set of global variables
|
||||
global startTime, log_timestamp, sql_connection, includedSections, sql
|
||||
global startTime, log_timestamp, sql_connection, sql
|
||||
|
||||
while True:
|
||||
# update NOW time
|
||||
time_now = datetime.datetime.now()
|
||||
|
||||
# re-load user configuration
|
||||
|
||||
if (sys.version_info > (3,0)):
|
||||
exec(open(PIALERT_PATH + "/config/pialert.conf").read())
|
||||
else:
|
||||
execfile (PIALERT_PATH + "/config/pialert.conf")
|
||||
|
||||
# proceed if 1 minute passed
|
||||
if last_run + timedelta(minutes=1) < time_now :
|
||||
|
||||
@@ -221,7 +176,7 @@ def main ():
|
||||
cycle = 'update_vendors'
|
||||
update_devices_MAC_vendors()
|
||||
|
||||
if last_network_scan + timedelta(minutes=network_scan_minutes) < time_now and os.path.exists(STOPARPSCAN) == False:
|
||||
if last_network_scan + timedelta(minutes=SCAN_CYCLE_MINUTES) < time_now and os.path.exists(STOPARPSCAN) == False:
|
||||
last_network_scan = time_now
|
||||
cycle = 1 # network scan
|
||||
scan_network()
|
||||
@@ -443,8 +398,8 @@ def cleanup_database ():
|
||||
print (' Optimize Database...')
|
||||
|
||||
# Cleanup Events
|
||||
print (' Cleanup Events, up to the lastest '+strdaystokeepEV+' days...')
|
||||
sql.execute ("DELETE FROM Events WHERE eve_DateTime <= date('now', '-"+strdaystokeepEV+" day')")
|
||||
print (' Cleanup Events, up to the lastest '+str(DAYS_TO_KEEP_EVENTS)+' days...')
|
||||
sql.execute ("DELETE FROM Events WHERE eve_DateTime <= date('now', '-"+str(DAYS_TO_KEEP_EVENTS)+" day')")
|
||||
|
||||
# Shrink DB
|
||||
print (' Shrink Database...')
|
||||
@@ -1505,7 +1460,7 @@ def email_reporting ():
|
||||
|
||||
|
||||
for eventAlert in sql :
|
||||
mail_section_Internet = 'internet' in includedSections
|
||||
mail_section_Internet = 'internet' in INCLUDED_SECTIONS
|
||||
# collect "internet" (IP changes) for the webhook json
|
||||
json_internet = add_json_list (eventAlert, json_internet)
|
||||
|
||||
@@ -1537,7 +1492,7 @@ def email_reporting ():
|
||||
ORDER BY eve_DateTime""")
|
||||
|
||||
for eventAlert in sql :
|
||||
mail_section_new_devices = 'new_devices' in includedSections
|
||||
mail_section_new_devices = 'new_devices' in INCLUDED_SECTIONS
|
||||
# collect "new_devices" for the webhook json
|
||||
json_new_devices = add_json_list (eventAlert, json_new_devices)
|
||||
|
||||
@@ -1568,7 +1523,7 @@ def email_reporting ():
|
||||
ORDER BY eve_DateTime""")
|
||||
|
||||
for eventAlert in sql :
|
||||
mail_section_devices_down = 'down_devices' in includedSections
|
||||
mail_section_devices_down = 'down_devices' in INCLUDED_SECTIONS
|
||||
# collect "down_devices" for the webhook json
|
||||
json_down_devices = add_json_list (eventAlert, json_down_devices)
|
||||
|
||||
@@ -1601,7 +1556,7 @@ def email_reporting ():
|
||||
ORDER BY eve_DateTime""")
|
||||
|
||||
for eventAlert in sql :
|
||||
mail_section_events = 'events' in includedSections
|
||||
mail_section_events = 'events' in INCLUDED_SECTIONS
|
||||
# collect "events" for the webhook json
|
||||
json_events = add_json_list (eventAlert, json_events)
|
||||
|
||||
@@ -1635,33 +1590,33 @@ def email_reporting ():
|
||||
if json_internet != [] or json_new_devices != [] or json_down_devices != [] or json_events != []:
|
||||
print ('\nChanges detected, sending reports...')
|
||||
|
||||
if REPORT_MAIL :
|
||||
if REPORT_MAIL and check_config('email'):
|
||||
print (' Sending report by email...')
|
||||
send_email (mail_text, mail_html)
|
||||
else :
|
||||
print (' Skip mail...')
|
||||
if REPORT_APPRISE :
|
||||
if REPORT_APPRISE and check_config('apprise'):
|
||||
print (' Sending report by Apprise...')
|
||||
send_apprise (mail_html)
|
||||
else :
|
||||
print (' Skip Apprise...')
|
||||
if REPORT_WEBHOOK :
|
||||
if REPORT_WEBHOOK and check_config('webhook'):
|
||||
print (' Sending report by webhook...')
|
||||
send_webhook (json_final, mail_text)
|
||||
else :
|
||||
print (' Skip webhook...')
|
||||
if REPORT_NTFY :
|
||||
if REPORT_NTFY and check_config('ntfy'):
|
||||
print (' Sending report by NTFY...')
|
||||
send_ntfy (mail_text)
|
||||
else :
|
||||
print (' Skip NTFY...')
|
||||
if REPORT_PUSHSAFER :
|
||||
if REPORT_PUSHSAFER and check_config('pushsafer'):
|
||||
print (' Sending report by PUSHSAFER...')
|
||||
send_pushsafer (mail_text)
|
||||
else :
|
||||
print (' Skip PUSHSAFER...')
|
||||
# Update MQTT entities
|
||||
if reportMQTT:
|
||||
if REPORT_MQTT and check_config('mqtt'):
|
||||
print (' Establishing MQTT thread...')
|
||||
# mqtt_thread_up = True # prevent this code to be run multiple times concurrently
|
||||
# start_mqtt_thread ()
|
||||
@@ -1687,6 +1642,52 @@ def email_reporting ():
|
||||
# Commit changes
|
||||
sql_connection.commit()
|
||||
closeDB()
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
def check_config(service):
|
||||
|
||||
if service == 'email':
|
||||
if SMTP_PASS == '' or SMTP_SERVER == '' or SMTP_USER == '' or REPORT_FROM == '' or REPORT_TO == '':
|
||||
print (' Error: Email service not set up correctly. Check your pialert.conf SMTP_*, REPORT_FROM and REPORT_TO variables.')
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
if service == 'apprise':
|
||||
if APPRISE_URL == '' or APPRISE_HOST == '':
|
||||
print (' Error: Apprise service not set up correctly. Check your pialert.conf APPRISE_* variables.')
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
if service == 'webhook':
|
||||
if WEBHOOK_URL == '':
|
||||
print (' Error: Webhook service not set up correctly. Check your pialert.conf WEBHOOK_* variables.')
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
if service == 'ntfy':
|
||||
if NTFY_HOST == '' or NTFY_TOPIC == '':
|
||||
print (' Error: NTFY service not set up correctly. Check your pialert.conf NTFY_* variables.')
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
if service == 'pushsafer':
|
||||
if PUSHSAFER_TOKEN == 'ApiKey':
|
||||
print (' Error: Pushsafer service not set up correctly. Check your pialert.conf PUSHSAFER_TOKEN variable.')
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
if service == 'mqtt':
|
||||
if MQTT_BROKER == '' or MQTT_PORT == '' or MQTT_USER == '' or MQTT_PASSWORD == '':
|
||||
print (' Error: MQTT service not set up correctly. Check your pialert.conf MQTT_* variables.')
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
def send_ntfy (_Text):
|
||||
headers = {
|
||||
@@ -1696,15 +1697,15 @@ def send_ntfy (_Text):
|
||||
"Tags": "warning"
|
||||
}
|
||||
# if username and password are set generate hash and update header
|
||||
if ntfyUser != "" and ntfyPassword != "":
|
||||
if NTFY_USER != "" and NTFY_PASSWORD != "":
|
||||
# Generate hash for basic auth
|
||||
usernamepassword = "{}:{}".format(ntfyUser,ntfyPassword)
|
||||
basichash = b64encode(bytes(ntfyUser + ':' + ntfyPassword, "utf-8")).decode("ascii")
|
||||
usernamepassword = "{}:{}".format(NTFY_USER,NTFY_PASSWORD)
|
||||
basichash = b64encode(bytes(NTFY_USER + ':' + NTFY_PASSWORD, "utf-8")).decode("ascii")
|
||||
|
||||
# add authorization header with hash
|
||||
headers["Authorization"] = "Basic {}".format(basichash)
|
||||
|
||||
requests.post("{}/{}".format( ntfyHost, ntfyTopic),
|
||||
requests.post("{}/{}".format( NTFY_HOST, NTFY_TOPIC),
|
||||
data=_Text,
|
||||
headers=headers)
|
||||
|
||||
@@ -1821,15 +1822,15 @@ def SafeParseGlobalBool(boolVariable):
|
||||
def send_webhook (_json, _html):
|
||||
|
||||
# use data type based on specified payload type
|
||||
if webhookPayload == 'json':
|
||||
if WEBHOOK_PAYLOAD == 'json':
|
||||
payloadData = _json
|
||||
if webhookPayload == 'html':
|
||||
if WEBHOOK_PAYLOAD == 'html':
|
||||
payloadData = _html
|
||||
if webhookPayload == 'text':
|
||||
if WEBHOOK_PAYLOAD == 'text':
|
||||
payloadData = to_text(_json)
|
||||
|
||||
#Define slack-compatible payload
|
||||
_json_payload = { "text": payloadData } if webhookPayload == 'text' else {
|
||||
_json_payload = { "text": payloadData } if WEBHOOK_PAYLOAD == 'text' else {
|
||||
"username": "Pi.Alert",
|
||||
"text": "There are new notifications",
|
||||
"attachments": [{
|
||||
@@ -1848,7 +1849,7 @@ def send_webhook (_json, _html):
|
||||
curlParams = ["curl","-i","-H", "Content-Type:application/json" ,"-d", json.dumps(_json_payload), _WEBHOOK_URL]
|
||||
else:
|
||||
_WEBHOOK_URL = WEBHOOK_URL
|
||||
curlParams = ["curl","-i","-X", webhookRequestMethod ,"-H", "Content-Type:application/json" ,"-d", json.dumps(_json_payload), _WEBHOOK_URL]
|
||||
curlParams = ["curl","-i","-X", WEBHOOK_REQUEST_METHOD ,"-H", "Content-Type:application/json" ,"-d", json.dumps(_json_payload), _WEBHOOK_URL]
|
||||
|
||||
# execute CURL call
|
||||
try:
|
||||
@@ -1893,7 +1894,7 @@ def publish_mqtt(client, topic, message):
|
||||
result = client.publish(
|
||||
topic=topic,
|
||||
payload=message,
|
||||
qos=mqttQoS,
|
||||
qos=MQTT_QOS,
|
||||
retain=True,
|
||||
)
|
||||
|
||||
@@ -1972,7 +1973,7 @@ def publish_sensor(client, sensorConf):
|
||||
# add the sensor to the global list to keep track of succesfully added sensors
|
||||
if publish_mqtt(client, topic, message):
|
||||
# hack - delay adding to the queue in case the process is
|
||||
time.sleep(mqttDelay) # restarted and previous publish processes aborted
|
||||
time.sleep(MQTT_DELAY_SEC) # restarted and previous publish processes aborted
|
||||
# (it takes ~2s to update a sensor config on the broker)
|
||||
mqtt_sensors.append(sensorConf)
|
||||
# print(len(mqtt_sensors))
|
||||
@@ -1997,11 +1998,11 @@ def mqtt_create_client():
|
||||
mqtt_connected_to_broker = False
|
||||
|
||||
|
||||
client = mqtt_client.Client(mqttClientId) # Set Connecting Client ID
|
||||
client.username_pw_set(mqttUser, mqttPassword)
|
||||
client = mqtt_client.Client(MQTT_CLIENT_ID) # Set Connecting Client ID
|
||||
client.username_pw_set(MQTT_USER, MQTT_PASSWORD)
|
||||
client.on_connect = on_connect
|
||||
client.on_disconnect = on_disconnect
|
||||
client.connect(mqttBroker, mqttPort)
|
||||
client.connect(MQTT_BROKER, MQTT_PORT)
|
||||
client.loop_start()
|
||||
|
||||
return client
|
||||
@@ -2291,19 +2292,19 @@ def logResult (stdout, stderr):
|
||||
|
||||
def to_text(_json):
|
||||
payloadData = ""
|
||||
if len(_json['internet']) > 0 and 'internet' in includedSections:
|
||||
if len(_json['internet']) > 0 and 'internet' in INCLUDED_SECTIONS:
|
||||
payloadData += "INTERNET\n"
|
||||
for event in _json['internet']:
|
||||
payloadData += event[3] + ' on ' + event[2] + '. ' + event[4] + '. New address:' + event[1] + '\n'
|
||||
|
||||
if len(_json['new_devices']) > 0 and 'new_devices' in includedSections:
|
||||
if len(_json['new_devices']) > 0 and 'new_devices' in INCLUDED_SECTIONS:
|
||||
payloadData += "NEW DEVICES:\n"
|
||||
for event in _json['new_devices']:
|
||||
if event[4] is None:
|
||||
event[4] = event[11]
|
||||
payloadData += event[1] + ' - ' + event[4] + '\n'
|
||||
|
||||
if len(_json['down_devices']) > 0 and 'down_devices' in includedSections:
|
||||
if len(_json['down_devices']) > 0 and 'down_devices' in INCLUDED_SECTIONS:
|
||||
write_file (LOG_PATH + '/down_devices_example.log', _json['down_devices'])
|
||||
payloadData += 'DOWN DEVICES:\n'
|
||||
for event in _json['down_devices']:
|
||||
@@ -2311,7 +2312,7 @@ def to_text(_json):
|
||||
event[4] = event[11]
|
||||
payloadData += event[1] + ' - ' + event[4] + '\n'
|
||||
|
||||
if len(_json['events']) > 0 and 'events' in includedSections:
|
||||
if len(_json['events']) > 0 and 'events' in INCLUDED_SECTIONS:
|
||||
payloadData += "EVENTS:\n"
|
||||
for event in _json['events']:
|
||||
if event[8] != "Internet":
|
||||
|
||||
@@ -23,19 +23,21 @@ cd /usr/share/ieee-data/
|
||||
sudo mkdir -p 2_backup
|
||||
sudo cp *.txt 2_backup
|
||||
sudo cp *.csv 2_backup
|
||||
|
||||
sudo curl $1 -# -O https://standards-oui.ieee.org/iab/iab.csv
|
||||
sudo curl $1 -# -O https://standards-oui.ieee.org/iab/iab.txt
|
||||
|
||||
sudo curl $1 -# -O https://standards-oui.ieee.org/oui28/mam.csv
|
||||
sudo curl $1 -# -O https://standards-oui.ieee.org/oui28/mam.txt
|
||||
|
||||
sudo curl $1 -# -O https://standards-oui.ieee.org/oui36/oui36.csv
|
||||
sudo curl $1 -# -O https://standards-oui.ieee.org/oui36/oui36.txt
|
||||
|
||||
sudo curl $1 -# -O https://standards-oui.ieee.org/oui/oui.csv
|
||||
sudo curl $1 -# -O https://standards-oui.ieee.org/oui/oui.txt
|
||||
|
||||
echo ""
|
||||
echo Download Start
|
||||
echo ""
|
||||
sudo curl $1 -O https://standards-oui.ieee.org/iab/iab.csv \
|
||||
-O https://standards-oui.ieee.org/iab/iab.txt \
|
||||
-O https://standards-oui.ieee.org/oui28/mam.csv \
|
||||
-O https://standards-oui.ieee.org/iab/iab.txt \
|
||||
-O https://standards-oui.ieee.org/oui28/mam.csv \
|
||||
-O https://standards-oui.ieee.org/oui28/mam.txt \
|
||||
-O https://standards-oui.ieee.org/oui36/oui36.csv \
|
||||
-O https://standards-oui.ieee.org/oui36/oui36.txt \
|
||||
-O https://standards-oui.ieee.org/oui/oui.csv \
|
||||
-O https://standards-oui.ieee.org/oui/oui.txt
|
||||
echo ""
|
||||
echo Download Finished
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
echo ""
|
||||
|
||||
@@ -11,7 +11,7 @@ services:
|
||||
# (optional) map an empty file with the name 'setting_darkmode' if you want to force the dark mode on container rebuilt
|
||||
- ${APP_DATA_LOCATION}/pialert/db/setting_darkmode:/home/pi/pialert/db/setting_darkmode
|
||||
# (optional) useful for debugging if you have issues setting up the container
|
||||
- ${LOGS_LOCATION}:/home/pi/pialert/log
|
||||
- ${LOGS_LOCATION}:/home/pi/pialert/front/log
|
||||
# comment out below 2 lines, they are only for development purposes
|
||||
- ${DEV_LOCATION}/back/pialert.py:/home/pi/pialert/back/pialert.py
|
||||
- ${DEV_LOCATION}/front:/home/pi/pialert/front
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
1. Database backup
|
||||
* Download the [original DB from GitHub](https://github.com/jokob-sk/Pi.Alert/blob/main/db/pialert.db).
|
||||
* Map the `pialert.db` file (⚠ not folder) from above to `/home/pi/pialert/db/pialert.db` (see [Examples](https://github.com/jokob-sk/Pi.Alert/tree/main/dockerfiles#-examples) for details).
|
||||
* If facing issues (AJAX errors, can't write to DB, etc,) make sure permissions are set correctly, and check the logs under `/home/pi/pialert/log`.
|
||||
* If facing issues (AJAX errors, can't write to DB, etc,) make sure permissions are set correctly, and check the logs under `/home/pi/pialert/front/log`.
|
||||
* To solve permission issues you can also try to create a DB backup and then run a DB Restore via the **Maintenance > Backup/Restore** section.
|
||||
* You can try also setting the owner and group of the `pialert.db` by executing the following on the host system: `docker exec pialert chown -R www-data:www-data /home/pi/pialert/db/pialert.db`.
|
||||
2. Map to local User nad Group IDs. Specify the enviroment variables `HOST_USER_ID` and `HOST_USER_GID` if needed.
|
||||
@@ -77,7 +77,7 @@ services:
|
||||
# (optional) map an empty file with the name 'setting_darkmode' if you want to force the dark mode on container rebuilt
|
||||
- ${APP_DATA_LOCATION}/pialert/db/setting_darkmode:/home/pi/pialert/db/setting_darkmode
|
||||
# (optional) useful for debugging if you have issues setting up the container
|
||||
- ${LOGS_LOCATION}:/home/pi/pialert/log
|
||||
- ${LOGS_LOCATION}:/home/pi/pialert/front/log
|
||||
environment:
|
||||
- TZ=${TZ}
|
||||
- PORT=${PORT}
|
||||
|
||||
@@ -18,4 +18,4 @@ chown -R www-data:www-data /home/pi/pialert/db/pialert.db
|
||||
|
||||
# cron -f
|
||||
|
||||
python /home/pi/pialert/back/pialert.py > /home/pi/pialert/log/pialert.log 2>&1
|
||||
python /home/pi/pialert/back/pialert.py > /home/pi/pialert/front/log/pialert.log 2>&1
|
||||
|
||||
@@ -20,6 +20,11 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
Text Classes
|
||||
----------------------------------------------------------------------------- */
|
||||
.logs
|
||||
{
|
||||
color:white;
|
||||
background-color: black;
|
||||
}
|
||||
.text-center {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
10
front/log/IP_changes.log
Executable file
10
front/log/IP_changes.log
Executable file
@@ -0,0 +1,10 @@
|
||||
#-------------------------------------------------------------------------------
|
||||
# Pi.Alert
|
||||
# Open Source Network Guard / WIFI & LAN intrusion detector
|
||||
#
|
||||
# IP_changes.log - Back module. Logfile for Internet IP changes
|
||||
#-------------------------------------------------------------------------------
|
||||
# Puche 2021 pi.alert.application@gmail.com GNU GPLv3
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
2021-01-01 00:00:00 0.0.0.0
|
||||
441
front/log/pialert.log
Executable file
441
front/log/pialert.log
Executable file
@@ -0,0 +1,441 @@
|
||||
|
||||
Loop start
|
||||
---------------------------
|
||||
Check Internet IP
|
||||
Timestamp: 2022-12-11 13:09:00
|
||||
|
||||
Retrieving Internet IP...
|
||||
103.210.27.85
|
||||
|
||||
Retrieving previous IP...
|
||||
103.210.27.85
|
||||
No changes to perform
|
||||
|
||||
Skipping Dynamic DNS update...
|
||||
Scan Devices
|
||||
ScanCycle: 1
|
||||
Timestamp: 2022-12-11 13:09:00
|
||||
|
||||
Scanning...
|
||||
arp-scan Method...
|
||||
arp-scan: Multiple interfaces
|
||||
Pi-hole Method...
|
||||
DHCP Leases Method...
|
||||
|
||||
Processing scan results...
|
||||
Devices Detected.......: 27
|
||||
arp-scan Method....: 25
|
||||
Pi-hole Method.....: +0
|
||||
New Devices........: 0
|
||||
|
||||
Devices in this cycle..: 27
|
||||
Down Alerts........: 0
|
||||
New Down Alerts....: 0
|
||||
New Connections....: 0
|
||||
Disconnections.....: 1
|
||||
IP Changes.........: 0
|
||||
|
||||
Updating DB Info...
|
||||
Sessions Events (connect / discconnect) ...
|
||||
Creating new devices...
|
||||
Updating Devices Info...
|
||||
Trying to resolve devices without name...
|
||||
Names updated: 0
|
||||
Voiding false (ghost) disconnections...
|
||||
Pairing session events (connection / disconnection) ...
|
||||
Creating sessions snapshot...
|
||||
Skipping repeated notifications...
|
||||
|
||||
Check if something to report...
|
||||
No changes to report...
|
||||
Notifications: 0
|
||||
Cleanup Database
|
||||
Timestamp: 2022-12-11 13:09:00
|
||||
Cleanup Online_History...
|
||||
Optimize Database...
|
||||
Cleanup Events, up to the lastest 90 days...
|
||||
Shrink Database...
|
||||
|
||||
Finished cycle: cleanup
|
||||
|
||||
|
||||
Loop end
|
||||
---------------------------
|
||||
|
||||
Wait 20s
|
||||
|
||||
Loop start
|
||||
---------------------------
|
||||
|
||||
Loop end
|
||||
---------------------------
|
||||
|
||||
Wait 20s
|
||||
|
||||
Wait 20s
|
||||
|
||||
Loop start
|
||||
---------------------------
|
||||
|
||||
Loop end
|
||||
---------------------------
|
||||
|
||||
Wait 20s
|
||||
|
||||
Wait 20s
|
||||
|
||||
Loop start
|
||||
---------------------------
|
||||
Check Internet IP
|
||||
Timestamp: 2022-12-11 13:13:00
|
||||
|
||||
Retrieving Internet IP...
|
||||
103.210.27.85
|
||||
|
||||
Retrieving previous IP...
|
||||
103.210.27.85
|
||||
No changes to perform
|
||||
|
||||
Skipping Dynamic DNS update...
|
||||
|
||||
Check if something to report...
|
||||
No changes to report...
|
||||
Notifications: 0
|
||||
|
||||
Finished cycle: internet_IP
|
||||
|
||||
|
||||
Loop end
|
||||
---------------------------
|
||||
|
||||
Wait 20s
|
||||
|
||||
Wait 20s
|
||||
|
||||
Loop start
|
||||
---------------------------
|
||||
|
||||
Loop end
|
||||
---------------------------
|
||||
|
||||
Wait 20s
|
||||
|
||||
Wait 20s
|
||||
|
||||
Loop start
|
||||
---------------------------
|
||||
Scan Devices
|
||||
ScanCycle: 1
|
||||
Timestamp: 2022-12-11 13:15:00
|
||||
|
||||
Scanning...
|
||||
arp-scan Method...
|
||||
arp-scan: Multiple interfaces
|
||||
Pi-hole Method...
|
||||
DHCP Leases Method...
|
||||
|
||||
Processing scan results...
|
||||
Devices Detected.......: 26
|
||||
arp-scan Method....: 24
|
||||
Pi-hole Method.....: +0
|
||||
New Devices........: 0
|
||||
|
||||
Devices in this cycle..: 26
|
||||
Down Alerts........: 0
|
||||
New Down Alerts....: 0
|
||||
New Connections....: 0
|
||||
Disconnections.....: 1
|
||||
IP Changes.........: 0
|
||||
|
||||
Updating DB Info...
|
||||
Sessions Events (connect / discconnect) ...
|
||||
Creating new devices...
|
||||
Updating Devices Info...
|
||||
Trying to resolve devices without name...
|
||||
Names updated: 0
|
||||
Voiding false (ghost) disconnections...
|
||||
Pairing session events (connection / disconnection) ...
|
||||
Creating sessions snapshot...
|
||||
Skipping repeated notifications...
|
||||
|
||||
Check if something to report...
|
||||
|
||||
Changes detected, sending reports...
|
||||
Sending report by email...
|
||||
Sending report by Apprise...
|
||||
Sending report by webhook...
|
||||
Sending report by NTFY...
|
||||
Skip PUSHSAFER...
|
||||
Establishing MQTT thread...
|
||||
Connected to broker
|
||||
Notifications: 1
|
||||
|
||||
Finished cycle: 1
|
||||
|
||||
|
||||
Loop end
|
||||
---------------------------
|
||||
|
||||
Loop start
|
||||
---------------------------
|
||||
Check Internet IP
|
||||
Timestamp: 2022-12-11 13:24:00
|
||||
|
||||
Retrieving Internet IP...
|
||||
103.210.27.85
|
||||
|
||||
Retrieving previous IP...
|
||||
103.210.27.85
|
||||
No changes to perform
|
||||
|
||||
Skipping Dynamic DNS update...
|
||||
Scan Devices
|
||||
ScanCycle: 1
|
||||
Timestamp: 2022-12-11 13:24:00
|
||||
|
||||
Scanning...
|
||||
arp-scan Method...
|
||||
arp-scan: Multiple interfaces
|
||||
Pi-hole Method...
|
||||
DHCP Leases Method...
|
||||
|
||||
Processing scan results...
|
||||
Devices Detected.......: 26
|
||||
arp-scan Method....: 24
|
||||
Pi-hole Method.....: +0
|
||||
New Devices........: 0
|
||||
|
||||
Devices in this cycle..: 26
|
||||
Down Alerts........: 0
|
||||
New Down Alerts....: 0
|
||||
New Connections....: 0
|
||||
Disconnections.....: 0
|
||||
IP Changes.........: 0
|
||||
|
||||
Updating DB Info...
|
||||
Sessions Events (connect / discconnect) ...
|
||||
Creating new devices...
|
||||
Updating Devices Info...
|
||||
Trying to resolve devices without name...
|
||||
Names updated: 0
|
||||
Voiding false (ghost) disconnections...
|
||||
Pairing session events (connection / disconnection) ...
|
||||
Creating sessions snapshot...
|
||||
Skipping repeated notifications...
|
||||
|
||||
Check if something to report...
|
||||
No changes to report...
|
||||
Notifications: 0
|
||||
|
||||
Finished cycle: 1
|
||||
|
||||
|
||||
Loop end
|
||||
---------------------------
|
||||
|
||||
Wait 20s
|
||||
|
||||
Loop start
|
||||
---------------------------
|
||||
|
||||
Loop end
|
||||
---------------------------
|
||||
|
||||
Wait 20s
|
||||
|
||||
Wait 20s
|
||||
|
||||
Loop start
|
||||
---------------------------
|
||||
|
||||
Loop end
|
||||
---------------------------
|
||||
|
||||
Wait 20s
|
||||
|
||||
Wait 20s
|
||||
|
||||
Loop start
|
||||
---------------------------
|
||||
Check Internet IP
|
||||
Timestamp: 2022-12-11 13:27:00
|
||||
|
||||
Retrieving Internet IP...
|
||||
103.210.27.85
|
||||
|
||||
Retrieving previous IP...
|
||||
103.210.27.85
|
||||
No changes to perform
|
||||
|
||||
Skipping Dynamic DNS update...
|
||||
|
||||
Check if something to report...
|
||||
No changes to report...
|
||||
Notifications: 0
|
||||
|
||||
Finished cycle: internet_IP
|
||||
|
||||
|
||||
Loop end
|
||||
---------------------------
|
||||
|
||||
Wait 20s
|
||||
|
||||
Wait 20s
|
||||
|
||||
Loop start
|
||||
---------------------------
|
||||
|
||||
Loop end
|
||||
---------------------------
|
||||
|
||||
Wait 20s
|
||||
|
||||
Wait 20s
|
||||
|
||||
Loop start
|
||||
---------------------------
|
||||
Scan Devices
|
||||
ScanCycle: 1
|
||||
Timestamp: 2022-12-11 13:29:00
|
||||
|
||||
Scanning...
|
||||
arp-scan Method...
|
||||
arp-scan: Multiple interfaces
|
||||
Pi-hole Method...
|
||||
DHCP Leases Method...
|
||||
|
||||
Processing scan results...
|
||||
Devices Detected.......: 27
|
||||
arp-scan Method....: 25
|
||||
Pi-hole Method.....: +0
|
||||
New Devices........: 0
|
||||
|
||||
Devices in this cycle..: 27
|
||||
Down Alerts........: 0
|
||||
New Down Alerts....: 0
|
||||
New Connections....: 1
|
||||
Disconnections.....: 0
|
||||
IP Changes.........: 0
|
||||
|
||||
Updating DB Info...
|
||||
Sessions Events (connect / discconnect) ...
|
||||
Creating new devices...
|
||||
Updating Devices Info...
|
||||
Trying to resolve devices without name...
|
||||
Names updated: 0
|
||||
Voiding false (ghost) disconnections...
|
||||
Pairing session events (connection / disconnection) ...
|
||||
Creating sessions snapshot...
|
||||
Skipping repeated notifications...
|
||||
|
||||
Check if something to report...
|
||||
|
||||
Changes detected, sending reports...
|
||||
Sending report by email...
|
||||
Sending report by Apprise...
|
||||
Sending report by webhook...
|
||||
Sending report by NTFY...
|
||||
Skip PUSHSAFER...
|
||||
Establishing MQTT thread...
|
||||
Notifications: 1
|
||||
|
||||
Finished cycle: 1
|
||||
|
||||
|
||||
Loop end
|
||||
---------------------------
|
||||
|
||||
Wait 20s
|
||||
|
||||
Loop start
|
||||
---------------------------
|
||||
Check Internet IP
|
||||
Timestamp: 2022-12-11 13:30:00
|
||||
|
||||
Retrieving Internet IP...
|
||||
103.210.27.85
|
||||
|
||||
Retrieving previous IP...
|
||||
103.210.27.85
|
||||
No changes to perform
|
||||
|
||||
Skipping Dynamic DNS update...
|
||||
|
||||
Check if something to report...
|
||||
No changes to report...
|
||||
Notifications: 0
|
||||
|
||||
Finished cycle: internet_IP
|
||||
|
||||
|
||||
Loop end
|
||||
---------------------------
|
||||
|
||||
Wait 20s
|
||||
|
||||
Wait 20s
|
||||
|
||||
Loop start
|
||||
---------------------------
|
||||
|
||||
Loop end
|
||||
---------------------------
|
||||
|
||||
Wait 20s
|
||||
|
||||
Wait 20s
|
||||
|
||||
Loop start
|
||||
---------------------------
|
||||
|
||||
Loop end
|
||||
---------------------------
|
||||
|
||||
Wait 20s
|
||||
|
||||
Wait 20s
|
||||
|
||||
Loop start
|
||||
---------------------------
|
||||
Check Internet IP
|
||||
Timestamp: 2022-12-11 13:33:00
|
||||
|
||||
Retrieving Internet IP...
|
||||
103.210.27.85
|
||||
|
||||
Retrieving previous IP...
|
||||
103.210.27.85
|
||||
No changes to perform
|
||||
|
||||
Skipping Dynamic DNS update...
|
||||
|
||||
Check if something to report...
|
||||
No changes to report...
|
||||
Notifications: 0
|
||||
|
||||
Finished cycle: internet_IP
|
||||
|
||||
|
||||
Loop end
|
||||
---------------------------
|
||||
|
||||
Wait 20s
|
||||
|
||||
Wait 20s
|
||||
|
||||
Loop start
|
||||
---------------------------
|
||||
Scan Devices
|
||||
ScanCycle: 1
|
||||
Timestamp: 2022-12-11 13:34:00
|
||||
|
||||
Scanning...
|
||||
arp-scan Method...
|
||||
arp-scan: Multiple interfaces
|
||||
Pi-hole Method...
|
||||
DHCP Leases Method...
|
||||
|
||||
Processing scan results...
|
||||
Devices Detected.......: 27
|
||||
arp-scan Method....:
|
||||
56
front/log/report_output.html
Executable file
56
front/log/report_output.html
Executable file
@@ -0,0 +1,56 @@
|
||||
<!-- ---------------------------------------------------------------------------
|
||||
# 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=80% border=1 bordercolor=#909090 cellpadding=0 cellspacing=0 style="border-collapse: collapse; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.5)">
|
||||
<tr>
|
||||
<td bgcolor=#EFB956 align=center style="padding: 20px 10px 10px 10px; font-size: 36px; font-weight: bold; color:#7F6000; text-shadow: 4px 4px 6px #909090">
|
||||
Pi.Alert Report
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
<table width=100% border=0 bgcolor=#FFD966 cellpadding=5px cellspacing=0 style="border-collapse: collapse; font-size: 16px; text-align:center; color:#5F5000">
|
||||
<tr>
|
||||
<td width=33%> Report Date: <b>2021-01-01 08:00</b> </td>
|
||||
<td width=34%> Scan Cycle: <b>1</b> </td>
|
||||
<td width=33%> Server: <b>pi4</b> </td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td bgcolor=#F5F5F5 height=200 valign=top style="padding: 10px">
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
<table width=100% border=0 bgcolor=#70AD47 cellpadding=5px cellspacing=0 style="border-collapse: collapse; font-size: 12px; font-weight: bold; color:#385723">
|
||||
<tr>
|
||||
<td width=25% style="text-align:Left"> Puche 2021</td>
|
||||
<td width=50% style="text-align:center"> Pi.Alert 2.50 / 2021-01-01 </td>
|
||||
<td width=25% style="text-align:right"> GNU GPLv3</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</font>
|
||||
</body>
|
||||
</html>
|
||||
15
front/log/report_output.txt
Executable file
15
front/log/report_output.txt
Executable file
@@ -0,0 +1,15 @@
|
||||
========================================
|
||||
Pi.Alert Report
|
||||
========================================
|
||||
|
||||
Report Date: 2021-01-01 08:00
|
||||
Scan Cycle: 1
|
||||
Server: pi4
|
||||
|
||||
|
||||
Events
|
||||
----------------------------------------------------------------------
|
||||
|
||||
|
||||
----------------------------------------------------------------------
|
||||
Puche 2021 Pi.Alert 2.50 / 2021-01-01 GNU GPLv3
|
||||
0
front/log/stderr.log
Executable file
0
front/log/stderr.log
Executable file
49
front/log/stdout.log
Executable file
49
front/log/stdout.log
Executable file
@@ -0,0 +1,49 @@
|
||||
% Total % Received % Xferd Average Speed Time Time Time Current
|
||||
Dload Upload Total Spent Left Speed
|
||||
|
||||
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
|
||||
100 3266 0 0 100 3266 0 2717 0:00:01 0:00:01 --:--:-- 2719
|
||||
100 3287 100 21 100 3266 11 1769 0:00:01 0:00:01 --:--:-- 1780
|
||||
100 3287 100 21 100 3266 11 1769 0:00:01 0:00:01 --:--:-- 1780
|
||||
HTTP/1.1 200 OK
|
||||
Server: nginx/1.18.0
|
||||
Date: Sat, 10 Dec 2022 23:41:47 GMT
|
||||
Content-Type: text/html; charset=utf-8
|
||||
Content-Length: 21
|
||||
Connection: keep-alive
|
||||
Expires: Sat, 10 Dec 2022 23:41:47 GMT
|
||||
Cache-Control: max-age=0, no-cache, no-store, must-revalidate, private
|
||||
|
||||
Notification(s) sent. % Total % Received % Xferd Average Speed Time Time Time Current
|
||||
Dload Upload Total Spent Left Speed
|
||||
|
||||
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
|
||||
100 594 100 34 100 560 400 6588 --:--:-- --:--:-- --:--:-- 7071
|
||||
HTTP/1.1 200 OK
|
||||
Content-Type: application/json; charset=utf-8
|
||||
Content-Length: 34
|
||||
ETag: W/"22-6OS7cK0FzqnV2NeDHdOSGS1bVUs"
|
||||
Vary: Accept-Encoding
|
||||
Date: Sat, 10 Dec 2022 23:41:47 GMT
|
||||
Connection: keep-alive
|
||||
Keep-Alive: timeout=5
|
||||
|
||||
{"message":"Workflow was started"} % Total % Received % Xferd Average Speed Time Time Time Current
|
||||
Dload Upload Total Spent Left Speed
|
||||
|
||||
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
|
||||
100 3263 0 0 100 3263 0 2714 0:00:01 0:00:01 --:--:-- 2716
|
||||
100 3284 100 21 100 3263 11 1859 0:00:01 0:00:01 --:--:-- 1871
|
||||
HTTP/1.1 200 OK
|
||||
Server: nginx/1.18.0
|
||||
Date: Sun, 11 Dec 2022 00:52:29 GMT
|
||||
Content-Type: text/html; charset=utf-8
|
||||
Content-Length: 21
|
||||
Connection: keep-alive
|
||||
Expires: Sun, 11 Dec 2022 00:52:29 GMT
|
||||
Cache-Control: max-age=0, no-cache, no-store, must-revalidate, private
|
||||
|
||||
Notification(s) sent. % Total % Received % Xferd Average Speed Time Time Time Current
|
||||
Dload Upload Total Spent Left Speed
|
||||
|
||||
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
|
||||
1
front/log/webhook_payload.json
Executable file
1
front/log/webhook_payload.json
Executable file
@@ -0,0 +1 @@
|
||||
{"username": "Pi.Alert", "text": "There are new notifications", "attachments": [{"title": "Pi.Alert Notifications", "title_link": "http://100.89.112.105:20211", "text": {"internet": [], "new_devices": [], "down_devices": [], "events": [["94:b5:55:c7:cb:e0", "192.168.1.151", "2022-12-11 11:52:00", "Connected", "", 1, null, "94:b5:55:c7:cb:e0", "ESP32 - ttgo", "House", "", "Espressif Inc.", 0, "", "", "2022-10-16 16:55:00", "2022-12-11 11:52:00", "192.168.1.151", 0, 1, 1, 1, 0, 0, "2022-12-11 10:41:48.466369", 1, 0, "", 0, "d0:21:f9:8c:59:f9", ""]]}}]}
|
||||
@@ -233,6 +233,7 @@ if ($_REQUEST['tab'] == '1') {
|
||||
<li class="active"><a href="#tab_Settings" data-toggle="tab"><?php echo $pia_lang['Maintenance_Tools_Tab_Settings'];?></a></li>
|
||||
<li><a href="#tab_DBTools" data-toggle="tab"><?php echo $pia_lang['Maintenance_Tools_Tab_Tools'];?></a></li>
|
||||
<li><a href="#tab_BackupRestore" data-toggle="tab"><?php echo $pia_lang['Maintenance_Tools_Tab_BackupRestore'];?></a></li>
|
||||
<li><a href="#tab_Logging" data-toggle="tab"><?php echo $pia_lang['Maintenance_Tools_Tab_Logging'];?></a></li>
|
||||
</ul>
|
||||
<div class="tab-content">
|
||||
<div class="tab-pane active" id="tab_Settings">
|
||||
@@ -371,8 +372,52 @@ if ($_REQUEST['tab'] == '1') {
|
||||
<div class="db_tools_table_cell_b"><?php echo $pia_lang['Maintenance_Tool_ImportCSV_text'];?></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- ---------------------------Logging-------------------------------------------- -->
|
||||
<div class="tab-pane" id="tab_Logging">
|
||||
<div class="db_info_table">
|
||||
<div class="db_info_table_row">
|
||||
<div class="db_tools_table_cell_a" style="">
|
||||
IP_changes.log
|
||||
</div>
|
||||
<div class="db_tools_table_cell_b">
|
||||
<textarea class="logs" cols="70" rows="10" ><?php echo file_get_contents( "./log/IP_changes.log" ); ?>
|
||||
</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="db_info_table_row">
|
||||
<div class="db_tools_table_cell_a" style="">
|
||||
pialert.log
|
||||
</div>
|
||||
<div class="db_tools_table_cell_b">
|
||||
<textarea class="logs" cols="70" rows="10" ><?php echo file_get_contents( "./log/pialert.log" ); ?>
|
||||
</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="db_info_table_row">
|
||||
<div class="db_tools_table_cell_a" style="">
|
||||
stderr.log
|
||||
</div>
|
||||
<div class="db_tools_table_cell_b">
|
||||
<textarea class="logs" cols="70" rows="10" ><?php echo file_get_contents( "./log/stderr.log" ); ?>
|
||||
</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="db_info_table_row">
|
||||
<div class="db_tools_table_cell_a" style="">
|
||||
stdout.log
|
||||
</div>
|
||||
<div class="db_tools_table_cell_b">
|
||||
<textarea class="logs" cols="70" rows="10" ><?php echo file_get_contents( "./log/stdout.log" ); ?>
|
||||
</textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- ------------------------------------------------------------------------------ -->
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="box">
|
||||
@@ -474,7 +519,7 @@ function deleteEvents30()
|
||||
});
|
||||
}
|
||||
|
||||
// delete Hostory
|
||||
// delete History
|
||||
function askDeleteActHistory () {
|
||||
// Ask
|
||||
showModalWarning('<?php echo $pia_lang['Maintenance_Tool_del_ActHistory_noti'];?>', '<?php echo $pia_lang['Maintenance_Tool_del_ActHistory_noti_text'];?>',
|
||||
|
||||
@@ -229,6 +229,7 @@ $pia_lang['Maintenance_lang_selector_apply'] = 'Übernehmen';
|
||||
$pia_lang['Maintenance_Tools_Tab_Settings'] = 'Einstellungen';
|
||||
$pia_lang['Maintenance_Tools_Tab_Tools'] = 'Werkzeuge';
|
||||
$pia_lang['Maintenance_Tools_Tab_BackupRestore'] = 'Sicherg. / Wiederherstellg.';
|
||||
$pia_lang['Maintenance_Tools_Tab_Logging'] = 'Logs';
|
||||
$pia_lang['Maintenance_Tool_darkmode'] = 'Darstellungswechsel (Dunkel/Hell)';
|
||||
$pia_lang['Maintenance_Tool_darkmode_text'] = 'Wechselt zwischen der hellen und der dunklen Darstellung. Wenn der Wechsel nicht richtig funktionieren sollte, versuchen Sie den Browsercache zu löschen. Die Änderung findet serverseitig statt, betrifft also alle verwendeten Geräte.';
|
||||
$pia_lang['Maintenance_Tool_darkmode_noti'] = 'Darstellungswechsel';
|
||||
@@ -361,7 +362,7 @@ $pia_lang['HelpFAQ_Cat_General_102docker_head'] = '(🐳 Docker only) Database i
|
||||
$pia_lang['HelpFAQ_Cat_General_102docker_text'] = 'Double-check you\'ve followed the <a href="https://github.com/jokob-sk/Pi.Alert/tree/main/dockerfiles">dockerfile readme (most up-to-date info)</a>. <br/> <br/> <ul data-sourcepos="49:4-52:146" dir="auto">
|
||||
<li data-sourcepos="49:4-49:106">Download the <a href="https://github.com/jokob-sk/Pi.Alert/blob/main/db/pialert.db">original DB from GitHub</a>.</li>
|
||||
<li data-sourcepos="50:4-50:195">Map the <code>pialert.db</code> file (<g-emoji class="g-emoji" alias="warning" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/26a0.png">⚠</g-emoji> not folder) from above to <code>/home/pi/pialert/db/pialert.db</code> (see <a href="https://github.com/jokob-sk/Pi.Alert/tree/main/dockerfiles#-examples">Examples</a> for details).</li>
|
||||
<li data-sourcepos="51:4-51:161">If facing issues (AJAX errors, can\'t write to DB, etc,) make sure permissions are set correctly, alternatively check the logs under <code>/home/pi/pialert/log</code>.</li>
|
||||
<li data-sourcepos="51:4-51:161">If facing issues (AJAX errors, can\'t write to DB, etc,) make sure permissions are set correctly, alternatively check the logs under <code>/home/pi/pialert/front/log</code>.</li>
|
||||
<li data-sourcepos="52:4-52:146">To solve permission issues you can also try to create a DB backup and then run a DB Restore via the <strong>Maintenance > Backup/Restore</strong> section.</li>
|
||||
<li data-sourcepos="53:4-53:228">If the database is in read-only mode you can solve this by setting the owner and group by executing the following command on the host system: <code>docker exec pialert chown -R www-data:www-data /home/pi/pialert/db/pialert.db</code>.</li>
|
||||
</ul>';
|
||||
|
||||
@@ -227,6 +227,7 @@ $pia_lang['Maintenance_lang_selector_apply'] = 'Apply';
|
||||
$pia_lang['Maintenance_Tools_Tab_Settings'] = 'Settings';
|
||||
$pia_lang['Maintenance_Tools_Tab_Tools'] = 'Tools';
|
||||
$pia_lang['Maintenance_Tools_Tab_BackupRestore'] = 'Backup / Restore';
|
||||
$pia_lang['Maintenance_Tools_Tab_Logging'] = 'Logs';
|
||||
$pia_lang['Maintenance_Tool_darkmode'] = 'Toggle Modes (Dark/Light)';
|
||||
$pia_lang['Maintenance_Tool_darkmode_text'] = 'Toggle between dark mode and light mode. If the switch does not work properly, try to clear the browser cache. The change takes place on the server side, so it affects all devices in use.';
|
||||
$pia_lang['Maintenance_Tool_darkmode_noti'] = 'Toggle Modes';
|
||||
@@ -374,7 +375,7 @@ $pia_lang['HelpFAQ_Cat_General_102docker_head'] = '(🐳 Docker only) Database i
|
||||
$pia_lang['HelpFAQ_Cat_General_102docker_text'] = 'Double-check you\'ve followed the <a href="https://github.com/jokob-sk/Pi.Alert/tree/main/dockerfiles">dockerfile readme (most up-to-date info)</a>. <br/> <br/> <ul data-sourcepos="49:4-52:146" dir="auto">
|
||||
<li data-sourcepos="49:4-49:106">Download the <a href="https://github.com/jokob-sk/Pi.Alert/blob/main/db/pialert.db">original DB from GitHub</a>.</li>
|
||||
<li data-sourcepos="50:4-50:195">Map the <code>pialert.db</code> file (<g-emoji class="g-emoji" alias="warning" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/26a0.png">⚠</g-emoji> not folder) from above to <code>/home/pi/pialert/db/pialert.db</code> (see <a href="https://github.com/jokob-sk/Pi.Alert/tree/main/dockerfiles#-examples">Examples</a> for details).</li>
|
||||
<li data-sourcepos="51:4-51:161">If facing issues (AJAX errors, can\'t write to DB, etc,) make sure permissions are set correctly, alternatively check the logs under <code>/home/pi/pialert/log</code>.</li>
|
||||
<li data-sourcepos="51:4-51:161">If facing issues (AJAX errors, can\'t write to DB, etc,) make sure permissions are set correctly, alternatively check the logs under <code>/home/pi/pialert/front/log</code>.</li>
|
||||
<li data-sourcepos="52:4-52:146">To solve permission issues you can also try to create a DB backup and then run a DB Restore via the <strong>Maintenance > Backup/Restore</strong> section.</li>
|
||||
<li data-sourcepos="53:4-53:228">If the database is in read-only mode you can solve this by setting the owner and group by executing the following command on the host system: <code>docker exec pialert chown -R www-data:www-data /home/pi/pialert/db/pialert.db</code>.</li>
|
||||
</ul>';
|
||||
|
||||
@@ -223,6 +223,7 @@ $pia_lang['Maintenance_lang_selector_apply'] = 'Aplicar';
|
||||
$pia_lang['Maintenance_Tools_Tab_Settings'] = 'Ajustes';
|
||||
$pia_lang['Maintenance_Tools_Tab_Tools'] = 'Tools';
|
||||
$pia_lang['Maintenance_Tools_Tab_BackupRestore'] = 'Respaldo / Restaurar';
|
||||
$pia_lang['Maintenance_Tools_Tab_Logging'] = 'Logs';
|
||||
$pia_lang['Maintenance_Tool_darkmode'] = 'Cambiar Modo (Dark/Light)';
|
||||
$pia_lang['Maintenance_Tool_darkmode_text'] = 'Alternar entre el modo oscuro y el modo de luz. Si el interruptor no funciona correctamente, intente borrar el caché del navegador. El cambio tiene lugar en el lado del servidor, por lo que afecta todos los dispositivos en uso.';
|
||||
$pia_lang['Maintenance_Tool_darkmode_noti'] = 'Cambiar Modo';
|
||||
@@ -367,7 +368,7 @@ $pia_lang['HelpFAQ_Cat_General_102docker_head'] = '(🐳 Docker only) Database i
|
||||
$pia_lang['HelpFAQ_Cat_General_102docker_text'] = 'Double-check you\'ve followed the <a href="https://github.com/jokob-sk/Pi.Alert/tree/main/dockerfiles">dockerfile readme (most up-to-date info)</a>. <br/> <br/> <ul data-sourcepos="49:4-52:146" dir="auto">
|
||||
<li data-sourcepos="49:4-49:106">Download the <a href="https://github.com/jokob-sk/Pi.Alert/blob/main/db/pialert.db">original DB from GitHub</a>.</li>
|
||||
<li data-sourcepos="50:4-50:195">Map the <code>pialert.db</code> file (<g-emoji class="g-emoji" alias="warning" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/26a0.png">⚠</g-emoji> not folder) from above to <code>/home/pi/pialert/db/pialert.db</code> (see <a href="https://github.com/jokob-sk/Pi.Alert/tree/main/dockerfiles#-examples">Examples</a> for details).</li>
|
||||
<li data-sourcepos="51:4-51:161">If facing issues (AJAX errors, can\'t write to DB, etc,) make sure permissions are set correctly, alternatively check the logs under <code>/home/pi/pialert/log</code>.</li>
|
||||
<li data-sourcepos="51:4-51:161">If facing issues (AJAX errors, can\'t write to DB, etc,) make sure permissions are set correctly, alternatively check the logs under <code>/home/pi/pialert/front/log</code>.</li>
|
||||
<li data-sourcepos="52:4-52:146">To solve permission issues you can also try to create a DB backup and then run a DB Restore via the <strong>Maintenance > Backup/Restore</strong> section.</li>
|
||||
<li data-sourcepos="53:4-53:228">If the database is in read-only mode you can solve this by setting the owner and group by executing the following command on the host system: <code>docker exec pialert chown -R www-data:www-data /home/pi/pialert/db/pialert.db</code>.</li>
|
||||
</ul>';
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
#-------------------------------------------------------------------------------
|
||||
# Pi.Alert
|
||||
# Open Source Network Guard / WIFI & LAN intrusion detector
|
||||
#
|
||||
# pialert.cron - Back module. Crontab jobs
|
||||
#-------------------------------------------------------------------------------
|
||||
# Puche 2021 pi.alert.application@gmail.com GNU GPLv3
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
TZ=Europe/Berlin
|
||||
|
||||
0 3 * * 1 python /home/pi/pialert/back/pialert.py update_vendors >/home/pi/pialert/log/pialert.vendors.log 2>&1
|
||||
*/3 * * * * python /home/pi/pialert/back/pialert.py internet_IP >/home/pi/pialert/log/pialert.IP.log 2>&1
|
||||
*/5 * * * * python /home/pi/pialert/back/pialert.py 1 >/home/pi/pialert/log/pialert.1.log 2>&1
|
||||
0 2 * * */4 python /home/pi/pialert/back/pialert.py cleanup >/home/pi/pialert/log/pialert.cleanup.log 2>&1
|
||||
|
||||
@@ -1,797 +0,0 @@
|
||||
#!/bin/bash
|
||||
# ------------------------------------------------------------------------------
|
||||
# Pi.Alert
|
||||
# Open Source Network Guard / WIFI & LAN intrusion detector
|
||||
#
|
||||
# pialert_install.sh - Installation script
|
||||
# ------------------------------------------------------------------------------
|
||||
# Puche 2021 pi.alert.application@gmail.com GNU GPLv3
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Variables
|
||||
# ------------------------------------------------------------------------------
|
||||
COLS=70
|
||||
ROWS=12
|
||||
|
||||
INSTALL_DIR=~
|
||||
PIALERT_HOME="$INSTALL_DIR/pialert"
|
||||
|
||||
LIGHTTPD_CONF_DIR="/etc/lighttpd"
|
||||
WEBROOT="/var/www/html"
|
||||
PIALERT_DEFAULT_PAGE=false
|
||||
|
||||
LOG="pialert_install_`date +"%Y-%m-%d_%H-%M"`.log"
|
||||
|
||||
# MAIN_IP=`ip -o route get 1 | sed -n 's/.*src \([0-9.]\+\).*/\1/p'`
|
||||
MAIN_IP=`ip -o route get 1 | sed 's/^.*src \([^ ]*\).*$/\1/;q'`
|
||||
|
||||
PIHOLE_INSTALL=false
|
||||
PIHOLE_ACTIVE=false
|
||||
DHCP_ACTIVATE=false
|
||||
DHCP_ACTIVE=false
|
||||
|
||||
DHCP_RANGE_START="192.168.1.200"
|
||||
DHCP_RANGE_END="192.168.1.251"
|
||||
DHCP_ROUTER="192.168.1.1"
|
||||
DHCP_LEASE="1"
|
||||
DHCP_DOMAIN="local"
|
||||
|
||||
USE_PYTHON_VERSION=0
|
||||
PYTHON_BIN=python
|
||||
|
||||
FIRST_SCAN_KNOWN=true
|
||||
|
||||
REPORT_MAIL=False
|
||||
REPORT_TO=user@gmail.com
|
||||
SMTP_SERVER=smtp.gmail.com
|
||||
SMTP_PORT=587
|
||||
SMTP_USER=user@gmail.com
|
||||
SMTP_PASS=password
|
||||
|
||||
DDNS_ACTIVE=False
|
||||
DDNS_DOMAIN='your_domain.freeddns.org'
|
||||
DDNS_USER='dynu_user'
|
||||
DDNS_PASSWORD='A0000000B0000000C0000000D0000000'
|
||||
DDNS_UPDATE_URL='https://api.dynu.com/nic/update?'
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Main
|
||||
# ------------------------------------------------------------------------------
|
||||
main() {
|
||||
print_superheader "Pi.Alert Installation"
|
||||
log "`date`"
|
||||
log "Logfile: $LOG"
|
||||
|
||||
check_pialert_home
|
||||
ask_config
|
||||
|
||||
set -e
|
||||
|
||||
install_pihole
|
||||
activate_DHCP
|
||||
add_pialert_DNS
|
||||
install_lighttpd
|
||||
install_arpscan
|
||||
install_python
|
||||
install_pialert
|
||||
|
||||
print_header "Installation process finished"
|
||||
print_msg "Use: - http://pi.alert/"
|
||||
print_msg " - http://$MAIN_IP/pialert/"
|
||||
print_msg "To access Pi.Alert web"
|
||||
print_msg ""
|
||||
|
||||
move_logfile
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Ask config questions
|
||||
# ------------------------------------------------------------------------------
|
||||
ask_config() {
|
||||
# Ask installation
|
||||
ask_yesno "This script will install Pi.Alert in this system using this path:\n$PIALERT_HOME" \
|
||||
"Do you want to continue ?"
|
||||
if ! $ANSWER ; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Ask Pi-hole Installation
|
||||
PIHOLE_ACTIVE=false
|
||||
if [ -e /usr/local/bin/pihole ] || [ -e /etc/pihole ]; then
|
||||
PIHOLE_ACTIVE=true
|
||||
fi
|
||||
|
||||
PIHOLE_INSTALL=false
|
||||
if $PIHOLE_ACTIVE ; then
|
||||
msgbox "Pi-hole is already installed in this system." \
|
||||
"Perfect: Pi-hole Installation is not necessary"
|
||||
else
|
||||
ask_yesno "Pi-hole is not installed." \
|
||||
"Do you want to install Pi-hole before installing Pi.Alert ?" "YES"
|
||||
if $ANSWER ; then
|
||||
PIHOLE_INSTALL=true
|
||||
msgbox "In the installation wizard of Pi-hole, select this options" \
|
||||
"'Install web admin interface' & 'Install web server lighttpd'"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Ask DHCP Activation
|
||||
DHCP_ACTIVE=false
|
||||
DHCP_ACTIVATE=false
|
||||
if $PIHOLE_ACTIVE ; then
|
||||
DHCP_ACTIVE=`sudo grep DHCP_ACTIVE /etc/pihole/setupVars.conf | awk -F= '/./{print $2}'`
|
||||
if [ "$DHCP_ACTIVE" = "" ] ; then DHCP_ACTIVE=false; fi
|
||||
|
||||
if ! $DHCP_ACTIVE ; then
|
||||
ask_yesno "Pi-hole DHCP server is not active." \
|
||||
"Do you want to activate Pi-hole DHCP server ?"
|
||||
if $ANSWER ; then
|
||||
DHCP_ACTIVATE=true
|
||||
fi
|
||||
fi
|
||||
|
||||
elif $PIHOLE_INSTALL ; then
|
||||
ask_yesno "Pi-hole installation." \
|
||||
"Do you want to activate Pi-hole DHCP server ?"
|
||||
if $ANSWER ; then
|
||||
DHCP_ACTIVATE=true
|
||||
fi
|
||||
fi
|
||||
|
||||
if $DHCP_ACTIVATE ; then
|
||||
msgbox "Default DHCP options will be used. Range=$DHCP_RANGE_START - $DHCP_RANGE_END / Router=$DHCP_ROUTER / Domain=$DHCP_DOMAIN / Leases=$DHCP_LEASE h." \
|
||||
"You can change this values in your Pi-hole Admin Portal"
|
||||
msgbox "Make sure your router's DHCP server is disabled" \
|
||||
"when using the Pi-hole DHCP server!"
|
||||
fi
|
||||
|
||||
# Ask Pi.Alert deafault page
|
||||
PIALERT_DEFAULT_PAGE=false
|
||||
if ! $PIHOLE_ACTIVE && ! $PIHOLE_INSTALL; then
|
||||
ask_yesno "As Pi-hole is not going to be available in this system," \
|
||||
"Do you want to use Pi.Alert as default web server page ?" "YES"
|
||||
if $ANSWER ; then
|
||||
PIALERT_DEFAULT_PAGE=true
|
||||
fi
|
||||
fi
|
||||
|
||||
# Ask Python version
|
||||
ask_option "What Python version do you want to use ?" \
|
||||
3 \
|
||||
0 " - Use Python already installed in the system (DEFAULT)" \
|
||||
2 " - Use Python 2" \
|
||||
3 " - Use Python 3"
|
||||
if [ "$ANSWER" = "" ] ; then
|
||||
USE_PYTHON_VERSION=0
|
||||
else
|
||||
USE_PYTHON_VERSION=$ANSWER
|
||||
fi
|
||||
|
||||
# Ask first scan options
|
||||
ask_yesno "First Scan options" \
|
||||
"Do you want to mark the new devices as known devices during the first scan?" "YES"
|
||||
FIRST_SCAN_KNOWN=$ANSWER
|
||||
|
||||
# Ask e-mail notification config
|
||||
MAIL_REPORT=false
|
||||
ask_yesno "Pi.Alert can notify you by e-mail when a network event occurs" \
|
||||
"Do you want to activate this feature ?"
|
||||
if $ANSWER ; then
|
||||
ask_yesno "e-mail notification needs a SMTP server (i.e. smtp.gmail.com)" \
|
||||
"Do you want to continue activating this feature ?"
|
||||
MAIL_REPORT=$ANSWER
|
||||
fi
|
||||
|
||||
if $MAIL_REPORT ; then
|
||||
ask_input "" "Notify alert to this e-mail address:" "user@gmail.com"
|
||||
REPORT_TO=$ANSWER
|
||||
|
||||
ask_input "" "SMTP server:" "smtp.gmail.com"
|
||||
SMTP_SERVER=$ANSWER
|
||||
|
||||
ask_input "" "SMTP user:" "user@gmail.com"
|
||||
SMTP_USER=$ANSWER
|
||||
|
||||
ask_input "" "SMTP password:" "password"
|
||||
SMTP_PASS=$ANSWER
|
||||
fi
|
||||
|
||||
# Ask Dynamic DNS config
|
||||
DDNS_ACTIVE=false
|
||||
ask_yesno "Pi.Alert can update your Dynamic DNS IP (i.e with www.dynu.net)" \
|
||||
"Do you want to activate this feature ?"
|
||||
if $ANSWER ; then
|
||||
ask_yesno "Dynamics DNS updater needs a DNS with IP Update Protocol" \
|
||||
"(i.e with www.dynu.net). Do you want to continue ?"
|
||||
DDNS_ACTIVE=$ANSWER
|
||||
fi
|
||||
|
||||
if $DDNS_ACTIVE ; then
|
||||
ask_input "" "Domain to update:" "your_domain.freeddns.org"
|
||||
DDNS_DOMAIN=$ANSWER
|
||||
|
||||
ask_input "" "DDNS user:" "dynu_user"
|
||||
DDNS_USER=$ANSWER
|
||||
|
||||
ask_input "" "DDNS password:" "A0000000B0000000C0000000D0000000"
|
||||
DDNS_PASSWORD=$ANSWER
|
||||
|
||||
ask_input "" "URL to update DDNS IP:" "https://api.dynu.com/nic/update?"
|
||||
DDNS_UPDATE_URL=$ANSWER
|
||||
fi
|
||||
|
||||
# Final config message
|
||||
msgbox "Configuration finished. To update the configuration, edit file:" \
|
||||
"$PIALERT_HOME/config/pialert.conf"
|
||||
|
||||
msgbox "" "The installation will start now"
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Install Pi-hole
|
||||
# ------------------------------------------------------------------------------
|
||||
install_pihole() {
|
||||
print_header "Pi-hole"
|
||||
|
||||
if ! $PIHOLE_INSTALL ; then
|
||||
return
|
||||
fi
|
||||
|
||||
print_msg "- Checking if Pi-hole is installed..."
|
||||
if [ -e /usr/local/bin/pihole ] || [ -e /etc/pihole ]; then
|
||||
print_msg " - Pi-hole already installed"
|
||||
print_msg "`pihole -v 2>&1`"
|
||||
print_msg ""
|
||||
|
||||
PIHOLE_ACTIVE=true
|
||||
return
|
||||
fi
|
||||
|
||||
print_msg "- Installing Pi-hole..."
|
||||
print_msg " - Pi-hole has its own logfile"
|
||||
curl -sSL https://install.pi-hole.net | bash
|
||||
print_msg ""
|
||||
PIHOLE_ACTIVE=true
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Activate DHCP
|
||||
# ------------------------------------------------------------------------------
|
||||
activate_DHCP() {
|
||||
if ! $DHCP_ACTIVATE ; then
|
||||
return
|
||||
fi
|
||||
|
||||
if ! $PIHOLE_ACTIVE ; then
|
||||
return
|
||||
fi
|
||||
|
||||
print_msg "- Checking if DHCP is active..."
|
||||
if [ -e /etc/pihole ]; then
|
||||
DHCP_ACTIVE= `grep DHCP_ACTIVE /etc/pihole/setupVars.conf | awk -F= '/./{print $2}'`
|
||||
fi
|
||||
|
||||
if $DHCP_ACTIVE ; then
|
||||
print_msg " - DHCP already active"
|
||||
fi
|
||||
|
||||
print_msg "- Activating DHCP..."
|
||||
sudo pihole -a enabledhcp "$DHCP_RANGE_START" "$DHCP_RANGE_END" "$DHCP_ROUTER" "$DHCP_LEASE" "$DHCP_DOMAIN" 2>&1 >> "$LOG"
|
||||
DHCP_ACTIVE=true
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Add Pi.Alert DNS
|
||||
# ------------------------------------------------------------------------------
|
||||
add_pialert_DNS() {
|
||||
if ! $PIHOLE_ACTIVE ; then
|
||||
return
|
||||
fi
|
||||
|
||||
print_msg "- Checking if 'pi.alert' is configured in Local DNS..."
|
||||
if grep -Fq pi.alert /etc/pihole/custom.list; then
|
||||
print_msg " - 'pi.alert' already in Local DNS..."
|
||||
return
|
||||
fi
|
||||
|
||||
print_msg "- Adding 'pi.alert' to Local DNS..."
|
||||
sudo sh -c "echo $MAIN_IP pi.alert >> /etc/pihole/custom.list" 2>&1 >> "$LOG"
|
||||
sudo pihole restartdns 2>&1 >> "$LOG"
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Install Lighttpd & PHP
|
||||
# ------------------------------------------------------------------------------
|
||||
install_lighttpd() {
|
||||
print_header "Lighttpd & PHP"
|
||||
|
||||
print_msg "- Installing apt-utils..."
|
||||
sudo apt-get install apt-utils -y 2>&1 >> "$LOG"
|
||||
|
||||
print_msg "- Installing lighttpd..."
|
||||
sudo apt-get install lighttpd -y 2>&1 >> "$LOG"
|
||||
|
||||
print_msg "- Installing PHP..."
|
||||
sudo apt-get install php php-cgi php-fpm php-sqlite3 -y 2>&1 >> "$LOG"
|
||||
|
||||
print_msg "- Activating PHP..."
|
||||
ERRNO=0
|
||||
sudo lighttpd-enable-mod fastcgi-php 2>&1 >>"$LOG" || ERRNO=$?
|
||||
log_no_screen "-- Command error code: $ERRNO"
|
||||
if [ "$ERRNO" = "1" ] ; then
|
||||
process_error "Error activating PHP"
|
||||
fi
|
||||
|
||||
print_msg "- Restarting lighttpd..."
|
||||
sudo service lighttpd restart 2>&1 >> "$LOG"
|
||||
# sudo /etc/init.d/lighttpd restart 2>&1 >> "$LOG"
|
||||
|
||||
print_msg "- Installing sqlite3..."
|
||||
sudo apt-get install sqlite3 -y 2>&1 >> "$LOG"
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Install arp-scan & dnsutils
|
||||
# ------------------------------------------------------------------------------
|
||||
install_arpscan() {
|
||||
print_header "arp-scan, dnsutils and nmap"
|
||||
|
||||
print_msg "- Installing arp-scan..."
|
||||
sudo apt-get install arp-scan -y 2>&1 >> "$LOG"
|
||||
|
||||
print_msg "- Testing arp-scan..."
|
||||
sudo arp-scan -l | head -n -3 | tail +3 | tee -a "$LOG"
|
||||
|
||||
print_msg "- Installing dnsutils & net-tools..."
|
||||
sudo apt-get install dnsutils net-tools -y 2>&1 >> "$LOG"
|
||||
|
||||
print_msg "- Installing nmap and zip..."
|
||||
sudo apt-get install nmap zip -y 2>&1 >> "$LOG"
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Install Python
|
||||
# ------------------------------------------------------------------------------
|
||||
install_python() {
|
||||
print_header "Python"
|
||||
|
||||
check_python_versions
|
||||
|
||||
if [ $USE_PYTHON_VERSION -eq 0 ] ; then
|
||||
print_msg "- Using the available Python version installed"
|
||||
if $PYTHON3 ; then
|
||||
print_msg " - Python 3 is available"
|
||||
USE_PYTHON_VERSION=3
|
||||
elif $PYTHON2 ; then
|
||||
print_msg " - Python 2 is available"
|
||||
USE_PYTHON_VERSION=2
|
||||
else
|
||||
print_msg " - Python is not available in this system"
|
||||
print_msg " - Python 3 will be installed"
|
||||
USE_PYTHON_VERSION=3
|
||||
fi
|
||||
echo ""
|
||||
fi
|
||||
|
||||
if [ $USE_PYTHON_VERSION -eq 2 ] ; then
|
||||
if $PYTHON2 ; then
|
||||
print_msg "- Using Python 2"
|
||||
else
|
||||
print_msg "- Installing Python 2..."
|
||||
sudo apt-get install python pip -y 2>&1 >> "$LOG"
|
||||
fi
|
||||
PYTHON_BIN="python"
|
||||
elif [ $USE_PYTHON_VERSION -eq 3 ] ; then
|
||||
if $PYTHON3 ; then
|
||||
print_msg "- Using Python 3"
|
||||
else
|
||||
print_msg "- Installing Python 3..."
|
||||
sudo apt-get install python3 pip -y 2>&1 >> "$LOG"
|
||||
python3 -m pip install requests
|
||||
fi
|
||||
PYTHON_BIN="python3"
|
||||
else
|
||||
process_error "Unknown Python version to use: $USE_PYTHON_VERSION"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Check Python versions available
|
||||
# ------------------------------------------------------------------------------
|
||||
check_python_versions() {
|
||||
print_msg "- Checking Python 2..."
|
||||
if [ -f /usr/bin/python ] ; then
|
||||
print_msg " - Python 2 is installed"
|
||||
print_msg " - `python -V 2>&1`"
|
||||
PYTHON2=true
|
||||
else
|
||||
print_msg " - Python 2 is NOT installed"
|
||||
PYTHON2=false
|
||||
fi
|
||||
echo ""
|
||||
|
||||
print_msg "- Checking Python 3..."
|
||||
if [ -f /usr/bin/python3 ] ; then
|
||||
print_msg " - Python 3 is installed"
|
||||
print_msg " - `python3 -V 2>&1`"
|
||||
PYTHON3=true
|
||||
else
|
||||
print_msg " - Python 3 is NOT installed"
|
||||
PYTHON3=false
|
||||
fi
|
||||
echo ""
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Install Pi.Alert
|
||||
# ------------------------------------------------------------------------------
|
||||
install_pialert() {
|
||||
print_header "Pi.Alert"
|
||||
|
||||
download_pialert
|
||||
configure_pialert
|
||||
test_pialert
|
||||
add_jobs_to_crontab
|
||||
publish_pialert
|
||||
set_pialert_default_page
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Download and uncompress Pi.Alert
|
||||
# ------------------------------------------------------------------------------
|
||||
download_pialert() {
|
||||
if [ -f "$INSTALL_DIR/pialert_latest.tar" ] ; then
|
||||
print_msg "- Deleting previous downloaded tar file"
|
||||
rm -r "$INSTALL_DIR/pialert_latest.tar"
|
||||
fi
|
||||
|
||||
print_msg "- Downloading installation tar file..."
|
||||
curl -Lo "$INSTALL_DIR/pialert_latest.tar" https://github.com/leiweibau/Pi.Alert/raw/main/tar/pialert_latest.tar
|
||||
echo ""
|
||||
|
||||
print_msg "- Uncompressing tar file"
|
||||
tar xf "$INSTALL_DIR/pialert_latest.tar" -C "$INSTALL_DIR" --checkpoint=100 --checkpoint-action="ttyout=." 2>&1 >> "$LOG"
|
||||
echo ""
|
||||
|
||||
print_msg "- Deleting downloaded tar file..."
|
||||
rm -r "$INSTALL_DIR/pialert_latest.tar"
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Configure Pi.Alert parameters
|
||||
# ------------------------------------------------------------------------------
|
||||
configure_pialert() {
|
||||
print_msg "- Settting Pi.Alert config file"
|
||||
|
||||
set_pialert_parameter PIALERT_PATH "'$PIALERT_HOME'"
|
||||
|
||||
set_pialert_parameter REPORT_MAIL "$REPORT_MAIL"
|
||||
set_pialert_parameter REPORT_TO "'$REPORT_TO'"
|
||||
set_pialert_parameter SMTP_SERVER "'$SMTP_SERVER'"
|
||||
set_pialert_parameter SMTP_PORT "$SMTP_PORT"
|
||||
set_pialert_parameter SMTP_USER "'$SMTP_USER'"
|
||||
set_pialert_parameter SMTP_PASS "'$SMTP_PASS'"
|
||||
|
||||
set_pialert_parameter DDNS_ACTIVE "$DDNS_ACTIVE"
|
||||
set_pialert_parameter DDNS_DOMAIN "'$DDNS_DOMAIN'"
|
||||
set_pialert_parameter DDNS_USER "'$DDNS_USER'"
|
||||
set_pialert_parameter DDNS_PASSWORD "'$DDNS_PASSWORD'"
|
||||
set_pialert_parameter DDNS_UPDATE_URL "'$DDNS_UPDATE_URL'"
|
||||
|
||||
set_pialert_parameter PIHOLE_ACTIVE "$PIHOLE_ACTIVE"
|
||||
set_pialert_parameter DHCP_ACTIVE "$DHCP_ACTIVE"
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Set Pi.Alert parameter
|
||||
# ------------------------------------------------------------------------------
|
||||
set_pialert_parameter() {
|
||||
if [ "$2" = "false" ] ; then
|
||||
VALUE="False"
|
||||
elif [ "$2" = "true" ] ; then
|
||||
VALUE="True"
|
||||
else
|
||||
VALUE="$2"
|
||||
fi
|
||||
|
||||
sed -i "/^$1.*=/s|=.*|= $VALUE|" $PIALERT_HOME/config/pialert.conf 2>&1 >> "$LOG"
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Test Pi.Alert
|
||||
# ------------------------------------------------------------------------------
|
||||
test_pialert() {
|
||||
print_msg "- Testing Pi.Alert HW vendors database update process..."
|
||||
print_msg "*** PLEASE WAIT A COUPLE OF MINUTES..."
|
||||
stdbuf -i0 -o0 -e0 $PYTHON_BIN $PIALERT_HOME/back/pialert.py update_vendors_silent 2>&1 | tee -ai "$LOG"
|
||||
|
||||
echo ""
|
||||
print_msg "- Testing Pi.Alert Internet IP Lookup..."
|
||||
stdbuf -i0 -o0 -e0 $PYTHON_BIN $PIALERT_HOME/back/pialert.py internet_IP 2>&1 | tee -ai "$LOG"
|
||||
|
||||
echo ""
|
||||
print_msg "- Testing Pi.Alert Network scan..."
|
||||
print_msg "*** PLEASE WAIT A COUPLE OF MINUTES..."
|
||||
stdbuf -i0 -o0 -e0 $PYTHON_BIN $PIALERT_HOME/back/pialert.py 1 2>&1 | tee -ai "$LOG"
|
||||
|
||||
echo ""
|
||||
print_msg "- Enable optional Speedtest..."
|
||||
chmod +x $PIALERT_HOME/back/speedtest-cli 2>&1 | tee -ai "$LOG"
|
||||
|
||||
echo ""
|
||||
print_msg "- Enable optional pialert-cli..."
|
||||
chmod +x $PIALERT_HOME/back/pialert-cli 2>&1 | tee -ai "$LOG"
|
||||
|
||||
if $FIRST_SCAN_KNOWN ; then
|
||||
echo ""
|
||||
print_msg "- Set devices as Known devices..."
|
||||
sqlite3 $PIALERT_HOME/db/pialert.db "UPDATE Devices SET dev_NewDevice=0, dev_AlertEvents=0 WHERE dev_NewDevice=1" 2>&1 >> "$LOG"
|
||||
fi
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Add Pi.Alert jobs to crontab
|
||||
# ------------------------------------------------------------------------------
|
||||
add_jobs_to_crontab() {
|
||||
if crontab -l 2>/dev/null | grep -Fq pialert ; then
|
||||
print_msg "- Pi.Alert crontab jobs already exists. This is your crontab:"
|
||||
crontab -l | grep -F pialert 2>&1 | tee -ai "$LOG"
|
||||
return
|
||||
fi
|
||||
|
||||
print_msg "- Adding jobs to the crontab..."
|
||||
if [ $USE_PYTHON_VERSION -eq 3 ] ; then
|
||||
sed -i "s/\<python\>/$PYTHON_BIN/g" $PIALERT_HOME/install/pialert.cron
|
||||
fi
|
||||
|
||||
(crontab -l 2>/dev/null || : ; cat $PIALERT_HOME/install/pialert.cron) | crontab -
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Publish Pi.Alert web
|
||||
# ------------------------------------------------------------------------------
|
||||
publish_pialert() {
|
||||
if [ -e "$WEBROOT/pialert" ] || [ -L "$WEBROOT/pialert" ] ; then
|
||||
print_msg "- Deleting previous Pi.Alert site"
|
||||
sudo rm -r "$WEBROOT/pialert" 2>&1 >> "$LOG"
|
||||
fi
|
||||
|
||||
print_msg "- Setting permissions..."
|
||||
sudo chgrp -R www-data $PIALERT_HOME/db 2>&1 >> "$LOG"
|
||||
chmod -R g+rwx $PIALERT_HOME/db 2>&1 >> "$LOG"
|
||||
chmod go+x $INSTALL_DIR 2>&1 >> "$LOG"
|
||||
|
||||
print_msg "- Publishing Pi.Alert web..."
|
||||
sudo ln -s "$PIALERT_HOME/front" "$WEBROOT/pialert" 2>&1 >> "$LOG"
|
||||
|
||||
print_msg "- Configuring http://pi.alert/ redirection..."
|
||||
if [ -e "$LIGHTTPD_CONF_DIR/conf-available/pialert_front.conf" ] ; then
|
||||
sudo rm -r "$LIGHTTPD_CONF_DIR/conf-available/pialert_front.conf" 2>&1 >> "$LOG"
|
||||
fi
|
||||
sudo cp "$PIALERT_HOME/install/pialert_front.conf" "$LIGHTTPD_CONF_DIR/conf-available" 2>&1 >> "$LOG"
|
||||
|
||||
if [ -e "$LIGHTTPD_CONF_DIR/conf-enabled/pialert_front.conf" ] || \
|
||||
[ -L "$LIGHTTPD_CONF_DIR/conf-enabled/pialert_front.conf" ] ; then
|
||||
sudo rm -r "$LIGHTTPD_CONF_DIR/conf-enabled/pialert_front.conf" 2>&1 >> "$LOG"
|
||||
fi
|
||||
|
||||
sudo ln -s ../conf-available/pialert_front.conf "$LIGHTTPD_CONF_DIR/conf-enabled/pialert_front.conf" 2>&1 >> "$LOG"
|
||||
|
||||
print_msg "- Restarting lighttpd..."
|
||||
sudo sudo service lighttpd restart 2>&1 >> "$LOG"
|
||||
# sudo /etc/init.d/lighttpd restart 2>&1 >> "$LOG"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Set Pi.Alert the default web server page
|
||||
# ------------------------------------------------------------------------------
|
||||
set_pialert_default_page() {
|
||||
if ! $PIALERT_DEFAULT_PAGE ; then
|
||||
return
|
||||
fi
|
||||
|
||||
print_msg "- Setting Pi.Alert as default web server page..."
|
||||
|
||||
if [ -e "$WEBROOT/index.lighttpd.html" ] ; then
|
||||
if [ -e "$WEBROOT/index.lighttpd.html.orig" ] ; then
|
||||
sudo rm "$WEBROOT/index.lighttpd.html" 2>&1 >> "$LOG"
|
||||
else
|
||||
sudo mv "$WEBROOT/index.lighttpd.html" "$WEBROOT/index.lighttpd.html.orig" 2>&1 >> "$LOG"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -e "$WEBROOT/index.html" ] || [ -L "$WEBROOT/index.html" ] ; then
|
||||
if [ -e "$WEBROOT/index.html.orig" ] ; then
|
||||
sudo rm "$WEBROOT/index.html" 2>&1 >> "$LOG"
|
||||
else
|
||||
sudo mv "$WEBROOT/index.html" "$WEBROOT/index.html.orig" 2>&1 >> "$LOG"
|
||||
fi
|
||||
fi
|
||||
|
||||
sudo cp "$PIALERT_HOME/install/index.html" "$WEBROOT/index.html" 2>&1 >>"$LOG"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Check Pi.Alert Installation Path
|
||||
# ------------------------------------------------------------------------------
|
||||
check_pialert_home() {
|
||||
mkdir -p "$INSTALL_DIR"
|
||||
if [ ! -d "$INSTALL_DIR" ] ; then
|
||||
process_error "Installation path does not exists: $INSTALL_DIR"
|
||||
fi
|
||||
|
||||
if [ -e "$PIALERT_HOME" ] || [ -L "$PIALERT_HOME" ] ; then
|
||||
process_error "Pi.Alert path already exists: $PIALERT_HOME"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Move Logfile
|
||||
# ------------------------------------------------------------------------------
|
||||
move_logfile() {
|
||||
NEWLOG="$PIALERT_HOME/log/$LOG"
|
||||
|
||||
mkdir -p "$PIALERT_HOME/log"
|
||||
mv $LOG $NEWLOG
|
||||
|
||||
LOG="$NEWLOG"
|
||||
NEWLOG=""
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# ASK
|
||||
# ------------------------------------------------------------------------------
|
||||
msgbox() {
|
||||
LINE1=$(printf "%*s" $(((${#1}+$COLS-5)/2)) "$1")
|
||||
LINE2=$(printf "%*s" $(((${#2}+$COLS-5)/2)) "$2")
|
||||
|
||||
END_DIALOG=false
|
||||
while ! $END_DIALOG ; do
|
||||
whiptail --title "Pi.Alert Installation" --msgbox "$LINE1\\n\\n$LINE2" $ROWS $COLS
|
||||
BUTTON=$?
|
||||
ask_cancel
|
||||
ANSWER=true
|
||||
done
|
||||
}
|
||||
|
||||
ask_yesno() {
|
||||
LINE1=$(printf "%*s" $(((${#1}+$COLS-5)/2)) "$1")
|
||||
LINE2=$(printf "%*s" $(((${#2}+$COLS-5)/2)) "$2")
|
||||
|
||||
if [ "$3" = "YES" ]; then
|
||||
DEF_BUTTON=""
|
||||
else
|
||||
DEF_BUTTON="--defaultno"
|
||||
fi
|
||||
|
||||
END_DIALOG=false
|
||||
while ! $END_DIALOG ; do
|
||||
whiptail --title "Pi.Alert Installation" --yesno $DEF_BUTTON "$LINE1\\n\\n$LINE2" $ROWS $COLS
|
||||
BUTTON=$?
|
||||
ask_cancel
|
||||
done
|
||||
|
||||
if [ "$BUTTON" = "0" ] ; then
|
||||
ANSWER=true
|
||||
else
|
||||
ANSWER=false
|
||||
fi
|
||||
}
|
||||
|
||||
ask_option() {
|
||||
MENU_ARGS=("$@")
|
||||
MENU_ARGS=("${MENU_ARGS[@]:1}")
|
||||
|
||||
END_DIALOG=false
|
||||
while ! $END_DIALOG ; do
|
||||
ANSWER=$(whiptail --title "Pi.Alert Installation" --menu "$1" $ROWS $COLS "${MENU_ARGS[@]}" 3>&2 2>&1 1>&3 )
|
||||
BUTTON=$?
|
||||
ask_cancel CANCEL
|
||||
done
|
||||
}
|
||||
|
||||
ask_input() {
|
||||
LINE1=$(printf "%*s" $(((${#1}+$COLS-5)/2)) "$1")
|
||||
LINE2=$(printf "%*s" $(((${#2}+$COLS-5)/2)) "$2")
|
||||
|
||||
END_DIALOG=false
|
||||
while ! $END_DIALOG ; do
|
||||
ANSWER=$(whiptail --title "Pi.Alert Installation" --inputbox "$LINE1\\n\\n$LINE2" $ROWS $COLS "$3" 3>&2 2>&1 1>&3 )
|
||||
BUTTON=$?
|
||||
ask_cancel CANCEL
|
||||
|
||||
if $END_DIALOG && [ "$ANSWER" = "" ] ; then
|
||||
msgbox "" "You must enter a value"
|
||||
END_DIALOG=false
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
ask_cancel() {
|
||||
LINE0="Do you want to cancel the installation process"
|
||||
LINE0=$(printf "\n\n%*s" $(((${#LINE0}+$COLS-5)/2)) "$LINE0")
|
||||
|
||||
if [ "$BUTTON" = "1" ] && [ "$1" = "CANCEL" ] ; then BUTTON="255"; fi
|
||||
|
||||
if [ "$BUTTON" = "255" ] ; then
|
||||
whiptail --title "Pi.Alert Installation" --yesno --defaultno "$LINE0" $ROWS $COLS
|
||||
|
||||
if [ "$?" = "0" ] ; then
|
||||
process_error "Installation Aborted by User"
|
||||
fi
|
||||
else
|
||||
END_DIALOG=true
|
||||
fi
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Log
|
||||
# ------------------------------------------------------------------------------
|
||||
log() {
|
||||
echo "$1" | tee -a "$LOG"
|
||||
}
|
||||
|
||||
log_no_screen () {
|
||||
echo "$1" >> "$LOG"
|
||||
}
|
||||
|
||||
log_only_screen () {
|
||||
echo "$1"
|
||||
}
|
||||
|
||||
print_msg() {
|
||||
log_no_screen ""
|
||||
log "$1"
|
||||
}
|
||||
|
||||
print_superheader() {
|
||||
log ""
|
||||
log "############################################################"
|
||||
log " $1"
|
||||
log "############################################################"
|
||||
}
|
||||
|
||||
print_header() {
|
||||
log ""
|
||||
log "------------------------------------------------------------"
|
||||
log " $1"
|
||||
log "------------------------------------------------------------"
|
||||
}
|
||||
|
||||
process_error() {
|
||||
log ""
|
||||
log "************************************************************"
|
||||
log "************************************************************"
|
||||
log "** ERROR INSTALLING PI.ALERT **"
|
||||
log "************************************************************"
|
||||
log "************************************************************"
|
||||
log ""
|
||||
log "$1"
|
||||
log ""
|
||||
log "Use 'cat $LOG' to view installation log"
|
||||
log ""
|
||||
|
||||
# msgbox "****** ERROR INSTALLING Pi.ALERT ******" "$1"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
main
|
||||
exit 0
|
||||
@@ -1,207 +0,0 @@
|
||||
#!/bin/bash
|
||||
# ------------------------------------------------------------------------------
|
||||
# Pi.Alert
|
||||
# Open Source Network Guard / WIFI & LAN intrusion detector
|
||||
#
|
||||
# pialert_uninstall.sh - Uninstallation script
|
||||
# ------------------------------------------------------------------------------
|
||||
# Puche 2021 pi.alert.application@gmail.com GNU GPLv3
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Variables
|
||||
# ------------------------------------------------------------------------------
|
||||
COLS=70
|
||||
ROWS=12
|
||||
|
||||
INSTALL_DIR=~
|
||||
PIALERT_HOME="$INSTALL_DIR/pialert"
|
||||
|
||||
LIGHTTPD_CONF_DIR="/etc/lighttpd"
|
||||
WEBROOT="/var/www/html"
|
||||
|
||||
LOG="pialert_uninstall_`date +"%Y-%m-%d_%H-%M"`.log"
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Main
|
||||
# ------------------------------------------------------------------------------
|
||||
main() {
|
||||
print_superheader "Pi.Alert Uninstallation"
|
||||
log "`date`"
|
||||
log "Logfile: $LOG"
|
||||
|
||||
# Ask uninstallation
|
||||
ask_yesno "This script will uninstall Pi.Alert from this system.\nUninstall path: $PIALERT_HOME" \
|
||||
"Do you want to continue ?"
|
||||
if ! $ANSWER ; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
msgbox "" "The uninstallation process will start now"
|
||||
|
||||
# Uninstall prrocess
|
||||
print_header "Removing files"
|
||||
sudo rm -r "$PIALERT_HOME" 2>&1 >> "$LOG"
|
||||
sudo rm "$WEBROOT/pialert" 2>&1 >> "$LOG"
|
||||
sudo rm "$LIGHTTPD_CONF_DIR/conf-available/pialert_front.conf" 2>&1 >> "$LOG"
|
||||
sudo rm "$LIGHTTPD_CONF_DIR/conf-enabled/pialert_front.conf" 2>&1 >> "$LOG"
|
||||
sudo rm -r /var/cache/lighttpd/compress/pialert 2>&1 >> "$LOG"
|
||||
|
||||
# Removing
|
||||
print_header "Removing Pi.Alert DNS name"
|
||||
if [ -f /etc/pihole/custom.list ] ; then
|
||||
sudo sed -i '/pi.alert/d' /etc/pihole/custom.list 2>&1 >> "$LOG"
|
||||
sudo pihole restartdns 2>&1 >> "$LOG"
|
||||
fi
|
||||
|
||||
# Uninstall crontab jobs
|
||||
print_header "Removing crontab jobs"
|
||||
crontab -l 2>/dev/null | sed '/pialert.py/d' | sed ':a;N;$!ba;s/#-------------------------------------------------------------------------------\n# Pi.Alert\n# Open Source Network Guard \/ WIFI & LAN intrusion detector \n#\n# pialert.cron - Back module. Crontab jobs\n#-------------------------------------------------------------------------------\n# Puche 2021 pi.alert.application@gmail.com GNU GPLv3\n#-------------------------------------------------------------------------------//g' | crontab -
|
||||
|
||||
# final message
|
||||
print_header "Uninstallation process finished"
|
||||
print_msg "Note1: If you installed Pi-hole during the Pi.Alert installation process"
|
||||
print_msg " Pi-hole will still be available after uninstalling Pi.Alert"
|
||||
print_msg ""
|
||||
print_msg "Note2: lighttpd, PHP, arp-scan & Python have not been uninstalled."
|
||||
print_msg " They may be required by other software"
|
||||
print_msg " You can uninstall them manually with command 'apt-get remove XX'"
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# ASK
|
||||
# ------------------------------------------------------------------------------
|
||||
msgbox() {
|
||||
LINE1=$(printf "%*s" $(((${#1}+$COLS-5)/2)) "$1")
|
||||
LINE2=$(printf "%*s" $(((${#2}+$COLS-5)/2)) "$2")
|
||||
|
||||
END_DIALOG=false
|
||||
while ! $END_DIALOG ; do
|
||||
whiptail --title "Pi.Alert Uninstallation" --msgbox "$LINE1\\n\\n$LINE2" $ROWS $COLS
|
||||
BUTTON=$?
|
||||
ask_cancel
|
||||
ANSWER=true
|
||||
done
|
||||
}
|
||||
|
||||
ask_yesno() {
|
||||
LINE1=$(printf "%*s" $(((${#1}+$COLS-5)/2)) "$1")
|
||||
LINE2=$(printf "%*s" $(((${#2}+$COLS-5)/2)) "$2")
|
||||
|
||||
if [ "$3" = "YES" ]; then
|
||||
DEF_BUTTON=""
|
||||
else
|
||||
DEF_BUTTON="--defaultno"
|
||||
fi
|
||||
|
||||
END_DIALOG=false
|
||||
while ! $END_DIALOG ; do
|
||||
whiptail --title "Pi.Alert Uninstallation" --yesno $DEF_BUTTON "$LINE1\\n\\n$LINE2" $ROWS $COLS
|
||||
BUTTON=$?
|
||||
ask_cancel
|
||||
done
|
||||
|
||||
if [ "$BUTTON" = "0" ] ; then
|
||||
ANSWER=true
|
||||
else
|
||||
ANSWER=false
|
||||
fi
|
||||
}
|
||||
|
||||
ask_option() {
|
||||
MENU_ARGS=("$@")
|
||||
MENU_ARGS=("${MENU_ARGS[@]:1}")
|
||||
|
||||
END_DIALOG=false
|
||||
while ! $END_DIALOG ; do
|
||||
ANSWER=$(whiptail --title "Pi.Alert Uninstallation" --menu "$1" $ROWS $COLS "${MENU_ARGS[@]}" 3>&2 2>&1 1>&3 )
|
||||
BUTTON=$?
|
||||
ask_cancel CANCEL
|
||||
done
|
||||
}
|
||||
|
||||
ask_input() {
|
||||
LINE1=$(printf "%*s" $(((${#1}+$COLS-5)/2)) "$1")
|
||||
LINE2=$(printf "%*s" $(((${#2}+$COLS-5)/2)) "$2")
|
||||
|
||||
END_DIALOG=false
|
||||
while ! $END_DIALOG ; do
|
||||
ANSWER=$(whiptail --title "Pi.Alert Uninstallation" --inputbox "$LINE1\\n\\n$LINE2" $ROWS $COLS "$3" 3>&2 2>&1 1>&3 )
|
||||
BUTTON=$?
|
||||
ask_cancel CANCEL
|
||||
|
||||
if $END_DIALOG && [ "$ANSWER" = "" ] ; then
|
||||
msgbox "" "You must enter a value"
|
||||
END_DIALOG=false
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
ask_cancel() {
|
||||
LINE0="Do you want to cancel the uninstallation process"
|
||||
LINE0=$(printf "\n\n%*s" $(((${#LINE0}+$COLS-5)/2)) "$LINE0")
|
||||
|
||||
if [ "$BUTTON" = "1" ] && [ "$1" = "CANCEL" ] ; then BUTTON="255"; fi
|
||||
|
||||
if [ "$BUTTON" = "255" ] ; then
|
||||
whiptail --title "Pi.Alert Uninstallation" --yesno --defaultno "$LINE0" $ROWS $COLS
|
||||
|
||||
if [ "$?" = "0" ] ; then
|
||||
process_error "Uninstallation Aborted by User"
|
||||
fi
|
||||
else
|
||||
END_DIALOG=true
|
||||
fi
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Log
|
||||
# ------------------------------------------------------------------------------
|
||||
log() {
|
||||
echo "$1" | tee -a "$LOG"
|
||||
}
|
||||
|
||||
log_no_screen () {
|
||||
echo "$1" >> "$LOG"
|
||||
}
|
||||
|
||||
log_only_screen () {
|
||||
echo "$1"
|
||||
}
|
||||
|
||||
print_msg() {
|
||||
log_no_screen ""
|
||||
log "$1"
|
||||
}
|
||||
|
||||
print_superheader() {
|
||||
log ""
|
||||
log "############################################################"
|
||||
log " $1"
|
||||
log "############################################################"
|
||||
}
|
||||
|
||||
print_header() {
|
||||
log ""
|
||||
log "------------------------------------------------------------"
|
||||
log " $1"
|
||||
log "------------------------------------------------------------"
|
||||
}
|
||||
|
||||
process_error() {
|
||||
log ""
|
||||
log "************************************************************"
|
||||
log "************************************************************"
|
||||
log "** ERROR UNINSTALLING PI.ALERT **"
|
||||
log "************************************************************"
|
||||
log "************************************************************"
|
||||
log ""
|
||||
|
||||
# msgbox "****** ERROR UNINSTALLING Pi.ALERT ******" "$1"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
main
|
||||
exit 0
|
||||
@@ -1,305 +0,0 @@
|
||||
#!/bin/bash
|
||||
# ------------------------------------------------------------------------------
|
||||
# Pi.Alert
|
||||
# Open Source Network Guard / WIFI & LAN intrusion detector
|
||||
#
|
||||
# pialert_update.sh - Update script
|
||||
# ------------------------------------------------------------------------------
|
||||
# Puche 2021 pi.alert.application@gmail.com GNU GPLv3
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Variables
|
||||
# ------------------------------------------------------------------------------
|
||||
INSTALL_DIR=~
|
||||
PIALERT_HOME="$INSTALL_DIR/pialert"
|
||||
LOG="pialert_update_`date +"%Y-%m-%d_%H-%M"`.log"
|
||||
PYTHON_BIN=python
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Main
|
||||
# ------------------------------------------------------------------------------
|
||||
main() {
|
||||
print_superheader "Pi.Alert Update"
|
||||
log "`date`"
|
||||
log "Logfile: $LOG"
|
||||
log ""
|
||||
|
||||
set -e
|
||||
|
||||
check_pialert_home
|
||||
check_python_version
|
||||
|
||||
create_backup
|
||||
move_files
|
||||
clean_files
|
||||
|
||||
check_packages
|
||||
download_pialert
|
||||
update_config
|
||||
update_db
|
||||
|
||||
test_pialert
|
||||
|
||||
print_header "Update process finished"
|
||||
print_msg ""
|
||||
|
||||
move_logfile
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Create backup
|
||||
# ------------------------------------------------------------------------------
|
||||
create_backup() {
|
||||
# Previous backups are not deleted
|
||||
# print_msg "- Deleting previous Pi.Alert backups..."
|
||||
# rm "$INSTALL_DIR/"pialert_update_backup_*.tar 2>/dev/null || :
|
||||
|
||||
print_msg "- Creating new Pi.Alert backup..."
|
||||
cd "$INSTALL_DIR"
|
||||
tar cvf "$INSTALL_DIR"/pialert_update_backup_`date +"%Y-%m-%d_%H-%M"`.tar pialert --checkpoint=100 --checkpoint-action="ttyout=." 2>&1 >> "$LOG"
|
||||
echo ""
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Move files to the new directory
|
||||
# ------------------------------------------------------------------------------
|
||||
move_files() {
|
||||
if [ -e "$PIALERT_HOME/back/pialert.conf" ] ; then
|
||||
print_msg "- Moving pialert.conf to the new directory..."
|
||||
mkdir -p "$PIALERT_HOME/config"
|
||||
mv "$PIALERT_HOME/back/pialert.conf" "$PIALERT_HOME/config"
|
||||
fi
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Move files to the new directory
|
||||
# ------------------------------------------------------------------------------
|
||||
clean_files() {
|
||||
print_msg "- Cleaning previous version..."
|
||||
rm -r "$PIALERT_HOME/back" 2>/dev/null || :
|
||||
rm -r "$PIALERT_HOME/doc" 2>/dev/null || :
|
||||
rm -r "$PIALERT_HOME/docs" 2>/dev/null || :
|
||||
rm -r "$PIALERT_HOME/front" 2>/dev/null || :
|
||||
rm -r "$PIALERT_HOME/install" 2>/dev/null || :
|
||||
rm -r "$PIALERT_HOME/"*.txt 2>/dev/null || :
|
||||
rm -r "$PIALERT_HOME/"*.md 2>/dev/null || :
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Check packages
|
||||
# ------------------------------------------------------------------------------
|
||||
check_packages() {
|
||||
print_msg "- Checking package apt-utils..."
|
||||
sudo apt-get install apt-utils -y 2>&1 >> "$LOG"
|
||||
|
||||
print_msg "- Checking package sqlite3..."
|
||||
sudo apt-get install sqlite3 -y 2>&1 >> "$LOG"
|
||||
|
||||
print_msg "- Checking packages dnsutils & net-tools..."
|
||||
sudo apt-get install dnsutils net-tools -y 2>&1 >> "$LOG"
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Download and uncompress Pi.Alert
|
||||
# ------------------------------------------------------------------------------
|
||||
download_pialert() {
|
||||
if [ -f "$INSTALL_DIR/pialert_latest.tar" ] ; then
|
||||
print_msg "- Deleting previous downloaded tar file"
|
||||
rm -r "$INSTALL_DIR/pialert_latest.tar"
|
||||
fi
|
||||
|
||||
print_msg "- Downloading update file..."
|
||||
curl -Lo "$INSTALL_DIR/pialert_latest.tar" https://github.com/leiweibau/Pi.Alert/raw/main/tar/pialert_latest.tar
|
||||
echo ""
|
||||
|
||||
print_msg "- Uncompressing tar file"
|
||||
tar xf "$INSTALL_DIR/pialert_latest.tar" -C "$INSTALL_DIR" \
|
||||
--exclude='pialert/config/pialert.conf' \
|
||||
--exclude='pialert/db/pialert.db' \
|
||||
--exclude='pialert/log/*' \
|
||||
--checkpoint=100 --checkpoint-action="ttyout=." 2>&1 >> "$LOG"
|
||||
echo ""
|
||||
|
||||
print_msg "- Deleting downloaded tar file..."
|
||||
rm -r "$INSTALL_DIR/pialert_latest.tar"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Update conf file
|
||||
# ------------------------------------------------------------------------------
|
||||
update_config() {
|
||||
print_msg "- Config backup..."
|
||||
cp "$PIALERT_HOME/config/pialert.conf" "$PIALERT_HOME/config/pialert.conf.back" 2>&1 >> "$LOG"
|
||||
|
||||
print_msg "- Updating config file..."
|
||||
sed -i '/VERSION/d' "$PIALERT_HOME/config/pialert.conf" 2>&1 >> "$LOG"
|
||||
sed -i 's/PA_FRONT_URL/REPORT_DEVICE_URL/g' "$PIALERT_HOME/config/pialert.conf" 2>&1 >> "$LOG"
|
||||
|
||||
if ! grep -Fq PIALERT_PATH "$PIALERT_HOME/config/pialert.conf" ; then
|
||||
echo "PIALERT_PATH = '$PIALERT_HOME'" >> "$PIALERT_HOME/config/pialert.conf"
|
||||
fi
|
||||
|
||||
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"
|
||||
fi
|
||||
|
||||
if ! grep -Fq SCAN_SUBNETS "$PIALERT_HOME/config/pialert.conf" ; then
|
||||
echo "SCAN_SUBNETS = '--localnet'" >> "$PIALERT_HOME/config/pialert.conf"
|
||||
fi
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# DB DDL
|
||||
# ------------------------------------------------------------------------------
|
||||
update_db() {
|
||||
print_msg "- Updating DB permissions..."
|
||||
sudo chgrp -R www-data $PIALERT_HOME/db 2>&1 >> "$LOG"
|
||||
chmod -R 770 $PIALERT_HOME/db 2>&1 >> "$LOG"
|
||||
|
||||
print_msg "- Installing sqlite3..."
|
||||
sudo apt-get install sqlite3 -y 2>&1 >> "$LOG"
|
||||
|
||||
print_msg "- Checking 'Parameters' table..."
|
||||
TAB=`sqlite3 $PIALERT_HOME/db/pialert.db "SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='Parameters' COLLATE NOCASE;"` 2>&1 >> "$LOG"
|
||||
if [ "$TAB" == "0" ] ; then
|
||||
print_msg " - Creating 'Parameters' table..."
|
||||
sqlite3 $PIALERT_HOME/db/pialert.db "CREATE TABLE Parameters (par_ID STRING (50) PRIMARY KEY NOT NULL COLLATE NOCASE, par_Value STRING (250) );" 2>&1 >> "$LOG"
|
||||
sqlite3 $PIALERT_HOME/db/pialert.db "CREATE INDEX IDX_par_ID ON Parameters (par_ID COLLATE NOCASE);" 2>&1 >> "$LOG"
|
||||
fi
|
||||
|
||||
print_msg "- Checking Devices new columns..."
|
||||
COL=`sqlite3 $PIALERT_HOME/db/pialert.db "SELECT COUNT(*) FROM PRAGMA_TABLE_INFO ('Devices') WHERE name='dev_NewDevice' COLLATE NOCASE";` 2>&1 >> "$LOG"
|
||||
if [ "$COL" == "0" ] ; then
|
||||
print_msg " - Adding column 'NewDevice' to 'Devices'..."
|
||||
sqlite3 $PIALERT_HOME/db/pialert.db "ALTER TABLE Devices ADD COLUMN dev_NewDevice BOOLEAN NOT NULL DEFAULT (1) CHECK (dev_NewDevice IN (0, 1) );" 2>&1 >> "$LOG"
|
||||
sqlite3 $PIALERT_HOME/db/pialert.db "CREATE INDEX IDX_dev_NewDevice ON Devices (dev_NewDevice);"
|
||||
fi
|
||||
|
||||
COL=`sqlite3 $PIALERT_HOME/db/pialert.db "SELECT COUNT(*) FROM PRAGMA_TABLE_INFO ('Devices') WHERE name='dev_Location' COLLATE NOCASE";` 2>&1 >> "$LOG"
|
||||
if [ "$COL" == "0" ] ; then
|
||||
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"
|
||||
fi
|
||||
|
||||
COL=`sqlite3 $PIALERT_HOME/db/pialert.db "SELECT COUNT(*) FROM PRAGMA_TABLE_INFO ('Devices') WHERE name='dev_Archived' 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"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Test Pi.Alert
|
||||
# ------------------------------------------------------------------------------
|
||||
test_pialert() {
|
||||
print_msg "- Testing Pi.Alert HW vendors database update process..."
|
||||
print_msg "*** PLEASE WAIT A COUPLE OF MINUTES..."
|
||||
stdbuf -i0 -o0 -e0 $PYTHON_BIN $PIALERT_HOME/back/pialert.py update_vendors_silent 2>&1 | tee -ai "$LOG"
|
||||
|
||||
echo ""
|
||||
print_msg "- Testing Pi.Alert Internet IP Lookup..."
|
||||
stdbuf -i0 -o0 -e0 $PYTHON_BIN $PIALERT_HOME/back/pialert.py internet_IP 2>&1 | tee -ai "$LOG"
|
||||
|
||||
echo ""
|
||||
print_msg "- Testing Pi.Alert Network scan..."
|
||||
print_msg "*** PLEASE WAIT A COUPLE OF MINUTES..."
|
||||
stdbuf -i0 -o0 -e0 $PYTHON_BIN $PIALERT_HOME/back/pialert.py 1 2>&1 | tee -ai "$LOG"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Check Pi.Alert Installation Path
|
||||
# ------------------------------------------------------------------------------
|
||||
check_pialert_home() {
|
||||
if [ ! -e "$PIALERT_HOME" ] ; then
|
||||
process_error "Pi.Alert directory dosn't exists: $PIALERT_HOME"
|
||||
fi
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Check Python versions available
|
||||
# ------------------------------------------------------------------------------
|
||||
check_python_version() {
|
||||
print_msg "- Checking Python..."
|
||||
if [ -f /usr/bin/python ] ; then
|
||||
PYTHON_BIN="python"
|
||||
elif [ -f /usr/bin/python3 ] ; then
|
||||
PYTHON_BIN="python3"
|
||||
else
|
||||
process_error "Python NOT installed"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Move Logfile
|
||||
# ------------------------------------------------------------------------------
|
||||
move_logfile() {
|
||||
NEWLOG="$PIALERT_HOME/log/$LOG"
|
||||
|
||||
mkdir -p "$PIALERT_HOME/log"
|
||||
mv $LOG $NEWLOG
|
||||
|
||||
LOG="$NEWLOG"
|
||||
NEWLOG=""
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Log
|
||||
# ------------------------------------------------------------------------------
|
||||
log() {
|
||||
echo "$1" | tee -a "$LOG"
|
||||
}
|
||||
|
||||
log_no_screen () {
|
||||
echo "$1" >> "$LOG"
|
||||
}
|
||||
|
||||
log_only_screen () {
|
||||
echo "$1"
|
||||
}
|
||||
|
||||
print_msg() {
|
||||
log_no_screen ""
|
||||
log "$1"
|
||||
}
|
||||
|
||||
print_superheader() {
|
||||
log ""
|
||||
log "############################################################"
|
||||
log " $1"
|
||||
log "############################################################"
|
||||
}
|
||||
|
||||
print_header() {
|
||||
log ""
|
||||
log "------------------------------------------------------------"
|
||||
log " $1"
|
||||
log "------------------------------------------------------------"
|
||||
}
|
||||
|
||||
process_error() {
|
||||
log ""
|
||||
log "************************************************************"
|
||||
log "************************************************************"
|
||||
log "** ERROR UPDATING PI.ALERT **"
|
||||
log "************************************************************"
|
||||
log "************************************************************"
|
||||
log ""
|
||||
log "$1"
|
||||
log ""
|
||||
log "Use 'cat $LOG' to view update log"
|
||||
log ""
|
||||
|
||||
exit 1
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
main
|
||||
exit 0
|
||||
4
log/pialert.log
Executable file
4
log/pialert.log
Executable file
@@ -0,0 +1,4 @@
|
||||
File "/home/pi/pialert/back/pialert.py", line 1639
|
||||
def check_config(service)
|
||||
^
|
||||
SyntaxError: invalid syntax
|
||||
@@ -0,0 +1,49 @@
|
||||
% Total % Received % Xferd Average Speed Time Time Time Current
|
||||
Dload Upload Total Spent Left Speed
|
||||
|
||||
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
|
||||
100 3266 0 0 100 3266 0 2717 0:00:01 0:00:01 --:--:-- 2719
|
||||
100 3287 100 21 100 3266 11 1769 0:00:01 0:00:01 --:--:-- 1780
|
||||
100 3287 100 21 100 3266 11 1769 0:00:01 0:00:01 --:--:-- 1780
|
||||
HTTP/1.1 200 OK
|
||||
Server: nginx/1.18.0
|
||||
Date: Sat, 10 Dec 2022 23:41:47 GMT
|
||||
Content-Type: text/html; charset=utf-8
|
||||
Content-Length: 21
|
||||
Connection: keep-alive
|
||||
Expires: Sat, 10 Dec 2022 23:41:47 GMT
|
||||
Cache-Control: max-age=0, no-cache, no-store, must-revalidate, private
|
||||
|
||||
Notification(s) sent. % Total % Received % Xferd Average Speed Time Time Time Current
|
||||
Dload Upload Total Spent Left Speed
|
||||
|
||||
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
|
||||
100 594 100 34 100 560 400 6588 --:--:-- --:--:-- --:--:-- 7071
|
||||
HTTP/1.1 200 OK
|
||||
Content-Type: application/json; charset=utf-8
|
||||
Content-Length: 34
|
||||
ETag: W/"22-6OS7cK0FzqnV2NeDHdOSGS1bVUs"
|
||||
Vary: Accept-Encoding
|
||||
Date: Sat, 10 Dec 2022 23:41:47 GMT
|
||||
Connection: keep-alive
|
||||
Keep-Alive: timeout=5
|
||||
|
||||
{"message":"Workflow was started"} % Total % Received % Xferd Average Speed Time Time Time Current
|
||||
Dload Upload Total Spent Left Speed
|
||||
|
||||
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
|
||||
100 3263 0 0 100 3263 0 2714 0:00:01 0:00:01 --:--:-- 2716
|
||||
100 3284 100 21 100 3263 11 1859 0:00:01 0:00:01 --:--:-- 1871
|
||||
HTTP/1.1 200 OK
|
||||
Server: nginx/1.18.0
|
||||
Date: Sun, 11 Dec 2022 00:52:29 GMT
|
||||
Content-Type: text/html; charset=utf-8
|
||||
Content-Length: 21
|
||||
Connection: keep-alive
|
||||
Expires: Sun, 11 Dec 2022 00:52:29 GMT
|
||||
Cache-Control: max-age=0, no-cache, no-store, must-revalidate, private
|
||||
|
||||
Notification(s) sent. % Total % Received % Xferd Average Speed Time Time Time Current
|
||||
Dload Upload Total Spent Left Speed
|
||||
|
||||
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
|
||||
1
log/webhook_payload.json
Executable file
1
log/webhook_payload.json
Executable file
@@ -0,0 +1 @@
|
||||
{"username": "Pi.Alert", "text": "There are new notifications", "attachments": [{"title": "Pi.Alert Notifications", "title_link": "http://100.89.112.105:20211", "text": {"internet": [], "new_devices": [], "down_devices": [], "events": [["94:b5:55:c7:cb:e0", "192.168.1.151", "2022-12-11 11:52:00", "Connected", "", 1, null, "94:b5:55:c7:cb:e0", "ESP32 - ttgo", "House", "", "Espressif Inc.", 0, "", "", "2022-10-16 16:55:00", "2022-12-11 11:52:00", "192.168.1.151", 0, 1, 1, 1, 0, 0, "2022-12-11 10:41:48.466369", 1, 0, "", 0, "d0:21:f9:8c:59:f9", ""]]}}]}
|
||||
Reference in New Issue
Block a user