def onion_up(request, onion): """Test if onion domain is up add get description if there is one.""" try: hs = HiddenWebsite.objects.get(id=onion) except ObjectDoesNotExist: answer = "There is no "+onion+" indexed. Please add it if it exists." return HttpResponseNotFound(answer) if request.method == 'PUT': # and request.user.is_authenticated(): ip_addr = helpers.get_client_ip(request) if not str(ip_addr) in "127.0.0.1": answer = "Only allowed form the localhost." return HttpResponseForbidden(answer) else: remove_historical_descriptions(onion) if request.body: try: json_data = request.body return add_info(json_data, onion) except Exception as error: return HttpResponseBadRequest(error) else: remove_offline_services(onion) return HttpResponse(onion + ".onion is offline") elif request.method == 'GET': #is this http server been online within 7 days if hs.online: return HttpResponse("up") else: return HttpResponse("down")
def onion_popularity(request, onion): """Return the popularity statistics of an onion.""" if request.method == 'GET': try: hs = HiddenWebsite.objects.get(id=onion) except ObjectDoesNotExist: answer = "There is no %s.onion indexed." % onion return HttpResponseNotFound(answer) try: popularity = HiddenWebsitePopularity.objects.get(about=hs) except ObjectDoesNotExist: answer = "No popularity data about %s.onion." % onion return HttpResponseNotFound("No popularity data about %s.onion.") if hs.banned: return HttpResponseForbidden("This page is banned.") template = loader.get_template('onion_popularity.json') content = Context({'popularity': popularity}) type_str = "application/json" return HttpResponse(template.render(content), content_type=type_str) elif request.method == 'PUT': # Allow PUT data only from the localhost ip_addr = helpers.get_client_ip(request) if not str(ip_addr) in "127.0.0.1" or not "127.0.0.1" in str(request.get_host()): return HttpResponseForbidden(answer) else: # Add new data data = request.body return add_popularity(data, onion)
def onion_up(request, onion): """Test if onion domain is up add get description if there is one.""" try: hs = HiddenWebsite.objects.get(id=onion) except ObjectDoesNotExist: answer = "There is no " + onion + " indexed. Please add it if it exists." return HttpResponseNotFound(answer) if request.method == 'PUT': # and request.user.is_authenticated(): ip_addr = helpers.get_client_ip(request) if not str(ip_addr) in "127.0.0.1": answer = "Only allowed form the localhost." return HttpResponseForbidden(answer) else: remove_historical_descriptions(onion) if request.body: try: json_data = request.body return add_info(json_data, onion) except Exception as error: return HttpResponseBadRequest(error) else: remove_offline_services(onion) return HttpResponse(onion + ".onion is offline") elif request.method == 'GET': #is this http server been online within 7 days if hs.online: return HttpResponse("up") else: return HttpResponse("down")
def banned_domains_plain(request): """Return the plain text list of banned onions.""" # Allow requests only from the localhost ip_addr = helpers.get_client_ip(request) if not str(ip_addr) in "127.0.0.1" or not "127.0.0.1" in str(request.get_host()): answer = "Only allowed form the localhost." return HttpResponseForbidden(answer) sites = HiddenWebsite.objects.filter(banned=True) url_list = [] for site in sites: url_list.append(site.url+"\n") return StreamingHttpResponse(url_list, content_type="text/plain")
def all_onions_txt(request): """Return a plain text list of onions including the banned ones.""" # Allow requests only from the localhost ip_addr = helpers.get_client_ip(request) if not str(ip_addr) in "127.0.0.1" or not "127.0.0.1" in str(request.get_host()): answer = "Only allowed form the localhost." return HttpResponseForbidden(answer) sites = HiddenWebsite.objects.all().order_by('url') site_list = [] for site in sites: site_list.append(site.url+"\n") return StreamingHttpResponse(site_list, content_type="text/plain")