New verifications (accept only acceptable domains) + new errors.

master
Philippe Pittoli 8 months ago
parent 41b790a4a8
commit d12af2047f

@ -12,7 +12,7 @@ class DNSManager::Request
def handle(dnsmanagerd : DNSManager::Service, event : IPC::Event) : IPC::JSON
user = dnsmanagerd.get_logged_user event
return Response::ErrorUserNotLogged.new unless user
dnsmanagerd.storage.new_domain user.uid, @domain
dnsmanagerd.storage.new_domain dnsmanagerd.configuration.accepted_domains.not_nil!, user.uid, @domain
end
end
DNSManager.requests << NewDomain

@ -24,4 +24,22 @@ class DNSManager::Response
end
end
DNSManager.responses << ErrorUserNotLogged
IPC::JSON.message DomainNotFound, 5 do
def initialize()
end
end
DNSManager.responses << DomainNotFound
IPC::JSON.message RRNotFound, 6 do
def initialize()
end
end
DNSManager.responses << RRNotFound
IPC::JSON.message UnacceptableDomain, 7 do
def initialize()
end
end
DNSManager.responses << UnacceptableDomain
end

@ -54,7 +54,7 @@ class DNSManager::Storage
Response::Success.new
end
def new_domain(user_id : Int32, domain : String) : IPC::JSON
def new_domain(accepted_domains : Array(String), user_id : Int32, domain : String) : IPC::JSON
# User must exist.
user_data = user_data_by_uid.get? user_id.to_s
unless user_data
@ -62,24 +62,35 @@ class DNSManager::Storage
return Response::UnknownUser.new
end
if zones_by_domain.get? domain
Response::DomainAlreadyExists.new
else
# Add the domain to the user's domain.
user_data.domains << domain
# Actually write data on-disk.
update_user_data user_data
return Response::DomainAlreadyExists.new if zones_by_domain.get? domain
# TODO: Fill a template zone.
# TODO: verify the domain name validity.
## # 2 NS
## zone << rr
## # Update the zone.
## zones_by_domain.update_or_create zone.domain, zone
# TODO: verify if the domain is acceptable.
matching_domains = accepted_domains.select { |adomain| domain.ends_with? adomain }
unless matching_domains
Baguette::Log.warning "trying to add an unacceptable domain: #{domain}"
return Response::UnacceptableDomain.new
end
Response::Success.new
matching_domains.each do |md|
Baguette::Log.info "Add new domain in #{md}: #{domain}"
end
# Add the domain to the user's domain.
user_data.domains << domain
# Actually write data on-disk.
update_user_data user_data
# TODO: Fill a template zone.
## # 2 NS
## zone << rr
## # Update the zone.
## zones_by_domain.update_or_create zone.domain, zone
Response::Success.new
end
def add_or_update_zone(user_id : Int32, zone : Zone) : IPC::JSON
@ -130,9 +141,7 @@ class DNSManager::Storage
# Zone must exist.
zone = zones_by_domain.get? domain
unless zone
return Response::InvalidZone.new ["Domain not found."]
end
return Response::DomainNotFound.new unless zone
# User must own the zone.
unless user_data.domains.includes?(domain) || user_data.admin
@ -169,9 +178,7 @@ class DNSManager::Storage
# Zone must exist.
zone = zones_by_domain.get? domain
unless zone
return Response::InvalidZone.new ["Domain not found."]
end
return Response::DomainNotFound.new unless zone
# User must own the zone.
unless user_data.domains.includes?(domain) || user_data.admin
@ -187,6 +194,13 @@ class DNSManager::Storage
end
end
# TODO: verify that this rr.rrid isn't ReadOnly.
stored_rr = zone.resources.select { |x| x.rrid == rr.rrid }
unless stored_rr.size > 0
Baguette::Log.warning "modifying a RR that doesn't exist (#{rr.rrid}) in domain #{domain}"
return Response::RRNotFound.new
end
zone.resources = zone.resources.map { |x| x.rrid == rr.rrid ? rr : x }
# Update the zone.

Loading…
Cancel
Save