diff --git a/backend/__init__.py b/backend/__init__.py index f209114d..ab3e9926 100644 --- a/backend/__init__.py +++ b/backend/__init__.py @@ -189,6 +189,10 @@ def changedetection_app(config=None, datastore_o=None): @app.route('/login', methods=['GET', 'POST']) def login(): + if not datastore.data['settings']['application']['password']: + flash("Login not required, no password enabled.", "notice") + return redirect(url_for('index')) + if request.method == 'GET': output = render_template("login.html") return output @@ -483,9 +487,6 @@ def changedetection_app(config=None, datastore_o=None): flash("Password protection enabled.", 'notice') flask_login.logout_user() return redirect(url_for('index')) - else: - # Unset it anyway, just to be sure. - datastore.data['settings']['application']['password'] = False flash("Settings updated.") diff --git a/backend/store.py b/backend/store.py index 927fb127..b755e28a 100644 --- a/backend/store.py +++ b/backend/store.py @@ -1,9 +1,7 @@ +from os import unlink, path, mkdir import json import uuid as uuid_builder -import os.path -from os import path from threading import Lock - from copy import deepcopy import logging @@ -115,6 +113,12 @@ class ChangeDetectionStore: self.__data['version_tag'] = "0.34" + # Helper to remove password protection + password_reset_lockfile = "{}/removepassword.lock".format(self.datastore_path) + if path.isfile(password_reset_lockfile): + self.__data['settings']['application']['password'] = False + unlink(password_reset_lockfile) + if not 'app_guid' in self.__data: import sys import os @@ -199,7 +203,7 @@ class ChangeDetectionStore: def unlink_history_file(self, path): try: - os.unlink(path) + unlink(path) except (FileNotFoundError, IOError): pass @@ -293,7 +297,7 @@ class ChangeDetectionStore: # Get the directory ready output_path = "{}/{}".format(self.datastore_path, new_uuid) try: - os.mkdir(output_path) + mkdir(output_path) except FileExistsError: print(output_path, "already exists.") @@ -362,4 +366,4 @@ class ChangeDetectionStore: for item in pathlib.Path(self.datastore_path).rglob("*/*txt"): if not str(item) in index: print ("Removing",item) - os.unlink(item) + unlink(item)