-- Leo's gemini proxy

-- Connecting to git.thebackupbox.net:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini

repo: shell-daemons
action: commit
revision:
path_from:
revision_from: fa3a04c105f28d3f5162cae8ae0335db58bf73d1:
path_to:
revision_to:

git.thebackupbox.net

shell-daemons

git://git.thebackupbox.net/shell-daemons

commit fa3a04c105f28d3f5162cae8ae0335db58bf73d1
Author: epoch <epoch@hack.thebackupbox.net>
Date:   Mon Jun 15 13:05:36 2020 +0000

    no sniffing me in httpd. renamed gemini to geminid

diff --git a/gemini b/gemini
deleted file mode 100755
index 41d32da6f5d70939db0111cde30c7242f807cd6c..0000000000000000000000000000000000000000
--- a/gemini
+++ /dev/null
@@ -1,29 +0,0 @@
-#!/bin/bash
-### response code then mime-type
-uri=$(head -n1 | tr -d '\r\n')
-path="$(printf "%s\n" "$uri" | uricut -p)"
-path="$(normalpath "/var/gemini/$path")"
-if ! printf "%s\n" "$path" | grep "^/var/gemini" >/dev/null 2>&1;then
-  printf '59 BAD REQUEST\r\n'
-  exit 1
-fi
-CONTENT_TYPE="$(mime-type "$path")"
-case "$CONTENT_TYPE" in
-  inode/directory)
-    printf "20 text/gemini\r\n"
-    echo $path | grep "^/var/gemini"
-    printf "%s\n" "$uri" | uricut
-    if [ -f "$path/index.gmi" ];then
-      cat "$path/index.gmi"
-    fi
-    find "$path" -type f | cut -d/ -f4- | tr '\n' '\0' | xargs -0 printf '=>%s\n'
-    ;;
-  *)
-    if [ -x "$path" ];then
-      "$path"
-    else
-      printf "20 %s\r\n" "$CONTENT_TYPE"
-      cat -- "$path"
-    fi
-    ;;
-esac
diff --git a/geminid b/geminid
new file mode 100755
index 0000000000000000000000000000000000000000..c92ec22bf3ce2f619c2a1dc727a025301f3a701b
--- /dev/null
+++ b/geminid
@@ -0,0 +1,54 @@
+#!/bin/bash
+### response code then mime-type
+uri=$(head -n1 | tr -d '\r\n')
+path="$(printf "%s\n" "$uri" | uricut -p)"
+export QUERY_STRING="$(printf "%s\n" "$uri" | uricut -q)"
+if grep '^/~' <<< $path 2>&1 >/dev/null ;then
+  user="$(printf "%s\n" "$path" | cut -d/ -f2 | tr -cd 'a-zA-Z')"
+  path="$(printf "%s\n" "$path" | cut -d/ -f3-)"
+  path="$(normalpath "/home/$user/public_gemini/$path")"
+  if ! printf "%s\n" "$path" | grep '^/home/'"$user"'/public_gemini/' >/dev/null 2>&1;then
+    printf '59 BAD REQUEST\r\n'
+    exit 1
+  fi
+else
+  unset user
+  path="$(normalpath "/var/gemini/$path")"
+  if ! printf "%s\n" "$path" | grep "^/var/gemini" >/dev/null 2>&1;then
+    printf '59 BAD REQUEST\r\n'
+    exit 1
+  fi
+fi
+CONTENT_TYPE="$(mime-type "$path")"
+case "$CONTENT_TYPE" in
+  inode/directory)
+    printf "20 text/gemini\r\n"
+    printf '> using gemini t. you\r\n'
+    printf "%s\n" "$uri" | uricut
+    if [ -f "$path/index.gmi" ];then
+      cat "$path/index.gmi"
+    fi
+    printf "## autogenerated list of stuff in this directory.\r\n"
+    if [ "$user" ];then
+      find "$path" -type d | cut -d/ -f5- | grep . | tr '\n' '\0' | xargs -r0 printf '=> %s [dir]\r\n'
+      find "$path" -type f | cut -d/ -f5- | grep . | tr '\n' '\0' | xargs -r0 printf '=> %s [file]\r\n'
+      find "$path" -type l | cut -d/ -f5- | grep . | tr '\n' '\0' | xargs -r0 printf '=> %s [link]\r\n'
+    else
+      find "$path" -type d | cut -d/ -f4- | grep . | tr '\n' '\0' | xargs -r0 printf '=> %s [dir]\r\n'
+      find "$path" -type f | cut -d/ -f4- | grep . | tr '\n' '\0' | xargs -r0 printf '=> %s [file]\r\n'
+      find "$path" -type l | cut -d/ -f4- | grep . | tr '\n' '\0' | xargs -r0 printf '=> %s [link]\r\n'
+    fi
+    ;;
+  *)
+    if [ -x "$path" ];then
+      if [ "$user" ];then
+        printf "47 CGIs for users not implemented yet\r\n"
+      else
+        "$path"
+      fi
+    else
+      printf "20 %s\r\n" "$CONTENT_TYPE"
+      cat -- "$path"
+    fi
+    ;;
+esac
diff --git a/httpd b/httpd

index 3370588f8e12fef03d30db04b872a1e21cc9c45c..

