diff options
| -rw-r--r-- | database/database_create_statements | 3 | ||||
| -rw-r--r-- | database/database_schema.sql | 15 | ||||
| -rw-r--r-- | jsonptest.sh | 2 | ||||
| -rwxr-xr-x | landscape | 163 | ||||
| -rw-r--r-- | move_to_server | 25 | ||||
| -rwxr-xr-x | pb/imlandscape_other.py | 101 | ||||
| -rwxr-xr-x | pb/landscape_other | 163 | ||||
| -rwxr-xr-x | pbserver_other.py | 227 |
8 files changed, 0 insertions, 699 deletions
diff --git a/database/database_create_statements b/database/database_create_statements deleted file mode 100644 index 9fa9e39..0000000 --- a/database/database_create_statements +++ /dev/null @@ -1,3 +0,0 @@ -create database if not exists asdfus; -grant all privileges on asdfus.* to asdfus@localhost identified by 'gTYgT&M6q'; -flush privileges; diff --git a/database/database_schema.sql b/database/database_schema.sql deleted file mode 100644 index 802aa49..0000000 --- a/database/database_schema.sql +++ /dev/null @@ -1,15 +0,0 @@ -CREATE TABLE if not exists `im_cmd` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `date` int(11) DEFAULT NULL, - `remote_addr` varchar(16) DEFAULT NULL, - `name` varchar(16) DEFAULT NULL, - `url` varchar(256) DEFAULT NULL, - `dir` varchar(2) DEFAULT NULL, - `oldfile` varchar(256) DEFAULT NULL, - `newfile` varchar(256) DEFAULT NULL, - `cmd` blob, - `dataobj` blob, - `tag` varchar(50) DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=MyISAM AUTO_INCREMENT=386739 DEFAULT CHARSET=utf8; - diff --git a/jsonptest.sh b/jsonptest.sh deleted file mode 100644 index 8539853..0000000 --- a/jsonptest.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -curl 'http://asdf.us/cgi-bin/im/generate?callback=jsonp1431361693303&url=http%3A%2F%2Fwww.maskworld.com%2Fpix%2Fmasks%2F025-party-face-gesicht-fasching-karneval-carnival-halloween-latex-film-movie-larp-theatre-theater-horror-rubber-gummi-mask-masks-maske-masken.jpg&name=test&transparent=true&fuzz=5' -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36' -H 'Accept: */*' -H 'Referer: http://carbonpictures.com/pb/' -H 'Cookie: imname=yo' -H 'Connection: keep-alive' --compressed diff --git a/landscape b/landscape deleted file mode 100755 index 10e8ede..0000000 --- a/landscape +++ /dev/null @@ -1,163 +0,0 @@ -#!/usr/bin/python2.7 -import cgi -import sys -import os -import re -import time -import string -import urllib -from subprocess import Popen, PIPE -import sha -import simplejson as json - -import mimetypes -import s3 - -import db -DB = db.db () - -import base64 -import urlparse - - -AWS_ACCESS_KEY_ID = 'AKIAIR53VPBXKJMXZIBA' -AWS_SECRET_ACCESS_KEY = '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' -BUCKET_NAME = 'i.asdf.us' -BASE_PATH = "/var/www/asdf.us/httpdocs/imlandscape" -BASE_URL = "http://i.asdf.us/" -PARAM_LIST = "heightmap texture name imgdata filename" -BIN_IDENTIFY = "/usr/bin/identify" - -print "Content-type: text/plain" -print "" -def insert_cmd (dir, newfile, name, texture, dataobj): - if texture == "": - texture = "NULL" - try: - sql = "INSERT INTO im_cmd (date,remote_addr,name,url,dir,oldfile,newfile,cmd, dataobj, tag) VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s, %s)" - - args = (now(), "NULL", name, texture, dir, "NULL", newfile, "NULL", dataobj, "imlandscape") - DB.execute(sql, args) - except (): - return - -def hash_dir (s): - return sha.new(s).hexdigest()[:2] - -def bin_identify (filename): - ident = Popen([BIN_IDENTIFY, filename], stdout=PIPE).communicate()[0] - partz = ident.split(" ") - width,height = partz[2].split("x") - return width, height - -def get_params (paramlist): - paramkeys = paramlist.split() - form = cgi.FieldStorage() - params = {} - for key in paramkeys: - if key in form: - if key == 'heightmap': - params[key] = form[key].value - elif key == 'imgdata': - params[key] = form[key].value - elif key == 'texture': - params[key] = form[key].value - else: - params[key] = sanitize(form[key].value) - else: - params[key] = None - return params - -def error (e): - print "#@imlandscape" - print "ERROR\t"+e - sys.exit() - -def now (): - return int(time.mktime(time.localtime())) - -def sanitize (str): - return re.sub(r'\W+', '', str) - -def filename_from_url (url, name=""): - if "?" in url: - url = url.split("?")[0] - if "/" in url: - url = urllib.unquote(url).replace(" ","") - filename = url.split("/")[-1] - filetype = "png" - filename = sanitize(filename[:-4]) - else: - filename = "" - if name != "": - name = name+"_" - return "{}_{}{}_{}.{}".format("imlandscape", name, filename,now(), "png") - -def saveImgData(url, filename): - try: - up = urlparse.urlparse(url) - head, data = up.path.split(',', 1) - bits = head.split(';') - mime_type = bits[0] if bits[0] else 'text/plain' - charset, b64 = 'ASCII', False - for bit in bits[1]: - if bit.startswith('charset='): - charset = bit[8:] - elif bit == 'base64': - b64 = True - - # Do something smart with charset and b64 instead of assuming - plaindata = base64.b64decode(data) - - with open(filename, 'wb') as f: - f.write(plaindata) - except Exception as e: - error(str(e)); - -def file_size (file): - return os.stat(file)[6] - -def moveToS3(filename,objectname): - conn = s3.AWSAuthConnection(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY) - sys.stderr.write( "Uploading %s" % filename) - filedata = open(filename, 'rb').read() - content_type = mimetypes.guess_type(filename)[0] - if not content_type: - content_type = 'text/plain' - conn.put(BUCKET_NAME, objectname, s3.S3Object(filedata), - {'x-amz-acl': 'public-read', 'Content-Type': content_type, 'x-amz-storage-class': 'REDUCED_REDUNDANCY'}) - -param = get_params(PARAM_LIST) -if param['imgdata'] is None: - error("no imgdata") -url = param['imgdata'] -if param['texture'] is None: - param['texture'] = ""; -if param['heightmap'] is None: - param['heightmap'] = ""; -if param['name'] is None: - param['name'] = ""; - -dataobj = json.dumps({ - 'texture' : param['texture'], - 'heightmap' : param['heightmap'], - 'name' : param['name'] -}) - -dir = hash_dir(param['imgdata']); - -filename = filename_from_url(param['texture'], param['name']); - -tag = "imlandscape" -objectname = "im/"+dir+"/"+filename - -saveImgData(param['imgdata'], filename); - -print "#@imlandscape" -#print ", ".join([k+"="+str(v) for k,v in param.iteritems()]) -print file_size (filename) -print bin_identify (filename) -print BASE_URL+objectname -insert_cmd(dir, filename, param['name'], param['texture'], dataobj); -moveToS3(filename, objectname); -os.remove(filename); diff --git a/move_to_server b/move_to_server deleted file mode 100644 index a5fb980..0000000 --- a/move_to_server +++ /dev/null @@ -1,25 +0,0 @@ -# -# insert_cmd(dir, oldfile, newfile, cmd, url, name, tag) -# -# insert_cmd(dir, oldfile, newfile, cmd, url, name, tag) -# -## jsonp callback -#if param['callback'] is not None: -# url = (BASE_URL+dir+"/"+newfile).replace("'", "\\'") -# width, height = bin_identify (WORKING_DIR, newfile) -# print param['callback'] + "({" -# print "'url':'" + url + "'," -# print "'size':" + str(file_size (WORKING_DIR, newfile)) + "," -# print "'width':" + width + "," -# print "'height':" + height -# print "});" -# moveToS3(os.path.join(WORKING_DIR, newfile), "im/"+dir+"/"+newfile) -#else: -# print "#@im" -# print ", ".join([k+"="+str(v) for k,v in param.iteritems()]) -# print " ".join(cmd) -# print BASE_URL+dir+"/"+newfile -# print file_size (WORKING_DIR, newfile) -# print bin_identify (WORKING_DIR, newfile) -# moveToS3(os.path.join(WORKING_DIR, newfile), "im/"+dir+"/"+newfile) -# diff --git a/pb/imlandscape_other.py b/pb/imlandscape_other.py deleted file mode 100755 index 60f1fef..0000000 --- a/pb/imlandscape_other.py +++ /dev/null @@ -1,101 +0,0 @@ -#!/usr/bin/python2.7 -import os -import sys -import random -import re -import pb.lib.utils as utils -import urllib -import urlparse -from pb.config import * - -import base64 -import time -import string -import urllib -from subprocess import Popen, PIPE -import sha -import simplejson as json - -import mimetypes - -class Imlandscape(object): - def __init__(self, **kwargs): - self.params = {} - self.tag = "imlandscape" - self.commands = []; - self._required_keys = [ - "heightmap", - "imgdata", - "texture", - "name", - ] - self.now = utils.now() - self.files_created = [] - for k in self._required_keys: - if k in kwargs: - self.params[k] = kwargs[k] - else: - self.params[k] = utils.bool_correct(utils.sanitize(kwargs[k])) - - def _filename_from_url (self, url, name=""): - if "?" in url: - url = url.split("?")[0] - if "/" in url: - url = urllib.unquote(url).replace(" ","") - filename = url.split("/")[-1] - filetype = "png" - filename = sanitize(filename[:-4]) - else: - filename = "" - if name != "": - name = name+"_" - return "{}_{}{}_{}.{}".format("imlandscape", name, filename,self.now, "png") - - def _saveImgData(self, imgdata, filename): - try: -# up = urlparse.urlparse(url) -# head, data = imgdata.split(',', 1) -# bits = head.split(';') - parts = imgdata.split(';') - mime_type = parts[0] if parts[0] else 'text/plain' - data = parts[1] - charset, b64 = 'ASCII', False - for part in parts[1]: - if part.startswith('charset='): - charset = part[8:] - elif part == 'base64': - b64 = True - - # Do something smart with charset and b64 instead of assuming - if b64: - plaindata = base64.b64decode(data) - else: - plaindata = data - with open(filename, 'wb') as f: - f.write(plaindata) - except Exception as e: - sys.stderr.write("ERROR: {}\n".format(str(e))); - -# def _cleanup(self): -# cmd = ["rm"]+self.files_created -# self._call_cmd(cmd) - - def create(self, breakmode=""): - self.filepath = self._filename_from_url(self.params.get('texture',""), self.params.get('name',"")); - self._saveImgData(self.params.get('imgdata'), self.filepath); - -if __name__ == "__main__": - f = open("/tmp/base64img") - data = f.read() - f.close() - TEST_PARAMS = { - "heightmap" : "https%3A%2F%2Fwww.google.com%2Fimages%2Fsrpr%2Flogo11w.png" , - "imgdata" : data, - "texture" : "https%3A%2F%2Fwww.google.com%2Fimages%2Fsrpr%2Flogo11w.png", - "name" : "pepper", - } - b = Imlandscape(**TEST_PARAMS) - b.create(); - print b.filepath - - diff --git a/pb/landscape_other b/pb/landscape_other deleted file mode 100755 index 10e8ede..0000000 --- a/pb/landscape_other +++ /dev/null @@ -1,163 +0,0 @@ -#!/usr/bin/python2.7 -import cgi -import sys -import os -import re -import time -import string -import urllib -from subprocess import Popen, PIPE -import sha -import simplejson as json - -import mimetypes -import s3 - -import db -DB = db.db () - -import base64 -import urlparse - - -AWS_ACCESS_KEY_ID = 'AKIAIR53VPBXKJMXZIBA' -AWS_SECRET_ACCESS_KEY = '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' -BUCKET_NAME = 'i.asdf.us' -BASE_PATH = "/var/www/asdf.us/httpdocs/imlandscape" -BASE_URL = "http://i.asdf.us/" -PARAM_LIST = "heightmap texture name imgdata filename" -BIN_IDENTIFY = "/usr/bin/identify" - -print "Content-type: text/plain" -print "" -def insert_cmd (dir, newfile, name, texture, dataobj): - if texture == "": - texture = "NULL" - try: - sql = "INSERT INTO im_cmd (date,remote_addr,name,url,dir,oldfile,newfile,cmd, dataobj, tag) VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s, %s)" - - args = (now(), "NULL", name, texture, dir, "NULL", newfile, "NULL", dataobj, "imlandscape") - DB.execute(sql, args) - except (): - return - -def hash_dir (s): - return sha.new(s).hexdigest()[:2] - -def bin_identify (filename): - ident = Popen([BIN_IDENTIFY, filename], stdout=PIPE).communicate()[0] - partz = ident.split(" ") - width,height = partz[2].split("x") - return width, height - -def get_params (paramlist): - paramkeys = paramlist.split() - form = cgi.FieldStorage() - params = {} - for key in paramkeys: - if key in form: - if key == 'heightmap': - params[key] = form[key].value - elif key == 'imgdata': - params[key] = form[key].value - elif key == 'texture': - params[key] = form[key].value - else: - params[key] = sanitize(form[key].value) - else: - params[key] = None - return params - -def error (e): - print "#@imlandscape" - print "ERROR\t"+e - sys.exit() - -def now (): - return int(time.mktime(time.localtime())) - -def sanitize (str): - return re.sub(r'\W+', '', str) - -def filename_from_url (url, name=""): - if "?" in url: - url = url.split("?")[0] - if "/" in url: - url = urllib.unquote(url).replace(" ","") - filename = url.split("/")[-1] - filetype = "png" - filename = sanitize(filename[:-4]) - else: - filename = "" - if name != "": - name = name+"_" - return "{}_{}{}_{}.{}".format("imlandscape", name, filename,now(), "png") - -def saveImgData(url, filename): - try: - up = urlparse.urlparse(url) - head, data = up.path.split(',', 1) - bits = head.split(';') - mime_type = bits[0] if bits[0] else 'text/plain' - charset, b64 = 'ASCII', False - for bit in bits[1]: - if bit.startswith('charset='): - charset = bit[8:] - elif bit == 'base64': - b64 = True - - # Do something smart with charset and b64 instead of assuming - plaindata = base64.b64decode(data) - - with open(filename, 'wb') as f: - f.write(plaindata) - except Exception as e: - error(str(e)); - -def file_size (file): - return os.stat(file)[6] - -def moveToS3(filename,objectname): - conn = s3.AWSAuthConnection(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY) - sys.stderr.write( "Uploading %s" % filename) - filedata = open(filename, 'rb').read() - content_type = mimetypes.guess_type(filename)[0] - if not content_type: - content_type = 'text/plain' - conn.put(BUCKET_NAME, objectname, s3.S3Object(filedata), - {'x-amz-acl': 'public-read', 'Content-Type': content_type, 'x-amz-storage-class': 'REDUCED_REDUNDANCY'}) - -param = get_params(PARAM_LIST) -if param['imgdata'] is None: - error("no imgdata") -url = param['imgdata'] -if param['texture'] is None: - param['texture'] = ""; -if param['heightmap'] is None: - param['heightmap'] = ""; -if param['name'] is None: - param['name'] = ""; - -dataobj = json.dumps({ - 'texture' : param['texture'], - 'heightmap' : param['heightmap'], - 'name' : param['name'] -}) - -dir = hash_dir(param['imgdata']); - -filename = filename_from_url(param['texture'], param['name']); - -tag = "imlandscape" -objectname = "im/"+dir+"/"+filename - -saveImgData(param['imgdata'], filename); - -print "#@imlandscape" -#print ", ".join([k+"="+str(v) for k,v in param.iteritems()]) -print file_size (filename) -print bin_identify (filename) -print BASE_URL+objectname -insert_cmd(dir, filename, param['name'], param['texture'], dataobj); -moveToS3(filename, objectname); -os.remove(filename); diff --git a/pbserver_other.py b/pbserver_other.py deleted file mode 100755 index 30095d3..0000000 --- a/pbserver_other.py +++ /dev/null @@ -1,227 +0,0 @@ -#!/usr/bin/python2.7 -from bottle import route, run, post, request, static_file - -from pb.gradient import Gradient -from pb.imgrid import Imgrid -from pb.breaker import Breaker -from pb.pattern import Pattern -from pb.generate import Generate -from pb.imlandscape import Imlandscape - -from pb.config import AWS_SECRET_ACCESS_KEY, AWS_ACCESS_KEY_ID, BUCKET_NAME, BIN_IDENTIFY -import pb.lib.utils as utils - -import os -import sys -import pb.lib.db as db - -import sha -from subprocess import call, Popen, PIPE -import simplejson as json - -from boto.s3.connection import S3Connection -from boto.s3.key import Key -# -try: - DB = db.db () -except Exception as e: - sys.stderr.write("Could not connect to db:\n{}".format(e)) - sys.exit(1); -BASE_URL = "http://i.asdf.us" - -def hashdir(filename): - return sha.new(filename).hexdigest()[:2] - -def bin_identify (filepath): - ident = Popen([BIN_IDENTIFY, filepath], stdout=PIPE).communicate()[0] - partz = ident.split(" ") - width,height = partz[2].split("x") - return [ width, height ] - -def cleanup(filepath): - try: - call(['rm', filepath]) - except Exception as e: - sys.stderr.write(str(e)) - raise - -def s3move(filename,objectname): - try: - conn = S3Connection(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, is_secure=False) - b = conn.get_bucket(BUCKET_NAME) - k = Key(b) - k.key = objectname - k.set_contents_from_filename(filename) - k.set_acl('public-read') - k.storage_class = 'REDUCED_REDUNDANCY' - except Exception as e: - sys.stderr.write(str(e)); - raise(e) - -def insert_cmd (date, remote_addr, username, url, directory, oldfile, newfile, cmd, dataobj, tag): - try: - sql = "INSERT INTO im_cmd " - sql += "(date, remote_addr, name, url, dir, oldfile, newfile, cmd, dataobj, tag) " - sql += "VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)" - #or "NULL" - args = (date, remote_addr, username, url, directory, oldfile, newfile, cmd, dataobj, tag) - #args = (now(), os.environ['REMOTE_ADDR'], name, url, dir, oldfile, newfile, " ".join(cmd),dataobj) - DB.execute(sql, args) - except Exception as e: - sys.stderr.write(str(e)) - return - - -def format_im_data(im, insert_url="NULL"): - directory = hashdir(im.filename) - dimensions = bin_identify(im.filepath) - size = utils.file_size(im.filepath) - objectname = "im/{}/{}".format(directory, im.filename) - try: - s3move(im.filepath, objectname) - cleanup(im.filepath) - insert_cmd( - im.now, - request.environ.get('REMOTE_ADDR'), - im.params['username'] or "NULL", - insert_url, - directory, - "NULL", - im.filename, - ";".join(im.commands), - json.dumps(im.params), - im.tag, - ) - return json.dumps({ - 'url' : "{}/{}".format(BASE_URL, objectname), - 'size' : size, - 'width' : "{}px".format(dimensions[0]), - 'height' : "{}px".format(dimensions[1]), - }) - except Exception as e: - sys.stderr.write(str(e)) - raise; - - -def return_image(im, insert_url="NULL"): - return format_im_data(im, insert_url) - - -def return_jsonp(im, insert_url="NULL"): - return "{}({})".format(im.get("callback"), format_im_data(im, insert_url)) - - -@post('/im/api/imgradient') -def gradient(): - try: - im = Gradient(**(dict(request.forms))) - im.create(); - return return_image(im) - except Exception as e: - sys.stderr.write("imgradient failure\n") - sys.stderr.write("params:\n") - for i in request.forms: - sys.stderr.write("{}:{}\n".format(i, request.forms[i])) - raise; - return json.dumps({ 'error' : 'Request could not be processed' }) - -@post('/im/api/imgrid') -def imgrid(): - try: - im = Imgrid(**(dict(request.forms))) - im.create(); - url= "NULL" - for elem in [ im.params.imageinstead , im.params.bgimage, im.params.planebgimage ]: - if elem: - url = elem['url'] - break - return return_image(im, url) - except Exception as e: - sys.stderr.write(str(e)) - return json.dumps({ 'error' : 'Request could not be processed' }) - -@post('/im/api/generate') -def generate(): - try: - im = Generate(**(dict(request.forms))) - im.create(); - return return_image(im) - except Exception as e: - sys.stderr.write(str(e)) - return json.dumps({ 'error' : 'Request could not be processed' }) - -@post('/im/api/imbreak') -def breaker(): - try: - im = Breaker(**(dict(request.forms))) - im.create(); - return return_image(im, im.params['url']) - except Exception as e: - sys.stderr.write(str(e)) - return json.dumps({ 'error' : 'Request could not be processed' }) - -@post('/im/api/impattern') -def pattern(): - try: - im = Pattern(**(dict(request.forms))) - im.create(); - return return_image(im, im.params['image_url']) - except Exception as e: - sys.stderr.write(str(e)+"\n") - for i in request.forms: - sys.stderr.write("{}:{}\n".format(i, request.forms[i])) - raise; - return json.dumps({ 'error' : 'Request could not be processed' }) - -<<<<<<< HEAD -#static routes -@route('/im/<filename>') -def server_static(filename): - return static_file(filename, root='frontend/im/') -@route('/im') -def server_static(): - return static_file("index.html", root='frontend/im/') -@route('/imgrid') -def server_static(): - return static_file("index.html", root='frontend/imgrid/') -@route('/imgradient') -def server_static(): - return static_file("index.html", root='frontend/imgradient/') -@route('/imlandscape') -def server_static(): - return static_file("index.html", root='frontend/imlandscape/') -@route('/impattern') -def server_static(): - return static_file("index.html", root='frontend/impattern/') -@route('/imbreak') -def server_static(): - return static_file("index.html", root='frontend/imbreak/') -@route('/') -def server_static(): - return static_file("index.html", root='frontend/im/') -@route('/css/<filename>') -def server_static(filename): - return static_file(filename, root='frontend/css/') -@route('/js/<filename>') -def server_static(filename): - return static_file(filename, root='frontend/js/') -@route('/img/<filename>') -def server_static(filename): - return static_file(filename, root='frontend/img/') - - -#run(host='0.0.0.0', server='flup', port=8999, debug=True) -run(host='0.0.0.0', port=8999, debug=True) -======= -@post('/im/api/imlandscape') -def imlandscape(): - try: - im = Imlandscape(**(dict(request.forms))) - im.create(); - sys.stderr.write(str(im.params)) - return return_image(im, im.params['texture']) - except Exception as e: - sys.stderr.write(str(e)) - return json.dumps({ 'error' : 'Request could not be processed' }) -run(host='0.0.0.0', server='flup', port=8999, debug=True) ->>>>>>> 8c860adf26be12d230cd146c6aae85efcb163a24 |
