Esempio n. 1
0
def server_main():
    opts = cmdline.parse_server()
    config_path = os.path.abspath(opts.confpath)
    try:
        cfg = config.get_server_configuration(config_path)
    except config.ConfigFileNotFoundError:
        sys.stderr.write('ERROR: Configuration file not found: %s\n' %
                         config_path)
        sys.stderr.flush()
        sys.exit(1)

    # Settings
    interface = cfg.get('main', 'interface')
    port = cfg.getint('main', 'port')
    user = cfg.get_or_default('main', 'user', '')
    group = cfg.get_or_default('main', 'group', '')
    logfile = os.path.abspath(
        cfg.get_or_default('main', 'logfile', config.DEFAULT_LOGFILE_PATH))
    loglevel = cfg.get_or_default('main', 'loglevel', config.DEFAULT_LOGLEVEL)
    use_keys = cfg.getboolean('main', 'use_keys')
    keys_dir = cfg.get('main', 'keys_dir')
    key_bits = cfg.getint('main', 'key_bits')

    # Initialize logging
    logger = logging.getLogger()
    if opts.debug:
        # Log to stderr
        applogger.init_std_stream_loggers(verbose=True)
        logger.debug('tinyidsd started in debug mode')
        logger.debug('Logging to standard streams: STDOUT, STDERR')
    else:
        # Log to file
        try:
            applogger.init_file_logger(logfile, loglevel)
        except applogger.LoggerError, strerror:
            sys.stderr.write('ERROR: Logger: %s\n' % strerror)
            sys.stderr.flush()
            sys.exit(1)

        # Set permissions and ownership on the logfile, if running as root
        if user:
            process.set_fs_permissions(logfile, user, group, 0600)

        logger.info('tinyidsd normal startup')
        logger.debug('Logging to file: %s' % logfile)
Esempio n. 2
0
def server_main():
    opts = cmdline.parse_server()
    config_path = os.path.abspath(opts.confpath)
    try:
        cfg = config.get_server_configuration(config_path)
    except config.ConfigFileNotFoundError:
        sys.stderr.write("ERROR: Configuration file not found: %s\n" % config_path)
        sys.stderr.flush()
        sys.exit(1)

    # Settings
    interface = cfg.get("main", "interface")
    port = cfg.getint("main", "port")
    user = cfg.get_or_default("main", "user", "")
    group = cfg.get_or_default("main", "group", "")
    logfile = os.path.abspath(cfg.get_or_default("main", "logfile", config.DEFAULT_LOGFILE_PATH))
    loglevel = cfg.get_or_default("main", "loglevel", config.DEFAULT_LOGLEVEL)
    use_keys = cfg.getboolean("main", "use_keys")
    keys_dir = cfg.get("main", "keys_dir")
    key_bits = cfg.getint("main", "key_bits")

    # Initialize logging
    logger = logging.getLogger()
    if opts.debug:
        # Log to stderr
        applogger.init_std_stream_loggers(verbose=True)
        logger.debug("tinyidsd started in debug mode")
        logger.debug("Logging to standard streams: STDOUT, STDERR")
    else:
        # Log to file
        try:
            applogger.init_file_logger(logfile, loglevel)
        except applogger.LoggerError, strerror:
            sys.stderr.write("ERROR: Logger: %s\n" % strerror)
            sys.stderr.flush()
            sys.exit(1)

        # Set permissions and ownership on the logfile, if running as root
        if user:
            process.set_fs_permissions(logfile, user, group, 0600)

        logger.info("tinyidsd normal startup")
        logger.debug("Logging to file: %s" % logfile)
Esempio n. 3
0
def main():
    opts = cmdline.parse_client()
    config_path = os.path.abspath(opts.confpath)
    try:
        cfg = config.get_client_configuration(config_path)
    except config.ConfigFileNotFoundError:
        sys.stderr.write('ERROR: Configuration file not found: %s\n' %
                         config_path)
        sys.stderr.flush()
        sys.exit(1)

    # Initialize logging
    logger = logging.getLogger()
    if opts.debug:
        applogger.init_std_stream_loggers(verbose=True)
        logger.debug('tinyids started in debug mode')
    else:
        applogger.init_std_stream_loggers()

    logger.debug('Using client configuration from: %s' % config_path)
    logger.debug('Logging to standard streams: STDOUT, STDERR')

    command = None
    if opts.test:
        command = 'TEST'
    if opts.check:
        command = 'CHECK'
    elif opts.update:
        command = 'UPDATE'
    elif opts.delete:
        command = 'DELETE'
    elif opts.changephrase:
        command = 'CHANGEPHRASE'

    client = TinyIDSClient(command)
    logger.info('TinyIDS Client v%s initialized' % info.version)
    logger.info('Running in mode: %s' % command)

    client.run()

    logger.debug('terminated')
Esempio n. 4
0
def main():
    opts = cmdline.parse_client()
    config_path = os.path.abspath(opts.confpath)
    try:
        cfg = config.get_client_configuration(config_path)
    except config.ConfigFileNotFoundError:
        sys.stderr.write("ERROR: Configuration file not found: %s\n" % config_path)
        sys.stderr.flush()
        sys.exit(1)

    # Initialize logging
    logger = logging.getLogger()
    if opts.debug:
        applogger.init_std_stream_loggers(verbose=True)
        logger.debug("tinyids started in debug mode")
    else:
        applogger.init_std_stream_loggers()

    logger.debug("Using client configuration from: %s" % config_path)
    logger.debug("Logging to standard streams: STDOUT, STDERR")

    command = None
    if opts.test:
        command = "TEST"
    if opts.check:
        command = "CHECK"
    elif opts.update:
        command = "UPDATE"
    elif opts.delete:
        command = "DELETE"
    elif opts.changephrase:
        command = "CHANGEPHRASE"

    client = TinyIDSClient(command)
    logger.info("TinyIDS Client v%s initialized" % info.version)
    logger.info("Running in mode: %s" % command)

    client.run()

    logger.debug("terminated")