Advertisement
teknoraver

httpd

Nov 30th, 2020 (edited)
799
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.60 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. [ "$#" -eq 0 ] && exec nc -klp 8080 -e "$0 serve"
  4.  
  5. IFS="$IFS"$'\r'
  6.  
  7. read -r get file http
  8.  
  9. if ! [ -e ".$file" ]; then
  10.     printf "$http 404 Not found\\r\\n"
  11. elif ! [ -r ".$file" ]; then
  12.     printf "$http 403 Access denied\\r\\n"
  13. elif [ -d ".$file" ]; then
  14.     printf "$http 200 OK\\r\\n\\r\\n"
  15.     (
  16.         cd ".$file"
  17.         echo '<pre>'
  18.         for i in *; do
  19.             if [ -d "$i" ]; then
  20.                 stat --printf='<a href="%n/">%n/</a><br>' "$i"
  21.             else
  22.                 stat --printf='<a href="%n">%n</a>\t%s bytes<br>' "$i"
  23.             fi
  24.         done
  25.         echo '</pre>'
  26.     )
  27. else
  28.     printf "$http 200 OK\\r\\n\\r\\n"
  29.     exec cat ".$file"
  30. fi
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement