def __init__(self): self.listing = Listing() self.whitelisting = WhiteListing() self.rule = Rule() self.asnum = ASNum() self.subnet = Subnet() self.rir = RIR() self.country = Country() self.peering = Peering()
def __init__(self): self.listing = Listing() self.whitelisting = WhiteListing() self.rule = Rule() self.asnum = ASNum() self.subnet = Subnet() self.rir = RIR() self.country = Country() self.peering = Peering()
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 socket import sys import os sys.path.append("/www/blacklist/app") os.environ["DJANGO_SETTINGS_MODULE"] = "settings" from blacklist.middleware.listing import Listing from blacklist.middleware.whitelisting import WhiteListing listing = Listing() whitelisting = WhiteListing() def help(): print "Usage: %s (listing|whitelisting) (add|del|list) [<value>]" % (os.path.basename(sys.argv[0])) print "" print "Examples:" print "* listing add 192.0.2.1 reason someuser" print "* listing add 192.0.2.0/24 reason someuser" print "* listing del 192.0.2.1" print "* listing list" print "* whitelisting add 192.0.2.1 host.example.com someuser" print "* whitelisting add 192.0.2.0/24 net.example.com someuser" print "* whitelisting del 192.0.2.1" print "* whitelisting list" sys.exit(1) if __name__ == "__main__": if not len(sys.argv) in range(3,7):
class API: def __init__(self): self.listing = Listing() self.whitelisting = WhiteListing() self.rule = Rule() self.asnum = ASNum() self.subnet = Subnet() self.rir = RIR() self.country = Country() self.peering = Peering() def add(self, data): (result, listing) = self.listing.add( ip=data['ip'], sensor=data['sensor'], sensor_host=data['sensor_host'], reason=data['reason'], reporter=data['username'], ) return (result, str(listing)) def get_rules(self): rules = {} (result, db_rules) = self.rule.all() if result: for r in db_rules: if not rules.has_key(r.sensor.name): rules[r.sensor.name] = [] rules[r.sensor.name].append([r.rule, r.pos_ip, r.pos_reason]) return (True, rules) else: return (False, db_rules) def get_peerings(self): peerings = [] (result, db_peerings) = self.peering.all() if result: for p in db_peerings: peerings.append({ "hostname": p.peer.hostname, "ip": p.peer.ip.ip, "af": p.peer.ip.af, "asnum": p.asnum.asnum, "key": p.key.data, }) return (True, peerings) else: return (False, db_peerings) def get_listings(self): listings = [] (result, db_listings) = self.listing.all() if result: for l in db_listings: listings.append((l.ip.ip, l.ip.last, l.ip.mask, l.ip.af)) (result, rir_listings) = self.rir.filter(listed=True) if result: for rir in rir_listings: (result, rir_subnets) = self.subnet.filter(rir=rir) if result: for s in rir_subnets: listings.append((s.subnet, s.last, s.mask, s.af)) (result, country_listings) = self.country.filter(listed=True) if result: for country in country_listings: (result, country_subnets) = self.subnet.filter(country=country) if result: for s in country_subnets: listings.append((s.subnet, s.last, s.mask, s.af)) (result, provider_listings) = self.asnum.filter(listed=True) if result: for asnum in provider_listings: (result, provider_subnets) = self.subnet.filter(asnum=asnum) if result: for s in provider_subnets: listings.append((s.subnet, s.last, s.mask, s.af)) (result, subnet_listings) = self.subnet.filter(listed=True) if result: for s in subnet_listings: listings.append((s.subnet, s.last, s.mask, s.af)) return (True, list(set(listings))) def get_whitelistings(self): listings = [] (result, db_listings) = self.whitelisting.all() if result: for l in db_listings: listings.append((l.ip.ip, l.ip.last, l.ip.mask, l.ip.af)) (result, rir_listings) = self.rir.filter(whitelisted=True) if result: for rir in rir_listings: (result, rir_subnets) = self.subnet.filter(rir=rir) if result: for s in rir_subnets: listings.append((s.subnet, s.last, s.mask, s.af)) (result, country_listings) = self.country.filter(whitelisted=True) if result: for country in country_listings: (result, country_subnets) = self.subnet.filter(country=country) if result: for s in country_subnets: listings.append((s.subnet, s.last, s.mask, s.af)) (result, provider_listings) = self.asnum.filter(whitelisted=True) if result: for asnum in provider_listings: (result, provider_subnets) = self.subnet.filter(asnum=asnum) if result: for s in provider_subnets: listings.append((s.subnet, s.last, s.mask, s.af)) (result, subnet_listings) = self.subnet.filter(whitelisted=True) if result: for s in subnet_listings: listings.append((s.subnet, s.last, s.mask, s.af)) return (True, list(set(listings)))
from blacklist.middleware.rir import RIR from blacklist.middleware.asnum import ASNum from blacklist.middleware.subnet import Subnet from blacklist.middleware.whitelisting import WhiteListing from blacklist.middleware.peering import Peering from blacklist.middleware.rule import Rule from blacklist.middleware.duration import Duration from blacklist.middleware.listing import Listing from blacklist.middleware.historylisting import HistoryListing config = Config() asnum = ASNum() country = Country() rir = RIR() subnet = Subnet() whitelisting = WhiteListing() peering = Peering() rule = Rule() duration = Duration() listing = Listing() historylisting = HistoryListing() def log(msg): stdout.write(msg) stdout.flush() def get_data(item): result = [] fname = "%s/r4ck-blacklist-%s.csv" % (basedir, item) counter = 0 data = "".join(open(fname, "r").readlines())
class API: def __init__(self): self.listing = Listing() self.whitelisting = WhiteListing() self.rule = Rule() self.asnum = ASNum() self.subnet = Subnet() self.rir = RIR() self.country = Country() self.peering = Peering() def add(self, data): (result, listing) = self.listing.add( ip=data['ip'], sensor=data['sensor'], sensor_host=data['sensor_host'], reason=data['reason'], reporter=data['username'], ) return (result, str(listing)) def get_rules(self): rules = {} (result, db_rules) = self.rule.all() if result: for r in db_rules: if not rules.has_key(r.sensor.name): rules[r.sensor.name] = [] rules[r.sensor.name].append([r.rule, r.pos_ip, r.pos_reason]) return (True, rules) else: return (False, db_rules) def get_peerings(self): peerings = [] (result, db_peerings) = self.peering.all() if result: for p in db_peerings: peerings.append({ "hostname": p.peer.hostname, "ip": p.peer.ip.ip, "af": p.peer.ip.af, "asnum": p.asnum.asnum, "key": p.key.data, }) return (True, peerings) else: return (False, db_peerings) def get_listings(self): listings = [] (result, db_listings) = self.listing.all() if result: for l in db_listings: listings.append((l.ip.ip, l.ip.last, l.ip.mask, l.ip.af)) (result, rir_listings) = self.rir.filter(listed=True) if result: for rir in rir_listings: (result, rir_subnets) = self.subnet.filter(rir=rir) if result: for s in rir_subnets: listings.append((s.subnet, s.last, s.mask, s.af)) (result, country_listings) = self.country.filter(listed=True) if result: for country in country_listings: (result, country_subnets) = self.subnet.filter(country=country) if result: for s in country_subnets: listings.append((s.subnet, s.last, s.mask, s.af)) (result, provider_listings) = self.asnum.filter(listed=True) if result: for asnum in provider_listings: (result, provider_subnets) = self.subnet.filter(asnum=asnum) if result: for s in provider_subnets: listings.append((s.subnet, s.last, s.mask, s.af)) (result, subnet_listings) = self.subnet.filter(listed=True) if result: for s in subnet_listings: listings.append((s.subnet, s.last, s.mask, s.af)) return (True, list(set(listings))) def get_whitelistings(self): listings = [] (result, db_listings) = self.whitelisting.all() if result: for l in db_listings: listings.append((l.ip.ip, l.ip.last, l.ip.mask, l.ip.af)) (result, rir_listings) = self.rir.filter(whitelisted=True) if result: for rir in rir_listings: (result, rir_subnets) = self.subnet.filter(rir=rir) if result: for s in rir_subnets: listings.append((s.subnet, s.last, s.mask, s.af)) (result, country_listings) = self.country.filter(whitelisted=True) if result: for country in country_listings: (result, country_subnets) = self.subnet.filter(country=country) if result: for s in country_subnets: listings.append((s.subnet, s.last, s.mask, s.af)) (result, provider_listings) = self.asnum.filter(whitelisted=True) if result: for asnum in provider_listings: (result, provider_subnets) = self.subnet.filter(asnum=asnum) if result: for s in provider_subnets: listings.append((s.subnet, s.last, s.mask, s.af)) (result, subnet_listings) = self.subnet.filter(whitelisted=True) if result: for s in subnet_listings: listings.append((s.subnet, s.last, s.mask, s.af)) return (True, list(set(listings)))