def browsers(request): """ Shows list of all browsers. """ ret = {} custom_log(request, "Admin: list of browsers") ret["entries"] = paginate(request, Browser.objects.all()) return render_to_response("admin_frontend/browsers.html", ret, context_instance=RequestContext(request))
def logs(request, **kwargs): """ Shows log entries for browser, user or for all users """ ret = {} custom_log(request, "Admin: logs") bid_public = kwargs.get("bid_public") username = kwargs.get("username") if bid_public: entries = Log.objects.filter(bid_public=bid_public) username = None try: ret["abrowser"] = Browser.objects.get(bid_public=bid_public) if ret["abrowser"].user: username = ret["abrowser"].user.username except Browser.DoesNotExist: ret["missing_browser"] = True custom_log(request, "Admin: entries for %s (%s)" % (bid_public, username)) elif username: ret["auser"] = get_object_or_404(User, username=username) entries = Log.objects.filter(user=ret["auser"]) custom_log(request, "Admin: entries for %s" % username) else: custom_log(request, "Admin: all entries") entries = Log.objects.all() ret["entries"] = paginate(request, entries) return render_to_response("admin_frontend/logs.html", ret, context_instance=RequestContext(request))
def logins(request): """ Shows list of active logins for all users. """ ret = {} custom_log(request, "Admin: list of active logins") entries = BrowserLogin.objects.filter(signed_out=False).filter(expires_at__gte=timezone.now()) ret["entries"] = paginate(request, entries) return render_to_response("admin_frontend/logins.html", ret, context_instance=RequestContext(request))
def yubikeys(request): """ Shows list of configured Yubikeys """ ret = {} custom_log(request, "Admin: list of Yubikeys") entries = Yubikey.objects.all() ret["entries"] = paginate(request, entries) return render_to_response("admin_frontend/yubikeys.html", ret, context_instance=RequestContext(request))
def users(request): """ Returns list of users. """ custom_log(request, "Admin: users") ret = {} entries = User.objects.all().order_by('username') ret["entries"] = paginate(request, entries) return render_to_response("admin_frontend/users.html", ret, context_instance=RequestContext(request))
def view_log(request, **kwargs): """ Shows log entries to the user """ ret = {} browsers = {} ret["browsers"] = [] list_of_browsers = Log.objects.filter(user=request.browser.user).order_by( "bid_public").values("bid_public").distinct() for item in list_of_browsers: try: browser_item = Browser.objects.get(bid_public=item["bid_public"]) except Browser.DoesNotExist: continue browsers[item["bid_public"]] = browser_item ret["browsers"].append(browser_item) entries = Log.objects.filter( user=request.browser.user).order_by("-timestamp") bid_public = kwargs.get("bid_public") if bid_public: entries = entries.filter(bid_public=bid_public) try: ret["this_browser"] = Browser.objects.get(bid_public=bid_public) except Browser.DoesNotExist: pass entries = paginate(request, entries) for entry in entries: browser = browsers.get(entry.bid_public) if not browser: try: browser = Browser.objects.get(bid_public=entry.bid_public) browsers[entry.bid_public] = browser except Browser.DoesNotExist: pass entry.browser = browser ret["entries"] = entries response = render_to_response("login_frontend/view_log.html", ret, context_instance=RequestContext(request)) return response
def view_log(request, **kwargs): """ Shows log entries to the user """ ret = {} browsers = {} ret["browsers"] = [] list_of_browsers = Log.objects.filter(user=request.browser.user).order_by("bid_public").values("bid_public").distinct() for item in list_of_browsers: try: browser_item = Browser.objects.get(bid_public=item["bid_public"]) except Browser.DoesNotExist: continue browsers[item["bid_public"]] = browser_item ret["browsers"].append(browser_item) entries = Log.objects.filter(user=request.browser.user).order_by("-timestamp") bid_public = kwargs.get("bid_public") if bid_public: entries = entries.filter(bid_public=bid_public) try: ret["this_browser"] = Browser.objects.get(bid_public=bid_public) except Browser.DoesNotExist: pass entries = paginate(request, entries) for entry in entries: browser = browsers.get(entry.bid_public) if not browser: try: browser = Browser.objects.get(bid_public=entry.bid_public) browsers[entry.bid_public] = browser except Browser.DoesNotExist: pass entry.browser = browser ret["entries"] = entries response = render_to_response("login_frontend/view_log.html", ret, context_instance=RequestContext(request)) return response