コード例 #1
0
ファイル: websetup.py プロジェクト: rellim78/baruwa
def setup_app(command, conf, variables):
    """Place any commands to setup baruwa here"""
    # Don't reload the app if it was loaded under the testing environment
    if not pylons.test.pylonsapp:
        load_environment(conf.global_conf, conf.local_conf)

    # Create the tables if they don't already exist
    print '-' * 100
    log.info("Creating tables")
    Base.metadata.create_all(bind=Session.bind)
    basepath = os.path.dirname(os.path.dirname(__file__))
    # Create the custom functions
    print '-' * 100
    log.info("Creating custom functions")
    sqlfile = os.path.join(basepath, 'baruwa', 'config', 'sql',
                           'functions.sql')
    if os.path.exists(sqlfile):
        with open(sqlfile, 'r') as handle:
            sql = handle.read()
            try:
                conn = Session.connection()
                conn.execute(text(sql))
                Session.commit()
            except ProgrammingError:
                Session.rollback()
    defaultserver = Session.query(Server)\
                    .filter(Server.hostname == 'default')\
                    .all()
    # Create the Mailscanner SQL config views
    print '-' * 100
    log.info("Populating initial sql")
    sqlfile = os.path.join(basepath, 'baruwa', 'config', 'sql',
                           'integration.sql')
    if os.path.exists(sqlfile):
        with open(sqlfile, 'r') as handle:
            sql = handle.read()
        for sqlcmd in sql.split(';'):
            if sqlcmd:
                try:
                    sqlcmd = "%s;" % sqlcmd
                    Session.execute(text(sqlcmd))
                    Session.commit()
                except ProgrammingError:
                    Session.rollback()
    if not defaultserver:
        log.info("Creating the default settings node")
        dfls = Server('default', True)
        Session.add(dfls)
        confserial = ConfigSettings('confserialnumber', 'ConfSerialNumber', 0)
        confserial.value = 1
        confserial.server_id = 1
        Session.add(confserial)
        Session.commit()
        log.info("Default settings node created !")
コード例 #2
0
ファイル: middleware.py プロジェクト: TetraAsh/baruwa2
def make_app(global_conf, full_stack=True, static_files=True, **app_conf):
    """Create a Pylons WSGI application and return it

    ``global_conf``
        The inherited configuration for this application. Normally from
        the [DEFAULT] section of the Paste ini file.

    ``full_stack``
        Whether this application provides a full WSGI stack (by default,
        meaning it handles its own exceptions and errors). Disable
        full_stack when this application is "managed" by another WSGI
        middleware.

    ``static_files``
        Whether this application serves its own static files; disable
        when another web server is responsible for serving them.

    ``app_conf``
        The application's local configuration. Normally specified in
        the [app:<name>] section of the Paste ini file (where <name>
        defaults to main).

    """
    # Configure the Pylons environment
    config = load_environment(global_conf, app_conf)

    # The Pylons WSGI app
    app = PylonsApp(config=config)

    # Routing/Session Middleware
    app = RoutesMiddleware(app, config['routes.map'], singleton=False)
    app = SessionMiddleware(app, config)

    # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)
    if 'what_log_file' in app_conf:
        what_log_file = app_conf['what_log_file']
    else:
        what_log_file = None

    app = make_middleware_with_config(app, global_conf, what_log_file)

    if asbool(full_stack):
        # Handle Python exceptions
        app = ErrorHandler(app, global_conf, **config['pylons.errorware'])

        # Display error documents for 401, 403, 404 status codes (and
        # 500 when debug is disabled)
        if asbool(config['debug']):
            app = StatusCodeRedirect(app)
        else:
            app = StatusCodeRedirect(app, [400, 401, 403, 404, 500])

    # Establish the Registry for this application
    app = RegistryManager(app)

    if asbool(static_files):
        # Serve static files
        static_app = StaticURLParser(config['pylons.paths']['static_files'])
        app = Cascade([static_app, app])
    app.config = config
    return app
