Exemple #1
0
    def __init__(self, server, cfg_manager):
        core_server_url  = cfg_manager.get_value( 'core_server_url', '' )
        self.script_name = urlparse.urlparse(core_server_url).path.split('/weblab')[0] or ''

        self.app = Flask('weblab.core.wl')
        self.app.config['SECRET_KEY'] = os.urandom(32)
        self.app.config['APPLICATION_ROOT'] = self.script_name
        self.app.config['SESSION_COOKIE_PATH'] = self.script_name + '/weblab/'
        self.app.config['SESSION_COOKIE_NAME'] = 'weblabsession'

        # Initialize internationalization code.
        initialize_i18n(self.app)

        # Mostly for debugging purposes, this snippet will print the site-map so that we can check
        # which methods we are routing.
        @self.app.route("/site-map")
        def site_map():
            lines = []
            for rule in self.app.url_map.iter_rules():
                line = str(escape(repr(rule)))
                lines.append(line)

            ret = "<br>".join(lines)
            return ret


        flask_debug = cfg_manager.get_value('flask_debug', False)
        core_facade_port = cfg_manager.get_value(configuration_doc.CORE_FACADE_PORT, 'unknown')
        if flask_debug and not is_testing():
            print("*" * 50, file=sys.stderr)
            print("WARNING " * 5, file=sys.stderr)
            print("flask_debug is set to True. This is an important security leak. Do not use it in production, only for bugfixing!!!", file=sys.stderr)
            print("If you want to see the debug toolbar in Flask pages, also use http://localhost:{0}/weblab/".format(core_facade_port), file=sys.stderr)
            print("WARNING " * 5, file=sys.stderr)
            print("*" * 50, file=sys.stderr)
        self.app.config['DEBUG'] = flask_debug
        if os.path.exists('logs'):
            f = os.path.join('logs','admin_app.log')
        else:
            f = 'admin_app.log'
        file_handler = RotatingFileHandler(f, maxBytes = 50 * 1024 * 1024)
        file_handler.setLevel(logging.WARNING)
        self.app.logger.addHandler(file_handler)

        super(WebLabFlaskServer, self).__init__(cfg_manager, self.app)

        json_api = Blueprint('json', __name__)
        weblab_api.apply_routes_api(json_api, server)
        self.app.register_blueprint(json_api, url_prefix = '/weblab/json')
        self.app.register_blueprint(json_api, url_prefix = '/weblab/login/json')
 
        authn_web = Blueprint('login_web', __name__)
        weblab_api.apply_routes_login_web(authn_web, server)
        self.app.register_blueprint(authn_web, url_prefix = '/weblab/login/web')

        static_folder = os.path.abspath(os.path.join(os.path.dirname(__file__), 'static'))
        core_web = Blueprint('core_web', __name__, static_folder=static_folder)
        weblab_api.apply_routes_web(core_web, server)
        self.app.register_blueprint(core_web, url_prefix = '/weblab/web')

        # Register the blueprint for the new (year 2015) flask-based web client.
        # The .apply_routes_webclient method is dynamically generated, the name matches
        # that in the wl.py module.
        # Attempt at setting the right static folder.
        core_webclient = Blueprint('core_webclient', __name__, static_folder=static_folder)
        weblab_api.apply_routes_webclient(core_webclient, server)
        self.app.register_blueprint(core_webclient, url_prefix = '/weblab/web/webclient')

        @self.app.context_processor
        def inject_weblab_api():
            return dict(weblab_api=weblab_api)

        self.admin_app = AdministrationApplication(self.app, cfg_manager, server)

        if flask_debug:
            from flask_debugtoolbar import DebugToolbarExtension
            toolbar = DebugToolbarExtension()
            toolbar.init_app(self.app)
            self.app.config['DEBUG_TB_INTERCEPT_REDIRECTS'] = False
            self.app.config['DEBUG_TB_PROFILER_ENABLED'] = True
Exemple #2
0
    app = Flask('weblab.core.server')
    app.config['SECRET_KEY'] = os.urandom(32)
    app.config['DEBUG_TB_INTERCEPT_REDIRECTS'] = False
    app.config['DEBUG'] = True

    @app.route("/site-map")
    def site_map():
        lines = []
        for rule in app.url_map.iter_rules():
            line = str(escape(repr(rule)))
            lines.append(line)

        ret = "<br>".join(lines)
        return ret

    admin_app = AdministrationApplication(app, cfg_manager, ups, bypass_authz = True)

    @admin_app.app.route('/')
    def index():
        return redirect('/weblab/administration/admin')
    
    initialize_i18n(app)

    toolbar = DebugToolbarExtension()
    toolbar.init_app(app)

    print("Open: http://localhost:5000/weblab/administration/admin/")
    app.run(debug=True, host='0.0.0.0')