Add or update new zone.
parent
bda2a08b4d
commit
3aa1785a97
|
@ -13,7 +13,7 @@ class DNSManager::Request
|
|||
def initialize(@key, @subject)
|
||||
end
|
||||
|
||||
def handle(dnsmanagerd : DNSManager::Service, event : IPC::Event) : IPC::JSON+
|
||||
def handle(dnsmanagerd : DNSManager::Service, event : IPC::Event) : IPC::JSON
|
||||
# This request means serious business.
|
||||
raise AdminAuthorizationException.new if key != dnsmanagerd.authd.key
|
||||
|
||||
|
|
|
@ -10,15 +10,17 @@ class DNSManager::Request
|
|||
user, _ = dnsmanagerd.decode_token token
|
||||
dnsmanagerd.logged_users[event.fd] = user
|
||||
|
||||
return dnsmanagerd.storage.ensure_user_data user.uid
|
||||
|
||||
# In case we want to log their last connection.
|
||||
#dnsmanagerd.auth.edit_profile_content user.uid, {
|
||||
# "dnsmanager-last-connection" => JSON::Any.new Time.utc.to_s
|
||||
#}
|
||||
|
||||
return Response::Success.new
|
||||
Response::Success.new
|
||||
rescue e
|
||||
# FIXME: Should those be logged?
|
||||
return Response::Error.new "unauthorized"
|
||||
Response::Error.new "unauthorized"
|
||||
end
|
||||
end
|
||||
DNSManager.requests << Login
|
||||
|
|
|
@ -9,8 +9,7 @@ class DNSManager::Request
|
|||
def initialize(@zone)
|
||||
end
|
||||
|
||||
def handle(dnsmanagerd : DNSManager::Service, event : IPC::Event)
|
||||
return Response::Success.new
|
||||
def handle(dnsmanagerd : DNSManager::Service, event : IPC::Event) : IPC::JSON
|
||||
user = dnsmanagerd.get_logged_user event
|
||||
raise NotLoggedException.new if user.nil?
|
||||
dnsmanagerd.storage.add_or_update_zone user.uid, zone
|
||||
|
@ -24,8 +23,7 @@ class DNSManager::Request
|
|||
def initialize(@domain)
|
||||
end
|
||||
|
||||
def handle(dnsmanagerd : DNSManager::Service, event : IPC::Event)
|
||||
return Response::Success.new
|
||||
def handle(dnsmanagerd : DNSManager::Service, event : IPC::Event) : IPC::JSON
|
||||
user = dnsmanagerd.get_logged_user event
|
||||
raise NotLoggedException.new if user.nil?
|
||||
dnsmanagerd.storage.delete_domain user.uid, @domain
|
||||
|
|
|
@ -44,8 +44,17 @@ class DNSManager::Storage
|
|||
user_data_by_uid.update_or_create user_data.uid.to_s, user_data
|
||||
end
|
||||
|
||||
def add_or_update_zone(user_id : Int32, zone : Zone)
|
||||
def ensure_user_data(user_id : Int32)
|
||||
user_data = user_data_by_uid.get? user_id.to_s
|
||||
unless user_data
|
||||
Baguette::Log.info "New user #{user_id}"
|
||||
@user_data << Storage::UserData.new user_id
|
||||
end
|
||||
|
||||
Response::Success.new
|
||||
end
|
||||
|
||||
def add_or_update_zone(user_id : Int32, zone : Zone) : IPC::JSON
|
||||
# Test zone validity.
|
||||
if errors = zone.get_errors?
|
||||
Baguette::Log.warning "zone #{zone.domain} update with errors: #{errors}"
|
||||
|
@ -66,12 +75,6 @@ class DNSManager::Storage
|
|||
Baguette::Log.warning "user #{user_id} doesn't own domain #{zone.domain}"
|
||||
return Response::NoOwnership.new
|
||||
end
|
||||
|
||||
# Domain cannot change (for security reasons).
|
||||
unless z.domain == zone.domain
|
||||
Baguette::Log.warning "user #{user_id} tries to change domain #{z.domain} by #{zone.domain}"
|
||||
return Response::DomainChanged.new
|
||||
end
|
||||
else
|
||||
# Add the domain to the user's domain.
|
||||
user_data.domains << zone.domain
|
||||
|
@ -89,7 +92,7 @@ class DNSManager::Storage
|
|||
Response::Error.new "error while updating the domain #{zone.domain}"
|
||||
end
|
||||
|
||||
def delete_domain(user_id : Int32, domain : String)
|
||||
def delete_domain(user_id : Int32, domain : String) : IPC::JSON
|
||||
# User must exist.
|
||||
user_data = user_data_by_uid.get? user_id.to_s
|
||||
unless user_data
|
||||
|
|
Loading…
Reference in New Issue