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
def do_update(self, path_info): self.header("text/plain") m = re.search(r"^update/(\w+)/(\d+)/(\w+)/([^:]*):(\d+)(.*)", path_info) if m is None: return False (datfile, stamp, id, host, port, path) = m.groups() if host == "": host = self.environ["REMOTE_ADDR"] node = Node(host=host, port=port, path=path) searchlist = SearchList() searchlist.append(node) searchlist.sync() lookuptable = LookupTable() lookuptable.add(datfile, node) lookuptable.sync() now = int(time()) if (int(stamp) < now - config.update_range) or \ (int(stamp) > now + config.update_range): return False rec = Record(datfile=datfile, idstr=stamp + "_" + id) updatelist = UpdateList() if rec in updatelist: return True else: queue = UpdateQueue() queue.append(datfile, stamp, id, node) queue.start() return True
def do_update(self, path_info): self.header("text/plain") m = re.search(r"^update/(\w+)/(\d+)/(\w+)/([^:]*):(\d+)(.*)",path_info) if m is None: return False (datfile, stamp, id, host, port, path) = m.groups() host = self.get_remote_hostname(host) if not host: return node = Node(host=host, port=port, path=path) searchlist = SearchList() searchlist.append(node) searchlist.sync() lookuptable = LookupTable() lookuptable.add(datfile, node) lookuptable.sync() now = int(time()) if (int(stamp) < now - config.update_range) or \ (int(stamp) > now + config.update_range): return False rec = Record(datfile=datfile, idstr=stamp+"_"+id) updatelist = UpdateList() if rec in updatelist: return True else: queue = UpdateQueue() queue.append(datfile, stamp, id, node) queue.start() return True
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
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]
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]
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]
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]