commit b4c45884166cf170b8b86dce0234e1e1cae70c7c
Author: Philippe PITTOLI
Date: Thu Jan 23 20:42:01 2020 +0100
dnsmanager v2, initial commit
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