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
|
def handle(dnsmanagerd : DNSManager::Service, event : IPC::Event) : IPC::JSON
|
||||||
user = dnsmanagerd.get_logged_user event
|
user = dnsmanagerd.get_logged_user event
|
||||||
return Response::ErrorUserNotLogged.new unless user
|
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
|
||||||
end
|
end
|
||||||
DNSManager.requests << NewDomain
|
DNSManager.requests << NewDomain
|
||||||
|
@ -24,4 +24,22 @@ class DNSManager::Response
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
DNSManager.responses << ErrorUserNotLogged
|
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
|
end
|
||||||
|
@ -54,7 +54,7 @@ class DNSManager::Storage
|
|||||||
Response::Success.new
|
Response::Success.new
|
||||||
end
|
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 must exist.
|
||||||
user_data = user_data_by_uid.get? user_id.to_s
|
user_data = user_data_by_uid.get? user_id.to_s
|
||||||
unless user_data
|
unless user_data
|
||||||
@ -62,24 +62,35 @@ class DNSManager::Storage
|
|||||||
return Response::UnknownUser.new
|
return Response::UnknownUser.new
|
||||||
end
|
end
|
||||||
|
|
||||||
if zones_by_domain.get? domain
|
return Response::DomainAlreadyExists.new 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.
|
# TODO: verify the domain name validity.
|
||||||
update_user_data user_data
|
|
||||||
|
|
||||||
# TODO: Fill a template zone.
|
# TODO: verify if the domain is acceptable.
|
||||||
|
matching_domains = accepted_domains.select { |adomain| domain.ends_with? adomain }
|
||||||
## # 2 NS
|
unless matching_domains
|
||||||
## zone << rr
|
Baguette::Log.warning "trying to add an unacceptable domain: #{domain}"
|
||||||
## # Update the zone.
|
return Response::UnacceptableDomain.new
|
||||||
## zones_by_domain.update_or_create zone.domain, zone
|
|
||||||
|
|
||||||
Response::Success.new
|
|
||||||
end
|
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
|
||||||
|
|
||||||
|
# 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
|
end
|
||||||
|
|
||||||
def add_or_update_zone(user_id : Int32, zone : Zone) : IPC::JSON
|
def add_or_update_zone(user_id : Int32, zone : Zone) : IPC::JSON
|
||||||
@ -130,9 +141,7 @@ class DNSManager::Storage
|
|||||||
|
|
||||||
# Zone must exist.
|
# Zone must exist.
|
||||||
zone = zones_by_domain.get? domain
|
zone = zones_by_domain.get? domain
|
||||||
unless zone
|
return Response::DomainNotFound.new unless zone
|
||||||
return Response::InvalidZone.new ["Domain not found."]
|
|
||||||
end
|
|
||||||
|
|
||||||
# User must own the zone.
|
# User must own the zone.
|
||||||
unless user_data.domains.includes?(domain) || user_data.admin
|
unless user_data.domains.includes?(domain) || user_data.admin
|
||||||
@ -169,9 +178,7 @@ class DNSManager::Storage
|
|||||||
|
|
||||||
# Zone must exist.
|
# Zone must exist.
|
||||||
zone = zones_by_domain.get? domain
|
zone = zones_by_domain.get? domain
|
||||||
unless zone
|
return Response::DomainNotFound.new unless zone
|
||||||
return Response::InvalidZone.new ["Domain not found."]
|
|
||||||
end
|
|
||||||
|
|
||||||
# User must own the zone.
|
# User must own the zone.
|
||||||
unless user_data.domains.includes?(domain) || user_data.admin
|
unless user_data.domains.includes?(domain) || user_data.admin
|
||||||
@ -187,6 +194,13 @@ class DNSManager::Storage
|
|||||||
end
|
end
|
||||||
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 }
|
zone.resources = zone.resources.map { |x| x.rrid == rr.rrid ? rr : x }
|
||||||
|
|
||||||
# Update the zone.
|
# Update the zone.
|
||||||
|
Loading…
Reference in New Issue
Block a user