Exemplo n.º 1
0
    def deny(self, scope, expr, ttl):
        timestamp = -1

        if ttl != -1:
            timestamp = dateutils.timestamp() + ttl

        self.deny_until(scope, expr, timestamp)
Exemplo n.º 2
0
    def fetched(self, scope, nick, url, key):
        now = dateutils.timestamp()
        due_date = now + self.__refresh_timeout

        cur = scope.get_handle()
        cur.execute(
            "update Avatar set Hash=?, DueDate=?, Errors=0 where nick=? and Url=?",
            (key, due_date, nick, url))
Exemplo n.º 3
0
    def count_pending_requests(self, scope, nick, ttl):
        timestamp = dateutils.timestamp() - ttl

        cur = scope.get_handle()
        cur.execute(
            "select count(*) from PasswordReset where Nick=? and Timestamp>=?",
            (nick, timestamp))

        return int(cur.fetchone()[0])
Exemplo n.º 4
0
    def deny_filter_exists(self, scope, expr):
        now = dateutils.timestamp()

        cur = scope.get_handle()
        cur.execute(
            "select count(*) from IPFilter where Expression=? and Action=1 and (Lifetime=-1 or Lifetime>=?)",
            (expr, now))

        return bool(cur.fetchone()[0])
Exemplo n.º 5
0
    def has_pending_request(self, scope, nick, code, email, ttl):
        timestamp = dateutils.timestamp() - ttl

        cur = scope.get_handle()
        cur.execute(
            "select count(*) from ConfirmationRequest where Nick=? and Email=? and Code=? and Timestamp>=?",
            (nick, email, code, timestamp))

        return bool(cur.fetchone()[0])
Exemplo n.º 6
0
    def load_deny_filters(self, scope):
        now = dateutils.timestamp()

        cur = scope.get_handle()
        cur.execute(
            "select Expression, Lifetime from IPFilter where Action=1 and (Lifetime=-1 or Lifetime>=?)",
            (now, ))

        return [(ipfilter.Factory.create(row["Expression"]), row["Lifetime"])
                for row in cur]
Exemplo n.º 7
0
    def create_request(self, scope, nick):
        code = make_password(8)
        now = dateutils.timestamp()

        cur = scope.get_handle()
        cur.execute(
            "insert into PasswordReset (Nick, Code, Timestamp) values (?, ?, ?)",
            (nick, code, now))

        return code
Exemplo n.º 8
0
    def add_message(self, scope, nick, sender, text):
        msgid = uuid.uuid4().hex
        timestamp = dateutils.timestamp()

        cur = scope.get_handle()
        cur.execute(
            "insert into Message (UUID, Sender, Receiver, Timestamp, Message) values (?, ?, ?, ?, ?)",
            (msgid, sender, nick, timestamp, text))

        return msgid
Exemplo n.º 9
0
    def create_request(self, scope, nick, email):
        code = make_password(8)
        now = dateutils.timestamp()

        cur = scope.get_handle()
        cur.execute(
            "insert into ConfirmationRequest (Nick, Email, Code, Timestamp) values (?, ?, ?, ?)",
            (nick, email, code, now))

        return code
Exemplo n.º 10
0
    def mta_error(self, scope, msgid):
        now = dateutils.timestamp()
        due_date = now + self.__retry_timeout

        cur = scope.get_handle()
        cur.execute(
            "update Mail set MTAErrors=MTAErrors + 1, DueDate = ? where UUID=?",
            (
                due_date,
                msgid.hex,
            ))
Exemplo n.º 11
0
    def put(self, scope, receiver, subject, body):
        msgid = uuid.uuid4().hex
        now = dateutils.timestamp()

        cur = scope.get_handle()
        cur.execute(
            "insert into Mail (UUID, Receiver, Subject, Body, Timestamp, DueDate) values (?, ?, ?, ?, ?, ?)",
            (msgid, receiver, subject, body, now, now))

        for l in self.__listeners:
            l.put(receiver, subject, body)