index ..8e9d1ffbd7cd8486f15659af3a73efdce586b515 100755

--- a/httpd
+++ b/httpd
@@ -62,6 +62,8 @@ if printf "%s\n" "$SCRIPT_NAME" | grep "^/~" 2>&1 >/dev/null;then
   TILDE=$(printf "%s\n" "$SCRIPT_NAME" | cut -d/ -f2 | tr -cd 'A-Za-z0-9')
   if ! cd /home/$TILDE/public_html;then
     printf "HTTP/1.1 404 Not Found\r\n"
+    printf "X-Content-Type-Options: nosniff\r\n"
+    logger "httpd 404 for page: ${SCRIPT_NAME} ?${QUERY_STRING}"
     printf "Content-Type: text/plain\r\n\r\n"
     echo "this user doesn't have a public html dir."
     exit 0
@@ -104,6 +106,7 @@ COMMENT

 if [ "$SCRIPT_NAME" = "/" -a "$TILDE" = "" ];then
   printf "HTTP/1.1 301 Found\r\n"
+  printf "X-Content-Type-Options: nosniff\r\n"
   if [ -f "${SCRIPT_FILENAME}/.redirect" ];then
     printf "Location: %s\r\n" "$(cat "${SCRIPT_FILENAME}/.redirect")"
   else
@@ -111,6 +114,7 @@ if [ "$SCRIPT_NAME" = "/" -a "$TILDE" = "" ];then
   fi
   printf "Content-Type: text/html\r\n\r\n"
   printf "please hold while your call is connected"
+  exit 0
 elif printf "%s\n" "$SCRIPT_NAME" | egrep "^/cgi-bin/|^/.well-known/webfinger" 2>&1 >/dev/null;then
   cd cgi-bin
   RET_STATUS=200
@@ -134,17 +138,23 @@ else
   if [ "$MIME_TYPE" = inode/directory ];then
     if ! printf "${SCRIPT_NAME}" | grep '/$' 2>&1 >/dev/null;then
       printf "HTTP/1.1 301 Redirect\r\n"
+  printf "X-Content-Type-Options: nosniff\r\n"
+      logger "httpd 301 for page: ${SCRIPT_NAME} ?${QUERY_STRING}"
       printf "Location: %s/\r\n\r\n" "${SCRIPT_NAME}"
-      exit 1
+      exit 0
     fi
     if [ -e "$(normalpath "${SCRIPT_FILENAME}/.redirect")" ];then
       printf "HTTP/1.1 307 Temporary Redirect\r\n"
+      printf "X-Content-Type-Options: nosniff\r\n"
+      logger "httpd 307 for page: ${SCRIPT_NAME} ?${QUERY_STRING}"
       printf "Location: %s\r\n" "$(cat "$(normalpath "${SCRIPT_FILENAME}/.redirect")")"
       printf "Content-Type: text/plain\r\n\r\n"
       echo what are you looking at?
+      exit 0
     fi
     if [ ! -e "$(normalpath "${SCRIPT_FILENAME}/index.html")" ];then
       printf "HTTP/1.1 200 OK\r\n"
+  printf "X-Content-Type-Options: nosniff\r\n"
       printf "Content-Type: text/html\r\n\r\n"
       printf '<html><head><title>%s %s autoindex</title><link rel="stylesheet" type="text/css" href="/style.css" /></head><body>' "${SCRIPT_NAME}" "${SCRIPT_FILENAME}"
       find "${SCRIPT_FILENAME}" -maxdepth 1 -print0 \
@@ -159,20 +169,9 @@ else
     SCRIPT_FILENAME="$(normalpath "${SCRIPT_FILENAME}/index.html")"
     MIME_TYPE="$(mime-type "${SCRIPT_FILENAME}")"
   fi
-  if [ "$EXT" = "css" ];then
-    MIME_TYPE="text/css"
-  fi
-  if [ "$EXT" = "txt" ];then
-    MIME_TYPE="text/plain"
-  fi
-  if [ "$EXT" = "sh" ];then
-    MIME_TYPE="text/plain"
-  fi
-  if [ "$EXT" = "js" ];then
-    MIME_TYPE="text/javascript"
-  fi
   if [ -e "${SCRIPT_FILENAME}" ];then
     printf "HTTP/1.1 200 OK\r\n"
+  printf "X-Content-Type-Options: nosniff\r\n"
     printf "Date: %s\r\n" "$(rfc7231date)"
     printf "Expires: %s\r\n" "$(rfc7231date +3600)"
     printf "Cache-Control: max-age=3600\r\n"
@@ -183,6 +182,8 @@ else
     cat "$SCRIPT_FILENAME"
   else
     printf "HTTP/1.1 404 Not Found\r\n"
+  printf "X-Content-Type-Options: nosniff\r\n"
+    logger "httpd 404 for page: ${SCRIPT_NAME} ?${QUERY_STRING}"
     printf "Date: %s\r\n" "$(rfc7231date)"
     if printf "%s\n" "${SCRIPT_NAME}" | grep -G '^/\.well-known/openpgpkey/' 2>&1 >/dev/null ;then
       printf 'Access-Control-Allow-Origin: *\r\n'

-----END OF PAGE-----

-- Response ended

-- Page fetched on Sun Jun 2 13:33:16 2024