summary refs log tree commit diff homepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cli.cr21
-rw-r--r--src/http.cr11
-rw-r--r--src/xhtml.cr32
3 files changed, 31 insertions, 33 deletions
diff --git a/src/cli.cr b/src/cli.cr
index 8cc79be..ecec1f8 100644
--- a/src/cli.cr
+++ b/src/cli.cr
@@ -27,26 +27,39 @@ enum Subcommand
 end
 
 struct Configuration
+  @sock : String
+  getter sock
   @db : Path
   getter db
-  @api : String
-  getter api
+  @css : Path
+  getter css
+
   @opennic_local : Path
   getter opennic_local
   @opennic_remote : String
   getter opennic_remote
+  @opennic_api : String
+  getter opennic_api
+
   @icann_local : Path
   getter icann_local
   @icann_remote : String
   getter icann_remote
+  @icann_api : String
+  getter icann_api
 
   def initialize(ini)
+    @sock = ini["general"]["sock"]
     @db = Path[ini["general"]["db"]]
-    @api = ini["general"]["api"]
+    @css = Path[ini["general"]["css"]]
+
     @opennic_local = Path[ini["opennic"]["local"]]
     @opennic_remote = ini["opennic"]["remote"]
+    @opennic_api = ini["opennic"]["api"]
+
     @icann_local = Path[ini["icann"]["local"]]
     @icann_remote = ini["icann"]["remote"]
+    @icann_api = ini["icann"]["api"]
   end
 end
 
@@ -115,7 +128,7 @@ end
   in .serve?
     server = Server.new cfg.not_nil!
     server.listen port do |address|
-      puts "Listening on http://#{address}"
+      puts "Listening on #{address}"
     end
   in .usage?
     die parser
diff --git a/src/http.cr b/src/http.cr
index 9562c2e..95a3069 100644
--- a/src/http.cr
+++ b/src/http.cr
@@ -36,13 +36,18 @@ def http_error(context, status, message = nil)
 end
 
 class Server
+  @sock : String
+
   def initialize(cfg)
+    @sock = cfg.sock
     @db = Database.new cfg.db, cfg.opennic_remote, cfg.icann_remote
 
     @opennic_host = URI.parse(cfg.opennic_remote).host
-    @opennic_page = Page.new cfg.opennic_local, cfg.opennic_remote, cfg.api, @db
+    @opennic_page = Page.new cfg.opennic_local, cfg.opennic_remote,
+                             cfg.opennic_api, cfg.css, @db
     @opennic_page.write
-    @icann_page = Page.new cfg.icann_local, cfg.icann_remote, cfg.api, @db
+    @icann_page = Page.new cfg.icann_local, cfg.icann_remote,
+                           cfg.icann_api, cfg.css, @db
     @icann_page.write
 
     @server = HTTP::Server.new do |context|
@@ -140,7 +145,7 @@ class Server
       end
     }, self.as Void*
 
-    yield @server.bind_tcp port
+    yield @server.bind_unix @sock
     @server.listen
   end
 
diff --git a/src/xhtml.cr b/src/xhtml.cr
index 52d089a..b9d6d4c 100644
--- a/src/xhtml.cr
+++ b/src/xhtml.cr
@@ -22,32 +22,11 @@ require "xml"
 require "./http"
 require "./sqlite"
 
-CSS = "
-      html {
-          margin: auto;
-          max-width: 72ch;
-      }
-      body { margin-bottom: 2rem }
-      h1, h2, h3, h4, h5, h6 { margin: 1ex 0 }
-      a { text-decoration: none }
-      a:hover { text-decoration: underline }
-      form {
-          display: grid;
-          grid-template-columns: max-content 1fr 0;
-      }
-      form input { margin-bottom: 1ex }
-      form label { margin-right: 1ch }
-      form label.error {
-        color: ActiveText;
-        margin-top: -1ex;
-        margin-bottom: 1ex;
-      }
-    "
-
 class Page
   def initialize(static_dir : Path, static_url : String, api_url : String,
-                 db : Database)
+                 css : Path, db : Database)
     Dir.mkdir_p static_dir
+    File.copy css, static_dir / "style.css"
     @static_file = static_dir / "index.xhtml"
     @static_url = static_url
     @static_host = URI.parse(static_url).host
@@ -110,10 +89,10 @@ class Page
             errors.fetch("opennic", nil), params.fetch("opennic", "")
       input xml, "url", "icann", "https://.*", "ICANN URL:",
             errors.fetch("icann", nil), params.fetch("icann", "")
-      xml.element "input", type: "hidden", name: "host", value: @static_host
       xml.element "span" do
-        xml.element "input", type: "submit", value: "Let me in!"
+        xml.element "input", type: "hidden", name: "host", value: @static_host
       end
+      xml.element "input", type: "submit", value: "Let me in!"
       xml.element "br"
     end
 
@@ -145,8 +124,9 @@ class Page
           xml.element "meta", name: "viewport",
                       content: "width=device-width,initial-scale=1.0"
           xml.element "meta", name: "color-scheme", content: "light dark"
+          xml.element "base", href: @static_url
           xml.element "link", rel: "icon", href: "data:,"
-          xml.element "style" do xml.text CSS end
+          xml.element "link", rel: "stylesheet", href: "style.css"
           xml.element "title" do xml.text "le cercle libre" end
         end
         xml.element "body" do