Esempio n. 1
0
def run() -> int:
    """
    Traktować to podobnie, jak `if __name__=="__main__"`. Funkcja uruchomiona powinna inicjalizować działające UI.
    Obiekt `main.Session` powinien być generowany dla każdego użytkownika. Wystarczy używać metod tego obiektu do interakcji z programem.

    :return: Exit code, -1 restartuje aplikację
    :rtype: int
    """
    webbrowser.open('http://127.0.0.1:5000', 2, autoraise=True)
    http_server = WSGIServer(app, host='127.0.0.1', port=5000)
    http_server.start()
Esempio n. 2
0
class APIServer:
    def __init__(self, ip, port, cwd, debug=False):
        self.ip = ip
        self.port = port
        self.cwd = cwd
        self.debug = debug
        Configuration.global_parameters = self.__dict__
        self.app = Flask(
            'WSGI-Flask Server on port: {port}'.format(port=self.port),
            template_folder='{}/vue_web_code/dist'.format(self.cwd),
            static_folder='{}/vue_web_code/dist'.format(self.cwd))
        self.http_server = None

        # Setup database and trigger Database.__enter__()
        self.database = Database()
        with self.database:
            pass

        # Start the API documentation services
        try:
            yaml.warnings({'YAMLLoadWarning': False})
        except Exception as error:
            print(error)
        Swagger(self.app, template=template)

        threading.Thread(target=self.run).start()

    def run(self):
        print('Starting WSGI-Flask Server on port: {port}'.format(
            port=self.port))
        print('API: http://{}:{}'.format(self.ip, self.port))
        self.app.config['JSON_SORT_KEYS'] = True
        self.app.config['TEMPLATES_AUTO_RELOAD'] = True
        self.app.config['SECRET_KEY'] = str(time.time())

        self.app.config['DEBUG'] = True
        self.app.config['SESSION_COOKIE_HTTPONLY'] = True
        self.app.config['REMEMBER_COOKIE_HTTPONLY'] = True
        self.app.config['SESSION_COOKIE_SAMESITE'] = 'Strict'
        self.app.debug = True
        self.app.register_blueprint(routes)

        self.http_server = WSGIServer(self.app, host='0.0.0.0', port=self.port)
        self.http_server.start()

    def stop(self):
        self.http_server.stop()
Esempio n. 3
0
    def run(self):
        print('Starting WSGI-Flask Server on port: {port}'.format(
            port=self.port))
        print('API: http://{}:{}'.format(self.ip, self.port))
        self.app.config['JSON_SORT_KEYS'] = True
        self.app.config['TEMPLATES_AUTO_RELOAD'] = True
        self.app.config['SECRET_KEY'] = str(time.time())

        self.app.config['DEBUG'] = True
        self.app.config['SESSION_COOKIE_HTTPONLY'] = True
        self.app.config['REMEMBER_COOKIE_HTTPONLY'] = True
        self.app.config['SESSION_COOKIE_SAMESITE'] = 'Strict'
        self.app.debug = True
        self.app.register_blueprint(routes)

        self.http_server = WSGIServer(self.app, host='0.0.0.0', port=self.port)
        self.http_server.start()
Esempio n. 4
0
 def _start():
     init_db(configuration)
     with open(LOG_FILE, "w+") as log_file, \
             daemon.DaemonContext(pidfile=PIDLockFile(PID_FILE),
                                  detach_process=True,
                                  stdout=log_file, stderr=log_file):
         if no_wsgi:
             API.run("0.0.0.0", configuration.server_port)
         else:
             WSGIServer(API, port=configuration.server_port).start()
Esempio n. 5
0
def standalone():
    """Standalone command for starting a server.
    """
    parser = argparse.ArgumentParser(
        description="Start Argo Workflow API Dispatch Server"
    )
    parser.add_argument(
        "-p", "--port", help="Server listening port", type=int, default=8080
    )
    parser.add_argument(
        "-b", "--bind-address", help="Server bind address", default="127.0.0.1"
    )
    parser.add_argument(
        "-m",
        "--mock",
        "--mock-authentication",
        action="store_true",
        help="Do not require a JWT; mock out authentication",
    )
    parser.add_argument(
        "--no-verify-signature",
        action="store_true",
        help="Do not verify JWT signature",
    )
    parser.add_argument(
        "--no-verify-audience",
        action="store_true",
        help="Do not verify JWT audience",
    )
    args = parser.parse_args()
    mock = args.mock
    v_s = True
    v_a = True
    if args.no_verify_signature:
        v_s = False
    if args.no_verify_audience:
        v_a = False
    server = Server(_mock=mock, verify_signature=v_s, verify_audience=v_a)
    httpd = WSGIServer(server.app, host=args.bind_address, port=args.port)
    httpd.start()
