예제 #1
0
파일: api.py 프로젝트: jesk78/blacklist
 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()
예제 #2
0
파일: api.py 프로젝트: r3boot/blacklist
	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()
예제 #3
0
파일: api.py 프로젝트: r3boot/blacklist
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)))
예제 #4
0
파일: rule.py 프로젝트: jesk78/blacklist
from django.contrib.auth.decorators import login_required
from django.core.paginator import Paginator, InvalidPage, EmptyPage
from django.core.urlresolvers import reverse
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template import RequestContext

from blacklist.common.broker import Broker
from blacklist.middleware.rule import Rule
from blacklist.table.rule import RuleTable
from blacklist.forms.rule import RuleForm

broker = Broker()
rule = Rule()


@login_required
def rules(request):
    (result, rule_data) = rule.all()
    if not result: return HttpResponseRedirect("/")

    try:
        page = int(request.GET.get('page', '1'))
    except:
        page = 1

    rule_table = RuleTable(rule_data,
                           order_by=request.GET.get('sort', 'title'))

    return render_to_response("rule/overview.html", {
        "rule_table": rule_table,
예제 #5
0
파일: api.py 프로젝트: jesk78/blacklist
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)))