#!/usr/bin/env python3 from htmlgen import * import traceback import sys import storage import cgi import random import base64 from io import BytesIO from captcha.image import ImageCaptcha import time, string print("Content-type: text/html\r\n\r\n") form=cgi.FieldStorage() aid=int(form["aid"].value) try: seed=int(form["seed"].value) random.seed(seed) checkstr="".join(random.choice(string.digits+string.ascii_lowercase) for _ in range(5)) if not checkstr == form["checkstr"].value: print("Captcha's wrong") raise Exception() username=form["username"].value message=form["message"].value timestamp=int(time.time()) data={"name":cgi.escape(form["title"].value),"markdown":cgi.escape(message),"author":cgi.escape(username),"date":timestamp} storage.append("comments-%i"%aid,data) except KeyError: pass seed=random.SystemRandom().randint(0,2**24) random.seed(seed) checkstr="".join(random.choice(string.digits+string.ascii_lowercase) for _ in range(5)) image = ImageCaptcha() capt = image.generate(checkstr) html=htmlgen.HTMLgen(pagelayout.getLayoutXML().decode('utf-8'),"Comments") html.appendHTML("
") count=storage.count("comments-%i"%aid) for i in range(count): html.addArticle(aid=aid,**(storage.get("comments-%i"%aid,i))) print("") sys.stdout.buffer.write(html.renderSite(True).encode('utf8')) #print(html.renderSite(True))