Esempio n. 1
0
def spike_init():
    logging.info("Initializing Spike")
    timestamp = int(time())

    app = create_app(__get_config_file())
    db.init_app(app)

    with app.app_context():
        db.create_all()

    for r in rulesets_seeds:
        logging.info("Adding ruleset: %s", r)
        rmks = "Ruleset for %s / auto-created %s" % (
            r, strftime("%F - %H:%M", localtime(time())))
        db.session.add(NaxsiRuleSets(r, rmks, timestamp))
    for w in whitelists_seeds:
        logging.info("Adding whitelistset: %s", w)
        rmks = "Ruleset for %s / auto-created %s" % (
            w, strftime("%F - %H:%M", localtime(time())))
        db.session.add(NaxsiWhitelistSets(w, rmks, timestamp))
    try:
        db.session.commit()
    except SQLAlchemyError:
        logging.error(
            'It seems that the database was already initialized. Did you meant to run `%s run` instead?',
            sys.argv[0])
    logging.info('Spike initialization completed')
Esempio n. 2
0
def create_app(config_filename=''):
    logging.info("Spike app.init()")

    app = Flask(__name__)

    if config_filename:
        app.config.from_pyfile(config_filename)

    if not app.config["SECRET_KEY"]:
        app.config["SECRET_KEY"] = base64.b64encode(os.urandom(128))

    app.config["SQLALCHEMY_BINDS"] = {'rules': 'sqlite:///rules.db'}

    db.init_app(app)
    db.app = app

    Bootstrap(app)  # add bootstrap templates and css

    # add blueprints
    app.register_blueprint(default.default)
    app.register_blueprint(rules.rules, url_prefix='/rules')
    app.register_blueprint(rulesets.rulesets, url_prefix='/rulesets')
    app.register_blueprint(sandbox.sandbox, url_prefix='/sandbox')
    app.register_blueprint(whitelists.whitelists, url_prefix='/whitelists')
    app.register_blueprint(whitelistsets.whitelistsets, url_prefix='/whitelistsets')

    # register filters
    app.jinja_env.globals['version'] = version

    return app
Esempio n. 3
0
def create_app(config_filename=''):
    logging.info("Spike app.init()")

    app = Flask(__name__)

    if config_filename:
        app.config.from_pyfile(config_filename)

    if not app.config["SECRET_KEY"]:
        app.config["SECRET_KEY"] = base64.b64encode(os.urandom(128))

    app.config["SQLALCHEMY_BINDS"] = {'rules': 'sqlite:///rules.db'}

    db.init_app(app)
    db.app = app

    Bootstrap(app)  # add bootstrap templates and css

    # add blueprints
    app.register_blueprint(default.default)
    app.register_blueprint(rules.rules, url_prefix='/rules')
    app.register_blueprint(rulesets.rulesets, url_prefix='/rulesets')
    app.register_blueprint(sandbox.sandbox, url_prefix='/sandbox')
    app.register_blueprint(whitelists.whitelists, url_prefix='/whitelists')
    app.register_blueprint(whitelistsets.whitelistsets,
                           url_prefix='/whitelistsets')

    # register filters
    app.jinja_env.globals['version'] = version

    return app
Esempio n. 4
0
 def setUp(self):
     app = create_app()
     db.init_app(app)
     app.config['TESTING'] = True
     self.app = app.test_client()
     self.created_rules = list()
     self.__create_rule()
Esempio n. 5
0
def run(debug=False):
    app = create_app(__get_config_file())
    db.init_app(app)

    if debug:
        app.test_request_context().push()

    try:
        host = app.config["APP_HOST"]
    except KeyError:
        host = '0.0.0.0'

    try:
        port = int(app.config["APP_PORT"])
    except KeyError:
        port = 5555

    app.run(debug=debug, host=host, port=port)
Esempio n. 6
0
def run(debug=False):
    app = create_app(__get_config_file())
    db.init_app(app)

    if debug:
        app.test_request_context().push()

    try:
        host = app.config["APP_HOST"]
    except KeyError:
        host = '127.0.0.1'

    try:
        port = int(app.config["APP_PORT"])
    except KeyError:
        port = 5555

    app.run(debug=debug, host=host, port=port)
Esempio n. 7
0
def spike_init():
    logging.info("Initializing Spike")
    timestamp = int(time())

    app = create_app(__get_config_file())
    db.init_app(app)

    with app.app_context():
        db.create_all()

    for r in rulesets_seeds:
        logging.info("Adding ruleset: %s", r)
        rmks = "Ruleset for %s / auto-created %s" % (r, strftime("%F - %H:%M", localtime(time())))
        db.session.add(NaxsiRuleSets(r, rmks, timestamp))
    for w in whitelists_seeds:
        logging.info("Adding whitelistset: %s", w)
        rmks = "Ruleset for %s / auto-created %s" % (w, strftime("%F - %H:%M", localtime(time())))
        db.session.add(NaxsiWhitelistSets(w, rmks, timestamp))
    try:
        db.session.commit()
    except SQLAlchemyError:
        logging.error('It seems that the database was already initialized. Did you meant to run `%s run` instead?',
                      sys.argv[0])
    logging.info('Spike initialization completed')
Esempio n. 8
0
 def setUp(self):
     app = create_app()
     db.init_app(app)
     app.config['TESTING'] = True
     self.app = app.test_client()
     self.wid = self.__create_whitelist()
Esempio n. 9
0
 def setUp(self):
     app = create_app()
     db.init_app(app)
     app.config['TESTING'] = True
     self.app = app.test_client()
     self.wid = self.__create_whitelist()
Esempio n. 10
0
 def setUp(self):
     app = create_app()
     db.init_app(app)
     app.config['TESTING'] = True
     self.app = app.test_client()
Esempio n. 11
0
 def setUp(self):
     app = create_app('../config.cfg')
     db.init_app(app)
     app.config['TESTING'] = True
     self.app = app.test_client()