コード例 #3
0
ファイル: websetup.py プロジェクト: aureg/baruwa2
def setup_app(command, conf, variables):
    """Place any commands to setup baruwa here"""
    # Don't reload the app if it was loaded under the testing environment
    if not pylons.test.pylonsapp:
        load_environment(conf.global_conf, conf.local_conf)

    # Create the tables if they don't already exist
    print '-' * 100
    log.info("Creating tables")
    Base.metadata.create_all(bind=Session.bind)
    basepath = os.path.dirname(os.path.dirname(__file__))
    # Create the custom functions
    print '-' * 100
    log.info("Creating custom functions")
    sqlfile = os.path.join(basepath,
                        'baruwa',
                        'config',
                        'sql',
                        'functions.sql')
    if os.path.exists(sqlfile):
        with open(sqlfile, 'r') as handle:
            sql = handle.read()
            try:
                conn = Session.connection()
                conn.execute(text(sql))
                Session.commit()
            except ProgrammingError:
                Session.rollback()
    defaultserver = Session.query(Server)\
                    .filter(Server.hostname == 'default')\
                    .all()
    # Create the Mailscanner SQL config views
    print '-' * 100
    log.info("Populating initial sql")
    sqlfile = os.path.join(basepath,
                        'baruwa',
                        'config',
                        'sql',
                        'integration.sql')
    if os.path.exists(sqlfile):
        with open(sqlfile, 'r') as handle:
            sql = handle.read()
        for sqlcmd in sql.split(';'):
            if sqlcmd:
                try:
                    sqlcmd = "%s;" % sqlcmd
                    Session.execute(text(sqlcmd))
                    Session.commit()
                except ProgrammingError:
                    Session.rollback()
    if not defaultserver:
        log.info("Creating the default settings node")
        dfls = Server('default', True)
        Session.add(dfls)
        confserial = ConfigSettings('confserialnumber',
                                    'ConfSerialNumber',
                                    0)
        confserial.value = 1
        confserial.server_id = 1
        Session.add(confserial)
        Session.commit()
        log.info("Default settings node created !")
    admin = Session.query(User).filter(User.account_type==1).all()
    if not admin:
        def timeout_handler(signum, frame):
            raise TimeoutException()

        old_handler = signal.signal(signal.SIGALRM, timeout_handler) 
        signal.alarm(30)
        try:
            create_user = raw_input('Do you want to configure '
                                'an admin account? (Y/N): ')
        except (TimeoutException, EOFError):
            sys.exit(0)
        finally:
            signal.signal(signal.SIGALRM, old_handler)
        signal.alarm(0)
        if str(create_user).lower() == 'y':
            print '-' * 100
            log.info("Creating initial admin account")
            value_map = {'username': True, 'password1': True,
                        'password2': True, 'firstname': False,
                        'lastname': False, 'email': True}
            values = {}

            def get_input(field, required):
                "Get user input"
                prompt = "Please enter the %s:" % field
                while 1:
                    if field in ['password1', 'password2']:
                        value = getpass.getpass(prompt=prompt)
                    else:
                        value = raw_input(prompt)
                    if not required:
                        break
                    if required and value.strip() != "":
                        if not field in ['email', 'password1', 'password2']:
                            break
                        if field == 'email':
                            if not ADDRESS_RE.match(value):
                                print "Please provide a valid email address."
                            else:
                                break
                        if field == 'password1':
                            try:
                                cracklib.VeryFascistCheck(value)
                            except ValueError, message:
                                print str(message)
                            else:
                                break
                        if field == 'password2':
                            if values['password1'] == value:
                                break
                            else:
                                print 'password2 does not match password1'
                return value

            for attr in value_map:
                value = get_input(attr, value_map[attr])
                values[attr] = value
            user = User(values['username'], values['email'])
            for name in ['firstname', 'lastname']:
                if values[name]:
                    setattr(user, name, values[name])
            user.internal = True
            user.active = True
            user.local = True
            user.account_type = 1
            user.set_password(values['password1'])
            Session.add(user)
            Session.commit()
コード例 #4
0
ファイル: middleware.py プロジェクト: l3dlp-sandbox/baruwa2
def make_app(global_conf, full_stack=True, static_files=True, **app_conf):
    """Create a Pylons WSGI application and return it

    ``global_conf``
        The inherited configuration for this application. Normally from
        the [DEFAULT] section of the Paste ini file.

    ``full_stack``
        Whether this application provides a full WSGI stack (by default,
        meaning it handles its own exceptions and errors). Disable
        full_stack when this application is "managed" by another WSGI
        middleware.

    ``static_files``
        Whether this application serves its own static files; disable
        when another web server is responsible for serving them.

    ``app_conf``
        The application's local configuration. Normally specified in
        the [app:<name>] section of the Paste ini file (where <name>
        defaults to main).

    """
    # Configure the Pylons environment
    config = load_environment(global_conf, app_conf)

    # The Pylons WSGI app
    app = PylonsApp(config=config)

    # Routing/Session Middleware
    app = RoutesMiddleware(app, config['routes.map'], singleton=False)
    app = SessionMiddleware(app, config)

    # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)
    if 'what_log_file' in app_conf:
        what_log_file = app_conf['what_log_file']
    else:
        what_log_file = None

    app = make_middleware_with_config(app, global_conf, what_log_file)

    if asbool(full_stack):
        # Handle Python exceptions
        app = ErrorHandler(app, global_conf, **config['pylons.errorware'])

        # Display error documents for 401, 403, 404 status codes (and
        # 500 when debug is disabled)
        if asbool(config['debug']):
            app = StatusCodeRedirect(app)
        else:
            app = StatusCodeRedirect(app, [400, 401, 403, 404, 500])

    # Establish the Registry for this application
    app = RegistryManager(app)

    if asbool(static_files):
        # Serve static files
        static_app = StaticURLParser(config['pylons.paths']['static_files'])
        app = Cascade([static_app, app])
    app.config = config
    return app
コード例 #5
0
ファイル: websetup.py プロジェクト: Kali-/baruwa
def setup_app(command, conf, variables):
    """Place any commands to setup baruwa here"""
    # Don't reload the app if it was loaded under the testing environment
    if not pylons.test.pylonsapp:
        load_environment(conf.global_conf, conf.local_conf)

    # Create the tables if they don't already exist
    print '-' * 100
    log.info("Creating tables")
    Base.metadata.create_all(bind=Session.bind)
    basepath = os.path.dirname(os.path.dirname(__file__))
    # Create the custom functions
    print '-' * 100
    log.info("Creating custom functions")
    sqlfile = os.path.join(basepath,
                        'baruwa',
                        'config',
                        'sql',
                        'functions.sql')
    if os.path.exists(sqlfile):
        with open(sqlfile, 'r') as handle:
            sql = handle.read()
            try:
                conn = Session.connection()
                conn.execute(text(sql))
                Session.commit()
            except ProgrammingError:
                Session.rollback()
    defaultserver = Session.query(Server)\
                    .filter(Server.hostname == 'default')\
                    .all()
    # Create the Mailscanner SQL config views
    print '-' * 100
    log.info("Populating initial sql")
    sqlfile = os.path.join(basepath,
                        'baruwa',
                        'config',
                        'sql',
                        'integration.sql')
    if os.path.exists(sqlfile):
        with open(sqlfile, 'r') as handle:
            sql = handle.read()
        for sqlcmd in sql.split(';'):
            if sqlcmd:
                try:
                    sqlcmd = "%s;" % sqlcmd
                    Session.execute(text(sqlcmd))
                    Session.commit()
                except ProgrammingError:
                    Session.rollback()
    if not defaultserver:
        log.info("Creating the default settings node")
        dfls = Server('default', True)
        Session.add(dfls)
        confserial = ConfigSettings('confserialnumber',
                                    'ConfSerialNumber',
                                    0)
        confserial.value = 1
        confserial.server_id = 1
        Session.add(confserial)
        Session.commit()
        log.info("Default settings node created !")
