Beispiel #1
0
 def removeLocation( locationName ):
     if not isinstance( locationName, str ):
         raise MaKaCError('locationName attribute must be string')
     root = MaKaC.common.DBMgr.getInstance().getDBConnection().root()
     locations = root[_ROOM_BOOKING_LOCATION_LIST]
     locations = [ loc for loc in locations if loc.friendlyName != locationName ]
     root[_ROOM_BOOKING_LOCATION_LIST] = locations
     from MaKaC.webinterface.rh.JSContent import RHGetVarsJs
     RHGetVarsJs.removeTmpVarsFile()
Beispiel #2
0
 def removeLocation(locationName):
     if not isinstance(locationName, str):
         raise MaKaCError('locationName attribute must be string')
     root = MaKaC.common.DBMgr.getInstance().getDBConnection().root()
     locations = root[_ROOM_BOOKING_LOCATION_LIST]
     locations = [
         loc for loc in locations if loc.friendlyName != locationName
     ]
     root[_ROOM_BOOKING_LOCATION_LIST] = locations
     from MaKaC.webinterface.rh.JSContent import RHGetVarsJs
     RHGetVarsJs.removeTmpVarsFile()
Beispiel #3
0
 def insertLocation( location ):
     if not isinstance( location, Location ):
         raise MaKaCError('location attribute must be of Location class')
     if Location.parse(location.friendlyName):
         # location with same name already exists
         return False
     root = MaKaC.common.DBMgr.getInstance().getDBConnection().root()
     locations = root[_ROOM_BOOKING_LOCATION_LIST]
     locations.append( location )
     root[_ROOM_BOOKING_LOCATION_LIST] = locations
     from MaKaC.webinterface.rh.JSContent import RHGetVarsJs
     RHGetVarsJs.removeTmpVarsFile()
Beispiel #4
0
 def insertLocation(location):
     if not isinstance(location, Location):
         raise MaKaCError('location attribute must be of Location class')
     if Location.parse(location.friendlyName):
         # location with same name already exists
         return False
     root = MaKaC.common.DBMgr.getInstance().getDBConnection().root()
     locations = root[_ROOM_BOOKING_LOCATION_LIST]
     locations.append(location)
     root[_ROOM_BOOKING_LOCATION_LIST] = locations
     from MaKaC.webinterface.rh.JSContent import RHGetVarsJs
     RHGetVarsJs.removeTmpVarsFile()
