From f8d8335199aa86a8fe19da6e20829a1b9ded3cf9 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Tue, 15 Nov 2016 16:19:14 +0800 Subject: webui/utils.py: Add function "gen_cookie_secret()" --- fg21sim/webui/utils.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'fg21sim') 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 -- cgit v1.2.2