Пример #1
0
def main():
    global app
    global conf
    global fs
    global mailer
    global users

    setproctitle('firelet')
    args = parse_args()

    try:
        conf = ConfReader(fn=args.cf)
    except Exception as e:
        logging.error("Exception %s while reading configuration file %r", e,
                      args.cf)
        sys.exit(1)

    if args.repodir:
        conf.data_dir = args.repodir

    setup_logging(args, conf)

    log.success("Firelet started.")

    users = Users(d=conf.data_dir)
    mailer = Mailer(
        sender=conf.email_sender,
        recipients=conf.email_recipients,
        smtp_server=conf.email_smtp_server,
    )

    if conf.demo_mode:
        fs = DemoGitFireSet(conf.data_dir)
        log.info("Configuration loaded. Demo mode.")

    else:
        fs = GitFireSet(conf.data_dir)
        log.info("Configuration loaded.")

    log.info("%d users, %d hosts, %d rules, %d networks loaded.",
             *map(len, (users, fs.hosts, fs.rules, fs.networks))
             )

    logging.getLogger('paste.httpserver.ThreadPool').setLevel(logging.WARN)
    try:
        bottle.run(
            app=app,
            host=conf.listen_address,
            port=conf.listen_port,
            quiet=not args.debug,
            reloader=args.debug,
            server='auto'
        )
    except:
        logging.error("Unhandled exception", exc_info=True)
        raise  # TODO: wrap this around main() ?
               # is it a duplicate of HTTPError logging?

    # Run until terminated by SIGKILL or SIGTERM
    mailer.join()
Пример #2
0
def main():
    global app
    global conf
    global fs
    global mailer
    global users

    setproctitle('firelet')
    args = parse_args()

    try:
        conf = ConfReader(fn=args.cf)
    except Exception as e:
        logging.error("Exception %s while reading configuration file %r", e,
                      args.cf)
        sys.exit(1)

    if args.repodir:
        conf.data_dir = args.repodir

    setup_logging(args, conf)

    log.success("Firelet started.")

    users = Users(d=conf.data_dir)
    mailer = Mailer(
        sender=conf.email_sender,
        recipients=conf.email_recipients,
        smtp_server=conf.email_smtp_server,
    )

    if conf.demo_mode:
        fs = DemoGitFireSet(conf.data_dir)
        log.info("Configuration loaded. Demo mode.")

    else:
        fs = GitFireSet(conf.data_dir)
        log.info("Configuration loaded.")

    log.info("%d users, %d hosts, %d rules, %d networks loaded.",
             *map(len, (users, fs.hosts, fs.rules, fs.networks)))

    logging.getLogger('paste.httpserver.ThreadPool').setLevel(logging.WARN)
    try:
        bottle.run(app=app,
                   host=conf.listen_address,
                   port=conf.listen_port,
                   quiet=not args.debug,
                   reloader=args.debug,
                   server='auto')
    except:
        logging.error("Unhandled exception", exc_info=True)
        raise  # TODO: wrap this around main() ?
        # is it a duplicate of HTTPError logging?

    # Run until terminated by SIGKILL or SIGTERM
    mailer.join()
Пример #3
0
def mailer(monkeypatch):
    mailer = Mailer(
        sender='*****@*****.**',
        recipients='*****@*****.**',
        smtp_server='bogus-email-server',
    )
    monkeypatch.setattr(mailer, 'send_msg', lambda *a, **kw: None)
    return mailer
Пример #4
0
        fh = logging.handlers.TimedRotatingFileHandler(
            logfile,
            when='midnight',
            utc=True,
        )
        fh.setLevel(logging.DEBUG)
        fh.setFormatter(logging.Formatter(
            '%(asctime)s [%(process)d] %(levelname)s %(name)s %(module)s:%(funcName)s:%(lineno)s %(message)s'))
        log.addHandler(fh)

    log.success("Firelet started.")

    users = Users(d=conf.data_dir)
    mailer = Mailer(
        sender = conf.email_sender,
        recipients = conf.email_recipients,
        smtp_server = conf.email_smtp_server,
    )

    session_opts = {
        'session.type': 'cookie',
        'session.validate_key': True,
        'session.cookie_expires': True,
        'session.timeout': 3600 * 24,  # 1 day
        'session.encrypt_key': urandom(32),
    }

    if conf.demo_mode:
        fs = DemoGitFireSet(conf.data_dir)
        log.info("Configuration loaded. Demo mode.")
        #session_opts['session.secure'] = True