Skip to content

Commit 89fb5c9

Browse files
committed
Online history work πŸ‘·β€
1 parent f5d8a9f commit 89fb5c9

File tree

22 files changed

+73
-63
lines changed

22 files changed

+73
-63
lines changed

β€Ždockerfiles/start.sh

+9-9
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ echo "---------------------------------------------------------"
77

88
INSTALL_DIR=/home/pi # Specify the installation directory here
99

10-
# # if custom variables not set we do not need to do anything
11-
# if [ -n "${TZ}" ]; then
12-
# FILECONF=$INSTALL_DIR/pialert/config/pialert.conf
13-
# if [ -f "$FILECONF" ]; then
14-
# sed -ie "s|Europe/Berlin|${TZ}|g" $INSTALL_DIR/pialert/config/pialert.conf
15-
# else
16-
# sed -ie "s|Europe/Berlin|${TZ}|g" $INSTALL_DIR/pialert/back/pialert.conf_bak
17-
# fi
18-
# fi
10+
# if custom variables not set we do not need to do anything
11+
if [ -n "${TZ}" ]; then
12+
FILECONF=$INSTALL_DIR/pialert/config/pialert.conf
13+
if [ -f "$FILECONF" ]; then
14+
sed -ie "s|Europe/Berlin|${TZ}|g" $INSTALL_DIR/pialert/config/pialert.conf
15+
else
16+
sed -ie "s|Europe/Berlin|${TZ}|g" $INSTALL_DIR/pialert/back/pialert.conf_bak
17+
fi
18+
fi
1919

2020
# Check if script is run as root
2121
if [[ $EUID -ne 0 ]]; then

