# AGPL 3 or any later version # (C) J.Y.Amihud ( Blender Dumbass ) from http.server import BaseHTTPRequestHandler, HTTPServer from subprocess import * import json import os import time import random import datetime import hashlib import urllib.request import urllib.parse import subprocess import os from modules import Set from modules import Render from modules.Common import * class handler(BaseHTTPRequestHandler): def log_message(self, format, *args): if "?" in self.path: self.path = self.path[:self.path.find("?")] q = clr["tbbl"] b = clr["tbbl"] if self.newview: b = clr["bold"]+clr["tbrd"] for i in self.parsed: if i != "password": q = q + "[ "+i+" : "+self.parsed[i][0]+" ] " else: q = q + "[ "+i+" : ******* ] " toprint = consoleForm(self.cookie)+" "+b+"[ "+str(datetime.datetime.now())+" ] "+self.path+" "+q print(toprint) folder = Set.Folder() filename = folder+"/logs/"+datetime.datetime.now().strftime('%Y-%m-%d')+".log" logfile = open(filename, "ab") logfile.write((toprint+"\n").encode('utf-8')) logfile.close() def do_GET(self): self.path = self.path.replace("/..", "/") self.path = self.path.replace("%27", "'") parsed_url = urllib.parse.urlparse(self.path) self.parsed = urllib.parse.parse_qs(parsed_url.query) self.cookie = self.headers.get("Cookie") if self.cookie: self.cookie = self.cookie[-50:] self.newview = False categories = list(Render.tabs().keys()) if self.path[:self.path.find("?")] == "/" or self.path == "/": Render.MainPage(self) elif self.path[1:] in categories or self.path[1:self.path.find("?")] in categories: url = self.path[1:] if "?" in url: url = url[:url.find("?")] Render.ListPage(self, url) elif self.path[1:].startswith(tuple(categories)): url = self.path[1:] if "?" in url: url = url[:url.find("?")] Render.ArticlePage(self, url) elif self.path[1:].startswith("account"): url = self.path[9:] if "?" in url: url = url[:url.find("?")] Render.AccountPage(self, url) elif self.path[1:].startswith("login"): Render.LoginPage(self) elif self.path[1:].startswith("register"): Render.RegisterPage(self) elif self.path[1:].startswith("settings"): Render.SettingsPage(self) elif self.path[1:].startswith("comment"): Render.DoComment(self) elif self.path[1:].startswith("delete_comment"): Render.DeleteComment(self) elif self.path[1:].startswith("update_account"): Render.UpdateAccount(self) elif self.path[1:].startswith("create_invite"): Render.CreateInvite(self) elif self.path[1:].startswith("cancel_invite"): Render.CancelInvite(self) elif self.path[1:].startswith("log_out"): Render.LogOut(self) elif self.path[1:].startswith("do_login"): Render.Login(self) elif self.path[1:].startswith("do_register"): Render.Register(self) elif self.path[1:].startswith("read_notification"): Render.ReadNotification(self) elif self.path.startswith("/graph/"): url = self.path[6:] if "?" in url: url = url[:url.find("?")] Render.Graph(self, url) elif self.path.startswith("/pictures/"): folder = Set.Folder() f = open(folder+self.path, "rb") f = f.read() Render.headers(self, 200) self.wfile.write(f) elif self.path == "/css": config = Set.Load() filename = config.get("css", "default.css") cssfile = open(filename, "rb") cssfile = cssfile.read() Render.headers(self, 200) self.wfile.write(cssfile) elif self.path.startswith("/icon/"): folder = "icons" icon = folder+"/"+self.path[6:]+".png" f = open(icon, "rb") f = f.read() Render.headers(self, 200) self.wfile.write(f) else: Render.NotFound(self) config = Set.Load() PORT = config.get("port", 8080) serve = HTTPServer(("", PORT), handler) try: serve.serve_forever() except KeyboardInterrupt: print("\nServer Stopped!")