Skip to content

Instantly share code, notes, and snippets.

@iwconfig
Created October 27, 2025 03:09
Show Gist options
  • Select an option

  • Save iwconfig/3aa0f39e4d0cf17f49ddade341f2b42a to your computer and use it in GitHub Desktop.

Select an option

Save iwconfig/3aa0f39e4d0cf17f49ddade341f2b42a to your computer and use it in GitHub Desktop.
simple directory tree browser
ncat -lk -p 8000 --sh-exec '
{
read request
url_path=$(echo "$request" | awk "{print \$2}" | sed "s|//\+|/|g")
current_path=${url_path%/}
echo $current_path > /dev/stderr
html=$(tree "$url_path" -H .)
echo "HTTP/1.0 200 Ok"
echo "Content-Type: text/html;charset=UTF-8"
echo
echo "$html" | awk "/<body>/ {print; exit} {print}"
echo "<script>"
echo "const observer = new MutationObserver((mutationsList, observer) => {"
echo " const link = document.querySelector(\"body p a\");"
echo " if (link) {"
echo " const path = \"${current_path:-/}\".replace(/\\/\\//g, \"/\");"
echo " link.text = path;"
echo " link.parentElement.prepend(document.createElement(\"br\"));"
echo " const parts = path.split(\"/\").filter(Boolean);"
echo " for (let i = parts.length - 1; i >= 0; i--) {"
echo " const path = \"/\" + parts.slice(0, i + 1).join(\"/\").replace(/\\/\\//g, \"/\");"
echo " const a = document.createElement(\"a\");"
echo " a.text = \"/\" + parts.slice(0, i).join(\"/\").replace(/\\/\\//g, \"/\");"
echo " a.href = path === \"\" ? \"/\" : path + \"/..\";"
echo " link.parentElement.prepend(a);"
echo " if (i != 0) {"
echo " link.parentElement.prepend(document.createElement(\"br\"));"
echo " }"
echo " }"
echo " observer.disconnect();" # Disconnects observer after execution
echo " }"
echo "});"
echo "observer.observe(document.body, { childList: true, subtree: true });"
echo "</script>"
echo "$html" | awk "/<body>/ {found=1; next} found"
echo
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment