#!/usr/bin/env python import cgitb;cgitb.enable() import sajax1 def multiply(x,y): try: float_x, float_y = float(x), float(y) except: return 0 return float_x * float_y sajax1.sajax_init() sajax1.sajax_export(multiply) sajax1.sajax_handle_client_request() print """ <html> <head> <title>PyMultiplier</title> <script> """ sajax1.sajax_show_javascript() print """ function do_multiply_cb(z) { document.getElementById("z").value = z; } function do_multiply() { var x, y; x = document.getElementById("x").value; y = document.getElementById("y").value;
def add_line(msg): f = open("/tmp/wall.html","a") datetime = datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S") msg = cgi.escape(msg) remote = os.environ['REMOTE_ADDR'] colour = colourify_ip(remote) f.write('<span style="color:#%(colour)s">%(datetime)s</span> %(msg)s<br />\n' % locals()) f.close() def refresh(): f = open("/tmp/wall.html") return '\n'.join(list(f)[-25:]) sajax1.sajax_init() sajax1.sajax_export(refresh, add_line) sajax1.sajax_handle_client_request() print """ <html> <head> <title>PyWall</title> <script> """ sajax1.sajax_show_javascript() print """ var check_n = 0; function refresh_cb(new_data) { document.getElementById("wall").innerHTML = new_data; document.getElementById("status").innerHTML = "Checked #" + check_n++;