121 lines
3.5 KiB
Crystal
121 lines
3.5 KiB
Crystal
# require "http/server"
|
|
require "option_parser"
|
|
|
|
require "ipc"
|
|
require "ipc/json"
|
|
|
|
require "authd"
|
|
require "./service"
|
|
|
|
require "./storage.cr"
|
|
require "./network.cr"
|
|
|
|
# First option parsing, same with all Baguette (service) applications.
|
|
simulation, no_configuration, configuration_file = Baguette::Configuration.option_parser
|
|
|
|
# DNSManagerd configuration.
|
|
configuration = if no_configuration
|
|
Baguette::Log.info "do not load a configuration file."
|
|
Baguette::Configuration::DNSManager.new
|
|
else
|
|
# In case there is a configuration file helping with the parameters.
|
|
Baguette::Configuration::DNSManager.get(configuration_file) ||
|
|
Baguette::Configuration::DNSManager.new
|
|
end
|
|
|
|
|
|
OptionParser.parse do |parser|
|
|
parser.on "-v verbosity-level", "--verbosity level", "Verbosity." do |opt|
|
|
Baguette::Log.info "Verbosity level: #{opt}."
|
|
configuration.verbosity = opt.to_i
|
|
end
|
|
|
|
# IPC Service options
|
|
parser.on "--service-name service_name", "Service name (IPC)." do |service_name|
|
|
Baguette::Log.info "Service name: #{service_name}."
|
|
configuration.service_name = service_name
|
|
end
|
|
|
|
parser.on "--storage-directory dir", "Storage directory." do |storage_directory|
|
|
Baguette::Log.info "Storage directory: #{storage_directory}."
|
|
configuration.storage_directory = storage_directory
|
|
end
|
|
|
|
parser.on "--recreate-indexes", "Recreate database indexes (symbolic links)." do
|
|
Baguette::Log.info "Recreate database indexes (symlinks)."
|
|
configuration.recreate_indexes = true
|
|
end
|
|
|
|
parser.on "--accepted-domains domains", "Accepted domains (coma separated)." do |doms|
|
|
Baguette::Log.info "Accepted domains: #{doms}."
|
|
configuration.accepted_domains = doms.split ','
|
|
end
|
|
|
|
parser.on "--template-directory domains", "Default domain template directory." do |dir|
|
|
Baguette::Log.info "Default domain template directory: #{dir}."
|
|
configuration.template_directory = dir
|
|
end
|
|
|
|
parser.on "-l login", "--login login", "DNS manager authd login." do |login|
|
|
Baguette::Log.info "Authd login for dnsmanager: #{login}."
|
|
configuration.login = login
|
|
end
|
|
|
|
parser.on "-p pass", "--pass pass", "DNS manager authd pass." do |pass|
|
|
Baguette::Log.info "Authd pass (not echoed)."
|
|
configuration.pass = pass
|
|
end
|
|
|
|
parser.on "-h", "--help", "Show this help" do
|
|
puts parser
|
|
exit 0
|
|
end
|
|
end
|
|
|
|
unless File.directory? configuration.template_directory
|
|
Baguette::Log.warning "template directory '#{configuration.template_directory}' doesn't exist"
|
|
if File.directory? "./templates"
|
|
Baguette::Log.info "using template directory './templates'"
|
|
configuration.template_directory = "./templates"
|
|
else
|
|
Baguette::Log.error "tried template directory './templates', but doesn't exist either"
|
|
Baguette::Log.error "no template directory detected, quitting"
|
|
exit 1
|
|
end
|
|
end
|
|
|
|
dir = configuration.template_directory
|
|
accepted_domains = configuration.accepted_domains
|
|
|
|
unless accepted_domains
|
|
Baguette::Log.error "Not even a single accepted domain configured. Probably an error."
|
|
exit 1
|
|
end
|
|
|
|
accepted_domains.each do |domain|
|
|
template_file = "#{dir}/#{domain}.json"
|
|
zone = DNSManager::Storage::Zone.from_json File.read "#{template_file}"
|
|
puts "default zone for #{domain}: #{zone}"
|
|
rescue e
|
|
Baguette::Log.error "error reading template #{template_file}: #{e}"
|
|
exit 1
|
|
end
|
|
|
|
if simulation
|
|
pp! configuration
|
|
exit 0
|
|
end
|
|
|
|
unless configuration.pass
|
|
Baguette::Log.error "no pass found"
|
|
Baguette::Log.error "Should be present in dnsmanager.yml or via command line arguments (-p)"
|
|
exit 1
|
|
end
|
|
|
|
if path = configuration.log_file
|
|
Baguette::Log.log_path = path
|
|
end
|
|
|
|
service = DNSManager::Service.new configuration
|
|
service.run
|