β€Ždockerfiles/user-mapping.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ array=( ${LINE//:/ } )
2626
USER_HOME=${array[4]}
2727

2828
# print debug output
29-
echo USER_ID: ${USER_ID};
30-
echo USER_GID: ${USER_GID};
29+
echo USER_ID : ${USER_ID};
30+
echo USER_GID : ${USER_GID};
3131
echo USER_HOME: ${USER_HOME};
32+
echo TZ : ${TZ};
3233

3334
sed -i -e "s/^${USER}:\([^:]*\):[0-9]*:[0-9]*/${USER}:\1:${USER_ID}:${USER_GID}/" /etc/passwd
3435
sed -i -e "s/^${USER}:\([^:]*\):[0-9]*/${USER}:\1:${USER_GID}/" /etc/group

β€Žfront/php/templates/language/en_us.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@
452452
"run_event_tooltip" : "Enable the setting and save your changes at first before you run it.",
453453
"run_event_icon" : "fa-play",
454454
"general_event_title" : "Executing an ad-hoc event",
455-
"general_event_description" : " The event you nove triggered might take a while until background processes finish. The execution ended once the below execution queue empties (Check the <a href='/maintenance.php#tab_Logging'>error log</a> if you encounter issues). <br/> <br/> Execution queue:",
455+
"general_event_description" : "The event you nove triggered might take a while until background processes finish. The execution ended once the below execution queue empties (Check the <a href='/maintenance.php#tab_Logging'>error log</a> if you encounter issues). <br/> <br/> Execution queue:",
456456
"Plugins_Unprocessed_Events" : "Unprocessed Events",
457457
"Plugins_Objects" : "Plugin Objects",
458458
"Plugins_DeleteAll" : "Delete all (filters are ignored)",

β€Žfront/plugins/_publisher_apprise/apprise.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def main():
3030

3131
# Check if basic config settings supplied
3232
if check_config() == False:
33-
mylog('none', [f'[{pluginName}] Error: Publisher notification gateway not set up correctly. Check your pialert.conf {pluginName}_* variables.'])
33+
mylog('none', [f'[{pluginName}] ⚠ ERROR: Publisher notification gateway not set up correctly. Check your pialert.conf {pluginName}_* variables.'])
3434
return
3535

3636
# Create a database connection

β€Žfront/plugins/_publisher_email/email_smtp.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def main():
3838

3939
# Check if basic config settings supplied
4040
if check_config() == False:
41-
mylog('none', [f'[{pluginName}] Error: Publisher notification gateway not set up correctly. Check your pialert.conf {pluginName}_* variables.'])
41+
mylog('none', [f'[{pluginName}] ⚠ ERROR: Publisher notification gateway not set up correctly. Check your pialert.conf {pluginName}_* variables.'])
4242
return
4343

4444
# Create a database connection
@@ -82,7 +82,7 @@ def check_config ():
8282
report_from = get_setting_value("SMTP_REPORT_FROM")
8383

8484
if server == '' or report_from == '' or report_to == '':
85-
mylog('none', ['[Email Check Config] Error: Email service not set up correctly. Check your pialert.conf SMTP_*, SMTP_REPORT_FROM and SMTP_REPORT_TO variables.'])
85+
mylog('none', ['[Email Check Config] ⚠ ERROR: Email service not set up correctly. Check your pialert.conf SMTP_*, SMTP_REPORT_FROM and SMTP_REPORT_TO variables.'])
8686
return False
8787
else:
8888
return True

β€Žfront/plugins/_publisher_mqtt/mqtt.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def main():
5151

5252
# Check if basic config settings supplied
5353
if check_config() == False:
54-
mylog('none', [f'[{pluginName}] Error: Publisher notification gateway not set up correctly. Check your pialert.conf {pluginName}_* variables.'])
54+
mylog('none', [f'[{pluginName}] ⚠ ERROR: Publisher notification gateway not set up correctly. Check your pialert.conf {pluginName}_* variables.'])
5555
return
5656

5757
# Create a database connection
@@ -70,7 +70,7 @@ def main():
7070
#-------------------------------------------------------------------------------
7171
def check_config():
7272
if get_setting_value('MQTT_BROKER') == '' or get_setting_value('MQTT_PORT') == '' or get_setting_value('MQTT_USER') == '' or get_setting_value('MQTT_PASSWORD') == '':
73-
mylog('none', ['[Check Config] Error: MQTT service not set up correctly. Check your pialert.conf MQTT_* variables.'])
73+
mylog('none', ['[Check Config] ⚠ ERROR: MQTT service not set up correctly. Check your pialert.conf MQTT_* variables.'])
7474
return False
7575
else:
7676
return True

β€Žfront/plugins/_publisher_ntfy/ntfy.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def main():
3333

3434
# Check if basic config settings supplied
3535
if check_config() == False:
36-
mylog('none', [f'[{pluginName}] Error: Publisher notification gateway not set up correctly. Check your pialert.conf {pluginName}_* variables.'])
36+
mylog('none', [f'[{pluginName}] ⚠ ERROR: Publisher notification gateway not set up correctly. Check your pialert.conf {pluginName}_* variables.'])
3737
return
3838

3939
# Create a database connection
@@ -118,7 +118,7 @@ def send(html, text):
118118
response_text = json.dumps(response.text)
119119

120120
except requests.exceptions.RequestException as e:
121-
mylog('none', [f'[{pluginName}] Error: ', e])
121+
mylog('none', [f'[{pluginName}] ⚠ ERROR: ', e])
122122

123123
response_text = e
124124

β€Žfront/plugins/_publisher_pushsafer/pushsafer.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def main():
3232

3333
# Check if basic config settings supplied
3434
if check_config() == False:
35-
mylog('none', [f'[{pluginName}] Error: Publisher notification gateway not set up correctly. Check your pialert.conf {pluginName}_* variables.'])
35+
mylog('none', [f'[{pluginName}] ⚠ ERROR: Publisher notification gateway not set up correctly. Check your pialert.conf {pluginName}_* variables.'])
3636
return
3737

3838
# Create a database connection
@@ -107,7 +107,7 @@ def send(text):
107107
response_text = json.dumps(response.text)
108108

109109
except requests.exceptions.RequestException as e:
110-
mylog('none', [f'[{pluginName}] Error: ', e])
110+
mylog('none', [f'[{pluginName}] ⚠ ERROR: ', e])
111111

112112
response_text = e
113113

β€Žfront/plugins/_publisher_webhook/webhook.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def main():
3636

3737
# Check if basic config settings supplied
3838
if check_config() == False:
39-
mylog('none', [f'[{pluginName}] Error: Publisher notification gateway not set up correctly. Check your pialert.conf {pluginName}_* variables.'])
39+
mylog('none', [f'[{pluginName}] ⚠ ERROR: Publisher notification gateway not set up correctly. Check your pialert.conf {pluginName}_* variables.'])
4040
return
4141

4242
# Create a database connection
@@ -177,7 +177,7 @@ def truncate_json(obj):
177177

178178
except subprocess.CalledProcessError as e:
179179
# An error occurred, handle it
180-
mylog('none', [f'[{pluginName}] Error: ', e.output])
180+
mylog('none', [f'[{pluginName}] ⚠ ERROR: ', e.output])
181181

182182
response_stderr = e.output
183183

β€Žfront/plugins/ddns_update/script.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def get_dynamic_DNS_IP (DDNS_DOMAIN):
109109
mylog('none', [f'[{pluginName}] DIG output :', dig_output])
110110
except subprocess.CalledProcessError as e:
111111
# An error occured, handle it
112-
mylog('none', [f'[{pluginName}] ERROR - ', e.output])
112+
mylog('none', [f'[{pluginName}] ⚠ ERROR - ', e.output])
113113
dig_output = '' # probably no internet
114114

115115
# Check result is an IP
@@ -135,7 +135,7 @@ def set_dynamic_DNS_IP (DDNS_UPDATE_URL, DDNS_USER, DDNS_PASSWORD, DDNS_DOMAIN):
135135
universal_newlines=True)
136136
except subprocess.CalledProcessError as e:
137137
# An error occured, handle it
138-
mylog('none', [f'[{pluginName}] ERROR - ',e.output])
138+
mylog('none', [f'[{pluginName}] ⚠ ERROR - ',e.output])
139139
curl_output = ""
140140

141141
return curl_output

β€Žfront/plugins/dhcp_leases/script.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def get_entries(path, plugin_objects):
4646

4747
# Check if the path exists
4848
if not os.path.exists(path):
49-
mylog('none', [f'[{pluginName}] Error: "{path}" does not exist.'])
49+
mylog('none', [f'[{pluginName}] ⚠ ERROR: "{path}" does not exist.'])
5050
else:
5151
# Detect file encoding
5252
with open(path, 'rb') as f:

β€Žfront/plugins/nmap_scan/script.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def performNmapScan(deviceIPs, deviceMACs, timeoutSec, args):
119119
except subprocess.CalledProcessError as e:
120120
# An error occured, handle it
121121
mylog('none', ["[NMAP Scan] " ,e.output])
122-
mylog('none', ["[NMAP Scan] Error - Nmap Scan - check logs", progress])
122+
mylog('none', ["[NMAP Scan] ⚠ ERROR - Nmap Scan - check logs", progress])
123123
except subprocess.TimeoutExpired as timeErr:
124124
mylog('verbose', ['[NMAP Scan] Nmap TIMEOUT - the process forcefully terminated as timeout reached for ', ip, progress])
125125

β€Žfront/plugins/pholus_scan/script.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def execute_pholus_on_interface(interface, timeoutSec, mask):
150150
except subprocess.CalledProcessError as e:
151151
# An error occured, handle it
152152
mylog('none', ['[PHOLUS]', e.output])
153-
mylog('none', ["[PHOLUS] Error - Pholus Scan - check logs"])
153+
mylog('none', ["[PHOLUS] ⚠ ERROR - Pholus Scan - check logs"])
154154
except subprocess.TimeoutExpired as timeErr:
155155
mylog('none', ['[PHOLUS] Pholus TIMEOUT - the process forcefully terminated as timeout reached'])
156156

β€Žpialert/__main__.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,7 @@ def main ():
187187
updateState("Process: Wait")
188188
mylog('verbose', ['[MAIN] Process: Wait'])
189189
else:
190-
# do something
191-
conf.cycle = ""
190+
# do something
192191
mylog('verbose', ['[MAIN] waiting to start next loop'])
193192

194193
#loop

β€Žpialert/api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,5 @@ def __init__(self, db, query, path):
8787
# update hash
8888
apiEndpoints[changedIndex].hash = self.hash
8989
else:
90-
mylog('minimal', [f'[API] ERROR Updating {self.fileName}'])
90+
mylog('minimal', [f'[API] ⚠ ERROR Updating {self.fileName}'])
9191

β€Žpialert/appevent.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,13 @@ def getPluginObject(**kwargs):
173173
return item
174174

175175

176-
mylog('debug', [f'[{module_name}] Error - Object not found - GUID:{GUID} | Plugin:{Plugin} | MAC:{MAC} | IP:{IP} | PrimaryID:{PrimaryID} | SecondaryID:{SecondaryID} | ForeignKey:{ForeignKey} | Index:{Index} | RowID:{RowID} '])
176+
mylog('debug', [f'[{module_name}] ⚠ ERROR - Object not found - GUID:{GUID} | Plugin:{Plugin} | MAC:{MAC} | IP:{IP} | PrimaryID:{PrimaryID} | SecondaryID:{SecondaryID} | ForeignKey:{ForeignKey} | Index:{Index} | RowID:{RowID} '])
177177

178178
return None
179179

180180
except (FileNotFoundError, json.JSONDecodeError, ValueError) as e:
181181
# Handle the case when the file is not found, JSON decoding fails, or data is not in the expected format
182-
mylog('none', [f'[{module_name}] Error - JSONDecodeError or FileNotFoundError for file {plugins_objects}'])
182+
mylog('none', [f'[{module_name}] ⚠ ERROR - JSONDecodeError or FileNotFoundError for file {plugins_objects}'])
183183

184184
return None
185185

β€Žpialert/device.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def create_new_devices (db):
172172
FROM CurrentScan"""
173173

174174

175-
# mylog('debug',f'[New Devices] Create devices SQL: {sqlQuery}')
175+
mylog('debug',f'[New Devices] Create devices SQL: {sqlQuery}')
176176

177177
sql.execute (sqlQuery, (startTime, startTime) )
178178

@@ -291,7 +291,7 @@ def update_devices_names (db):
291291
# Try IP matching only
292292
if newName == nameNotFound:
293293
newName = resolve_device_name_pholus (device['dev_MAC'], device['dev_LastIP'], pholusResults, nameNotFound, True)
294-
294+
295295
# count
296296
if newName != nameNotFound:
297297
foundPholus += 1
@@ -359,6 +359,6 @@ def query_MAC_vendor (pMAC):
359359

360360
return -1 # MAC address not found in the database
361361
except FileNotFoundError:
362-
mylog('none', [f"[Vendor Check] Error: Vendors file {vendorsPath} not found."])
362+
mylog('none', [f"[Vendor Check] ⚠ ERROR: Vendors file {vendorsPath} not found."])
363363
return -1
364364

β€Žpialert/helper.py

+24-16
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,16 @@
2323
#-------------------------------------------------------------------------------
2424
# Get the current time in the current TimeZone
2525
def timeNowTZ():
26-
if isinstance(conf.TIMEZONE, str):
27-
tz = pytz.timezone(conf.TIMEZONE)
26+
if conf.tz:
27+
return datetime.datetime.now(conf.tz).replace(microsecond=0)
2828
else:
29-
tz = conf.TIMEZONE
29+
return datetime.datetime.now().replace(microsecond=0)
30+
# if isinstance(conf.TIMEZONE, str):
31+
# tz = pytz.timezone(conf.TIMEZONE)
32+
# else:
33+
# tz = conf.TIMEZONE
3034

31-
return datetime.datetime.now(tz).replace(microsecond=0)
35+
# return datetime.datetime.now(tz).replace(microsecond=0)
3236

3337
def timeNow():
3438
return datetime.datetime.now().replace(microsecond=0)
@@ -173,7 +177,7 @@ def initialiseFile(pathToCheck, defaultFile):
173177
stdout, stderr = p.communicate()
174178

175179
if str(os.access(pathToCheck, os.R_OK)) == "False":
176-
mylog('none', ["[Setup] Error copying ("+defaultFile+") to ("+pathToCheck+"). Make sure the app has Read & Write access to the parent directory."])
180+
mylog('none', ["[Setup] ⚠ ERROR copying ("+defaultFile+") to ("+pathToCheck+"). Make sure the app has Read & Write access to the parent directory."])
177181
else:
178182
mylog('none', ["[Setup] ("+defaultFile+") copied over successfully to ("+pathToCheck+")."])
179183

@@ -182,7 +186,7 @@ def initialiseFile(pathToCheck, defaultFile):
182186

183187
except subprocess.CalledProcessError as e:
184188
# An error occured, handle it
185-
mylog('none', ["[Setup] Error copying ("+defaultFile+"). Make sure the app has Read & Write access to " + pathToCheck])
189+
mylog('none', ["[Setup] ⚠ ERROR copying ("+defaultFile+"). Make sure the app has Read & Write access to " + pathToCheck])
186190
mylog('none', [e.output])
187191

188192
#-------------------------------------------------------------------------------
@@ -255,13 +259,13 @@ def get_setting(key):
255259
if item.get("Code_Name") == key:
256260
return item
257261

258-
mylog('debug', [f'[Settings] Error - setting_missing - Setting not found for key: {key} in file {settingsFile}'])
262+
mylog('debug', [f'[Settings] ⚠ ERROR - setting_missing - Setting not found for key: {key} in file {settingsFile}'])
259263

260264
return None
261265

262266
except (FileNotFoundError, json.JSONDecodeError, ValueError) as e:
263267
# Handle the case when the file is not found, JSON decoding fails, or data is not in the expected format
264-
mylog('none', [f'[Settings] Error - JSONDecodeError or FileNotFoundError for file {settingsFile}'])
268+
mylog('none', [f'[Settings] ⚠ ERROR - JSONDecodeError or FileNotFoundError for file {settingsFile}'])
265269

266270
return None
267271

@@ -290,10 +294,14 @@ def get_setting_value(key):
290294
value = str(set_value)
291295
elif set_type in ['boolean', 'integer.checkbox']:
292296

293-
value = True
294-
295-
if set_value in ['false', 'False', 'FALSE', 0]:
296-
value = False
297+
value = False
298+
299+
if isinstance(set_value, str) and set_value.lower() in ['true', '1']:
300+
value = True
301+
elif isinstance(set_value, int) and set_value == 1:
302+
value = True
303+
elif isinstance(set_value, bool):
304+
value = set_value
297305

298306
elif set_type in ['integer.select', 'integer']:
299307
value = int(set_value)
@@ -304,8 +312,8 @@ def get_setting_value(key):
304312
# Assuming set_value is a JSON object in this case
305313
value = json.loads(set_value)
306314
else:
307-
mylog('none', [f'[SETTINGS] ERROR - set_type not handled:{set_type}'])
308-
mylog('none', [f'[SETTINGS] ERROR - setting json:{json.dumps(setting)}'])
315+
mylog('none', [f'[SETTINGS] ⚠ ERROR - set_type not handled:{set_type}'])
316+
mylog('none', [f'[SETTINGS] ⚠ ERROR - setting json:{json.dumps(setting)}'])
309317

310318

311319
return value
@@ -378,7 +386,7 @@ def resolve_device_name_dig (pMAC, pIP):
378386

379387
except subprocess.CalledProcessError as e:
380388
# An error occured, handle it
381-
mylog('none', ['[resolve_device_name_dig] ERROR: ', e.output])
389+
mylog('none', ['[resolve_device_name_dig] ⚠ ERROR: ', e.output])
382390
# newName = "Error - check logs"
383391
return nameNotFound
384392

@@ -693,7 +701,7 @@ def checkNewVersion():
693701
text = url.text
694702
data = json.loads(text)
695703
except requests.exceptions.ConnectionError as e:
696-
mylog('minimal', ["[Version check] Error: Couldn't check for new release."])
704+
mylog('minimal', ["[Version check] ⚠ ERROR: Couldn't check for new release."])
697705
data = ""
698706

699707
# make sure we received a valid response and not an API rate limit exceeded message

β€Žpialert/initialise.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@ def importConfigs (db):
123123

124124
# TODO cleanup later ----------------------------------------------------------------------------------
125125
# init all time values as we have timezone - all this shoudl be moved into plugin/plugin settings
126-
conf.time_started = datetime.datetime.now(conf.tz)
127-
conf.cycle = ""
126+
conf.time_started = datetime.datetime.now(conf.tz)
128127
conf.plugins_once_run = False
129128

130129
# timestamps of last execution times

β€Žpialert/logger.py

+3
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ def timeNowTZ():
2020

2121

2222
#-------------------------------------------------------------------------------
23+
# More verbose as the numbers go up
2324
debugLevels = [
2425
('none', 0), ('minimal', 1), ('verbose', 2), ('debug', 3)
2526
]
2627

28+
currentLevel = 0
29+
2730
def mylog(requestedDebugLevel, n):
2831

2932
setLvl = 0

0 commit comments

Comments
Β (0)