From 4100860d10e2fb015db01d22bbf3f4735bcf10ec Mon Sep 17 00:00:00 2001 From: yo mama Date: Fri, 13 Feb 2015 01:33:31 -0800 Subject: first --- impattern/im/cgi-bin/gallery.cgi | 474 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 474 insertions(+) create mode 100755 impattern/im/cgi-bin/gallery.cgi (limited to 'impattern/im/cgi-bin/gallery.cgi') diff --git a/impattern/im/cgi-bin/gallery.cgi b/impattern/im/cgi-bin/gallery.cgi new file mode 100755 index 0000000..0f762eb --- /dev/null +++ b/impattern/im/cgi-bin/gallery.cgi @@ -0,0 +1,474 @@ +#!/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 ""+titlephrase+"" +print""" + + + + +
+ key controls +
+ ESC toggle
+ C clear
+ R reverse
+ BACKSPACE delete
+ LEFT ARROW newer
+ RIGHT ARROW older
+
+
+
+
+ +
+
copy
+
+ +
+
+""" + + +files = get_files(params) +count = 0 +for f in files: + # url = BASE_HREF + f.replace(" ","%20") + url = BASE_HREF + f[5] + "/" + f[7] + print "
" % (url) +print "
" + +lowest_id = files[-1][0] +previous_id = lowest_id + (LIMIT * 2) +back = ["start=%d" % lowest_id, "limit=%d" % LIMIT] +newer = ["start=%d" % previous_id, "limit=%d" % LIMIT] +random_time = [] +if params['name'] is not None: + back.append("name=%s" % params['name']) + newer.append("name=%s" % params['name']) + random_time.append("name=%s" % params['name']) + +newer_QS = "&".join(newer) +back_QS = "&".join(back) +random_time_QS = "&".join(back) +print "
" +print "← newer" % newer_QS; +print "|" +print "editor" +print "|" +print "random" % random_time_QS; +print "|" +print "older →" % back_QS; +print "
" +print """ + + + + + + + +""" + -- cgit v1.2.3-70-g09d2