Admin: enable searching for a domain.
This commit is contained in:
		
							parent
							
								
									7a1e3d4755
								
							
						
					
					
						commit
						a448b68fcc
					
				
					 3 changed files with 55 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -54,6 +54,29 @@ class DNSManager::Request
 | 
			
		|||
	end
 | 
			
		||||
	DNSManager.requests << Maintenance
 | 
			
		||||
 | 
			
		||||
	# Force the generation of a zone file.
 | 
			
		||||
	IPC::JSON.message SearchDomain, 24 do
 | 
			
		||||
		property domain : String
 | 
			
		||||
		property offset : Int32?
 | 
			
		||||
 | 
			
		||||
		def initialize(@domain)
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		def to_s(io : IO)
 | 
			
		||||
			super io
 | 
			
		||||
			io << " (domain: #{@domain})"
 | 
			
		||||
		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.user_must_be_admin! user.uid
 | 
			
		||||
			dnsmanagerd.storage.search_domain @domain
 | 
			
		||||
		end
 | 
			
		||||
	end
 | 
			
		||||
	DNSManager.requests << SearchDomain
 | 
			
		||||
 | 
			
		||||
	# Generate all zone files.
 | 
			
		||||
	# TODO: should conveniently skip already generated zones.
 | 
			
		||||
	IPC::JSON.message GenerateAllZoneFiles, 100 do
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -192,4 +192,16 @@ class DNSManager::Response
 | 
			
		|||
		end
 | 
			
		||||
	end
 | 
			
		||||
	DNSManager.responses << OrphanDomainList
 | 
			
		||||
 | 
			
		||||
	IPC::JSON.message FoundDomains, 25 do
 | 
			
		||||
		property domains : Array(String)
 | 
			
		||||
		def initialize(@domains)
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		def to_s(io : IO)
 | 
			
		||||
			super io
 | 
			
		||||
			io << " (domains: #{@domains[0..5].join ","})"
 | 
			
		||||
		end
 | 
			
		||||
	end
 | 
			
		||||
	DNSManager.responses << FoundDomains
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -106,6 +106,26 @@ class DNSManager::Storage
 | 
			
		|||
		Response::Success.new
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	# Only an admin can access this function.
 | 
			
		||||
	def search_domain(domain_to_search : String) : IPC::JSON
 | 
			
		||||
		# WIP: test the request first.
 | 
			
		||||
		unless domain_to_search =~ /^([_0-9A-Za-z-.]+)$/
 | 
			
		||||
			return Response::Error.new "Invalid domain request"
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		Baguette::Log.info "(admin) searching for a domain: #{domain_to_search}"
 | 
			
		||||
 | 
			
		||||
		pattern = Regex.new domain_to_search, Regex::Options::IGNORE_CASE
 | 
			
		||||
		domains = Array(String).new
 | 
			
		||||
		@domains.each do |d|
 | 
			
		||||
			if pattern =~ d.name
 | 
			
		||||
				domains << d.name
 | 
			
		||||
			end
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		Response::FoundDomains.new domains
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	# Provides the generated zone file to a user.
 | 
			
		||||
	def get_generated_zonefile(user_id : UserDataID, domain : String) : IPC::JSON
 | 
			
		||||
		zone      = zone_must_exist! domain
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue