Update AppImage

This commit is contained in:
MacRimi
2025-11-07 19:25:36 +01:00
parent fc7d0f2cd5
commit 25fc3d931e
6 changed files with 258 additions and 74 deletions

View File

@@ -26,6 +26,7 @@ AUTH_CONFIG_FILE = CONFIG_DIR / "auth.json"
JWT_SECRET = "proxmenux-monitor-secret-key-change-in-production"
JWT_ALGORITHM = "HS256"
TOKEN_EXPIRATION_HOURS = 24
TOKEN_EXPIRATION_DAYS_REMEMBER = 30 # Token más largo para "recordar contraseña"
def ensure_config_dir():
@@ -94,15 +95,18 @@ def verify_password(password, password_hash):
return hash_password(password) == password_hash
def generate_token(username):
def generate_token(username, remember_me=False): # Añadido parámetro remember_me
"""Generate a JWT token for the given username"""
if not JWT_AVAILABLE:
return None
expiration_delta = timedelta(days=TOKEN_EXPIRATION_DAYS_REMEMBER) if remember_me else timedelta(hours=TOKEN_EXPIRATION_HOURS)
payload = {
'username': username,
'exp': datetime.utcnow() + timedelta(hours=TOKEN_EXPIRATION_HOURS),
'iat': datetime.utcnow()
'exp': datetime.utcnow() + expiration_delta,
'iat': datetime.utcnow(),
'remember_me': remember_me # Guardar preferencia en el token
}
try:
@@ -147,7 +151,7 @@ def get_auth_status():
config = load_auth_config()
return {
"auth_enabled": config.get("enabled", False),
"auth_configured": config.get("configured", False), # Frontend expects this field name
"auth_configured": config.get("configured", False),
"declined": config.get("declined", False),
"username": config.get("username") if config.get("enabled") else None,
"authenticated": False # Will be set to True by the route handler if token is valid
@@ -202,13 +206,16 @@ def disable_auth():
Disable authentication (different from decline - can be re-enabled)
Returns (success: bool, message: str)
"""
config = load_auth_config()
config["enabled"] = False
# Keep configured=True and don't set declined=True
# This allows re-enabling without showing the setup modal again
config = {
"enabled": False,
"username": None,
"password_hash": None,
"declined": False,
"configured": False
}
if save_auth_config(config):
return True, "Authentication disabled"
return True, "Authentication disabled successfully"
else:
return False, "Failed to save configuration"
@@ -232,7 +239,7 @@ def enable_auth():
return False, "Failed to save configuration"
def change_password(old_password, new_password):
def change_password(current_password, new_password): # Corregido nombre del parámetro
"""
Change the authentication password
Returns (success: bool, message: str)
@@ -242,7 +249,7 @@ def change_password(old_password, new_password):
if not config.get("enabled"):
return False, "Authentication is not enabled"
if not verify_password(old_password, config.get("password_hash", "")):
if not verify_password(current_password, config.get("password_hash", "")):
return False, "Current password is incorrect"
if len(new_password) < 6:
@@ -256,7 +263,7 @@ def change_password(old_password, new_password):
return False, "Failed to save new password"
def authenticate(username, password):
def authenticate(username, password, remember_me=False): # Añadido parámetro remember_me
"""
Authenticate a user with username and password
Returns (success: bool, token: str or None, message: str)
@@ -272,7 +279,7 @@ def authenticate(username, password):
if not verify_password(password, config.get("password_hash", "")):
return False, None, "Invalid username or password"
token = generate_token(username)
token = generate_token(username, remember_me)
if token:
return True, token, "Authentication successful"
else: