예제 #1
0
    def do_post_from_mail(self, datfile, bodystr, attach, suffix):
        """Post article."""
        suffix = re.sub(r"[^0-9A-Za-z]", "", suffix)
        stamp = int(time())

        body = {'body': self.escape(bodystr)}
        if attach:
            body['attach'] = attach
            body['suffix'] = suffix
        if not body:
            return None

        cache = Cache(datfile)
        rec = Record(datfile=cache.datfile)
        id = rec.build(stamp, body)

        if len(rec.recstr) > config.record_limit * 1024:
            return None
        elif spam.check(rec.recstr):
            return None

        if cache.exists():
            cache.add_data(rec)
            cache.sync_status()
        else:
            return None

        queue = UpdateQueue()
        queue.append(cache.datfile, stamp, id, None)
        queue.start()

        return True
예제 #2
0
    def do_post_from_mail(self, datfile, bodystr, attach, suffix):
        """Post article."""
        suffix = re.sub(r"[^0-9A-Za-z]", "", suffix)
        stamp = int(time())

        body = {"body": self.escape(bodystr)}
        if attach:
            body["attach"] = attach
            body["suffix"] = suffix
        if not body:
            return None

        cache = Cache(datfile)
        rec = Record(datfile=cache.datfile)
        id = rec.build(stamp, body)

        if len(rec.recstr) > config.record_limit * 1024:
            return None
        elif spam.check(rec.recstr):
            return None

        if cache.exists():
            cache.add_data(rec)
            cache.sync_status()
        else:
            return None

        queue = UpdateQueue()
        queue.append(cache.datfile, stamp, id, None)
        queue.start()

        return True
예제 #3
0
    def do_post(self, path, form):
        """Post article."""
        if form.getfirst("error", "") != "":
            stamp = self.error_time()
        else:
            stamp = int(time())

        body = {}
        for key in ("base_stamp", "base_id", "name", "mail", "body"):
            value = form.getfirst(key, "")
            if value != "":
                value = unicode(value, 'shift-jis', 'replace')
                value = value.encode('utf-8', 'replace')
                body[key] = self.escape(value)

        if not body:
            self.header(self.message["null_article"], deny_robot=True)
            self.footer()
            return None

        cache = Cache(form.getfirst("file"))
        rec = Record(datfile=cache.datfile)
        id = rec.build(stamp, body)

        if len(rec.recstr) > config.record_limit*1024:
            self.header(self.message['big_file'], deny_robot=True)
            self.footer()
            return None
        elif spam.check(rec.recstr):
            self.header(self.message['spam'], deny_robot=True)
            self.footer()
            return None

        if cache.exists():
            cache.add_data(rec)
            cache.sync_status()
        else:
            self.print404()
            return None

        if form.getfirst("dopost", "") != "":
            queue = UpdateQueue()
            queue.append(cache.datfile, stamp, id, None)
            queue.start()

        return id[:8]
예제 #4
0
    def do_post(self, path, form):
        """Post article."""
        if form.getfirst("error", "") != "":
            stamp = self.error_time()
        else:
            stamp = int(time())

        body = {}
        for key in ("base_stamp", "base_id", "name", "mail", "body"):
            value = form.getfirst(key, "")
            if value != "":
                value = unicode(value, 'shift-jis', 'replace')
                value = value.encode('utf-8', 'replace')
                body[key] = self.escape(value)

        if not body:
            self.header(self.message["null_article"], deny_robot=True)
            self.footer()
            return None

        cache = Cache(form.getfirst("file"))
        rec = Record(datfile=cache.datfile)
        id = rec.build(stamp, body)

        if len(rec.recstr) > config.record_limit * 1024:
            self.header(self.message['big_file'], deny_robot=True)
            self.footer()
            return None
        elif spam.check(rec.recstr):
            self.header(self.message['spam'], deny_robot=True)
            self.footer()
            return None

        if cache.exists():
            cache.add_data(rec)
            cache.sync_status()
        else:
            self.print404()
            return None

        if form.getfirst("dopost", "") != "":
            queue = UpdateQueue()
            queue.append(cache.datfile, stamp, id, None)
            queue.start()

        return id[:8]
