12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- require 'async'
- require 'logger'
- require_relative 'registry'
- require_relative 'utilities'
- require_relative 'config'
- require_relative 'whoisd'
- Async do |task|
- logger = Logger.new($stdout)
- logger.level = Logger::WARN
- original_formatter = Logger::Formatter.new
- logger.formatter = proc { |severity, datetime, progname, msg|
- original_formatter.call(severity, datetime, progname, msg.sanitize)
- }
- begin
- configuration_file = (ARGV.empty? ? "#{Dir.home}#{File::SEPARATOR}.dnet-whois.json" : ARGV[0].strip)
- config = Config.new(configuration_file:).read
- case config.logging_level
- when 'fatal'
- logger.level = Logger::FATAL
- when 'error'
- logger.level = Logger::ERROR
- when 'warning'
- logger.level = Logger::WARN
- when 'info'
- logger.level = Logger::INFO
- when 'debug'
- logger.level = Logger::DEBUG
- else
- raise 'Unknown logging level'
- end
- rescue ArgumentError, RuntimeError => e
- logger.fatal e.message
- exit!
- end
- logger.debug '###### WARNUNG: In debug mode both the request and the IP address are logged. This can lead to privacy problems. It is not suitable for permanent productive operation. ######'
- begin
- registry = Registry.new(dir: config.registry_directory, logger:)
- rescue StandardError
- logger.fatal 'Failed to initialize the registry. Exiting now.'
- exit!
- end
- task.async(transient: true) do |subtask|
- loop do
- begin
- logger.info 'Update registry data.'
- registry.update
- rescue ArgumentError => e
- logger.error "Error: #{e} Continue."
- end
- subtask.sleep config.registry_reload_interval * 60
- end
- end
- task.async do
- whois = WhoisServer.new(registry:, logger:, endpoint: config.whois_endpoint)
- logger.info 'Start server.'
- whois.run
- end
- end.wait
|