def show(self): if self.cfg is None or self.cfgPath is None: Msg.showWarning( "No information found for cfg file. Did you load it?") return pprint(self.cfg) Msg.flush()
def createPassword(): Security.deletePassword() p = Security.promptForPassword(True) Msg.flush() Msg.show("Thanks ... please wait") Msg.flush() h = Security.hashAndSaltPassword(p) File.setContent(Security.__passwordPath, {"Password": h}, asJson=True)
def run(cocoscats): Web.cocoscats = cocoscats Web.useHttps = Text.isTrue(Web.cocoscats.cfg["Web"]["UseHttps"]) Web.useAuthentication = Text.isTrue( Web.cocoscats.cfg["Web"]["UseAuthentication"]) sessionOptions = { "session.type": "memory", "session.cookie_expires": 300, "session.auto": True } if Text.isTrue(Web.cocoscats.cfg["Web"]["Debug"]): WebSecurity.getSubresourceIntegrityHashes(True) Web.setupPassword() Web.setupCertificate() if Web.useHttps: Web.scheme = "https" Web.url = "{0}://{1}:{2}/".format(Web.scheme, Web.cocoscats.cfg["Web"]["Host"], Web.cocoscats.cfg["Web"]["Port"]) server = WebSecurity(host=Web.cocoscats.cfg["Web"]["Host"], port=Web.cocoscats.cfg["Web"]["Port"]) threading.Thread(target=bottle.run, kwargs=dict( app=SessionMiddleware(bottle.app(), sessionOptions), debug=Text.toTrueOrFalse( Web.cocoscats.cfg["Web"]["Debug"]), reloader=Text.toTrueOrFalse( Web.cocoscats.cfg["Web"]["Reloader"]), server=server)).start() else: Web.scheme = "http" Web.url = "{0}://{1}:{2}/".format(Web.scheme, Web.cocoscats.cfg["Web"]["Host"], Web.cocoscats.cfg["Web"]["Port"]) threading.Thread( target=bottle.run, kwargs=dict( app=SessionMiddleware(bottle.app(), sessionOptions), debug=Text.toTrueOrFalse( Web.cocoscats.cfg["Web"]["Debug"]), host=Web.cocoscats.cfg["Web"]["Host"], port=Web.cocoscats.cfg["Web"]["Port"], reloader=Text.toTrueOrFalse( Web.cocoscats.cfg["Web"]["Reloader"]))).start() Msg.flush() for client in Web.cocoscats.cfg["Web"]["Browser"]: if Text.isNothing(client) or client.lower() == "default": if webbrowser.open(Web.url): break else: if webbrowser.get(client).open(Web.url): break