MemeTech/cloudvarslol
0
1import flask # for the UI and API2import time # for rate limiting3import json # for listing, CORRECTLY4 5app = flask.Flask(__name__)6# woah, VS, it's python, not whatever that down arrow is7 8vars = {} # a dictionary of variables9ips = {} # a dictionary of IPs and the last time they made a request10 11# get a variable12@app.route('/get/<var>')13def get(var):14 try:15 global ips16 ips[flask.request.remote_addr] = time.time()17 global vars18 return vars[var]19 except Exception as e:20 return str(e), 404 # we all know this means "not found"21# set a variable22@app.route('/set/<var>/<val>')23def set(var, val):24 try:25 global ips26 ips[flask.request.remote_addr] = time.time()27 global vars28 vars[var] = val29 return vars[var] # return the value of the variable, just in case it fails30 except Exception as e:31 return str(e), 40432# delete a variable, making it return 40433@app.route('/del/<var>')34def delete(var):35 try:36 global vars37 del vars[var]38 global ips39 ip = flask.request.remote_addr40 if ip not in ips:41 ips[ip] = 042 if time.time() - ips[ip] < 0.1:43 time.sleep(1) # rate limiting (10 requests per second, but lower if you're exceeding it)44 # should you use a scratch project and port it, you should be fine so long as you abide by their rate limits45 # otherwise, this is significantly more strict, it's kind of just a "don't wipe the database" thing46 return vars[var], 429 # too many requests, but also success47 return vars[var]48 except Exception as e:49 return str(e), 40450# list all variables51@app.route('/')52def list():53 # this uses ACTUAL JSON54 # NOT the fake json used by joecooldo55 # (he makes a cool library)56 # "error: json does not allow single quotes (')"57 global vars58 return json.dumps(vars)59# list ips60@app.route('/ips')61def listips():62 global ips63 return json.dumps(ips)64# run the app65app.run(port=7860)