Ejemplo n.º 1
0
def adminSessionsPost(handler, p_key, p_action, p_value = None):
	handler.title('Sessions')
	requirePriv(handler, 'Admin')
	print "<script src=\"/static/admin-sessions.js\" type=\"text/javascript\"></script>"

	if not p_key in Session.getIDs():
		ErrorBox.die("Retrieve session", "No session exists with key <b>%s</b>" % stripTags(p_key))
	session = Session.load(p_key)

	for case in switch(p_action):
		if case('reassign'):
			handler.title('Reassign Session')
			if p_value:
				user = User.load(int(p_value))
				if not user:
					ErrorBox.die("Load user", "No user exists with ID <b>%s</b>" % stripTags(p_value))
				session['user'] = user
				redirect('/admin/sessions')
			else:
				print "<form method=\"post\" action=\"/admin/sessions\">"
				print "<input type=\"hidden\" name=\"action\" value=\"reassign\">"
				print "<input type=\"hidden\" name=\"key\" value=\"%s\">" % p_key
				print "<select id=\"selectUser\" name=\"value\">"
				for user in sorted(User.loadAll()):
					print "<option value=\"%d\">%s</option>" % (user.id, user.safe.username)
				print "</select><br>"
				print Button('Reassign', type = 'submit').positive()
				print Button('Cancel', id = 'cancel-button', type = 'button', url = '/admin/sessions').negative()
				print "</form>"
				break
		if case('destroy'):
			Session.destroy(p_key)
			redirect('/admin/sessions')
			break
		break
Ejemplo n.º 2
0
def oldSessions():
	ids = Session.getIDs()
	print "Processing %s<br><br>" % pluralize(len(ids), 'session', 'sessions')
	toDelete = []
	now = getNow()
	for key in ids:
		session = Session.load(key)
		age = (now - session['timestamp']) if session['timestamp'] else None

		if session['user']:
			if not age or age.days >= 7: # Logged-in sessions dead for a week
				toDelete.append(key)
				print "<div style=\"color: #a00;\"><b>%s</b>: queued for deletion (owned by %s, age: %s)</div>" % (key, session['user'], age or '&#8734;')
			else:
				print "<div style=\"color: #0a0;\"><b>%s</b>: retained (owned by %s, age: %s)</div>" % (key, session['user'], age)
		else:
			if not age or age.days >= 1: # Anonymous sessions dead for a day
				toDelete.append(key)
				print "<div style=\"color: #a00;\"><b>%s</b>: queued for deletion (anonymous %s, age: %s)</div>" % (key, session['address'] or 'unknown', age or '&#8734;')
			else:
				print "<div style=\"color: #0a0;\"><b>%s</b>: retained (anonymous %s, age: %s)</div>" % (key, session['address'] or 'unknown', age)

	print "<br>Deleting %s... " % pluralize(len(toDelete), 'session', 'sessions'),
	for key in toDelete:
		Session.destroy(key)
	print "done"
Ejemplo n.º 3
0
def adminSessions(handler, username = None):
	handler.title("Sessions for %s" % stripTags(username) if username else "Sessions")
	requirePriv(handler, 'Admin')

	undelay(handler)

	def cmpSessionTimes(s1, s2):
		if 'timestamp' in s1 and 'timestamp' in s2:
			return cmp(s1['timestamp'], s2['timestamp'])
		elif 'timestamp' in s1:
			return 1
		elif 'timestamp' in s2:
			return -1
		else:
			return 0

	print "<table border=0 cellspacing=4>"
	print "<tr><th>Key</th><th>User</th><th>Last address</th><th>Last seen</th><th>&nbsp;</th></tr>"
	sessions = {sessionID: Session.load(sessionID) for sessionID in Session.getIDs()}
	for key, session in sorted(sessions.iteritems(), lambda (k1, s1), (k2, s2): cmpSessionTimes(s1, s2), reverse = True):