def setup_server(): class Root: def index(self): return "This is public." index.exposed = True class BasicProtected: def index(self): return "Hello %s, you've been authorized." % cherrypy.request.login index.exposed = True class BasicProtected2: def index(self): return "Hello %s, you've been authorized." % cherrypy.request.login index.exposed = True userpassdict = {'xuser' : 'xpassword'} userhashdict = {'xuser' : md5(ntob('xpassword')).hexdigest()} def checkpasshash(realm, user, password): p = userhashdict.get(user) return p and p == md5(ntob(password)).hexdigest() or False conf = {'/basic': {'tools.auth_basic.on': True, 'tools.auth_basic.realm': 'wonderland', 'tools.auth_basic.checkpassword': auth_basic.checkpassword_dict(userpassdict)}, '/basic2': {'tools.auth_basic.on': True, 'tools.auth_basic.realm': 'wonderland', 'tools.auth_basic.checkpassword': checkpasshash}, } root = Root() root.basic = BasicProtected() root.basic2 = BasicProtected2() cherrypy.tree.mount(root, config=conf)
def start(self): if not self.started: self.started = True current_dir = os.path.join(self.guiUtility.utility.getPath(), 'Tribler', 'Main', 'webUI') config = {'/': {'tools.staticdir.root': current_dir, 'tools.staticdir.on': True, 'tools.staticdir.dir': "static", 'response.headers.connection': "close", } } if self.hasauth: userpassdict = {'hello': 'world'} checkpassword = checkpassword_dict(userpassdict) config['/'] = {'tools.auth_basic.on': True, 'tools.auth_basic.realm': 'Tribler-WebUI', 'tools.auth_basic.checkpassword': checkpassword} app = cherrypy.tree.mount(self, '/gui', config) app.log.access_log.setLevel(logging.NOTSET) app.log.error_log.setLevel(logging.NOTSET) self.server = cherrypy._cpserver.Server() self.server.socket_port = self.port self.server._socket_host = '0.0.0.0' self.server.thread_pool = 5 self.server.subscribe() self.server.start()
def start(self): if not self.started: self.started = True current_dir = os.path.dirname(os.path.abspath(__file__)) current_dir = os.path.join(self.guiUtility.utility.getPath(), 'Tribler', 'Main', 'webUI') cherrypy.server.socket_host = "0.0.0.0" cherrypy.server.socket_port = self.port cherrypy.server.thread_pool = 5 cherrypy.server.environment = "production" cherrypy.log.screen = False config = {'/': { 'tools.staticdir.root': current_dir, 'tools.staticdir.on': True, 'tools.staticdir.dir': "static", } } if self.hasauth: userpassdict = {'hello':'world'} checkpassword = checkpassword_dict(userpassdict) config['/'] = {'tools.auth_basic.on': True, 'tools.auth_basic.realm': 'Tribler-WebUI', 'tools.auth_basic.checkpassword': checkpassword} cherrypy.tree.mount(self, '/gui', config) cherrypy.engine.start()
def start(self): if not self.started: self.started = True current_dir = os.path.dirname(os.path.abspath(__file__)) current_dir = os.path.join(self.guiUtility.utility.getPath(), 'Tribler', 'Main', 'webUI') cherrypy.server.socket_host = "0.0.0.0" cherrypy.server.socket_port = self.port cherrypy.server.thread_pool = 5 cherrypy.server.environment = "production" cherrypy.log.screen = False config = { '/': { 'tools.staticdir.root': current_dir, 'tools.staticdir.on': True, 'tools.staticdir.dir': "static", } } if self.hasauth: userpassdict = {'hello': 'world'} checkpassword = checkpassword_dict(userpassdict) config['/'] = { 'tools.auth_basic.on': True, 'tools.auth_basic.realm': 'Tribler-WebUI', 'tools.auth_basic.checkpassword': checkpassword } cherrypy.tree.mount(self, '/gui', config) cherrypy.engine.start()
def setup_server(): class Root: def index(self): return "This is public." index.exposed = True class BasicProtected: def index(self): return "Hello %s, you've been authorized." % (cherrypy.request.login) index.exposed = True class BasicProtected2: def index(self): return "Hello %s, you've been authorized." % (cherrypy.request.login) index.exposed = True userpassdict = {"xuser": "******"} userhashdict = {"xuser": md5(ntob("xpassword")).hexdigest()} def checkpasshash(realm, user, password): p = userhashdict.get(user) return p and p == md5(ntob(password)).hexdigest() or False basic_checkpassword_dict = auth_basic.checkpassword_dict(userpassdict) conf = { "/basic": { "tools.auth_basic.on": True, "tools.auth_basic.realm": "wonderland", "tools.auth_basic.checkpassword": basic_checkpassword_dict, }, "/basic2": { "tools.auth_basic.on": True, "tools.auth_basic.realm": "wonderland", "tools.auth_basic.checkpassword": checkpasshash, }, } root = Root() root.basic = BasicProtected() root.basic2 = BasicProtected2() cherrypy.tree.mount(root, config=conf)
if __name__ == "__main__": logging.basicConfig( format="%(asctime)s : %(levelname)s : %(module)s:%(lineno)d : %(funcName)s(%(threadName)s) : %(message)s", level=logging.DEBUG, ) logger.info("running %s", " ".join(sys.argv)) program = os.path.basename(sys.argv[0]) if len(sys.argv) < 2: print(globals()["__doc__"] % locals()) sys.exit(1) data_directory = sys.argv[1] conf_file = os.path.join(data_directory, "artik.conf") conf = cherrypy.lib.reprconf.Config(conf_file) conf['/'] = { 'tools.auth_basic.on': False, # Basic Auth disabled until HTTPS on. 'tools.auth_basic.realm': 'galaxy', 'tools.auth_basic.checkpassword': auth_basic.checkpassword_dict(BASIC_AUTH_USERS), } logger.info("web server configuration: %s", conf) pid_file = conf['global'].get('pid_file', None) if pid_file: PIDFile(cherrypy.engine, pid_file).subscribe() cherrypy.quickstart(ArtikServer(), "/", config=conf) logger.info("finished running %s", program)
def setup_server(): class Root: @cherrypy.expose def index(self): return 'This is public.' class BasicProtected: @cherrypy.expose def index(self): return "Hello %s, you've been authorized." % ( cherrypy.request.login) class BasicProtected2: @cherrypy.expose def index(self): return "Hello %s, you've been authorized." % ( cherrypy.request.login) class BasicProtected2_u: @cherrypy.expose def index(self): return "Hello %s, you've been authorized." % ( cherrypy.request.login) userpassdict = {'xuser': '******'} userhashdict = {'xuser': md5(b'xpassword').hexdigest()} userhashdict_u = {'xюзер': md5(ntob('їжа', 'utf-8')).hexdigest()} def checkpasshash(realm, user, password): p = userhashdict.get(user) return p and p == md5(ntob(password)).hexdigest() or False def checkpasshash_u(realm, user, password): p = userhashdict_u.get(user) return p and p == md5(ntob(password, 'utf-8')).hexdigest() or False basic_checkpassword_dict = auth_basic.checkpassword_dict(userpassdict) conf = { '/basic': { 'tools.auth_basic.on': True, 'tools.auth_basic.realm': 'wonderland', 'tools.auth_basic.checkpassword': basic_checkpassword_dict }, '/basic2': { 'tools.auth_basic.on': True, 'tools.auth_basic.realm': 'wonderland', 'tools.auth_basic.checkpassword': checkpasshash, 'tools.auth_basic.accept_charset': 'ISO-8859-1', }, '/basic2_u': { 'tools.auth_basic.on': True, 'tools.auth_basic.realm': 'wonderland', 'tools.auth_basic.checkpassword': checkpasshash_u, 'tools.auth_basic.accept_charset': 'UTF-8', }, } root = Root() root.basic = BasicProtected() root.basic2 = BasicProtected2() root.basic2_u = BasicProtected2_u() cherrypy.tree.mount(root, config=conf)