def listings(request): errmsg = "" if "q" in request.GET.keys() and len(request.GET["q"]) != 0: s = Search( model=Listing(), fields={ "ip": "ip__ip", "reason": "reason__reason", "sensor": "sensor__name", "sensor_host": "sensor_host__hostname", "timestamp": "timestamp", "duration": "duration__duration", "reporter": "reporter", } ) (result, listing_data) = s.find(request.GET["q"]) if not result: errmsg = listing_data, (result, listing_data) = listing.all() else: (result, listing_data) = listing.all() if not result: return HttpResponseRedirect("/") try: page = int(request.GET.get('page', '1')) except: page = 1 listing_table = ListingTable( listing_data, order_by=request.GET.get('sort', 'title') ) if request.method == "GET": search_form = SearchForm(request.GET) else: search_form = SearchForm() return render_to_response("listing/overview.html", { "errmsg": errmsg, "search_form": search_form, "listing_table": listing_table, }, context_instance=RequestContext(request))
def listings(request): errmsg = "" if "q" in request.GET.keys() and len(request.GET["q"]) != 0: s = Search(model=Listing(), fields={ "ip": "ip__ip", "reason": "reason__reason", "sensor": "sensor__name", "sensor_host": "sensor_host__hostname", "timestamp": "timestamp", "duration": "duration__duration", "reporter": "reporter", }) (result, listing_data) = s.find(request.GET["q"]) if not result: errmsg = listing_data, (result, listing_data) = listing.all() else: (result, listing_data) = listing.all() if not result: return HttpResponseRedirect("/") try: page = int(request.GET.get('page', '1')) except: page = 1 listing_table = ListingTable(listing_data, order_by=request.GET.get('sort', 'title')) if request.method == "GET": search_form = SearchForm(request.GET) else: search_form = SearchForm() return render_to_response("listing/overview.html", { "errmsg": errmsg, "search_form": search_form, "listing_table": listing_table, }, context_instance=RequestContext(request))
def whitelistings(request): errmsg = "" if "q" in request.GET.keys() and len(request.GET["q"]) != 0: s = Search( model=WhiteListing(), fields={ "ip": "ip__ip", "hostname": "hostname", } ) (result, whitelist_data) = s.find(request.GET["q"]) if not result: errmsg = whitelist_data (result, whitelist_data) = whitelisting.all() else: (result, whitelist_data) = whitelisting.all() if not result: return HttpResponseRedirect("/") try: page = int(request.GET.get('page', '1')) except: page = 1 whitelist_table = WhiteListingTable( whitelist_data, order_by=request.GET.get('sort', 'title') ) if request.method == "GET": search_form = SearchForm(request.GET) else: search_form = SearchForm() return render_to_response("whitelist/overview.html", { "errmsg": errmsg, "search_form": search_form, "whitelist_table": whitelist_table, }, context_instance=RequestContext(request))
#!/usr/bin/env python import sys import os.path import os sys.path.append("/www/blacklist/app") os.environ["DJANGO_SETTINGS_MODULE"] = "settings" from blacklist.common.search import Search from blacklist.middleware.subnet import Subnet if __name__ == "__main__": s = Search( model=Subnet(), fields={ "subnet": "subnet", "mask": "mask", "last": "last", "provider": "asnum__name", "af": "af", "code": "country__code", "country": "country__name", "rir": "rir__name", "regdate": "regdate", "listed": "listed", "whitelisted": "whitelisted", } ) print s.find("subnet=213.154.229.25 or rir=afrinic")
#!/usr/bin/env python import sys import os.path import os sys.path.append("/www/blacklist/app") os.environ["DJANGO_SETTINGS_MODULE"] = "settings" from blacklist.common.search import Search from blacklist.middleware.subnet import Subnet if __name__ == "__main__": s = Search(model=Subnet(), fields={ "subnet": "subnet", "mask": "mask", "last": "last", "provider": "asnum__name", "af": "af", "code": "country__code", "country": "country__name", "rir": "rir__name", "regdate": "regdate", "listed": "listed", "whitelisted": "whitelisted", }) print s.find("subnet=213.154.229.25 or rir=afrinic")
def countries(request): errmsg = "" listing_changed = False whitelisting_changed = False for item in request.GET.keys(): if item.startswith("id_"): (result, cc) = country.get(id=item[3:]) if result: if request.GET["bulk_action"] == "blacklist": cc.listed = not cc.listed listing_changed = True if cc.whitelisted: cc.whitelisted = False whitelisting_changed = True elif request.GET["bulk_action"] == "whitelist": cc.whitelisted = not cc.whitelisted whitelisting_changed = True if cc.listed: cc.listed = False listing_changed = True cc.save() if listing_changed: broker.update_listings() if whitelisting_changed: broker.update_whitelistings() if "q" in request.GET.keys() and len(request.GET["q"]) != 0: s = Search( model=Country(), fields={ "code": "code", "name": "name", "additional": "additional", "rir": "rir__name", "listed": "listed", "whitelisted": "whitelisted", } ) (result, country_data) = s.find(request.GET["q"]) if not result: errmsg = country_data (result, country_data) = country.all() else: (result, country_data) = country.all() if not result: return HttpResponseRedirect("/") try: page = int(request.GET.get('page', '1')) except: page = 1 country_table = CountryTable( country_data, order_by=request.GET.get('sort', 'title') ) if request.method == "GET": search_form = SearchForm(request.GET) else: search_form = SearchForm() return render_to_response("registry/country/overview.html", { "errmsg": errmsg, "country_table": country_table, "search_form": search_form, }, context_instance=RequestContext(request))
def subnets(request): errmsg = "" listing_changed = False whitelisting_changed = False for item in request.GET.keys(): if item.startswith("id_"): (result, sn) = subnet.get(id=item[3:]) if result: if request.GET["bulk_action"] == "blacklist": sn.listed = not sn.listed listing_changed = True if sn.whitelisted: sn.whitelisted = False whitelisting_changed = True elif request.GET["bulk_action"] == "whitelist": sn.whitelisted = not sn.whitelisted whitelisting_changed = True if sn.listed: sn.listed = False listing_changed = True sn.save() if listing_changed: broker.update_listings() if whitelisting_changed: broker.update_whitelistings() if "q" in request.GET.keys() and len(request.GET["q"]) != 0: s = Search( model=Subnet(), fields={ "subnet": "subnet", "mask": "mask", "last": "last", "provider": "asnum__name", "af": "af", "code": "country__code", "country": "country__name", "rir": "rir__name", "regdate": "regdate", "listed": "listed", "whitelisted": "whitelisted", } ) (result, subnet_data) = s.find(request.GET["q"]) if not result: errmsg = subnet_data (result, subnet_data) = subnet.all() else: (result, subnet_data) = subnet.all() if not result: return HttpResponseRedirect("/") try: page = int(request.GET.get('page', '1')) except: page = 1 subnet_table = SubnetTable( subnet_data, order_by=request.GET.get('sort', 'title') ) if request.method == "GET": search_form = SearchForm(request.GET) else: search_form = SearchForm() return render_to_response("registry/subnet/overview.html", { "errmsg": errmsg, "search_form": search_form, "subnet_table": subnet_table, }, context_instance=RequestContext(request))