Beispiel #1
0
def application(environ, start_response):
    # cwd gets set to /, which is annoying :(
    cwd = os.path.dirname(__file__)
    sys.path.insert(0, cwd)
    import util_regexes
    from util_baseconvert import base32_to_base16
    from util_baseconvert import base16_to_base32
    from util_http import http_response
    import conf

    # Setup our output
    output = http_response(environ, start_response)
    sys.stdout = output
    wsgi_errors = environ['wsgi.errors']

    # Get the hash
    QUERY = environ.get('QUERY_STRING', '')
    if not util_regexes.base16_or_32.match(QUERY):
        return output.user_failure(
            "No hash supplied, or invalid hash format. hash=%s" % QUERY)

    # Send a redirection header
    # We just dumbly assume jpeg
    return output.redirect("%st%s.jpg" %
                           (conf.THUMB_URLBASE, base32_to_base16(QUERY)))
Beispiel #2
0
def application(environ, start_response):
	# cwd gets set to /, which is annoying :(
	cwd = os.path.dirname(__file__)
	sys.path.insert(0, cwd)
	import util_regexes
	from util_baseconvert import base32_to_base16
	from util_baseconvert import base16_to_base32
	from util_http import http_response
	import conf

	# Setup our output
	output = http_response(environ, start_response)
	sys.stdout = output
	wsgi_errors = environ['wsgi.errors']

	# Get the hash
	QUERY = environ.get('QUERY_STRING', '')
	if not util_regexes.base16_or_32.match(QUERY):
		return output.user_failure("No hash supplied, or invalid hash format. hash=%s" % QUERY)

	# Send a redirection header
	# We just dumbly assume jpeg
	return output.redirect("%sm%s.jpg" % (conf.MID_URLBASE, base32_to_base16(QUERY)))
Beispiel #3
0
# New-style config
import frontend_config
config = frontend_config.get_config_for_hostname(
    os.environ.get('SERVER_NAME', 'NO_HOSTNAME'))

# Automatically close the HTML cleanly, whether we finish normally, or halfway through something
import atexit
atexit.register(meidokon_html_footers)

# Import form data
form = cgi.FieldStorage()

mode = form.getfirst("mode", "").lower()

items_to_tag = set([
    base32_to_base16(x) for x in form.getlist("hashes")
    if util_regexes.base16_or_32.search(x)
])
items_to_tag = list(items_to_tag)

tag_string = form.getfirst("tag_string", "")
keywords = util_regexes.chunkify_tag_input(tag_string)

# Handle adverse conditions
if len(items_to_tag) == 0:
    http_error(400, "No valid hashes were supplied")

if len(keywords) < 1:
    http_error(400, "No tags were given for revision")

if mode not in ["add", "replace", "remove"]:
Beispiel #4
0
# Automatically close the HTML cleanly, whether we finish normally, or halfway through something
import atexit
atexit.register(meidokon_html_footers)

# If the user passes a cookie specifying another content server, use it
# Expects util_general to be imported as `from X import Y`
full_resolver = get_value_from_cookie('full_resolver')
mid_resolver = get_value_from_cookie('mid_resolver')
thumb_resolver = get_value_from_cookie('thumb_resolver')

# Deal with POSTed hashes, which are the result of mark-and-tag from the index page
form = cgi.FieldStorage()
hashes = set()
for one_hash in form.getlist("hashes"):
    if util_regexes.base16_or_32.search(one_hash):
        hashes.add(base32_to_base16(one_hash))
# Throw in a hash sent as the QUERY_STRING
query_string = os.environ.get('QUERY_STRING', '')
if util_regexes.base16_or_32.search(query_string):
    hashes.add(base32_to_base16(query_string))
# It's now more convenient to index into hashes
hashes = list(hashes)

if len(hashes) == 0:
    http_error(400, "No valid hashes were supplied")

if len(hashes) == 1:
    page_title = "Edit tags for %s" % hashes[0]
else:
    page_title = "Edit tags for multiple files"
Beispiel #5
0
from util_errors import gen_error
from util_errors import HOMEPAGE_LINK
from util_html import meidokon_html_headers
from util_html import meidokon_html_footers

# New-style config
import frontend_config
config = frontend_config.get_config_for_hostname(os.environ.get('SERVER_NAME', 'NO_HOSTNAME'))

# Automatically close the HTML cleanly, whether we finish normally, or halfway through something
import atexit
atexit.register(meidokon_html_footers)


form = cgi.FieldStorage()
hashes = set([base32_to_base16(x) for x in form.getlist("hashes") if util_regexes.base16_or_32.search(x)])
hashes = list(hashes)
password = form.getfirst("password", "")

if len(hashes) == 0:
        http_error(400, "No valid hashes were supplied")


print "Content-Type: text/html"
print '''P3P: policyref="/w3c/privacy.p3p", CP=""'''
print ""
meidokon_html_headers("File deletion")

print """<div style="position:fixed; left:1em; top:1em; border:1px dotted"><a href="%s">Go home</a></div>""" % HOMEPAGE_LINK

print """<h3>Deleting:</h3><div><ul class="tag_tree">"""
Beispiel #6
0
atexit.register(meidokon_html_footers)


# If the user passes a cookie specifying another content server, use it
# Expects util_general to be imported as `from X import Y`
full_resolver = get_value_from_cookie('full_resolver')
mid_resolver = get_value_from_cookie('mid_resolver')
thumb_resolver = get_value_from_cookie('thumb_resolver')


# Deal with POSTed hashes, which are the result of mark-and-tag from the index page
form = cgi.FieldStorage()
hashes = set()
for one_hash in form.getlist("hashes"):
	if util_regexes.base16_or_32.search(one_hash):
		hashes.add(base32_to_base16(one_hash))
# Throw in a hash sent as the QUERY_STRING
query_string = os.environ.get('QUERY_STRING', '')
if util_regexes.base16_or_32.search(query_string):
	hashes.add(base32_to_base16(query_string))
# It's now more convenient to index into hashes
hashes = list(hashes)


if len(hashes) == 0:
	http_error(400, "No valid hashes were supplied")

if len(hashes) == 1:
	page_title = "Edit tags for %s" % hashes[0]
else:
	page_title = "Edit tags for multiple files"