diff options
author | Aaron LI <aaronly.me@outlook.com> | 2016-11-15 16:19:14 +0800 |
---|---|---|
committer | Aaron LI <aaronly.me@outlook.com> | 2016-11-15 16:19:14 +0800 |
commit | f8d8335199aa86a8fe19da6e20829a1b9ded3cf9 (patch) | |
tree | cdbe92eb988c83a49e0c791600fd50e7ce4c9d3e | |
parent | 6f34464b51e7c3fc2ad6e6f146eb071cac4a75a7 (diff) | |
download | fg21sim-f8d8335199aa86a8fe19da6e20829a1b9ded3cf9.tar.bz2 |
webui/utils.py: Add function "gen_cookie_secret()"
-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 |