Esempio n. 1
0
 def __init__(self):
     self.objs = util.locking_dict()
     self.hist = 50
     self.lines_per_interval = 4
     self.bytes_per_interval = 1024
     self.word_spam = 10
     self.pm_per_target = 5
     self.interval = 5
     self.ignore_interval = 60
     self.flooders = util.locking_dict()
Esempio n. 2
0
    def check_flood(self,lines):
        '''
        given a list of (data, timestamp) tuples
        check for "flooding"
        '''

        a = locking_dict()
        for line , tstamp in lines:
            tstamp /= self.flood_interval
            if tstamp not in a:
                d = dict(self.limits)
                d['bytes'] = 0
                d['lines'] = 0
                a[tstamp] = d

            d = a[tstamp]
            d['bytes'] += len(line)
            d['lines'] += 1
            # check for flooding bytes wise
            if d['bytes'] >= self.flood_bpi:
                return True
            # check for flooding line wise
            elif d['lines'] >= self.flood_lpi:
                return True
            # check for flooding command wise
            for k in self.limits:
                line =  line.lower().replace(':',' ').replace(' ','')
                if line.startswith(k):
                    d[k] -= 1
                    if d[k] <= 0:
                        return True
        return False
Esempio n. 3
0
 def __init__(self,server,onion,client_class,host='127.0.0.1',port=11009,db_fname='tc_cookies.db'):
     dispatcher.__init__(self)
     self.create_socket(socket.AF_INET,socket.SOCK_STREAM)
     self.set_reuse_addr()
     self.bind((host,port))
     self.listen(5)
     self.tc_client_name = 'NamelessIRCD'
     self.tc_version = '0.0.1'
     self.tc_onion = onion
     self._db_fname = db_fname
     self.clients = locking_dict()
     self.onions = locking_dict()
     self.client_class = client_class
     self.server = server
     self.dbg = server.dbg
     self.cookie = self.gen_cookie()
Esempio n. 4
0
 def __init__(self,name,server):
     self.users = []
     self.server =  server
     self.name = str(name)
     self.topic = util.get(self.name)
     self.link = server.link
     # is anon means that the channel does not relay nicknames
     self.is_anon = self.name[0] == '&'
     self.empty = lambda : len(self.users) == 0
     # is invisible means that parts and joins are not relayed and the
     # channel is not in the server channel list
     self.is_invisible = self.name[1] == '.'
     self._trips = locking_dict()
     self.remotes = []
     self.torchats = []
     self.limit = 300
     self.key = None
Esempio n. 5
0
    def __init__(self,addr,name,ipv6=False,do_log=False,poni=None,configs={},link_auth=False):
        self._no_log = not do_log
        self.poniponi = poni
        self.flood = flood.flood()
        self.flood.choke = self.flood_choke
        self.flood.unchoke = self.flood_unchoke
        self.flooders = locking_dict()
        dispatcher.__init__(self)
        af = ( not ipv6 and socket.AF_INET ) or socket.AF_INET6
        self.create_socket(af,socket.SOCK_STREAM)
        self.set_reuse_addr()
        self.bind(addr)
        self.listen(5)
        self.configs = configs
        self.admin_backlog = []
        self.handlers = []
        self.admin = None
        self.name = name
        self.spams = []
        self.require_auth = link_auth
        self.wl_file = 'whitelist' in self.configs and self.configs['whitelist'] or 'whitelist.txt'
        self.motd_file = 'motd' in self.configs and self.configs['motd'] or 'motd.txt'
        limits = {
            'nick':5,
            'topic':5,
            'privmsg&':5,
            'privmsg#':5,
            'join':10,
            }
        self.limits = locking_dict(limits)
        self.flood_kill = False
        # flood interval in seconds
        self.flood_interval = 10
        # lines per interval
        self.flood_lpi = 20
        # bytes per interval
        self.flood_bpi = 1024
        # topic limit
        self.topic_limit = 60

        self.force_check = False

        self.chans = locking_dict()
        self.users = locking_dict()
        self.pingtimeout = 60 * 5
        self.ping_retry = 2
        self._check_ping = True
        self.whitelist = []
        self._check_ping = True
        self.handle_accepted = self._accepted_3_3
        self.load_wl()
        self.on =True

        self.init_services()

        def ping_loop():
            while self.on:
                try:
                    self.check_ping()
                except:
                    self.handle_error()
                sleep(1)
        def flood_loop():
            while self.on:
                try:
                    self.flood.tick()
                except:
                    self.handle_error()
                sleep(1)
        self.threads = []
        self.threads.append(Thread(target=ping_loop,args=()))
        self.threads.append(Thread(target=flood_loop,args=()))