Exemplo n.º 12
0
    def head(self, scope):
        now = dateutils.timestamp()

        query = """select * from Mail
                     where Sent=0 and %d - Timestamp <= %d and MTAErrors < %d and DueDate <= %d
                     order by MTAErrors, Timestamp asc limit 1""" % (
            now, self.__ttl, self.__max_errors, now)

        cur = scope.get_handle()
        cur.execute(query)

        m = cur.fetchone()

        msg = None

        if m:
            msg = self.__to_email__(m)

        return msg
Exemplo n.º 13
0
    def head(self, scope):
        now = dateutils.timestamp()

        cur = scope.get_handle()

        query = """select * from Avatar
                     where DueDate <= %d and Active = 1
                     order by Errors, DueDate asc limit 1""" % (now, )

        cur.execute(query)

        m = cur.fetchone()

        msg = None

        if m:
            msg = self.__to_request__(m)

        return msg
Exemplo n.º 14
0
    def __show_ip_filters__(self, session_id, argv):
        if argv:
            raise LtdErrorException("Usage: ipfilter show")

        filters = []

        with self.__ipfilter_connection.enter_scope() as scope:
            for f, l in self.__ipfilters.load_deny_filters(scope):
                lifetime = "forever"

                if l > -1:
                    time_left = max(1, l - dateutils.timestamp())
                    lifetime = dateutils.elapsed_time(time_left)

                filters.append((f.expression, lifetime))

        if filters:
            for entry in sorted(filters, key=lambda e: "@".join(reversed(e[0].split("@", 1))).lower()):
                self.broker.deliver(session_id, ltd.encode_status_msg("IP-Filter", "%s denied (%s)" % entry))
        else:
            self.broker.deliver(session_id, ltd.encode_status_msg("IP-Filter", "List is empty."))
Exemplo n.º 15
0
    def error(self, scope, nick, url):
        cur = scope.get_handle()

        cur.execute("select Errors from Avatar where Nick=? and Url=?",
                    (nick, url))

        row = cur.fetchone()

        if row:
            errors = row[0]
            now = dateutils.timestamp()

            if errors == self.__max_errors:
                due_date = now + self.__error_timeout
            else:
                due_date = now + self.__retry_timeout
                errors += 1

            cur.execute(
                "update Avatar set Errors=?, DueDate=? where Nick=? and Url=?",
                (errors, due_date, nick, url))
Exemplo n.º 16
0
    def put(self, scope, nick, url):
        now = dateutils.timestamp()

        cur = scope.get_handle()

        cur.execute("update Avatar set Active=0 where Nick=?", (nick, ))

        cur.execute("select count(*) from Avatar where Nick=? and url=?",
                    (nick, url))

        count = cur.fetchone()[0]

        if count:
            cur.execute(
                "update Avatar set Active=1, DueDate=?, Errors=0 where Nick=? and Url=?",
                (now, nick, url))
        else:
            cur.execute(
                "insert into Avatar (Nick, Active, DueDate, Url) values (?, 1, ?, ?)",
                (nick, now, url))

        for l in self.__listeners:
            l.put(nick, url)
Exemplo n.º 17
0
    def cleanup(self, scope, ttl):
        timestamp = dateutils.timestamp() - ttl

        cur = scope.get_handle()
        cur.execute("delete from ConfirmationRequest where Timestamp<?",
                    (timestamp, ))
Exemplo n.º 18
0
    def cleanup(self, scope, ttl):
        timestamp = dateutils.timestamp() - ttl

        cur = scope.get_handle()
        cur.execute("delete from PasswordReset where Timestamp<?",
                    (timestamp, ))
Exemplo n.º 19
0
    def cleanup(self, scope):
        now = dateutils.timestamp()

        cur = scope.get_handle()
        cur.execute("delete from Mail where %d - Timestamp > %d" %
                    (now, self.__ttl))
Exemplo n.º 20
0
    def cleanup(self, scope):
        now = dateutils.timestamp()

        cur = scope.get_handle()
        cur.execute("delete from IPFilter where Lifetime>-1 and Lifetime<?",
                    (now, ))