def group(request, group): if not CONFIG.valid(group): return never_cache_redirect_to(request, url="/") fixed_group = group.replace('-', '_') config = CONFIG.config(group) template = request.GET.get('template', 'group') if not re.match('[a-z]+', template): # Is the request coming from the room? for ipregex in LOCALIPS: if re.match(ipregex, request.remote_addr): template = 'inroom' break else: return never_cache_redirect_to(request, url="/") screenstr = request.GET.get('screen', 'False') if screenstr.lower()[0] in ('y', 't'): screen = True else: screen = False return render_to_response('%s.html' % template, locals())
def client_common(request, group): """Check the common information for an client request.""" if request.method != "POST": return (never_cache_redirect_to(request, url="/"), None, None) response = http.HttpResponse(content_type="application/javascript") if not CONFIG.valid(group): response.write(simplejson.dumps({"code": error.ERROR_GROUP, "error": "Unknown group", "next": -1})) return (response, None, None) # Check the cookie value exists if "user" not in request.COOKIES: response.set_cookie("user", value=user_key(request)) response.write(simplejson.dumps({"code": error.WARNING_COOKIE, "error": "No cookie set", "next": 0})) return (response, None, None) # Check the cookie value is valid salt, digest = request.COOKIES["user"].split(":") if user_key(request, salt) != request.COOKIES["user"]: response.delete_cookie("user") response.write(simplejson.dumps({"code": error.WARNING_COOKIE, "error": "Cookie was invalid?", "next": 0})) return (response, None, None) return (None, group, request.COOKIES["user"])
def logs(request, group): if not CONFIG.valid(group): return never_cache_redirect_to(request, url="/") config = CONFIG.config(group) log = config['irclog'] soup = BeautifulSoup(urllib2.urlopen(log).read()) body = soup.find("body") body['style'] = "background: transparent;" # Fix up the css link l = soup.find("link") l['href'] = "%s/%s" % (os.path.dirname(log), l['href']) # Remove the unwanted decoration. [x.decompose() for x in soup.find_all("div", {"class": "navigation"})] [x.decompose() for x in soup.find_all("div", {"class": "generatedby"})] [x.decompose() for x in soup.find_all("h1")] [x.decompose() for x in soup.find_all("div", {"class": "searchbox"})] # Reverse the table rows. table = soup.find("table") new_order = [] for row in list(table.children): new_order.insert(0, row.extract()) for row in new_order: table.append(row) table['style'] = "font-size: 8pt;" response = http.HttpResponse(content_type='text/html') response.write(soup) return response
def encoder_common(request): """Check the common information for an encoder request.""" if request.method != "POST": return never_cache_redirect_to(request, url="/") response = http.HttpResponse(content_type="text/plain") if not CONFIG["config"].get("secret", None): response.write("ERROR CONFIG (No secret)\n") return response, None, None secret = request.POST.get("secret", "") if secret != CONFIG["config"]["secret"]: response.write("ERROR SECRET\n") return response, None, None group = request.POST.get("group", "") if not CONFIG.valid(group): response.write("ERROR GROUP\n") return response, None, None ip = request.META["HTTP_X_REAL_IP"] return None, group, ip