Esempio n. 1
0
    def login(self):
        """ Show login form.
        """

        if request.method != 'POST':
            cfg = NipapConfig()
            try:
                c.welcome_message = cfg.get('www', 'welcome_message')
            except NoOptionError:
                pass

            return render('login.html')

        # Verify username and password.
        auth_fact = AuthFactory()
        auth = auth_fact.get_auth(request.params.get('username'), request.params.get('password'), 'nipap')
        if not auth.authenticate():
            c.error = 'Invalid username or password'
            return render('login.html')

        # Mark user as logged in
        session['user'] = auth.username
        session['full_name'] = auth.full_name
        session['current_vrfs'] = {}
        session.save()

        # Send user back to the page he originally wanted to get to
        if session.get('path_before_login'):
            redirect(session['path_before_login'])

        else:
            # if previous target is unknown just send the user to a welcome page
            redirect(url(controller='vrf', action='list'))
Esempio n. 2
0
def load_environment(global_conf, app_conf):
    """Configure the Pylons environment via the ``pylons.config``
    object
    """
    config = PylonsConfig()
    
    # Pylons paths
    root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    paths = dict(root=root,
                 controllers=os.path.join(root, 'controllers'),
                 static_files=os.path.join(root, 'public'),
                 templates=[os.path.join(root, 'templates')])

    # Initialize config with the basic options
    config.init_app(global_conf, app_conf, package='nipapwww', paths=paths)

    config['routes.map'] = make_map(config)
    config['pylons.app_globals'] = app_globals.Globals(config)
    config['pylons.h'] = nipapwww.lib.helpers
    
    # Setup cache object as early as possible
    import pylons
    pylons.cache._push_object(config['pylons.app_globals'].cache)
    

    # Create the Jinja2 Environment
    jinja2_env = Environment(autoescape=True,
            extensions=['jinja2.ext.autoescape'],
            loader=FileSystemLoader(paths['templates']))
    config['pylons.app_globals'].jinja2_env = jinja2_env

    # CONFIGURATION OPTIONS HERE (note: all config options will override
    # any Pylons config options)
    config['pylons.strict_c'] = False

    # Make sure that there is a configuration object
    cfg = NipapConfig(config['nipap_config_path'], 
        { 'auth_cache_timeout': '3600' })

    # set XML-RPC URI in pynipap module
    pynipap.xmlrpc_uri = cfg.get('www', 'xmlrpc_uri')

    return config
Esempio n. 3
0
def load_environment(global_conf, app_conf):
    """Configure the Pylons environment via the ``pylons.config``
    object
    """
    config = PylonsConfig()

    # Pylons paths
    root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    paths = dict(
        root=root,
        controllers=os.path.join(root, "controllers"),
        static_files=os.path.join(root, "public"),
        templates=[os.path.join(root, "templates")],
    )

    # Initialize config with the basic options
    config.init_app(global_conf, app_conf, package="nipapwww", paths=paths)

    config["routes.map"] = make_map(config)
    config["pylons.app_globals"] = app_globals.Globals(config)
    config["pylons.h"] = nipapwww.lib.helpers

    # Setup cache object as early as possible
    import pylons

    pylons.cache._push_object(config["pylons.app_globals"].cache)

    # Create the Jinja2 Environment
    jinja2_env = Environment(loader=FileSystemLoader(paths["templates"]))
    config["pylons.app_globals"].jinja2_env = jinja2_env

    # CONFIGURATION OPTIONS HERE (note: all config options will override
    # any Pylons config options)
    config["pylons.strict_c"] = False

    # Make sure that there is a configuration object
    cfg = NipapConfig(config["nipap_config_path"], {"auth_cache_timeout": "3600"})

    # set XML-RPC URI in pynipap module
    pynipap.xmlrpc_uri = cfg.get("www", "xmlrpc_uri")

    return config
Esempio n. 4
0
def _register_inet(oid=None, conn_or_curs=None):
    """Create the INET type and an Inet adapter."""
    from psycopg2 import extensions as _ext
    if not oid: oid = 869
    _ext.INET = _ext.new_type((oid, ), "INET",
            lambda data, cursor: data and Inet(data) or None)
    _ext.register_type(_ext.INET, conn_or_curs)
    return _ext.INET



if __name__ == '__main__':

    # connect to old database
    # Get database configuration
    cfg = NipapConfig(nipap_cfg_path)
    db_args = {}
    db_args['host'] = cfg.get('nipapd', 'db_host')
    db_args['database'] = 'nipap_old'
    db_args['user'] = cfg.get('nipapd', 'db_user')
    db_args['password'] = cfg.get('nipapd', 'db_pass')
    db_args['sslmode'] = cfg.get('nipapd', 'db_sslmode')
    # delete keys that are None, for example if we want to connect over a
    # UNIX socket, the 'host' argument should not be passed into the DSN
    if db_args['host'] is not None and db_args['host'] == '':
        db_args['host'] = None
    for key in db_args.copy():
        if db_args[key] is None:
            del(db_args[key])

    # Create database connection to old db