Beispiel #5
0
def start_web_server(host='localhost', port=0, with_ssl=False, keep_base_url=True, ssl_cert=None, ssl_key=None,
                     reload_on_change=False):
    """
    Sets up a Werkzeug-based web server based on the parameters provided
    """

    config = Config.getInstance()
    # Let Indico know that we are using the embedded server. This causes it to re-raise exceptions so they
    # end up in the Werkzeug debugger.
    config._configVars['EmbeddedWebserver'] = True
    # We obviously do not have X-Sendfile or X-Accel-Redirect support in the embedded server
    config._configVars['StaticFileMethod'] = None

    # Get appropriate base url and defaults
    base_url = config.getBaseSecureURL() if with_ssl else config.getBaseURL()
    if not base_url:
        base_url = config.getBaseURL() or 'http://localhost'
        if with_ssl:
            port = 443
        console.warning(' * You should set {0}; retrieving host information from {1}'.format(
            'BaseSecureURL' if with_ssl else 'BaseURL',
            base_url))
    default_port = 443 if with_ssl else 80
    url_data = urlparse.urlparse(base_url)

    # commandline data has priority, fallback to data from base url (or default in case of port)
    host = host or url_data.netloc.partition(':')[0]
    requested_port = used_port = port or url_data.port or default_port

    # Don't let people bind on a port they cannot use.
    if used_port < 1024 and not _can_bind_port(used_port):
        used_port += 8000
        console.warning(' * You cannot open a socket on port {0}, using {1} instead.'.format(requested_port, used_port))

    # By default we update the base URL with the actual host/port. The user has the option to
    # disable this though in case he wants different values, e.g. to use iptables to make his
    # development server available via port 443 while listening on a non-privileged port:
    # iptables -t nat -A PREROUTING -d YOURIP/32 -p tcp -m tcp --dport 443 -j REDIRECT --to-port 8443
    if not keep_base_url:
        scheme = 'https' if with_ssl else 'http'
        netloc = host
        if used_port != default_port:
            netloc += ':%d' % used_port
        base_url = '{0}://{1}{2}'.format(scheme, netloc, url_data.path)
    # However, if we had to change the port to avoid a permission issue we always rewrite BaseURL.
    # In this case it is somewhat safe to assume that the user is not actually trying to use the iptables hack
    # mentioned above but simply did not consider using a non-privileged port.
    elif requested_port != used_port:
        netloc = '{0}:{1}'.format(url_data.netloc.partition(':')[0], used_port)
        base_url = '{0}://{1}{2}'.format(url_data.scheme, netloc, url_data.path)

    # If we need to perform internal requests for some reason we want to use the true host:port
    server_netloc = '{0}:{1}'.format(host, port) if port != default_port else host
    config._configVars['EmbeddedWebserverBaseURL'] = urlparse.urlunsplit(
        urlparse.urlsplit(base_url)._replace(netloc=server_netloc))

    # We update both BaseURL and BaseSecureURL to something that actually works.
    # In case of SSL-only we need both URLs to be set to the same SSL url to prevent some stuff being "loaded"
    # from an URL that is not available.
    # In case of not using SSL we clear the BaseSecureURL so the user does not need to update the config during
    # development if he needs to disable SSL for some reason.
    if with_ssl:
        config._configVars['BaseURL'] = base_url
        config._configVars['BaseSecureURL'] = base_url
    else:
        config._configVars['BaseURL'] = base_url
        config._configVars['BaseSecureURL'] = ''
    config._deriveOptions()
    # Regenerate JSVars to account for the updated URLs
    RHGetVarsJs.removeTmpVarsFile()

    console.info(' * Using BaseURL {0}'.format(base_url))
    app = make_indico_dispatcher(make_app())
    server = WerkzeugServer(app, host, used_port, reload_on_change=reload_on_change,
                            enable_ssl=with_ssl, ssl_cert=ssl_cert, ssl_key=ssl_key)
    signal.signal(signal.SIGINT, _sigint)
    server.run()
Beispiel #6
0
 def setDefaultLocation( locationName ):
     root = MaKaC.common.DBMgr.getInstance().getDBConnection().root()
     root[_DEFAULT_ROOM_BOOKING_LOCATION] = locationName
     from MaKaC.webinterface.rh.JSContent import RHGetVarsJs
     RHGetVarsJs.removeTmpVarsFile()
Beispiel #7
0
 def setRoomBookingModuleActive( self, active = False ):
     self._roomBookingModuleActive = active
     from MaKaC.webinterface.rh.JSContent import RHGetVarsJs
     RHGetVarsJs.removeTmpVarsFile()
Beispiel #8
0
 def setDefaultLocation(locationName):
     root = MaKaC.common.DBMgr.getInstance().getDBConnection().root()
     root[_DEFAULT_ROOM_BOOKING_LOCATION] = locationName
     from MaKaC.webinterface.rh.JSContent import RHGetVarsJs
     RHGetVarsJs.removeTmpVarsFile()
Beispiel #9
0
 def setRoomBookingModuleActive(self, active=False):
     self._roomBookingModuleActive = active
     from MaKaC.webinterface.rh.JSContent import RHGetVarsJs
     RHGetVarsJs.removeTmpVarsFile()
