def file_list_get(pauth): msgfrom, addr = points.check_point(pauth) if addr: result = get_file_index() else: result = "auth error!" return result
def post_file(): response.set_header("content-type", "text/plain; charset=utf-8") try: pauth = request.POST["pauth"] except: pauth = False try: filename = request.POST["filename"] except: filename = False if not filename: return "not filename found" write_to_log("x/file/%s/%s POST" % (pauth, filename)) files = [] msgfrom, addr = points.check_point(pauth) if addr: for line in codecs.open("files/indexes/public_files.txt", "r", "utf8").read().split("\n"): try: files.append(line.split(":")[0]) except: None for line in codecs.open("files/indexes/files.txt", "r", "utf8").read().split("\n"): try: files.append(line.split(":")[0]) except: None if os.path.exists("files/indexes/" + msgfrom + "_files.txt"): for line in codecs.open("files/indexes/" + msgfrom + "_files.txt", "r", "utf8").read().split("\n"): try: files.append(line.split(":")[0]) except: None fechoes = [] for fecho in os.listdir("fecho"): fechoes.append(fecho) for fecho in fechoes: f = codecs.open("fecho/%s" % fecho, "r").read().split("\n") for row in f: if len(row) > 0: r = row.split(":") files.append(fecho + "/" + r[1]) if filename in files: return static_file(filename, "files/") else: return "file not found" files = [] for line in codecs.open("files/indexes/public_files.txt", "r", "utf8").read().split("\n"): try: files.append(line.split(":")[0]) except: None if filename in files: return static_file(filename, "files/") else: return "file not found"
def index(): api.load_config() echoareas = [] s = request.get_cookie("subscription", secret='some-secret-key') if not s: subscription = [] for ea in api.echoareas: subscription.append(ea[0]) response.set_cookie("subscription", subscription, path="/", max_age=180 * 24 * 60 * 60, secret='some-secret-key') s = subscription if api.nosubscription: subscription = api.echoareas else: subscription = [] for ea in s: flag = False for e in api.echoareas: if ea in e: flag = True subscription.append(e) if not flag: subscription.append([ea, ""]) ea = [[echoarea[0], echoarea[1], api.get_time(echoarea[0])] for echoarea in subscription] for echoarea in sorted(ea, key=lambda ea: ea[2], reverse=True)[0:5]: last = request.get_cookie(echoarea[0], secret='some-secret-key') if not last in api.get_echo_msgids(echoarea[0]): last = False if not last or len(last) == 0: last = api.get_last_msgid(echoarea[0]) if last and len(last) > 0: page = get_page(api.get_echoarea(echoarea[0]).index(last)) else: page = get_page(len(api.get_echoarea(echoarea[0]))) echoareas.append({ "echoname": echoarea[0], "count": api.get_echoarea_count(echoarea[0]), "dsc": echoarea[1], "msg": api.get_last_msg(echoarea[0]), "last": last, "page": page }) allechoareas = echoes(subscription) auth = request.get_cookie("authstr") msgfrom, addr = points.check_point(auth) return template("tpl/index.tpl", nodename=api.nodename, dsc=api.nodedsc, echoareas=echoareas, allechoareas=allechoareas, addr=addr, auth=auth, background=api.background, nosubscription=api.nosubscription)
def profile(): auth = request.get_cookie("authstr") username, addr = points.check_point(auth) return template("tpl/profile.tpl", nodename=api.nodename, dsc=api.nodedsc, background=api.background, username=username, auth=auth, addr=addr)
def from_echoarea_count(auth): r = 0 username, addr = points.check_point(auth) if username == "": return r addr = nodename + "," + str(addr) c = connect() q = c.execute("SELECT msgid FROM msg WHERE ( addr = ? );", (addr, )) for row in q: r += 1 return r
def from_echo_msgids(auth): msgids = [] username, addr = points.check_point(auth) if username == "": return msgids addr = nodename + "," + str(addr) c = connect() for row in c.execute( "SELECT msgid FROM msg WHERE ( addr = ? ) ORDER BY id;", (addr, )): msgids.append(row[0]) return msgids
def upload_form(): auth = request.get_cookie("authstr") username, addr = points.check_point(auth) if addr: return template("tpl/upload.tpl", nodename=api.nodename, dsc=api.nodedsc, background=api.background, fechoareas=api.fechoareas) else: redirect("/")
def netmail_echo_msgids(auth): msgids = [] username, addr = points.check_point(auth) if username == "": return msgids addr = "%<" + nodename + "," + str(addr) + ">%" c = connect() for row in c.execute( "SELECT msgid FROM msg WHERE ( echoarea LIKE 'private%' and (t = ? or t like ?)) ORDER BY id;", (username, addr)): msgids.append(row[0]) return msgids
def netmail_last_msgid(auth): username, addr = points.check_point(auth) if username == "": return False addr = "%<" + nodename + "," + str(addr) + ">%" try: c = connect() return c.execute( "SELECT msgid FROM msg WHERE ( echoarea LIKE 'private%' and ( t = ? or t like ?)) ORDER BY id DESC LIMIT 1;", (username, addr)).fetchone()[0] except: return False
def from_last_msgid(auth): username, addr = points.check_point(auth) if username == "": return False addr = nodename + "," + str(addr) try: c = connect() return c.execute( "SELECT msgid FROM msg WHERE ( addr = ? ) ORDER BY id DESC LIMIT 1;", (addr, )).fetchone()[0] except: return False
def showmsg(msgid): api.load_config() if api.msg_filter(msgid): body = api.get_msg(msgid).split("\n") if body != [""]: msgfrom, addr = points.check_point(request.get_cookie("authstr")) kludges = body[0].split("/") if "repto" in kludges: repto = kludges[kludges.index("repto") + 1] else: repto = False if len(body) > 0: echoarea = [ea for ea in api.echoareas if ea[0] == body[1]] if len(echoarea) == 0: echoarea = [body[1], ""] else: echoarea = echoarea[0] else: echoarea = ["", ""] t = api.formatted_time(body[2]) point = body[3] address = body[4] to = body[5] subj = body[6] body = body[8:] index = api.get_echoarea(echoarea[0]) current = index.index(msgid) response.set_cookie(echoarea[0], msgid, max_age=180 * 24 * 60 * 60, secret='some-secret-key') auth = request.get_cookie("authstr") return template("tpl/message.tpl", nodename=api.nodename, echoarea=echoarea, index=index, msgid=msgid, repto=repto, current=current, time=t, point=point, address=address, to=to, subj=subj, body=body, msgfrom=msgfrom, background=api.background, auth=auth) else: redirect("/") else: redirect("/")
def file_list_post(): pauth = request.POST["pauth"] try: filename = request.POST["filename"] except: filename = False msgfrom, addr = points.check_point(pauth) if addr: if filename: return static_file(filename, "files/") else: return get_file_index() else: return ""
def mail_echoarea_count(auth): r = 0 username, addr = points.check_point(auth) if username == "": return r addr = "%<" + nodename + "," + str(addr) + ">%" try: c = connect() q = c.execute("SELECT msgid FROM msg WHERE ( t = ? or t like ? );", (username, addr)) except: return 0 for row in q: r += 1 return r
def private_filelist(pauth = False): response.set_header("content-type", "text/plain; charset=utf-8") if not pauth: try: pauth = request.POST["pauth"] except: return "auth error!" write_to_log("x/filelist %s" % pauth) result = "" files = sorted(api.get_public_file_index()) msgfrom, addr = points.check_point(pauth) if not addr: for f in sorted(files): result = result + ":".join(f) return result files = files + api.get_file_index() try: files = files + api.get_private_file_index(msgfrom) except: None for f in sorted(files): result = result + ":".join(f) return result
def save_messsage(echoarea, msgid=False): if api.echo_filter(echoarea): subj = request.forms.get("subj") msgbody = request.forms.get("msgbody") if len(subj) > 0 and len(msgbody) > 0: pauth = request.forms.get("authstr") msgfrom, addr = points.check_point(pauth) if not addr: return "auth error!" response.set_cookie("authstr", pauth, path="/", max_age=3600000000) msg = "" msg = msg + echoarea + "\n" msg = msg + request.forms.get("to") + "\n" msg = msg + subj + "\n\n" if msgid: msg = msg + "@repto:" + msgid + "\n" msg = msg + msgbody msg = base64.b64encode(msg.encode("utf8")) message = api.toss_msg(msgfrom, addr, msg) if message.startswith("msg ok"): redirect("/%s" % message[7:]) else: redirect("/")
def private_filelist(pauth=False): response.set_header("content-type", "text/plain; charset=utf-8") if not pauth: try: pauth = request.POST["pauth"] except: return "auth error!" write_to_log("x/filelist %s" % pauth) result = "" files = sorted(api.get_public_file_index()) msgfrom, addr = points.check_point(pauth) if not addr: for f in sorted(files): result = result + ":".join(f) return result files = files + api.get_file_index() try: files = files + api.get_private_file_index(msgfrom) except: None for f in sorted(files): result = result + ":".join(f) return result
def echolist(): api.load_config() echoareas = [] s = request.get_cookie("subscription", secret='some-secret-key') if not s: subscription = [] for ea in api.echoareas: subscription.append(ea[0]) response.set_cookie("subscription", subscription, path="/", max_age=180 * 24 * 60 * 60, secret='some-secret-key') s = subscription if api.nosubscription: subscription = api.echoareas else: subscription = [] for ea in s: flag = False for e in api.echoareas: if ea in e: flag = True subscription.append(e) if not flag: subscription.append([ea, ""]) allechoareas = echoes(subscription) auth = request.get_cookie("authstr") msgfrom, addr = points.check_point(auth) return template("tpl/echolist.tpl", nodename=api.nodename, dsc=api.nodedsc, allechoareas=allechoareas, addr=addr, auth=auth, background=api.background, nosubscription=api.nosubscription)
def filelist(d=False): auth = request.get_cookie("authstr") msgfrom, addr = points.check_point(auth) files = api.get_public_file_index(d) if not addr: return template("tpl/filelist.tpl", nodename=api.nodename, dsc=api.nodedsc, files=sort_files(files), auth=False, background=api.background, d=d) files = files + api.get_file_index(d) try: files = files + api.get_private_file_index(msgfrom, d) except: None return template("tpl/filelist.tpl", nodename=api.nodename, dsc=api.nodedsc, files=sort_files(files), auth=auth, background=api.background, d=d)
def fecho_post(): response.set_header("content-type", "text/plain; charset=utf-8") try: pauth = request.POST["pauth"] except: pauth = False try: fecho = request.POST["fecho"] except: fecho = False try: f = request.files.get("file") except: f = False try: dsc = request.POST["dsc"] except: dsc = False if pauth and fecho and f and dsc: if not api.file_filter(f.raw_filename): return 'incorrect filename' if api.fecho_filter(fecho): msgfrom, addr = points.check_point(pauth) if addr: f.save("temp") if not os.path.exists("files/%s" % fecho): os.makedirs("files/%s" % fecho) hsh = api.fhsh(open("./temp", "rb").read()) hshs = [] try: for row in open("fecho/%s" % fecho, "r").read().split("\n"): hshs.append(row.split(":")[0]) except: None blacklist = open("fblacklist.txt", "r").read().split("\n") if not hsh in hshs and not hsh in blacklist: name = f.raw_filename while os.path.exists("files/%s/%s" % (fecho, name)): tmp = name.split(".") name = ".".join(tmp[:-1]) suffix = name.split("_")[-1] if suffix == name: suffix = "0" try: s = int(suffix) s += 1 post = "_" + str(s) except: post = "_1" if suffix != "0": Name = name.replace("_" + suffix, post) + "." + tmp[-1] else: name = name + post + "." + tmp[-1] try: size = str(os.stat("temp").st_size) except: size = "0" copyfile("temp", "files/%s/%s" % (fecho, name)) os.remove("temp") codecs.open("fecho/%s" % fecho, "a", "utf8").write( "%s:%s:%s:%s,%s:%s\n" % (hsh, name, size, api.nodename, addr, dsc.replace("\n", " ").replace("\r", ""))) codecs.open("files/indexes/files.txt", "a", "utf8").write( "%s/%s:%s\n" % (fecho, name, dsc.replace( "\n", " ").replace("\r", ""))) return "file ok:%s" % hsh else: os.remove("./temp") return "file exists" os.remove("./temp") else: return "error: no auth" else: return "incorrect file echoarea"
def mail_decode(auth): username, addr = points.check_point(auth) if username == "": return arg return username
def savefile(): auth = request.get_cookie("authstr") username, addr = points.check_point(auth) if addr: dest = request.forms.get("dest") fileecho = request.forms.get("fileecho") tfileecho = request.forms.get("tfileecho") f = request.files.get("file") dsc = request.forms.get("dsc") if fileecho == "": fecho = tfileecho else: fecho = fileecho path = "files/" + fecho if not api.file_filter(f.raw_filename): return template("tpl/upload_message.tpl", nodename=api.nodename, dsc=api.nodedsc, background=api.background, message="Некорректное имя файла") if api.fecho_filter(fecho): f.save("temp") if not os.path.exists("files/%s" % fecho): os.makedirs("files/%s" % fecho) hsh = api.fhsh(open("./temp", "rb").read()) hshs = [] try: for row in open("fecho/%s" % fecho, "r").read().split("\n"): hshs.append(row.split(":")[0]) except: None blacklist = open("fblacklist.txt", "r").read().split("\n") if not hsh in hshs and not hsh in blacklist: name = f.raw_filename while os.path.exists("files/%s/%s" % (fecho, name)): tmp = name.split(".") name = ".".join(tmp[:-1]) suffix = name.split("_")[-1] if suffix == name: suffix = "0" try: s = int(suffix) s += 1 post = "_" + str(s) except: post = "_1" if suffix != "0": Name = name.replace("_" + suffix, post) + "." + tmp[-1] else: name = name + post + "." + tmp[-1] try: size = str(os.stat("temp").st_size) except: size = "0" copyfile("temp", "files/%s/%s" % (fecho, name)) os.remove("temp") codecs.open("fecho/%s" % fecho, "a", "utf8").write( "%s:%s:%s:%s,%s:%s\n" % (hsh, name, size, api.nodename, addr, dsc.replace( "\n", " ").replace("\r", ""))) codecs.open("files/indexes/files.txt", "a", "utf8").write( "%s/%s:%s\n" % (fecho, name, dsc.replace("\n", " ").replace("\r", ""))) return template("tpl/upload_message.tpl", nodename=api.nodename, dsc=api.nodedsc, background=api.background, message="Файл успешно загружен") else: os.remove("./temp") return template("tpl/upload_message.tpl", nodename=api.nodename, dsc=api.nodedsc, background=api.background, message="Такой файл уже существует") os.remove("./temp") else: return template("tpl/upload_message.tpl", nodename=api.nodename, dsc=api.nodedsc, background=api.background, message="Некорректное имя файлэхоконференции") else: redirect("/")
def fecho_post(): response.set_header("content-type", "text/plain; charset=utf-8") try: pauth = request.POST["pauth"] except: pauth = False try: fecho = request.POST["fecho"] except: fecho = False try: f = request.files.get("file") except: f = False try: dsc = request.POST["dsc"] except: dsc = False if pauth and fecho and f and dsc: if not api.file_filter(f.raw_filename): return 'incorrect filename' if api.fecho_filter(fecho): msgfrom, addr = points.check_point(pauth) if addr: f.save("temp") if not os.path.exists("files/%s" % fecho): os.makedirs("files/%s" % fecho) hsh = api.fhsh(open("./temp", "rb").read()) hshs = [] try: for row in open("fecho/%s" % fecho, "r").read().split("\n"): hshs.append(row.split(":")[0]) except: None blacklist = open("fblacklist.txt", "r").read().split("\n") if not hsh in hshs and not hsh in blacklist: name = f.raw_filename while os.path.exists("files/%s/%s" % (fecho, name)): tmp = name.split(".") name = ".".join(tmp[:-1]) suffix = name.split("_")[-1] if suffix == name: suffix = "0" try: s = int(suffix) s += 1 post = "_" + str(s) except: post = "_1" if suffix != "0": Name = name.replace("_" + suffix, post) + "." + tmp[-1] else: name = name + post + "." + tmp[-1] try: size = str(os.stat("temp").st_size) except: size = "0" copyfile("temp", "files/%s/%s" % (fecho, name)) os.remove("temp") codecs.open("fecho/%s" % fecho, "a", "utf8").write("%s:%s:%s:%s,%s:%s\n" % (hsh, name, size, api.nodename, addr, dsc.replace("\n", " ").replace("\r", ""))) codecs.open("files/indexes/files.txt", "a", "utf8").write("%s/%s:%s\n" % (fecho, name, dsc.replace("\n", " ").replace("\r", ""))) return "file ok:%s" % hsh else: os.remove("./temp") return "file exists" os.remove("./temp") else: return "error: no auth" else: return "incorrect file echoarea"
def file_get(pauth, filename): msgfrom, addr = points.check_point(pauth) if addr: return static_file(filename, "files/")
def point(pauth, tmsg): msgfrom, addr = points.check_point(pauth) if not addr: return "auth error!" return api.toss_msg(msgfrom, addr, tmsg)