def view_orders_create(environ): """ Form to create a new order. """ user = environ["emapps.user"] if not user.is_authenticated(): return kgi.html_response( unauthorized(user, 'You need to log in to the forums.') ) if environ["REQUEST_METHOD"] == "POST": form = cgi.FieldStorage() ordertext = form.getfirst("ordertext", None) source = form.getfirst("source", None) comment = form.getfirst("comment", "") comment = comment.strip() if comment == "": comment = None if None in (ordertext, source): return kgi.redirect_response('http://www.electusmatari.com/market/order/create/') sql_create_order(user.username, ordertext, source, comment) return kgi.redirect_response('http://www.electusmatari.com/market/order/') return kgi.template_response('market/order_create.html', user=environ["emapps.user"], sources=SOURCES )
def view_info(environ): """ Show authentication status. """ user = environ["emapps.user"] if not user.is_authenticated(): return kgi.html_response( unauthorized(user, 'You need to log in to the forums.') ) db = kgi.connect('dbforcer') c = db.cursor() c.execute("SELECT last_attempt, message, authenticated, disabled " "FROM auth_user WHERE username = %s LIMIT 1", (user.username,)) if c.rowcount == 1: (last_attempt, message, authenticated, disabled) = c.fetchone() else: (last_attempt, message, authenticated, disabled) = (None, None, None, None) return kgi.template_response('auth/info.html', user=user, last_attempt=last_attempt, message=message, authenticated=authenticated, disabled=disabled)
def handler(environ, *args, **kwargs): user = environ['emapps.user'] if not user.has_permission(permission): return kgi.html_response( unauthorized(user, 'You are not an admin.') ) else: return func(environ, *args, **kwargs)
def view_oplist(environ): import simplejson as json db = kgi.connect('dbforcer') c = db.cursor() c.execute("SELECT id, created, title FROM opwarn_list " "WHERE created > NOW() - INTERVAL 1 HOUR " "ORDER BY created DESC LIMIT 1") if c.rowcount == 0: return kgi.html_response(json.dumps({}), header=[('Content-Type', 'application/json')] ) (id, created, title) = c.fetchone() delta = datetime.datetime.utcnow() - created return kgi.html_response(json.dumps({'id': id, 'created': eve_time(created), 'seconds': delta.seconds, 'title': title}), header=[('Content-Type', 'application/json')] )
def handler(environ, *args, **kwargs): user = environ['emapps.user'] if require_admin and not user.has_permission('corpadmin'): return kgi.html_response( unauthorized(user, 'You are not an admin.') ) db = kgi.connect('dbdjango') c = db.cursor() c.execute("SELECT corp FROM emauth_profile " "WHERE mybb_username = %s AND active", (user.username,)) if c.rowcount == 0: return kgi.html_response( unauthorized(user, 'You are not API authenticated.') ) corpname = c.fetchone()[0] if corpname != 'Gradient': return kgi.html_response( unauthorized(user, 'You are not in Gradient.') ) return func(environ, *args, **kwargs)
def standings_check(environ): user = environ['emapps.user'] if not user.has_permission(environ["org"]): return kgi.html_response( unauthorized(user, 'You are not authorized.') ) tids = {} bogus = [] to_set = [] to_diplo = [] to_act = {} now = datetime.datetime.utcnow() for (tid, subject, edittime, prefix, editor) in get_threads(standings_forums[environ["org"]]): try: edittime = datetime.datetime.utcfromtimestamp(edittime) except: edittime = now p = parse_subject(subject) if p is None: bogus.append((subject, tid)) else: (entity, ticker, standing, comments, internal) = p tids.setdefault(entity, []) tids[entity].append((subject, tid)) if prefix in PREFIX_TOSET: age = (now - edittime).days to_set.append((subject, tid, age)) elif prefix in PREFIX_DIPLO: age = (now - edittime).days to_diplo.append((subject, tid, age)) elif prefix in PREFIX_ACT: age = (now - edittime).days if editor is None: editor = "None?" to_act.setdefault(editor, []) to_act[editor].append((subject, tid, age)) dups = [] for (entity, threads) in tids.items(): if len(threads) > 1: dups.append((entity, threads)) bogus.sort() dups.sort() to_act = to_act.items() to_act.sort(lambda a, b: cmp((a[0].lower(), a[1]), (b[0].lower(), b[1]))) return kgi.template_response('standings/check.html', user=environ["emapps.user"], current_time=eve_time(), to_diplo=to_diplo, to_set=to_set, to_act=to_act, bogus=bogus, dups=dups)
def view_sales_rss(environ): """ RSS feed of all active sell orders """ import PyRSS2Gen as RSS2 rss = RSS2.RSS2( title='Electus Market', link='http://www.electusmatari.com/market/', description='Alliance offers', lastBuildDate=datetime.datetime.now(), items = [ RSS2.RSSItem( title=sale.item, link="http://www.electusmatari.com/market/", description="%s ISK<br />%s" % (humane(sale.price), sale.comment), guid=RSS2.Guid(str(sale.id)), pubDate=sale.created) for sale in get_sales(sortby="age")] ) return kgi.html_response(rss.to_xml(), header=[('Content-Type', 'application/rss+xml')])
def view_auth(environ): """ User authentication form. Update details. """ user = environ["emapps.user"] if not user.is_authenticated(): return kgi.html_response( unauthorized(user, 'You need to log in to the forums.') ) if environ["REQUEST_METHOD"] == 'POST': form = cgi.FieldStorage() username = user.username userid = form.getfirst("userid", None) apikey = form.getfirst("apikey", None) if userid == '' or userid is None: (userid, apikey) = get_apikey(username) update_allies() try: update_user(username, userid, apikey) except Exception, e: return kgi.template_response('auth/error.html', user=user, error=str(e)) return kgi.redirect_response('http://www.electusmatari.com/auth/')
def view_gallery(environ, path): user = environ['emapps.user'] gallerydir = os.path.normpath(os.path.join(BASEDIR, path)) breadcrumbs = make_breadcrumbs(path) if not gallerydir.startswith(BASEDIR): return kgi.html_response( unauthorized(user, 'File or directory does not exist.') ) if os.path.isdir(gallerydir): if path != "" and not path.endswith("/"): return kgi.redirect_response('http://www.electusmatari.com/gallery/' + path + '/') (series, images, thumbs) = get_album(gallerydir) return kgi.template_response('gallery/index.html', user=user, current_time=eve_time(), breadcrumbs=breadcrumbs, series=series, images=images, thumbs=thumbs ) elif os.path.isfile(gallerydir): if gallerydir.endswith(".png"): ct = "image/png" elif gallerydir.endswith(".jpg"): ct = "image/jpeg" else: ct = "application/binary" return kgi.html_response(file(gallerydir).read(), header=[('Content-Type', ct), ('Cache-Control', 'max-age=604800')]) else: imagefile = None for ext in [".png", ".jpg"]: if os.path.isfile(gallerydir + ext): (seriesdir, imagename) = os.path.split(gallerydir) imagefile = imagename + ext if os.path.isfile(gallerydir + "_preview" + ext): imagepreviewfile = imagename + "_preview" + ext else: imagepreviewfile = imagefile break if imagefile is None: return kgi.template_response('404.html', status='404 Not Found') if environ["REQUEST_METHOD"] == 'POST': form = cgi.FieldStorage() comment = form.getfirst("comment") add_comment(path, user.username, comment) return kgi.redirect_response('http://www.electusmatari.com/gallery/' + path) (series, images, thumbs) = get_album(seriesdir) thisindex = images.index(imagename) if thisindex > 0: prev = images[thisindex - 1] else: prev = None if thisindex + 1 < len(images): next = images[thisindex + 1] else: next = None return kgi.template_response('gallery/image.html', user=user, current_time=eve_time(), breadcrumbs=breadcrumbs, imagename=imagename, imagefile=imagefile, imagepreviewfile=imagepreviewfile, prev=prev, next=next, comments=get_comments(path), )