Find orphan domains.
parent
62ac51c54b
commit
b2fdc4df5b
|
@ -1,4 +1,17 @@
|
|||
class DNSManager::Request
|
||||
# Periodic actions to perform as an administrator.
|
||||
IPC::JSON.message GetOrphanDomains, 6 do
|
||||
def initialize()
|
||||
end
|
||||
|
||||
def handle(dnsmanagerd : DNSManager::Service, event : IPC::Event) : IPC::JSON
|
||||
user = dnsmanagerd.get_logged_user event
|
||||
return Response::ErrorUserNotLogged.new unless user
|
||||
dnsmanagerd.storage.get_orphan_domains dnsmanagerd.authd, user.uid
|
||||
end
|
||||
end
|
||||
DNSManager.requests << GetOrphanDomains
|
||||
|
||||
# Periodic actions to perform as an administrator.
|
||||
IPC::JSON.message Maintenance, 7 do
|
||||
enum Subject
|
||||
|
@ -18,7 +31,6 @@ 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
|
||||
|
||||
return Response::InsufficientRights.new unless user.admin
|
||||
|
||||
case @subject
|
||||
|
|
|
@ -110,5 +110,12 @@ class DNSManager::Response
|
|||
end
|
||||
end
|
||||
DNSManager.responses << GeneratedZone
|
||||
|
||||
IPC::JSON.message OrphanDomainList, 24 do
|
||||
property domains : Array(String)
|
||||
def initialize(@domains)
|
||||
end
|
||||
end
|
||||
DNSManager.responses << OrphanDomainList
|
||||
end
|
||||
|
||||
|
|
|
@ -260,6 +260,29 @@ class DNSManager::Storage
|
|||
Response::DomainDeleted.new domain
|
||||
end
|
||||
|
||||
def get_orphan_domains(authd : AuthD::Client, user_id : UserDataID) : IPC::JSON
|
||||
user_must_be_admin! user_id
|
||||
|
||||
Baguette::Log.warning "list all orphan domains (long computation)"
|
||||
# Get all removed users from `authd`.
|
||||
orphans = [] of String
|
||||
user_data.each do |user|
|
||||
begin
|
||||
authd.get_user? user.uid
|
||||
rescue e
|
||||
Baguette::Log.warning "cannot get authd info on user #{user.uid}: #{e}"
|
||||
Baguette::Log.warning "-> get his domains!"
|
||||
# Verify the user still exists in `authd`.
|
||||
user.domains.each do |domain|
|
||||
orphans << domain
|
||||
end
|
||||
end
|
||||
end
|
||||
Baguette::Log.warning "total: #{orphans.size} orphans"
|
||||
|
||||
Response::OrphanDomainList.new orphans
|
||||
end
|
||||
|
||||
def get_zone(user_id : UserDataID, domain : String) : IPC::JSON
|
||||
user_data = user_must_exist! user_id
|
||||
zone = zone_must_exist! domain
|
||||
|
|
Loading…
Reference in New Issue