Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions pm_dashboard/pm_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ def on_mqtt_connected(client, userdata, flags, rc):
__mqtt_connected__ = False

def _get_log(name, line_count=100, filter=[], level="INFO"):
if path.exists(f"{__log_path__}/{name}") == False:
normalized_filename = basename(name)
if path.exists(f"{__log_path__}/{normalized_filename}") == False:
return False
with open(f"{__log_path__}/{name}", 'r') as f:
with open(f"{__log_path__}/{normalized_filename}", 'r') as f:
lines = f.readlines()
lines = lines[-line_count:]
data = []
Expand Down Expand Up @@ -432,12 +433,13 @@ def clear_history():
@cross_origin()
def delete_log_file():
filename = request.json["filename"]
if filename is None:
normalized_filename = basename(filename)
if normalized_filename is None:
return {"status": False, "error": "[ERROR] file not found"}
if path.exists(f"{__log_path__}/{filename}") == False:
return {"status": False, "error": f"[ERROR] file {filename} not found"}
if path.exists(f"{__log_path__}/{normalized_filename}") == False:
return {"status": False, "error": f"[ERROR] file {normalized_filename} not found"}
try:
remove(f"{__log_path__}/{filename}")
remove(f"{__log_path__}/{normalized_filename}")
return {"status": True, "data": "OK"}
except Exception as e:
return {"status": False, "error": str(e)}
Expand Down