1#!/usr/bin/env python3 2import json 3import os, cgi 4import re 5 6jenc = json.JSONEncoder() 7 8def get_var(name: str, def_val: str = ""): 9 if name in os.environ: 10 return os.environ[name] 11 return def_val 12 13def get_json_var(name: str, def_val: str = ""): 14 var = get_var(name, def_val=def_val) 15 return jenc.encode(var) 16 17 18name = None 19try: 20 form = cgi.FieldStorage() 21 if 'name' in form: 22 name = str(form['name'].value) 23except Exception: 24 pass 25 26print("Content-Type: application/json\n") 27if name: 28 print(f"""{{ "{name}" : {get_json_var(name, '')}}}""") 29else: 30 print(f"""{{ "https" : {get_json_var('HTTPS', '')}, 31 "host" : {get_json_var('SERVER_NAME', '')}, 32 "protocol" : {get_json_var('SERVER_PROTOCOL', '')}, 33 "ssl_protocol" : {get_json_var('SSL_PROTOCOL', '')}, 34 "ssl_cipher" : {get_json_var('SSL_CIPHER', '')} 35}}""") 36 37