Compare commits
No commits in common. "8bec7eb33cacef6dc780097cf0adcc7644d9af09" and "a708d8fc469b101761e5d748972aff70bc97153a" have entirely different histories.
8bec7eb33c
...
a708d8fc46
@ -19,7 +19,7 @@ class DNSManager::Client < IPC
|
|||||||
def login(token : String)
|
def login(token : String)
|
||||||
request = Request::Login.new token
|
request = Request::Login.new token
|
||||||
send_now request
|
send_now request
|
||||||
parse_message [ Response::Logged ], read
|
parse_message [ Response::Success ], read
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -94,18 +94,11 @@ class DNSManager::Client < IPC
|
|||||||
# Admin stuff
|
# Admin stuff
|
||||||
#
|
#
|
||||||
|
|
||||||
def admin_maintenance(subject : Request::Maintenance::Subject,
|
def admin_maintenance(subject : Request::Maintenance::Subject, value : Int32? = nil)
|
||||||
int : Int32? = nil,
|
|
||||||
string : String? = nil)
|
|
||||||
request = Request::Maintenance.new(subject)
|
request = Request::Maintenance.new(subject)
|
||||||
request.int = int if int
|
if value
|
||||||
request.string = string if string
|
request.value = value
|
||||||
send_now request
|
end
|
||||||
parse_message [ Response::Success ], read
|
|
||||||
end
|
|
||||||
|
|
||||||
def generate_zonefile(domain : String)
|
|
||||||
request = Request::GenerateZoneFile.new(domain)
|
|
||||||
send_now request
|
send_now request
|
||||||
parse_message [ Response::Success ], read
|
parse_message [ Response::Success ], read
|
||||||
end
|
end
|
||||||
@ -130,7 +123,7 @@ class DNSManager::Client < IPC
|
|||||||
m.not_nil!
|
m.not_nil!
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: should raise exception if response not anticipated
|
# TODO: parse_message should raise exception if response not anticipated
|
||||||
def parse_message(expected_messages, message)
|
def parse_message(expected_messages, message)
|
||||||
em = Array(IPC::JSON.class).new
|
em = Array(IPC::JSON.class).new
|
||||||
expected_messages.each do |e|
|
expected_messages.each do |e|
|
||||||
|
@ -34,7 +34,6 @@ class Actions
|
|||||||
|
|
||||||
# Maintenance.
|
# Maintenance.
|
||||||
@the_call["admin-maintenance"] = ->admin_maintenance
|
@the_call["admin-maintenance"] = ->admin_maintenance
|
||||||
@the_call["admin-generate-zonefile"] = ->admin_generate_zonefile
|
|
||||||
|
|
||||||
# Domain operations.
|
# Domain operations.
|
||||||
@the_call["user-domain-add"] = ->user_domain_add
|
@the_call["user-domain-add"] = ->user_domain_add
|
||||||
@ -64,11 +63,11 @@ class Actions
|
|||||||
end
|
end
|
||||||
|
|
||||||
if past_is_verbosity
|
if past_is_verbosity
|
||||||
sub = DNSManager::Request::Maintenance::Subject::Verbosity
|
sub = DNSManager::Request::Maintenance::Subject::Verbosity
|
||||||
int = subject.to_i
|
value = subject.to_i
|
||||||
@dnsmanagerd.admin_maintenance sub, int
|
@dnsmanagerd.admin_maintenance sub, value
|
||||||
else
|
else
|
||||||
sub = DNSManager::Request::Maintenance::Subject.parse(subject)
|
sub = DNSManager::Request::Maintenance::Subject.parse(subject)
|
||||||
pp! sub
|
pp! sub
|
||||||
pp! @dnsmanagerd.admin_maintenance sub
|
pp! @dnsmanagerd.admin_maintenance sub
|
||||||
end
|
end
|
||||||
@ -78,18 +77,6 @@ class Actions
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def admin_generate_zonefile
|
|
||||||
domains = Context.args.not_nil!
|
|
||||||
domains.each do |domain|
|
|
||||||
begin
|
|
||||||
pp! domain
|
|
||||||
pp! @dnsmanagerd.generate_zonefile domain
|
|
||||||
rescue e
|
|
||||||
puts "error for user_domain_add: #{e.message}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def user_domain_add
|
def user_domain_add
|
||||||
domains = Context.args.not_nil!
|
domains = Context.args.not_nil!
|
||||||
domains.each do |domain|
|
domains.each do |domain|
|
||||||
@ -233,21 +220,8 @@ def main
|
|||||||
# Authd authentication, get the token and quit right away.
|
# Authd authentication, get the token and quit right away.
|
||||||
token = authd_get_token login: login, pass: pass
|
token = authd_get_token login: login, pass: pass
|
||||||
# Then push the token to the dnsmanager daemon.
|
# Then push the token to the dnsmanager daemon.
|
||||||
logged_message = dnsmanagerd.login token
|
dnsmanagerd.login token
|
||||||
case logged_message
|
Baguette::Log.info "logged."
|
||||||
when DNSManager::Response::Logged
|
|
||||||
Baguette::Log.info "logged to dnsmanagerd"
|
|
||||||
Baguette::Log.debug "from logging message, accepted domains:"
|
|
||||||
logged_message.accepted_domains.each do |d|
|
|
||||||
Baguette::Log.debug "- #{d}"
|
|
||||||
end
|
|
||||||
Baguette::Log.debug "from logging message, owned domains:"
|
|
||||||
logged_message.my_domains.each do |d|
|
|
||||||
Baguette::Log.debug "- #{d}"
|
|
||||||
end
|
|
||||||
else
|
|
||||||
Baguette::Log.info "not logged to dnsmanagerd?"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
actions = Actions.new dnsmanagerd, config
|
actions = Actions.new dnsmanagerd, config
|
||||||
|
@ -98,14 +98,6 @@ def parsing_cli(authd_config : Baguette::Configuration::Auth)
|
|||||||
unrecognized_args_to_context_args.call parser, nil, 1
|
unrecognized_args_to_context_args.call parser, nil, 1
|
||||||
end
|
end
|
||||||
|
|
||||||
# Generate a zone file.
|
|
||||||
parser.on("genzone", "Generate a zone file.") do
|
|
||||||
Baguette::Log.info "generate a zone file on the server."
|
|
||||||
Context.command = "admin-generate-zonefile"
|
|
||||||
parser.banner = "COMMAND: admin genzone domain [domain…]"
|
|
||||||
unrecognized_args_to_context_args.call parser, nil, 1
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# User section.
|
# User section.
|
||||||
|
@ -4,14 +4,10 @@ class DNSManager::Request
|
|||||||
IPC::JSON.message Maintenance, 7 do
|
IPC::JSON.message Maintenance, 7 do
|
||||||
enum Subject
|
enum Subject
|
||||||
Verbosity # Change the verbosity of dnsmanagerd.
|
Verbosity # Change the verbosity of dnsmanagerd.
|
||||||
SanityCheck # Perform various verifications, including:
|
|
||||||
# - TODO: debug print and removal of domains not linked to existing users
|
|
||||||
# - TODO: check that at least an admin exists
|
|
||||||
end
|
end
|
||||||
|
|
||||||
property subject : Subject
|
property subject : Subject
|
||||||
property int : Int32? = nil
|
property value : Int32?
|
||||||
property string : String? = nil
|
|
||||||
|
|
||||||
def initialize(@subject)
|
def initialize(@subject)
|
||||||
end
|
end
|
||||||
@ -25,36 +21,14 @@ class DNSManager::Request
|
|||||||
|
|
||||||
case @subject
|
case @subject
|
||||||
when Subject::Verbosity
|
when Subject::Verbosity
|
||||||
if verbosity = @int
|
if verbosity = @value
|
||||||
Baguette::Context.verbosity = verbosity
|
Baguette::Context.verbosity = verbosity
|
||||||
end
|
end
|
||||||
Response::Success.new
|
Response::Success.new
|
||||||
when Subject::SanityCheck
|
|
||||||
Baguette::Log.info "TODO: sanity check"
|
|
||||||
Response::Error.new "not implemented"
|
|
||||||
else
|
else
|
||||||
Response::Error.new "not implemented"
|
Response::Error.new "not implemented"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
DNSManager.requests << Maintenance
|
DNSManager.requests << Maintenance
|
||||||
|
|
||||||
IPC::JSON.message GenerateZoneFile, 100 do
|
|
||||||
property domain : String
|
|
||||||
|
|
||||||
def initialize(@domain)
|
|
||||||
end
|
|
||||||
|
|
||||||
def handle(dnsmanagerd : DNSManager::Service, event : IPC::Event) : IPC::JSON
|
|
||||||
user = dnsmanagerd.get_logged_user event
|
|
||||||
return Response::ErrorUserNotLogged.new unless user
|
|
||||||
|
|
||||||
return Response::Error.new "unauthorized" unless user.admin
|
|
||||||
# This request means serious business.
|
|
||||||
# TODO: check for admin.
|
|
||||||
|
|
||||||
Response::Error.new "not implemented"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
DNSManager.requests << GenerateZoneFile
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user