Add function for controlling session timeout

This commit is contained in:
Taylor Helsper 2021-03-27 17:46:56 -05:00
parent be3a7f0d60
commit aef0e015d1
2 changed files with 16 additions and 1 deletions

View File

@ -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

View File

@ -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)