#!/usr/bin/bash
FILE=./index.html
cat <<EOT > $FILE
<html>
  <head>
    <title>Sharnoby Server</title>
  </head>
  <body>
    <details>
      <summary>Welcome to Sharnoby Server from {{.RemoteIP}}</summary>
      <ul>
        <li>Time : {{placeholder "time.now.http"}}</li>
        <li>Requested Host : {{placeholder "http.request.hostport"}}</li>
        <li>Remote IP : {{placeholder "http.request.remote.host"}}</li>
        <li>Remote Port: {{placeholder "http.request.remote.port"}}</li>
        <li>TLS Version: {{placeholder "http.request.tls.version"}}</li>
        <li>TLS Cipher: {{placeholder "http.request.tls.cipher_suite"}}</li>
        <li>Method: {{placeholder "http.request.method"}}</li>
        <li>URI : {{placeholder "http.request.uri"}}</li>
      </ul>
    </details>
    <details open>
      <summary>Links</summary>
      <ul>
EOT
# cat Caddyfile | grep -i "^\s*import.*host" | cut -d ' ' -f 3 | head -n -1 | tail -n +3
cat Caddyfile | grep -i "^\s*import.*host" | cut -d ' ' -f 3 | head -n -1 | awk '{print "        <li><a href=\"https://"$1".sharnoby.eu.org\">"$1"</a></li>"}' >> $FILE
cat <<EOT >> $FILE
      </ul>
    </details>
  </body>
</html>
EOT