コード例 #6
0
def setup_app(command, conf, variables):
    """Place any commands to setup baruwa here"""
    # Don't reload the app if it was loaded under the testing environment
    if not pylons.test.pylonsapp:
        load_environment(conf.global_conf, conf.local_conf)

    # Create the tables if they don't already exist
    print '-' * 100
    log.info("Creating tables")
    Base.metadata.create_all(bind=Session.bind)
    basepath = os.path.dirname(os.path.dirname(__file__))
    # Create the custom functions
    print '-' * 100
    log.info("Creating custom functions")
    sqlfile = os.path.join(basepath, 'baruwa', 'config', 'sql',
                           'functions.sql')
    if os.path.exists(sqlfile):
        with open(sqlfile, 'r') as handle:
            sql = handle.read()
            try:
                conn = Session.connection()
                conn.execute(text(sql))
                Session.commit()
            except ProgrammingError:
                Session.rollback()
    defaultserver = Session.query(Server)\
                    .filter(Server.hostname == 'default')\
                    .all()
    # Create the Mailscanner SQL config views
    print '-' * 100
    log.info("Populating initial sql")
    sqlfile = os.path.join(basepath, 'baruwa', 'config', 'sql',
                           'integration.sql')
    if os.path.exists(sqlfile):
        with open(sqlfile, 'r') as handle:
            sql = handle.read()
        for sqlcmd in sql.split(';'):
            if sqlcmd:
                try:
                    sqlcmd = "%s;" % sqlcmd
                    Session.execute(text(sqlcmd))
                    Session.commit()
                except ProgrammingError:
                    Session.rollback()
    if not defaultserver:
        log.info("Creating the default settings node")
        dfls = Server('default', True)
        Session.add(dfls)
        confserial = ConfigSettings('confserialnumber', 'ConfSerialNumber', 0)
        confserial.value = 1
        confserial.server_id = 1
        Session.add(confserial)
        Session.commit()
        log.info("Default settings node created !")
    admin = Session.query(User).filter(User.account_type == 1).all()
    if not admin:

        def timeout_handler(signum, frame):
            raise TimeoutException()

        old_handler = signal.signal(signal.SIGALRM, timeout_handler)
        signal.alarm(30)
        try:
            create_user = raw_input('Do you want to configure '
                                    'an admin account? (Y/N): ')
        except (TimeoutException, EOFError):
            sys.exit(0)
        finally:
            signal.signal(signal.SIGALRM, old_handler)
        signal.alarm(0)
        if str(create_user).lower() == 'y':
            print '-' * 100
            log.info("Creating initial admin account")
            value_map = {
                'username': True,
                'password1': True,
                'password2': True,
                'firstname': False,
                'lastname': False,
                'email': True
            }
            values = {}

            def get_input(field, required):
                "Get user input"
                prompt = "Please enter the %s:" % field
                while 1:
                    if field in ['password1', 'password2']:
                        value = getpass.getpass(prompt=prompt)
                    else:
                        value = raw_input(prompt)
                    if not required:
                        break
                    if required and value.strip() != "":
                        if not field in ['email', 'password1', 'password2']:
                            break
                        if field == 'email':
                            if not ADDRESS_RE.match(value):
                                print "Please provide a valid email address."
                            else:
                                break
                        if field == 'password1':
                            try:
                                cracklib.VeryFascistCheck(value)
                            except ValueError, message:
                                print str(message)
                            else:
                                break
                        if field == 'password2':
                            if values['password1'] == value:
                                break
                            else:
                                print 'password2 does not match password1'
                return value

            for attr in value_map:
                value = get_input(attr, value_map[attr])
                values[attr] = value
            user = User(values['username'], values['email'])
            for name in ['firstname', 'lastname']:
                if values[name]:
                    setattr(user, name, values[name])
            user.internal = True
            user.active = True
            user.local = True
            user.account_type = 1
            user.set_password(values['password1'])
            Session.add(user)
            Session.commit()