summary refs log tree commit diff homepage
path: root/xhtml.cr
diff options
context:
space:
mode:
authorNguyễn Gia Phong <mcsinyx@disroot.org>2023-02-23 01:28:29 +0900
committerNguyễn Gia Phong <mcsinyx@disroot.org>2023-02-23 02:28:41 +0900
commit2be9ea60d7f171ee3375258b774191f4cf911752 (patch)
tree073a0adc138bdd99613b60572f420df1053b0a6b /xhtml.cr
parent9310cff78765b2a8588aaa19e8fb10d6183f0979 (diff)
downloadhybring-2be9ea60d7f171ee3375258b774191f4cf911752.tar.gz
Handle requests to both ICANN and OpenNIC hosts
Diffstat (limited to 'xhtml.cr')
-rw-r--r--xhtml.cr14
1 files changed, 12 insertions, 2 deletions
diff --git a/xhtml.cr b/xhtml.cr
index 7e21309..4749af1 100644
--- a/xhtml.cr
+++ b/xhtml.cr
@@ -16,6 +16,7 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with hybring.  If not, see <https://www.gnu.org/licenses/>.
 
+require "uri"
 require "xml"
 
 CSS = "
@@ -35,8 +36,11 @@ CSS = "
     "
 
 class Page
-  def initialize(static_url : String, api_url : String)
+  def initialize(static_dir : String, static_url : String, api_url : String)
+    Dir.mkdir_p static_dir
+    @static_file = Path[static_dir] / "index.xhtml"
     @static_url = static_url
+    @static_host = URI.parse(static_url).host
     @api_url = api_url
   end
 
@@ -87,7 +91,9 @@ class Page
         errors.fetch("opennic", nil), params.fetch("opennic", nil)
       input xml, "icann", "ICANN URL", "e.g. https://example.net",
         errors.fetch("icann", nil), params.fetch("icann", nil)
-      xml.element "span"
+      xml.element "span" do
+        xml.element "input", type: "hidden", name: "host", value: @static_host
+      end
       xml.element "input", type: "submit", value: "Let me in!"
       xml.element "br"
     end
@@ -172,4 +178,8 @@ class Page
       end
     end
   end
+
+  def write(members)
+    File.write @static_file, self.build members
+  end
 end