#!/usr/bin/python import os import cgi import re import random import db db = db.db() BASE_HREF = "http://i.asdf.us/im/" PARAMLIST = "addr start limit name interface random" LIMIT = 20 def get_params (paramlist): paramkeys = paramlist.split() form = {} try: qs = os.environ['QUERY_STRING'] except: qs = "" if len(qs): pairs = qs.replace("&", "&").split("&") for pair in pairs: k,v = pair.split("=", 1) form[k] = v params = {} for key in paramkeys: if key in form: params[key] = sanitize(form[key]) else: params[key] = None return params def sanitize (str): return re.sub(r'\W+', '', str) def get_files (params): sql = "SELECT * FROM im_cmd " args = [] where = [] if params['start'] is not None: where.append("id < %s") args.append(params['start']) if params['name'] is not None: where.append("name=%s") args.append(params['name']) if len(where): sql += "WHERE " sql += " AND ".join(where) sql += " " if params['random'] is not None: sql += "ORDER BY RAND() " else: sql += "ORDER BY id DESC " sql += "LIMIT %s" if params['limit'] is not None: args.append( int(params['limit']) ) else: args.append( LIMIT ) db.execute(sql, args) rows = db.cursor.fetchall () return rows def is_image (img): if "jpeg" in img: return True if "jpg" in img: return True if "gif" in img: return True if "png" in img: return True return False params = get_params(PARAMLIST) titlephrase = random.choice([ 'Keep on pickin\' on..', 'Pickolaus Pickleby by Charles Pickens!', 'You pick potato and I pick potahto...', 'Take your piq!', 'Show em what you got', 'I sure know how to pick \'em', 'Jus pick somethin already!', 'You can\'t pick your friends...', 'Select your image my liege', 'There\'s a time to choose...', 'gimme a choice! gimme lil\' choice-a-that...', 'You choose you lose', 'novels by James CHOICE...', 'Choose away, chooser-man...', ]) print "Content-type: text/html" print "Pragma: no-cache" print print """
""" print "