New verifications (accept only acceptable domains) + new errors.
This commit is contained in:
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,9 +62,21 @@ class DNSManager::Storage
|
||||
return Response::UnknownUser.new
|
||||
end
|
||||
|
||||
if zones_by_domain.get? domain
|
||||
Response::DomainAlreadyExists.new
|
||||
else
|
||||
return Response::DomainAlreadyExists.new if zones_by_domain.get? domain
|
||||
|
||||
# TODO: verify the domain name validity.
|
||||
|
||||
# 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
|
||||
|
||||
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
|
||||
|
||||
@ -80,7 +92,6 @@ class DNSManager::Storage
|
||||
|
||||
Response::Success.new
|
||||
end
|
||||
end
|
||||
|
||||
def add_or_update_zone(user_id : Int32, zone : Zone) : IPC::JSON
|
||||
# Test zone validity.
|
||||
@ -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…
Reference in New Issue
Block a user