예제 #5
0
파일: cache.py 프로젝트: hangingman/saku
 def check_data(self, res, stamp=None, id=None, begin=None, end=None):
     '''Check a data and add it cache.'''
     flag_got = False
     flag_spam = False
     spam_count = 0
     count = 0
     for i in res:
         count += 1
         r = Record(datfile=self.datfile)
         parse_ok = r.parse(i)
         if parse_ok and \
            ((stamp is None) or (r['stamp'] == str(stamp))) and \
            ((not id) or (r['id'] == id)) and \
            ((begin is None) or (begin <= r.stamp)) and \
            ((end is None) or (r.stamp <= end)) and \
            r.md5check():
             flag_got = True
             if (len(i) > config.record_limit * 1024) or spam.check(i):
                 sys.stderr.write(
                     'Warning: %s/%s: too large or spam record.\n' %
                     (self.datfile, r.idstr))
                 self.add_data(r, False)
                 r.remove()
                 flag_spam = True
                 spam_count += 1
             else:
                 self.add_data(r)
         else:
             if stamp is not None:
                 str_stamp = '/%s' % stamp
             elif 'stamp' in r:
                 str_stamp = '/%s' % r['stamp']
             else:
                 str_stamp = ''
             sys.stderr.write("Warning: %s%s: broken record.\n" %
                              (self.datfile, str_stamp))
         r.free()
         if spam_count > config.accept_spam_count:
             sys.stderr.write(
                 "Warning: %s: too many spams. skip fetching it.\n" %
                 self.datfile)
             break
     return count, flag_got, flag_spam
예제 #6
0
 def check_data(self, res, stamp=None, id=None, begin=None, end=None):
     '''Check a data and add it cache.'''
     flag_got = False
     flag_spam = False
     spam_count = 0
     count = 0
     for i in res:
         count += 1
         r = Record(datfile=self.datfile)
         parse_ok = r.parse(i)
         if parse_ok and \
            ((stamp is None) or (r['stamp'] == str(stamp))) and \
            ((not id) or (r['id'] == id)) and \
            ((begin is None) or (begin <= r.stamp)) and \
            ((end is None) or (r.stamp <= end)) and \
            r.md5check():
             flag_got = True
             if (len(i) > config.record_limit*1024) or spam.check(i):
                 sys.stderr.write(
                     'Warning: %s/%s: too large or spam record.\n' %
                     (self.datfile, r.idstr))
                 self.add_data(r, False)
                 r.remove()
                 flag_spam = True
                 spam_count += 1
             else:
                 self.add_data(r)
         else:
             if stamp is not None:
                 str_stamp = '/%s' % stamp
             elif 'stamp' in r:
                 str_stamp = '/%s' % r['stamp']
             else:
                 str_stamp = ''
             sys.stderr.write("Warning: %s%s: broken record.\n" %
                              (self.datfile, str_stamp))
         r.free()
         if spam_count > config.accept_spam_count:
             sys.stderr.write("Warning: %s: too many spams. skip fetching it.\n" % self.datfile)
             break
     return count, flag_got, flag_spam
