diff options
Diffstat (limited to 'fg21sim/webui/utils.py')
-rw-r--r-- | fg21sim/webui/utils.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/fg21sim/webui/utils.py b/fg21sim/webui/utils.py index bf62525..4d84c95 100644 --- a/fg21sim/webui/utils.py +++ b/fg21sim/webui/utils.py @@ -13,12 +13,16 @@ get_local_ip : ip_in_network : Whether the IP address is contained in the network? + +gen_cookie_secret : + Generate the secret key for cookie signing from the local hostname. """ import ipaddress import socket from urllib.parse import urlparse +import base64 def get_host_ip(url): @@ -105,3 +109,12 @@ def ip_in_network(ip, network): if not isinstance(network, ipaddress.IPv4Network): network = ipaddress.IPv4Network(network) return ip in network + + +def gen_cookie_secret(): + """ + Generate the secret key for cookie signing from the local hostname. + """ + hostname = socket.gethostname() + secret = base64.b64encode(hostname.encode("utf-8")).decode("ascii") + return secret |