Beispiel #10
0
def start_web_server(app, host='localhost', port=0, with_ssl=False, keep_base_url=True, ssl_cert=None, ssl_key=None,
                     reload_on_change=False, enable_evalex=False, evalex_from=None):
    config = Config.getInstance()
    # Let Indico know that we are using the embedded server. This causes it to re-raise exceptions so they
    # end up in the Werkzeug debugger.
    config._configVars['EmbeddedWebserver'] = True
    # We obviously do not have X-Sendfile or X-Accel-Redirect support in the embedded server
    config._configVars['StaticFileMethod'] = None

    # Get appropriate base url and defaults
    base_url = config.getBaseSecureURL() if with_ssl else config.getBaseURL()
    if not base_url:
        base_url = config.getBaseURL() or 'http://localhost'
        if with_ssl:
            port = 443
        console.warning(' * You should set {0}; retrieving host information from {1}'.format(
            'BaseSecureURL' if with_ssl else 'BaseURL',
            base_url)
        )
    default_port = 443 if with_ssl else 80
    url_data = urlparse.urlparse(base_url)

    # commandline data has priority, fallback to data from base url (or default in case of port)
    host = host or url_data.netloc.partition(':')[0]
    requested_port = used_port = port or url_data.port or default_port

    # Don't let people bind on a port they cannot use.
    if used_port < 1024 and not _can_bind_port(used_port):
        used_port += 8000
        console.warning(' * You cannot open a socket on port {}, using {} instead.'.format(requested_port, used_port))

    # By default we update the base URL with the actual host/port. The user has the option to
    # disable this though in case he wants different values, e.g. to use iptables to make his
    # development server available via port 443 while listening on a non-privileged port:
    # iptables -t nat -A PREROUTING -d YOURIP/32 -p tcp -m tcp --dport 443 -j REDIRECT --to-port 8443
    if not keep_base_url:
        scheme = 'https' if with_ssl else 'http'
        netloc = host
        if used_port != default_port:
            netloc += ':%d' % used_port
        base_url = '{0}://{1}{2}'.format(scheme, netloc, url_data.path)
    # However, if we had to change the port to avoid a permission issue we always rewrite BaseURL.
    # In this case it is somewhat safe to assume that the user is not actually trying to use the iptables hack
    # mentioned above but simply did not consider using a non-privileged port.
    elif requested_port != used_port:
        netloc = '{0}:{1}'.format(url_data.netloc.partition(':')[0], used_port)
        base_url = '{0}://{1}{2}'.format(url_data.scheme, netloc, url_data.path)

    # If we need to perform internal requests for some reason we want to use the true host:port
    server_netloc = '{0}:{1}'.format(host, port) if port != default_port else host
    config._configVars['EmbeddedWebserverBaseURL'] = urlparse.urlunsplit(
        urlparse.urlsplit(base_url)._replace(netloc=server_netloc))

    # We update both BaseURL and BaseSecureURL to something that actually works.
    # In case of SSL-only we need both URLs to be set to the same SSL url to prevent some stuff being "loaded"
    # from an URL that is not available.
    # In case of not using SSL we clear the BaseSecureURL so the user does not need to update the config during
    # development if he needs to disable SSL for some reason.
    if with_ssl:
        config._configVars['BaseURL'] = base_url
        config._configVars['BaseSecureURL'] = base_url
    else:
        config._configVars['BaseURL'] = base_url
        config._configVars['BaseSecureURL'] = ''
    config._deriveOptions()
    # Regenerate JSVars to account for the updated URLs
    RHGetVarsJs.removeTmpVarsFile()

    if not enable_evalex:
        evalex_whitelist = False
    elif evalex_from:
        evalex_whitelist = evalex_from
    else:
        evalex_whitelist = True

    console.info(' * Using BaseURL {0}'.format(base_url))
    app.wsgi_app = make_indico_dispatcher(app.wsgi_app)
    app.wsgi_app = SharedDataMiddleware(app.wsgi_app, {
        '/htmlcov': os.path.join(app.root_path, '..', 'htmlcov')
    }, cache=False)
    server = WerkzeugServer(app, host, used_port, reload_on_change=reload_on_change, evalex_whitelist=evalex_whitelist,
                            enable_ssl=with_ssl, ssl_cert=ssl_cert, ssl_key=ssl_key)
    signal.signal(signal.SIGINT, _sigint)
    server.run()