dnsmanager v2, initial commit

master
Philippe PITTOLI 2020-01-23 20:42:01 +01:00
commit b4c4588416
4 changed files with 82 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
shard.lock
bin
drop
lib

22
shard.yml Normal file
View File

@ -0,0 +1,22 @@
name: dnsmanager
version: 0.1.0
authors:
- karchnu <karchnu@karchnu.fr>
description: |
A registrar tool.
dependencies:
ipc:
git: https://git.karchnu.fr/WeirdOS/ipc.cr
dodb:
git: https://git.karchnu.fr/WeirdOS/dodb.cr
authd:
git: https://git.karchnu.fr/WeirdOS/authd
targets:
dnsmanager:
main: src/main.cr
license: MIT

29
src/main.cr Normal file
View File

@ -0,0 +1,29 @@
require "http/server"
require "option_parser"
require "authd"
service_name = "dnsmanager"
verbosity = 1
authd_key_file = nil
require "./parser"
begin
authd = AuthD::Client.new
authd.key = File.read(Context.authd_key_file.not_nil!).chomp
server = HTTP::Server.new do |context|
context.response.content_type = "text/plain"
pp! context.request
context.response.print "Hello. New version of DNSManager, soon."
end
address = server.bind_tcp Context.activation_server_port
puts "Listening on http://#{address}"
server.listen
rescue e
puts "Error: #{e}"
exit 1
end

27
src/parser.cr Normal file
View File

@ -0,0 +1,27 @@
class Context
class_property verbosity = 1
class_property authd_key_file : String? = nil
class_property activation_server_port : Int32 = 9000
end
OptionParser.parse do |parser|
parser.on "-v verbosity-level", "--verbosity level", "Verbosity." do |opt|
Context.verbosity = opt.to_i
end
parser.on "-p port", "--port port", "Listening port." do |port|
Context.activation_server_port = port.to_i
end
parser.on "-K key-file", "--key-file file", "Key file." do |opt|
Context.authd_key_file = opt
end
parser.on "-h", "--help", "Show this help" do
puts parser
exit 0
end
end