# AGPL 3 or any later version # (C) J.Y.Amihud ( Blender Dumbass ) from modules.Common import * import os import sys import json def Folder(): conf = "BDServer" try: data_dir = os.environ["XDG_DATA_HOME"] + "/" + conf except: data_dir = os.path.expanduser("~/.local/share/"+ conf) try: os.makedirs(data_dir) except: pass # Adding nessesary subcategories for i in ["pictures", "tabs", "logs", "accounts"]: try: os.makedirs(data_dir+"/"+i) except: pass return data_dir def Load(): try: with open(Folder()+"/config.json") as o: data = json.load(o) except Exception as e: data = {} print(clr["bold"]+clr["tdyl"]+"Error:"+clr["norm"]+" Config doesn't exist! Making new config.") return data def Save(data): try: with open(Folder()+"/config.json", "w") as save: json.dump(data, save, indent=4) except Exception as e: print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Cannot save config!", e) def Set(): if len(sys.argv) < 3: from modules import Help Help.Set() if "--title" in sys.argv: try: title = sys.argv[ sys.argv.index("--title") + 1] if "--" in title: 1/0 # Failing this for the error message. Title(title) except Exception as e: print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Title Wasn't Specified!") print('Use: $ python3 run.py --set --title "My Website"') if "--account" in sys.argv: try: account = sys.argv[ sys.argv.index("--account") + 1] if "--" in account: 1/0 # Failing this for the error message. MainAccount(account) except Exception as e: print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Account Wasn't Specified!") print('Use: $ python3 run.py --set --account blenderdumbass') if "--tagline" in sys.argv: try: tagline = sys.argv[ sys.argv.index("--tagline") + 1] if "--" in tagline: 1/0 # Failing this for the error message. Tagline(tagline) except Exception as e: print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Tagline Wasn't Specified!") print('Use: $ python3 run.py --set --title "Ultimate Club for Ultimate Hackers"') if "--domain" in sys.argv: try: domain = sys.argv[ sys.argv.index("--domain") + 1] if "--" in domain: 1/0 # Failing this for the error message. Domain(domain) except Exception as e: print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Didn't specify the domain.") print('Use: $ python3 run.py --set --domain blenderdumbass.org') if "--tor" in sys.argv: try: domain = sys.argv[ sys.argv.index("--tor") + 1] if "--" in domain: 1/0 # Failing this for the error message. Tor(domain) except Exception as e: print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Didn't specify the tor domain.") print('Use: $ python3 run.py --set --domain blenderdumbass.org') if "--editor" in sys.argv: try: editor = sys.argv[ sys.argv.index("--editor") + 1] if "--" in editor: 1/0 # Failing this for the error message. Editor(editor) except Exception as e: print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Didn't specify the editor!") print('Use: $ python3 run.py --set --editor emacs') if "--email" in sys.argv: Email() if "--port" in sys.argv: try: port = int(sys.argv[ sys.argv.index("--port") + 1]) Port(port) except Exception as e: print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Port Wasn't Specified Correctly!") print('Use: $ python3 run.py --set --port 8080') if "--add_tab" in sys.argv: try: tab = sys.argv[ sys.argv.index("--add_tab") + 1] if "--" in tab: 1/0 # Failing this for the error message. AddTab(tab) except Exception as e: print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Tab Name Wasn't Specified!") print('Use: $ python3 run.py --set --add_tab "Articles"') if "--edit_tab" in sys.argv: try: tab = sys.argv[ sys.argv.index("--edit_tab") + 1] if "--" in tab: 1/0 # Failing this for the error message. EditTab(tab) except Exception as e: print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Tab Name Wasn't Specified!") print('Use: $ python3 run.py --set --edit_tab "Articles"') if "--tab_rows" in sys.argv: try: tab_rows = int(sys.argv[ sys.argv.index("--tab_rows") + 1]) TabRows(tab_rows) except Exception as e: print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Number Wasn't Specified Correctly!") print('Use: $ python3 run.py --set --tab_rows 2') if "--css" in sys.argv: try: filename = sys.argv[ sys.argv.index("--css") + 1] if "--" in filename: 1/0 # Failing this for the error message. SetCSS(filename) except Exception as e: print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" CSS File Wasn't Specified!", e) print('Use: $ python3 run.py --set --css ~/mycssfile.css') if "--favicon" in sys.argv: try: filename = sys.argv[ sys.argv.index("--favicon") + 1] if "--" in filename: 1/0 # Failing this for the error message. SetFavicon(filename) except Exception as e: print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" File Wasn't Specified!", e) print('Use: $ python3 run.py --set --css ~/favicon.png') if "--css_edit" in sys.argv: config = Load() os.system("nano "+config.get("css", "default.css")) if "--fc_api" in sys.argv: try: api = sys.argv[ sys.argv.index("--fc_api") + 1] if "--" in api: 1/0 # Failing this for the error message. FreeCompetitors(api) except Exception as e: print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" API Link Wasn't Specified!") print('Use: $ python3 run.py --set --fc_api https://sudo.madiator.com') def Title(title): data = Load() data["title"] = title Save(data) print(clr["bold"]+clr["tbyl"]+title+clr["norm"]+" is set as title.") def Tagline(tagline): data = Load() data["tagline"] = tagline Save(data) print(clr["bold"]+clr["tbyl"]+tagline+clr["norm"]+" is set as tagline.") def Domain(domain): data = Load() data["domain"] = domain Save(data) print(clr["bold"]+clr["tbyl"]+domain+clr["norm"]+" is set as domain.") def Tor(domain): data = Load() data["tor"] = domain Save(data) print(clr["bold"]+clr["tbyl"]+domain+clr["norm"]+" is set as tor domain.") def Editor(editor): data = Load() data["editor"] = editor Save(data) print(clr["bold"]+clr["tbyl"]+editor+clr["norm"]+" is set as the editor.") def Port(port): data = Load() data["port"] = port Save(data) print(clr["bold"]+clr["tbyl"]+str(port)+clr["norm"]+" is set as the website's port.") def AddTab(tab): # Tab's Folder tabsFolder = Folder()+"/tabs/"+Simplify(tab) try: os.makedirs(tabsFolder) except Exception as e: print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Could not add tab!", e) return # Tab's Config File data = {"title":tab, "icon":"folder"} try: with open(tabsFolder+"/config.json", "w") as save: json.dump(data, save, indent=4, sort_keys=True) except Exception as e: print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Cannot save tab's config!", e) return print(clr["bold"]+clr["tbyl"]+tab+clr["norm"]+" tab is added as "+clr["bold"]+"/"+Simplify(tab)+clr["norm"]) def EditTab(tab): tabsFolder = Folder()+"/tabs/"+Simplify(tab) os.system(Load().get("editor", "nano")+" "+tabsFolder+"/config.json") def SetCSS(filename): try: f = open(filename, "r") f = f.read() except Exception as e: print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Cannot Read CSS file!", e) return css = open(Folder()+"/style.css", "w") css.write(f) css.close() config = Load() config["css"] = Folder()+"/style.css" Save(config) print("New CSS is set at "+clr["bold"]+Folder()+"/style.css"+clr["norm"]) def SetFavicon(filename): try: f = open(filename, "rb") f = f.read() except Exception as e: print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Cannot Read Image!", e) return css = open(Folder()+"/pictures/favicon.png", "wb") css.write(f) css.close() config = Load() config["favicon"] = "/pictures/favicon.png" Save(config) print("New favicon is set at "+clr["bold"]+Folder()+"/pictures/favicon.png"+clr["norm"]) def Email(): print("Please make sure your email provider supports") print("SMTP protocol.") server = input("SMTP server : ") port = input("SMTP port : ") username = input("Username : ") password = input("Password : ") sender = input("Sender Address : ") visible = input("Visible Address: ") config = Load() email = { "server":server, "port":port, "username":username, "password":password, "sender":sender, "visible":visible } config["email"] = email Save(config) print("Email credentials saved!") def TabRows(tab_rows): data = Load() data["tab_rows"] = tab_rows Save(data) print(clr["bold"]+clr["tbyl"]+str(tab_rows)+clr["norm"]+" is set as amount of rows to render tabs.") def MainAccount(account): data = Load() data["main_account"] = account Save(data) print(clr["bold"]+clr["tbyl"]+account+clr["norm"]+" is set as main account.") def FreeCompetitors(api): data = Load() data["free_competitors"] = api Save(data) print(clr["bold"]+clr["tbyl"]+api+clr["norm"]+" is set as Free Competitors API.")