teknoraver

httpd.sh

Nov 30th, 2020 (edited)
441
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.     exec ls -lhA ".$file"
  16. else
  17.     printf "$http 200 OK\\r\\n\\r\\n"
  18.     exec cat ".$file"
  19. fi
  20.  
RAW Paste Data