def start(): Log.info("Initializing server...") # update config cherrypy.config.update({ "server.socket_port": Config.port, "server.socket_host": Config.host, "environment": "embedded", "tools.encode.text_only": False, "cors.expose.on": Config.cors, }) # update config for verbose mode if Config.verbose: cherrypy.config.update({ "log.screen": True, }) # cors if Config.cors: cherrypy_cors.install() Log.info("CORS enabled") # listen for signal def signal_handler(signal, frame): Log.info("Shutting down server...") cherrypy.engine.exit() Log.ok("Server shutdown successfully") signal.signal(signal.SIGINT, signal_handler) # start server cherrypy.quickstart(CherryPyServer())
def main(): engine = create_engine(os.environ.get('DATABASE_URL', DATABASE_URL)) models.init_models(engine) # web server cherrypy_cors.install() cherrypy.config.update({ 'global': { 'server.socket_host': '0.0.0.0', 'server.socket_port': int(os.environ.get('PORT', 8000)), 'request.show_tracebacks': False, 'tools.json_out.handler': json_handler } }) cherrypy.tree.mount(RootCtl(), '/', config={ '/': { 'tools.staticdir.on': True, 'tools.staticdir.dir': os.path.join(root, 'static'), 'cors.expose_public.on': True, } }) cherrypy.engine.start() cherrypy.engine.block()
def run(cls): cherrypy_cors.install() config = { '/': { 'cors.expose.on': True, }, } cherrypy.quickstart(cls(), config=config)
def run(cls): cherrypy_cors.install() config = { '/': { 'cors.expose.on': True, }, } cherrypy.server.socket_host = '127.0.0.1' cherrypy.server.socket_port = 5000 cherrypy.quickstart(cls(), config=config)
def setup_server(): class Root: @cherrypy.expose @cherrypy_cors.tools.expose() def index(self): return "hello" cherrypy.tree.mount(Root()) cherrypy_cors.install()
def run(cls, host='127.0.0.1', port=8080): cherrypy_cors.install() cherrypy.config.update({ 'server.socket_host': host, 'server.socket_port': port, }) config = { '/': { 'cors.expose.on': True, }, } cherrypy.quickstart(cls(), config=config)
def run_server(top10k, top100k, nlp, model): cherrypy.config.update({ "environment": "production", "log.screen": True }) cherrypy.server.socket_port = 16384 #cherrypy.server.socket_host = "0.0.0.0" rest_conf = {"/": { "request.dispatch": cherrypy.dispatch.MethodDispatcher(), 'cors.expose.on': True }} cherrypy_cors.install() cherrypy.quickstart(SimplifyEndpoint(top10k, top100k, nlp, model), "/simplify", rest_conf)
def serve(ip, port): cherrypy_cors.install() config = { '/': { 'tools.staticdir.on': True, 'tools.staticdir.dir': PATH, 'tools.staticdir.index': 'index.html', 'cors.expose.on': True, } } cherrypy.server.socket_host = ip cherrypy.server.socket_port = port cherrypy.quickstart(TCAServer(), '/', config)
def __init__(self, config, store, thread_pool): self._config = config self._pool = thread_pool self._store = store cherrypy_cors.install() cherrypy.tree.mount(self, "/", self._cherry_config()) self._student = StudentController(app=self) self._admin = AdminController(app=self) self._static_root = os.path.join(os.path.abspath(os.getcwd()), self._config["server"]["static_path"]) cherrypy.engine.subscribe('stop', self._on_stop) self._init_users()
def setup_server(): class Root: @cherrypy.expose def index(self): return "hello" config = { '/': { 'cors.expose.on': True, }, } cherrypy.tree.mount(Root(), config=config) cherrypy_cors.install()
def main(args): cherrypy_cors.install() cherrypy.tools.CORS = cherrypy.Tool('before_handler', CORS) cherrypy.config.update({ 'server.socket_host': '0.0.0.0', 'server.socket_port': args.port, 'log.access_file': './access.log', 'log.error_file': './error.log', 'tools.staticdir.on': True, 'tools.staticdir.dir': os.getcwd() + '/static', 'tools.staticdir.index': 'index.html', 'tools.CORS.on': True, 'cors.expose.on': True }) cherrypy.quickstart(WordPredict(args.validate), '/skyeng')
def start(cls, log_screen=False): cherrypy_cors.install() config = { 'global': { 'server.socket_host': '::0', 'server.socket_port': int(os.environ.get('PORT', 8080)), 'environment': 'production', 'log.screen': log_screen, }, '/': { 'cors.expose_public.on': True, }, } cherrypy.config.update(config) cherrypy.tree.mount(cls(), '', config) cherrypy.engine.start()
def setup_server(): class Root: @cherrypy.expose def index(self): return "hello" origins = 'http://example.com', 'https://example.com' config = { '/': { 'cors.expose.on': True, 'cors.expose.origins': origins, 'cors.preflight.origins': origins, }, } cherrypy.tree.mount(Root(), config=config) cherrypy_cors.install()
def setup_server(): class Root: @cherrypy.expose def index(self): return "hello" pattern = re.compile(r'(http|https)://svr[1-9]\.example\.com') config = { '/': { 'cors.expose.on': True, 'cors.expose.origins': [pattern], 'cors.preflight.origins': [pattern], }, } cherrypy.tree.mount(Root(), config=config) cherrypy_cors.install()
def main(): cherrypy.config.update({ 'server.socket_host': "ec2-3-6-38-167.ap-south-1.compute.amazonaws.com", 'server.socket_port': 8001, 'cors.expose.on': True, }) cherrypy.tree.mount(host(), '/') cherrypy.response.headers["Access-Control-Allow-Origin"] = "*" #cherrypy.response.headers[ "Content-Type"] = "application/json" cherrypy.response.headers[ "Access-Control-Allow-Methods"] = "GET, POST, HEAD, PUT, DELETE" allow_headers = [ "Cache-Control", "X-Proxy-Authorization", "X-Requested-With", "Content-Type" ] cherrypy.response.headers["Access-Control-Allow-Headers"] = ",".join( allow_headers) cherrypy_cors.install() cherrypy.engine.start() cherrypy.engine.block()
def web_services(): """Configures how the web services should run """ cherrypy_cors.install() conf = { '/': { 'request.dispatch': cherrypy.dispatch.MethodDispatcher(), 'cors.expose.on': True, 'tools.response_headers.on': True, 'tools.response_headers.headers': [ ('Content-Type', 'text/plain'), ('Access-Control-Allow-Origin', '*') ] } } # cherrypy.config.update({'server.socket_host': 'localhost'}) # cherrypy.config.update({'server.socket_host': '3.51.55.92'}) cherrypy.config.update({'server.socket_host': '192.168.1.85'}) cherrypy.config.update({'server.socket_port': 8086}) cherrypy.response.headers["Access-Control-Allow-Origin"] = "*" cherrypy.quickstart(WebServices(), '/', conf)
def init(database_filename, host, port): """ Configure and starts the server. :param database_filename: Location of the database file. :param host: Address on which to listen. :param port: Port on which to listen. """ cherrypy_cors.install() config = { '/': { 'cors.expose.on': True, 'tools.sessions.on': True, 'tools.response_headers.on': True, 'tools.response_headers.headers': [('Content-Type', 'text/plain')], }, } cherrypy.config.update({ 'server.socket_host': host, 'server.socket_port': port, }) cherrypy.quickstart(Server(database_filename), "/api", config=config)
def main(dev, mode, database, host, port): if dev and mode: raise click.ClickException('Conflict between --dev and --mode') if dev: mode = ServerMode.DEVELOPMENT # If the user provides no options, the existing config values get re-set through click cherrypy.config['database']['uri'] = database if six.PY2: # On Python 2, click returns the value as unicode and CherryPy expects a str # Keep this conversion explicitly for Python 2 only, so it can be removed when Python 2 # support is dropped host = str(host) cherrypy_cors.install() cherrypy.config['server.socket_host'] = host cherrypy.config['server.socket_port'] = port cherrypy.config['cors.expose.on'] = True _attachFileLogHandlers() server.setup(mode) cherrypy.engine.start() cherrypy.engine.block()
def run(): global outdir, dburl parser = argparse.ArgumentParser() parser.add_argument('--out', default=DEFAULT_OUTDIR, help='output directory') parser.add_argument('--port', type=int, default=8080, help='port to listen to web requests') parser.add_argument('--dburl', default=None, help='database URL') args = parser.parse_args() outdir = os.path.join(os.getcwd(), args.out) if args.dburl is None: outdb = os.path.join(outdir, 'cmonkey_run.db') print("connecting to database at ", outdb) dburl = cm2db.make_sqlite_url(outdb) else: dburl = args.dburl cherrypy_cors.install() conf = { '/': { 'request.dispatch': setup_routes(), 'cors.expose.on': True }, '/static': { 'tools.staticdir.on': True, 'tools.staticdir.dir': os.path.join(current_dir, 'static') } } cherrypy.config.update(conf) app = cherrypy.tree.mount(None, config=conf) cherrypy.server.socket_host = '0.0.0.0' cherrypy.server.socket_port = args.port cherrypy.quickstart(app)
def run(): global outdir, dburl parser = argparse.ArgumentParser() parser.add_argument('--out', default=DEFAULT_OUTDIR, help='output directory') parser.add_argument('--port', type=int, default=8080, help='port to listen to web requests') parser.add_argument('--dburl', default=None, help='database URL') args = parser.parse_args() outdir = os.path.join(os.getcwd(), args.out) if args.dburl is None: outdb = os.path.join(outdir, 'cmonkey_run.db') print("connecting to database at ", outdb) dburl = cm2db.make_sqlite_url(outdb) else: dburl = args.dburl cherrypy_cors.install() conf = {'/': {'request.dispatch': setup_routes(), 'cors.expose.on': True }, '/static': {'tools.staticdir.on': True, 'tools.staticdir.dir': os.path.join(current_dir, 'static')}} cherrypy.config.update(conf) app = cherrypy.tree.mount(None, config=conf) cherrypy.server.socket_host = '0.0.0.0' cherrypy.server.socket_port = args.port cherrypy.quickstart(app)
def start_web_server(sfWebUiConfig, sfConfig): """Start the web server so you can start looking at results Args: sfWebUiConfig (dict): web server options sfConfig (dict): SpiderFoot config options """ web_host = sfWebUiConfig.get('host', '127.0.0.1') web_port = sfWebUiConfig.get('port', 5001) web_root = sfWebUiConfig.get('root', '/') # Place your whitelisted CORS origins here # Example: cors_origins = ['http://example.com'] cors_origins = [] cherrypy.config.update({ 'log.screen': False, 'server.socket_host': web_host, 'server.socket_port': int(web_port) }) log.info(f"Starting web server at {web_host}:{web_port} ...") # Disable auto-reloading of content cherrypy.engine.autoreload.unsubscribe() sf = SpiderFoot(sfConfig) # Enable access to static files via the web directory conf = { '/query': { 'tools.encode.text_only': False, 'tools.encode.add_charset': True, }, '/static': { 'tools.staticdir.on': True, 'tools.staticdir.dir': 'static', 'tools.staticdir.root': sf.myPath() } } secrets = dict() passwd_file = sf.dataPath() + '/passwd' if os.path.isfile(passwd_file): if not os.access(passwd_file, os.R_OK): log.error("Could not read passwd file. Permission denied.") sys.exit(-1) pw = open(passwd_file, 'r') for line in pw.readlines(): if ':' not in line: log.error( "Incorrect format of passwd file, must be username:password on each line." ) sys.exit(-1) u = line.strip().split(":")[0] p = ':'.join(line.strip().split(":")[1:]) if not u or not p: log.error( "Incorrect format of passwd file, must be username:password on each line." ) sys.exit(-1) secrets[u] = p if secrets: log.info("Enabling authentication based on supplied passwd file.") conf['/'] = { 'tools.auth_digest.on': True, 'tools.auth_digest.realm': web_host, 'tools.auth_digest.get_ha1': auth_digest.get_ha1_dict_plain(secrets), 'tools.auth_digest.key': random.SystemRandom().randint(0, 99999999) } else: warn_msg = "\n********************************************************************\n" warn_msg += "Warning: passwd file contains no passwords. Authentication disabled.\n" warn_msg += "Please consider adding authentication to protect this instance!\n" warn_msg += "Refer to https://www.spiderfoot.net/documentation/#security.\n" warn_msg += "********************************************************************\n" log.warning(warn_msg) using_ssl = False key_path = sf.dataPath() + '/spiderfoot.key' crt_path = sf.dataPath() + '/spiderfoot.crt' if os.path.isfile(key_path) and os.path.isfile(crt_path): if not os.access(crt_path, os.R_OK): log.critical(f"Could not read {crt_path} file. Permission denied.") sys.exit(-1) if not os.access(key_path, os.R_OK): log.critical(f"Could not read {key_path} file. Permission denied.") sys.exit(-1) log.info("Enabling SSL based on supplied key and certificate file.") cherrypy.server.ssl_module = 'builtin' cherrypy.server.ssl_certificate = crt_path cherrypy.server.ssl_private_key = key_path using_ssl = True if using_ssl: url = "https://" cors_origins.append(f"https://{web_host}:{web_port}") else: url = "http://" cors_origins.append(f"http://{web_host}:{web_port}") if web_host == "0.0.0.0": # nosec url = f"{url}<IP of this host>" else: url = f"{url}{web_host}" url = f"{url}:{web_port}{web_root}" cherrypy_cors.install() cherrypy.config.update({ 'cors.expose.on': True, 'cors.expose.origins': cors_origins, 'cors.preflight.origins': cors_origins }) print("") print("*************************************************************") print(" Use SpiderFoot by starting your web browser of choice and ") print(f" browse to {url}") print("*************************************************************") print("") cherrypy.quickstart(SpiderFootWebUi(sfWebUiConfig, sfConfig), script_name=web_root, config=conf)
'tools.sessions.on': True, 'tools.staticdir.root': os.path.abspath(os.getcwd()), # 'tools.staticdir.root': bundle_dir, 'cors.expose.on': True }, 'global': { 'server.socket_host': '127.0.0.1', # REMOTE 'server.socket_host': 'hive2.cci.drexel.edu', 'server.socket_port': 8080, 'server.thread_pool': 10 }, '/static': { 'tools.staticdir.on': True, 'tools.staticdir.dir': './public' # REMOTE 'tools.staticdir.dir': 'site-packages/cherrypy/HIVE2a/public' , } } access_log = os.path.join(os.path.dirname(__file__), "access.log") error_log = os.path.join(os.path.dirname(__file__), "error.log") cherrypy.config.update({ 'log.screen': False, 'log.error_file': error_log, 'log.access_file': access_log }) import cherrypy_cors # CORS if __name__ == '__main__': cherrypy_cors.install() # CORS: Cross-origin resource support cherrypy.quickstart(HiveHome(), config=conf)
def main(): global recentBlogs global pool global commentsToServer global usersToServer pool = multiprocessing.Pool() # recentBlogs = json.loads(open('comments.json', 'r').read()) recentBlogs = set() try: qwer = open(path + '/comments.json', 'r') wert = qwer.readline() commentsToServer = json.loads(wert) for comment in commentsToServer: comments[comment['commentId']] = (comment['username'], comment['count'], comment['postId']) qwer.close() except: print(42) # recentBlogs = set(map(str, range(1, 25000))) recentBlogs = recentBlogs.union(updateRecentActions()) try: qwer = open(path + '/blogs.json', 'r') wert = qwer.readline() blogsToServer = json.loads(wert) for blog in blogsToServer: blogs[blog['postId']] = (blog['count'], blog['username']) except: print("ok") try: qwer = open(path + '/users.json', 'r') wert = qwer.readline() usersToServer = json.loads(wert) for user in usersToServer: users[user['username']] = user['count'] except: print("ok") download1 = threading.Thread(target=updateBlogsFromRecentActions) download2 = threading.Thread(target=recentActionsThread) download1.start() download2.start() conf = { '/': { 'tools.sessions.on': True, 'cors.expose.on': True, }, '/generator': { 'request.dispatch': cherrypy.dispatch.MethodDispatcher(), 'tools.response_headers.on': True, 'tools.response_headers.headers': [('Content-Type', 'text/plain')], }, } cherrypy_cors.install() webapp = CodeForcesServer() cherrypy.response.headers["Access-Control-Allow-Origin"] = "*" cherrypy.config.update({ 'server.socket_port': port, 'server.socket_host': host }) cherrypy.quickstart(webapp, '/', conf) download1.join() download2.join()
def __init__(self): self.env = Environment(loader=FileSystemLoader('../')) cherrypy_cors.install()
def main(): global recentBlogs global pool global commentsToServer global usersToServer pool = multiprocessing.Pool() # recentBlogs = json.loads(open('comments.json', 'r').read()) recentBlogs = set() try: qwer = open(path + '/comments.json', 'r') wert = qwer.readline() commentsToServer = json.loads(wert) for comment in commentsToServer: comments[comment['commentId']] = (comment['username'], comment['count'], comment['postId']) qwer.close() except: print(42) # recentBlogs = set(map(str, range(1, 25000))) recentBlogs = recentBlogs.union(updateRecentActions()) try: qwer = open(path + '/blogs.json', 'r') wert = qwer.readline() blogsToServer = json.loads(wert) for blog in blogsToServer: blogs[blog['postId']] = (blog['count'], blog['username']) except: print("ok") try: qwer = open(path + '/users.json', 'r') wert = qwer.readline() usersToServer = json.loads(wert) for user in usersToServer: users[user['username']] = user['count'] except: print("ok") download1 = threading.Thread(target=updateBlogsFromRecentActions) download2 = threading.Thread(target=recentActionsThread) download1.start() download2.start() conf = { '/': { 'tools.sessions.on': True, 'cors.expose.on': True, }, '/generator': { 'request.dispatch': cherrypy.dispatch.MethodDispatcher(), 'tools.response_headers.on': True, 'tools.response_headers.headers': [('Content-Type', 'text/plain')], }, } cherrypy_cors.install() webapp = CodeForcesServer() cherrypy.response.headers["Access-Control-Allow-Origin"] = "*" cherrypy.config.update({'server.socket_port': port, 'server.socket_host': host}) cherrypy.quickstart(webapp, '/', conf) download1.join() download2.join()
htmlstr = f.read() template = Template(htmlstr) concurrent_timestamps, concurrent_values = stats.get_concurrent_reqs_timeset( ) rendered = template.render( successes=success, fails=fail, errors=error, concurrent_timestamps=str(concurrent_timestamps), concurrent_values=str(concurrent_values)) return rendered else: raise cherrypy.HTTPError(status=400) cherrypy_cors.install() cors_expose = True try: if os.getenv('ALLOW_CORS') == "true": cors_expose = True except Exception: pass print("CORS Bypass: " + str(cors_expose)) cherrypy.config.update({ 'server.socket_host': '0.0.0.0', 'server.socket_port': 9090, 'tools.staticdir.on': True,
print category, products db = MongoClient().catemail collections = db.messages products = products.split('_') query = {'category': category, 'products': {'$in': products}} res = collections.find(query).sort('timestamp', -1).limit(100) ret = [] for doc in res: doc.pop('_id', None) ret.append(doc) return json.dumps({'status': 'OK', 'data': ret}) if __name__ == '__main__': cherrypy_cors.install() import sys reload(sys) sys.setdefaultencoding('utf8') current_dir = os.path.dirname(os.path.abspath(__file__)) cherrypy.server.socket_host = INTERNAL_IP #cherrypy.config.update({'server.socket_port': 80}) cherrypy.server.socket_port = 80 #cherrypy.config.update('config') cherrypy.config.update({'environment': 'production', 'log.error_file': 'site.log', 'cors.expose.on': True, 'log.screen': True, 'tools.proxy.on': True, 'tools.proxy.local': 'X-Forwarded-Host'})
def __init__(self): cherrypy.response.headers['Content-Type'] = 'application/json' cherrypy_cors.install() self.service = Service()