#!/usr/bin/env python import json import cgi import os from utils import simple_success_response_JSON, simple_failure_response_JSON, test_if_room args = cgi.FieldStorage() json_string = args['json_data'].value r_id = args['r_id'].value json_data = json.loads(json_string) ### Verify r_id is a valid room id if not test_if_room(r_id): simple_failure_response_JSON() exit(1) ### Write out the room's data ### ------------------------------------------------------------- json_path = os.path.join('..', 'content', 'room_data_' + r_id + '.json') with open(json_path, 'w+') as f: json.dump(json_data, f, indent=4, separators=(',', ': ')) ### ------------------------------------------------------------- simple_success_response_JSON()
if "REMOTE_ADDR" not in os.environ or "HTTP_USER_AGENT" not in os.environ or "interaction" not in args or "r_id" not in args: valid = False ## Validate interaction if "interaction" in args and re.match("^[a-z]+$", args["interaction"].value): interaction = args["interaction"].value else: valid = False ## Validate data if provided, else set a default of empty string if "data" in args: if re.match("^[\\w,=; ]*$", args["data"].value): extraData = args["data"].value else: valid = False else: extraData = "" if "r_id" in args and not test_if_room(args["r_id"].value): valid = False if valid != True: simple_failure_response_JSON() exit(1) formattedTime = time.strftime("%Y-%m-%d %H:%M:%S") ip = os.environ["REMOTE_ADDR"] ua = os.environ["HTTP_USER_AGENT"] room = args["r_id"].value ## Make sure UA isn't too long and there are no special characters maxUAlen = 200 ua = re.sub("\\s", " ", ua)
import json import cgi import os from utils import simple_success_response_JSON, simple_failure_response_JSON, test_if_room from render_rooms import render_room_if_stale args = cgi.FieldStorage() json_string = args['json_data'].value r_id = args['r_id'].value ver = int(args['ver'].value) json_data = json.loads(json_string) ### Verify r_id is a valid room id if not test_if_room(r_id): simple_failure_response_JSON() exit(1) # write in content json data version number json_data.append(ver) # write out that user's new board conent data json_path = os.path.join('..', 'content', r_id + '.json') with open(json_path, 'w+') as f: json.dump(json_data, f, indent=4, separators=(',', ': ')) ### potentially render the room to a png if it's stale ### -------------------------------------------------------------
if "REMOTE_ADDR" not in os.environ or "HTTP_USER_AGENT" not in os.environ or "interaction" not in args or "r_id" not in args: valid = False ## Validate interaction if "interaction" in args and re.match("^[a-z]+$", args["interaction"].value): interaction = args["interaction"].value else: valid = False ## Validate data if provided, else set a default of empty string if "data" in args: if re.match("^[\\w,=; ]*$", args["data"].value): extraData = args["data"].value else: valid = False else: extraData = "" if "r_id" in args and not test_if_room(args["r_id"].value): valid = False if valid != True: simple_failure_response_JSON() exit(1) formattedTime = time.strftime("%Y-%m-%d %H:%M:%S") ip = os.environ["REMOTE_ADDR"] ua = os.environ["HTTP_USER_AGENT"] room = args["r_id"].value ## Make sure UA isn't too long and there are no special characters maxUAlen = 200 ua = re.sub("\\s", " ", ua) if (len(ua) > maxUAlen):