From aef0e015d18da34efeb7f79f3b747b5f1564c91b Mon Sep 17 00:00:00 2001 From: Taylor Helsper Date: Sat, 27 Mar 2021 17:46:56 -0500 Subject: [PATCH] Add function for controlling session timeout --- rootfs/standard/var/www/mynode/device_info.py | 15 +++++++++++++++ rootfs/standard/var/www/mynode/mynode.py | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/rootfs/standard/var/www/mynode/device_info.py b/rootfs/standard/var/www/mynode/device_info.py index b12287a3..467c8417 100644 --- a/rootfs/standard/var/www/mynode/device_info.py +++ b/rootfs/standard/var/www/mynode/device_info.py @@ -8,6 +8,7 @@ from lightning_info import is_lnd_ready, get_lnd_status, get_lnd_status_color from systemctl_info import * from electrum_info import get_electrs_status, is_electrs_active from bitcoin_info import get_bitcoin_status, is_bitcoind_synced +from datetime import timedelta import time import json import os @@ -713,6 +714,20 @@ def get_flask_secret_key(): set_file_contents("/home/bitcoin/.mynode/flask_secret_key", key) return key +def get_flask_session_timeout(): + try: + if os.path.isfile("/home/bitcoin/.mynode/flask_session_timeout"): + timeout = get_file_contents("/home/bitcoin/.mynode/flask_session_timeout") + parts = timeout.split(",") + d = parts[0] + h = parts[1] + return timedelta(days=d, hours=h) + else: + set_file_contents("/home/bitcoin/.mynode/flask_session_timeout", "90,0") + return timedelta(days=90, hours=0) + except: + return timedelta(days=90, hours=0) + #================================== # Uploader Functions diff --git a/rootfs/standard/var/www/mynode/mynode.py b/rootfs/standard/var/www/mynode/mynode.py index 69e8316f..40ce6925 100644 --- a/rootfs/standard/var/www/mynode/mynode.py +++ b/rootfs/standard/var/www/mynode/mynode.py @@ -61,7 +61,7 @@ app.config['MAX_CONTENT_LENGTH'] = 32 * 1024 * 1024 # 32 MB upload file max app.config['UPLOAD_FOLDER'] = "/tmp/flask_uploads" app.config["SESSION_COOKIE_NAME"] = "mynode_session_id" app.secret_key = get_flask_secret_key() -app.permanent_session_lifetime = timedelta(days=90) +app.permanent_session_lifetime = get_flask_session_timeout() app.register_error_handler(LoginError, handle_login_exception) app.wsgi_app = ReverseProxied(app.wsgi_app)