Пример #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)
Пример #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)
Пример #3
0
 def __init__(self, server_address, RequestHandlerClass, pki):
     """Constructor of the TinyIDS Server.
     
     Extra instance attributes:
     
     cfg - the server ConfigParser instance
     db - database.HashDatabase instance
     pki - crypto.RSAModule instance
     
     Security Considerations
     
     If PKI module has been enabled, the server's private key should
     have been loaded before dropping privileges, so that the server
     process does not have read access to it while operating.
     
     """
     # Server Configuration
     self.cfg = config.get_server_configuration()
     
     # Debug protocol
     self.debug_protocol = self.cfg.getboolean('main', 'debug_protocol')
     
     # Hash Database
     db_path = self.cfg.get_or_default('main', 'db_path', config.DEFAULT_DATABASE_PATH)
     self.db = database.HashDatabase(db_path)
     
     # PKI Module
     self.pki = pki
     
     # Bind and activate
     try:
         SocketServer.ThreadingTCPServer.__init__(self, server_address, RequestHandlerClass)
     except InternalServerError:
         self.server_forced_shutdown()
         raise InternalServerError
     
     # Register signal handlers
     signal.signal(signal.SIGTERM, self.SIGTERM_handler)
     signal.signal(signal.SIGINT, self.SIGINT_handler)
     signal.signal(signal.SIGHUP, self.SIGHUP_handler)