Esempio n. 6
0
def main():
    # TODO: Добавить автоматическое приведение типов аргументов
    # TODO: Добавить авторизацию пользователей
    # TODO: Добавить обработку завершающего слеша

    from wsgiserver import WSGIRequestHandler, WSGIServer

    server = WSGIServer(port=8080, request_handler_cls=WSGIRequestHandler)
    server.set_app(app)
    server.serve_forever()
Esempio n. 7
0
def main():
    global tap, password
    if len(sys.argv) != 2:
        print("Usage: %s password" % sys.argv[0])
        sys.exit(1)
    password = sys.argv[1]
    tap = TunTapDevice(flags=IFF_TAP)
    tap.addr = ".".join(map(str, IP_PREFIX + (0, 1)))
    tap.netmask = '255.255.0.0'
    tap.mtu = 1300
    tap.hwaddr = MYMAC
    tap.up()
    tap_reader = threading.Thread(target=read_data, daemon=True)
    tap_reader.start()
    print('Serving on 8088...')
    WSGIServer(application, port=8088, numthreads=1000).start()
Esempio n. 8
0
def session() -> BaseUrlSession:
    """Start server and create new base URL session"""
    config = load_configuration(DEFAULT_CFG_PATH)
    port = config.server_port
    init_db(config)
    srv = Process(target=WSGIServer(API, port=port).start, daemon=True)
    srv.start()
    session = BaseUrlSession(f"http://localhost:{port}")
    end_time = time.monotonic() + 10

    def _not_up():
        """Returns True if server is down"""
        try:
            return session.get("").status_code != 200
        except requests.ConnectionError:
            return True

    while _not_up():  # wait until server is up and running
        time.sleep(0.1)
        if time.monotonic() > end_time:
            raise RuntimeError
    yield session
    session.close()
    srv.terminate()
Esempio n. 9
0
def main():
    from wsgiserver import WSGIRequestHandler, WSGIServer

    server = WSGIServer(port=8080, request_handler_cls=WSGIRequestHandler)
    server.set_app(application)
    server.serve_forever()
Esempio n. 10
0
import configparser
from app import create_app, socketio

app = create_app()

config = configparser.ConfigParser()
config.read("config.ini")

if __name__ == '__main__':
    if config['ssl']['enabled'] == 'yes':
        import ssl
        from wsgiserver import WSGIServer

        ctx = ssl.SSLContext(protocol=ssl.PROTOCOL_TLSv1_2)
        ctx.load_cert_chain(config['ssl']['certificate'], config['ssl']['key'])

        http_server = WSGIServer(
            (config['server']['host'], config['server']['port']),
            app,
            certfile=config['ssl']['certificate'],
            keyfile=config['ssl']['key'])
        http_server.serve_forever()
        socketio.run(app,
                     config['server']['host'],
                     int(config['server']['port']),
                     ssl_context=ctx)
    else:
        socketio.run(app, config['server']['host'],
                     int(config['server']['port']))
Esempio n. 11
0
 def handle(self, *args, **options):
     port = int(options['port'])
     server = WSGIServer(StaticFilesHandler(application), port=port)
     server.start()
Esempio n. 12
0
def entrypoint():
    from wsgiserver import WSGIServer
    port = int(os.environ.get("PORT", 8081))
    server = WSGIServer(app, host='127.0.0.1', port=port)
    server.start()
Esempio n. 13
0
File: run.py Progetto: NaitLee/PHFS
            Config.port = arg
        else:
            if os.path.exists(arg):
                arg = os.path.abspath(arg).replace('\\', '/')
                if os.path.isdir(arg):
                    Config.base_path = arg
                    Account.accounts[''] = ('', arg)
                    print(I18n.get_string('base_path_set_to_0').format(arg))
                elif os.path.isfile(arg):
                    tempdir = tempfile.mkdtemp()
                    smartcopy(arg, tempdir)
                    Config.base_path = tempdir
                    Account.accounts[''] = ('', tempdir)
                    print(I18n.get_string('base_path_set_to_0_which_includes_copy_of_all_selected_files').format(tempdir))
    else:
        tempdir = tempfile.mkdtemp()
        for i in sys.argv[1:]:
            if os.path.exists(i):
                smartcopy(os.path.abspath(i), tempdir)
        Config.base_path = tempdir
        Account.accounts[''] = ('', tempdir)
        print(I18n.get_string('base_path_set_to_0_which_includes_copy_of_all_selected_files').format(tempdir))

from serverLib import PHFSServer
from wsgiserver import WSGIServer

if __name__ == '__main__':
    print(I18n.get_string('running_at_port_0').format(Config.port))
    server = WSGIServer(PHFSServer(), Config.host, int(Config.port))
    server.start()