Client: can be built again. Add a makefile rule to generate all zones.

dev
Philippe PITTOLI 2024-04-28 12:56:45 +02:00
parent 1f69839333
commit 4606f852cc
5 changed files with 34 additions and 17 deletions

View File

@ -64,6 +64,9 @@ run-client-rr-update-a:
run-client-rr-del:
$(Q)$(LD_P) ./bin/dnsmanager-client user rr del $(DOMAIN) $(RRID) $(LOGIN_OPT)
run-admin-generate-all-zonefiles:
$(Q)$(LD_P) ./bin/dnsmanager-client admin genall $(LOGIN_OPT)
##################
### SETUP COMMANDS
##################

View File

@ -59,11 +59,13 @@ def parsing_cli(authd_config : Baguette::Configuration::Auth)
# either we test with the exact expected number of arguments or the least.
if exact = nexact
if args.size != exact
Baguette::Log.error "Wrong number of parameters: expected #{exact}, got #{args.size}"
Baguette::Log.error "#{parser}"
exit 1
end
elsif least = at_least
if args.size < least
Baguette::Log.error "Wrong number of parameters: expected at least #{least}, got #{args.size}"
Baguette::Log.error "#{parser}"
exit 1
end

5
src/service.cr Normal file
View File

@ -0,0 +1,5 @@
require "ipc"
# Useful to enable the client to be built.
class DNSManager::Service < IPC
end

View File

@ -2,11 +2,10 @@ require "json"
require "uuid"
require "uuid/json"
require "baguette-crystal-base"
require "./service.cr"
require "dodb"
alias UserDataID = UInt32
class DNSManager::Storage
getter domains : DODB::CachedDataBase(Domain)
getter domains_by_name : DODB::Index(Domain)
@ -72,26 +71,33 @@ class DNSManager::Storage
end
end
# Only an admin can access this function.
def generate_all_zonefiles() : IPC::JSON
Baguette::Log.info "writing all zone files in #{@zonefiledir}/"
zones.each do |zone|
# TODO: safe write.
File.open("#{@zonefiledir}/#{zone.domain}", "w") do |file|
zone.to_bind9 file
end
def generate_zonefile_(domain : String) : Nil
zone = zone_must_exist! domain
# Safe write.
filename_final = "#{@zonefiledir}/#{zone.domain}"
filename_wip = "#{filename_final}.wip"
Baguette::Log.info "writing zone file #{filename_final}"
File.open(filename_wip, "w") do |file|
zone.to_bind9 file
end
Response::Success.new
# Rename WIP filename to final file name.
File.rename filename_wip, filename_final
end
# Only an admin can access this function.
def generate_zonefile(domain : String) : IPC::JSON
zone = zone_must_exist! domain
generate_zonefile_ domain
Response::Success.new
end
Baguette::Log.info "writing zone file #{@zonefiledir}/#{zone.domain}"
# TODO: safe write.
File.open("#{@zonefiledir}/#{zone.domain}", "w") do |file|
zone.to_bind9 file
# Only an admin can access this function.
def generate_all_zonefiles() : IPC::JSON
Baguette::Log.info "writing all zone files in #{@zonefiledir}/"
zones.each do |zone|
generate_zonefile_ zone.domain
end
Response::Success.new
end
@ -195,7 +201,7 @@ class DNSManager::Storage
@domains_by_name.update_or_create domain_name, domain
Response::DomainChanged.new domain
else
Response::Error.new "You are't the only owner."
Response::Error.new "You are not the only owner."
end
end

1
src/storage/userid.cr Normal file
View File

@ -0,0 +1 @@
alias UserDataID = UInt32