예제 #7
0
파일: gateway.py 프로젝트: kuznetz/saku-ex
    def do_post(self, path, form):
        """Post article."""
        import base64
        try:
            attach = form['attach']
        except KeyError:
            attach = None
        str_attach = ''

        if (attach is not None) and attach.file:
            if len(attach.value) > config.record_limit*1024:
                self.header(self.message["big_file"], deny_robot=True)
                self.footer()
                return None
            str_attach = base64.encodestring(attach.value).replace("\n", "")
        guess_suffix = "txt"
        if (attach is not None) and attach.filename:
            found = re.search(r"\.([^.]+)$", attach.filename)
            if found:
                guess_suffix = found.group(1).lower()

        suffix = form.getfirst("suffix", "")
        if (suffix == "") or (suffix == "AUTO"):
            suffix = guess_suffix
        elif suffix.startswith("."):
            suffix = suffix[1:].lower()
        else:
            suffix = suffix.lower()
        suffix = re.sub(r"[^0-9A-Za-z]", "", suffix)

        if form.getfirst("error", "") != "":
            stamp = self.error_time()
        else:
            stamp = int(time.time())

        body = {}
        value = form.getfirst("body", "")
        if value != "":
            body["body"] = self.escape(value)

        if str_attach != "":
            body["attach"] = str_attach
            body["suffix"] = re.sub(r"[\r\n]", "", suffix)

        if not body:
            self.header(self.message["null_article"], deny_robot=True)
            self.footer()
            return None

        for key in ("base_stamp", "base_id", "name", "mail"):
            value = form.getfirst(key, "")
            if value != "":
                body[key] = self.escape(value)

        if not body:
            self.header(self.message["null_article"], deny_robot=True)
            self.footer()
            return None

        cache = Cache(form.getfirst("file"))
        rec = Record(datfile=cache.datfile)
        passwd = form.getfirst("passwd", "")
        id = rec.build(stamp, body, passwd=passwd)

        proxy_client = self.environ.get('HTTP_X_FORWARDED_FOR', 'direct')
        self.stderr.write('post %s/%d_%s from %s/%s\n' %
                          (cache.datfile, stamp, id,
                           self.remoteaddr, proxy_client))

        if len(rec.recstr) > config.record_limit*1024:
            self.header(self.message['big_file'], deny_robot=True)
            self.footer()
            return None
        elif spam.check(rec.recstr):
            self.header(self.message['spam'], deny_robot=True)
            self.footer()
            return None

        if cache.exists():
            cache.add_data(rec)
            cache.sync_status()
        else:
            self.print404()
            return None

        if form.getfirst("dopost", "") != "":
            queue = UpdateQueue()
            queue.append(cache.datfile, stamp, id, None)
            queue.start()

        return id[:8]
예제 #8
0
    def do_post(self, path, form):
        """Post article."""
        import base64
        try:
            attach = form['attach']
        except KeyError:
            attach = None
        str_attach = ''

        if (attach is not None) and attach.file:
            if len(attach.value) > config.record_limit * 1024:
                self.header(self.message["big_file"], deny_robot=True)
                self.footer()
                return None
            str_attach = base64.encodestring(attach.value).replace("\n", "")
        guess_suffix = "txt"
        if (attach is not None) and attach.filename:
            found = re.search(r"\.([^.]+)$", attach.filename)
            if found:
                guess_suffix = found.group(1).lower()

        suffix = form.getfirst("suffix", "")
        if (suffix == "") or (suffix == "AUTO"):
            suffix = guess_suffix
        elif suffix.startswith("."):
            suffix = suffix[1:].lower()
        else:
            suffix = suffix.lower()
        suffix = re.sub(r"[^0-9A-Za-z]", "", suffix)

        if form.getfirst("error", "") != "":
            stamp = self.error_time()
        else:
            stamp = int(time.time())

        body = {}
        value = form.getfirst("body", "")
        if value != "":
            body["body"] = self.escape(value)

        if str_attach != "":
            body["attach"] = str_attach
            body["suffix"] = re.sub(r"[\r\n]", "", suffix)

        if not body:
            self.header(self.message["null_article"], deny_robot=True)
            self.footer()
            return None

        for key in ("base_stamp", "base_id", "name", "mail"):
            value = form.getfirst(key, "")
            if value != "":
                body[key] = self.escape(value)

        if not body:
            self.header(self.message["null_article"], deny_robot=True)
            self.footer()
            return None

        cache = Cache(form.getfirst("file"))
        rec = Record(datfile=cache.datfile)
        passwd = form.getfirst("passwd", "")
        id = rec.build(stamp, body, passwd=passwd)

        proxy_client = self.environ.get('HTTP_X_FORWARDED_FOR', 'direct')
        self.stderr.write(
            'post %s/%d_%s from %s/%s\n' %
            (cache.datfile, stamp, id, self.remoteaddr, proxy_client))

        if len(rec.recstr) > config.record_limit * 1024:
            self.header(self.message['big_file'], deny_robot=True)
            self.footer()
            return None
        elif spam.check(rec.recstr):
            self.header(self.message['spam'], deny_robot=True)
            self.footer()
            return None

        if cache.exists():
            cache.add_data(rec)
            cache.sync_status()
        else:
            self.print404()
            return None

        if form.getfirst("dopost", "") != "":
            queue = UpdateQueue()
            queue.append(cache.datfile, stamp, id, None)
            queue.start()

        return id[:8]