Agent Zero AI framework
login page polishing
frdel681477786904
diff --git a/run_ui.py b/run_ui.pyindex d96ad70bd..4066c3328 100644--- a/run_ui.py+++ b/run_ui.py@@ -1,6 +1,7 @@from datetime import timedeltaimport osimport secrets+import hashlibimport timeimport socketimport struct@@ -38,7 +39,6 @@ webapp.config.update(PERMANENT_SESSION_LIFETIME=timedelta(days=1))-lock = threading.Lock()# Set up basic authentication for UI and API but not MCP@@ -114,16 +114,23 @@ def requires_loopback(f):return decorated+def _get_credentials_hash():+ user = dotenv.get_dotenv_value("AUTH_LOGIN")+ password = dotenv.get_dotenv_value("AUTH_PASSWORD")+ if not user:+ return None+ return hashlib.sha256(f"{user}:{password}".encode()).hexdigest()+# require authentication for handlersdef requires_auth(f):@wraps(f)async def decorated(*args, **kwargs):- user = dotenv.get_dotenv_value("AUTH_LOGIN")+ user_pass_hash = _get_credentials_hash()# If no auth is configured, just proceed- if not user:+ if not user_pass_hash:return await f(*args, **kwargs)-- if not session.get('authenticated'):++ if session.get('authentication') != user_pass_hash:return redirect(url_for('login'))return await f(*args, **kwargs)@@ -151,7 +158,7 @@ async def login():password = dotenv.get_dotenv_value("AUTH_PASSWORD")if request.form['username'] == user and request.form['password'] == password:- session['authenticated'] = True+ session['authentication'] = _get_credentials_hash()return redirect(url_for('serve_index'))else:error = 'Invalid Credentials. Please try again.'@@ -161,7 +168,7 @@ async def login():@webapp.route("/logout")async def logout():- session.pop('authenticated', None)+ session.pop('authentication', None)return redirect(url_for('login'))# handle default address, load indexdiff --git a/webui/index.html b/webui/index.htmlindex c36cfaba2..2da86a490 100644--- a/webui/index.html+++ b/webui/index.html@@ -130,7 +130,6 @@<script type="text/javascript" src="js/settings.js"></script><script type="text/javascript" src="js/file_browser.js"></script><script type="text/javascript" src="js/modal.js"></script>- <script type="module" src="js/tunnel.js"></script></head><body class="dark-mode device-pointer">diff --git a/webui/js/api.js b/webui/js/api.jsindex c9cb7901e..eeec492b5 100644--- a/webui/js/api.js+++ b/webui/js/api.js@@ -52,6 +52,9 @@ export async function fetchApi(url, request) {// retry the request with new tokencsrfToken = null;return await _wrap(false);+ }else if(response.redirected && response.url.endsWith("/login")){+ // redirect to login+ window.location.href = response.url;}// return the response