From b4c45884166cf170b8b86dce0234e1e1cae70c7c Mon Sep 17 00:00:00 2001 From: Philippe PITTOLI Date: Thu, 23 Jan 2020 20:42:01 +0100 Subject: [PATCH] dnsmanager v2, initial commit --- .gitignore | 4 ++++ shard.yml | 22 ++++++++++++++++++++++ src/main.cr | 29 +++++++++++++++++++++++++++++ src/parser.cr | 27 +++++++++++++++++++++++++++ 4 files changed, 82 insertions(+) create mode 100644 .gitignore create mode 100644 shard.yml create mode 100644 src/main.cr create mode 100644 src/parser.cr diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8f0270e --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +shard.lock +bin +drop +lib diff --git a/shard.yml b/shard.yml new file mode 100644 index 0000000..6da003f --- /dev/null +++ b/shard.yml @@ -0,0 +1,22 @@ +name: dnsmanager +version: 0.1.0 + +authors: + - karchnu + +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 diff --git a/src/main.cr b/src/main.cr new file mode 100644 index 0000000..51a1bfd --- /dev/null +++ b/src/main.cr @@ -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 diff --git a/src/parser.cr b/src/parser.cr new file mode 100644 index 0000000..19c9706 --- /dev/null +++ b/src/parser.cr @@ -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