-- Leo's gemini proxy
-- Connecting to git.thebackupbox.net:1965...
-- Connected
-- Sending request
-- Meta line: 20 text/gemini
repo: www_git action: commit revision: path_from: revision_from: e0e140b78ec40ef0274839d1a00d20281041b7d9: path_to: revision_to:
commit e0e140b78ec40ef0274839d1a00d20281041b7d9 Author: epoch <epoch@hack.thebackupbox.net> Date: Sat May 8 07:40:45 2021 +0000 switched from grep to using case with a wildcard diff --git a/index.cgi b/index.cgi
--- a/index.cgi +++ b/index.cgi @@ -1,28 +1,38 @@ #!/bin/bash -export PI_1="$(printf "%s\n" "$PATH_INFO" | cut -d/ -f2 | tr -cd 'a-zA-Z0-9_-')" ### REPO -export PI_2="$(printf "%s\n" "$PATH_INFO" | cut -d/ -f3 | tr -cd 'a-zA-Z0-9_-')" ### branch +export PI_1="$(printf "%s\n" "$PATH_INFO" | cut -d/ -f2 | tr -cd 'a-zA-Z0-9_.-')" ### REPO +export PI_2="$(printf "%s\n" "$PATH_INFO" | cut -d/ -f3 | tr -cd 'a-zA-Z0-9_.-')" ### branch export PI_3="$(printf "%s\n" "$PATH_INFO" | cut -d/ -f4- | tr -cd 'a-zA-Z0-9_/.-')" ### path in git repo of.. file or dir I guess if [ "$PI_3" ];then trailing_slash="$(printf "%s\n" "${PI_3}" | rev | cut -b1 | grep /)" export PI_3="$(normalpath "/$PI_3" | cut -b2-)${trailing_slash}" fi if [ "${PI_1}" ];then - if printf "%s\n" "$PATH_INFO" | grep -v '^/'"${PI_1}"'/' 2>&1 >/dev/null;then + case "$PATH_INFO" in + "/${PI_1}/"*) + true + ;; + *) printf "Status: 301\r\n" printf "Location: /%s/\r\n" "${PI_1}" printf "Content-Type: text/plain\r\n\r\n" printf "redirect to: /%s/" "${PI_1}" exit 0 - fi + ;; + esac fi if [ "${PI_2}" ];then - if printf "%s\n" "$PATH_INFO" | grep -v '^/'"${PI_1}"'/'"${PI_2}"'/' 2>&1 >/dev/null;then + case "$PATH_INFO" in + "/${PI_1}/${PI_2}/"*) + true + ;; + *) printf "Status: 301\r\n" printf "Location: /%s/%s/\r\n" "${PI_1}" "${PI_2}" printf "Content-Type: text/plain\r\n\r\n" printf "redirect to: /%s/%s/" "${PI_1}" "${PI_2}" exit 0 - fi + ;; + esac fi printf "Content-Type: text/html\r\n\r\n" printf "<html><head><title>%s</title></head><body>\n" "git shit" @@ -32,9 +42,8 @@ if [ ! "${PI_1}" ];then | sed 's|^\(.*\)$|<a href="/\1/">/\1/</a><br/>|g' else gitroot="$(normalpath /var/git/${PI_1})" - if printf "%s\n" "$gitroot" | grep -v '^/var/git/' 2>&1 >/dev/null;then - printf "derp." - else ## we are in a valid git repo + case "$gitroot" in + /var/git/*) printf '<h1><a href="/">git.thebackupbox.net</a> / <a href="/%s/">%s</a>' "$PI_1" "$PI_1" if [ "$PI_2" ];then printf ' / <a href="/%s/%s/">%s</a>' "$PI_1" "$PI_2" "$PI_2" @@ -60,7 +69,11 @@ else echo "</pre>" fi fi - fi + ;; + *) + printf "good luck finding bugs. lemme know if you find any.\n" + ;; + esac fi printf "</body></html>\n"
-----END OF PAGE-----
-- Response ended
-- Page fetched on Sun Jun 2 18:31:12 2024