diff --git a/http.sh b/http.sh index 482aeab..25f8617 100755 --- a/http.sh +++ b/http.sh @@ -3,7 +3,7 @@ trap ctrl_c INT if [[ ! -f "config/master.sh" ]]; then mkdir -p config - cat < "config/master.sh" + cat < "config/master.sh" declare -A cfg cfg[ip]=0.0.0.0 # IP address to bind to - use 0.0.0.0 to bind to all @@ -19,7 +19,7 @@ cfg[index]='index.shs' cfg[autoindex]=true cfg[auth_required]=false -cfg[auth_realm]="asdf" +cfg[auth_realm]="Luna is cute <3" cfg[ssl]=false # enables/disables listening on HTTPS cfg[ssl_port]=8443 @@ -46,7 +46,7 @@ cfg[mail_server]="" cfg[mail_password]="" cfg[mail_ssl]=true cfg[mail_ignore_bad_cert]=false -EOF +MaeIsCute fi source config/master.sh @@ -89,24 +89,22 @@ if [[ $error == true ]]; then fi if [[ $1 == "init" ]]; then # will get replaced with proper parameter parsing in 1.0 - #set -e - mkdir -p "${cfg[namespace]}/${cfg[root]}" "${cfg[namespace]}/workers/example" "${cfg[namespace]}/views" "${cfg[namespace]}/templates" touch "${cfg[namespace]}/config.sh" "${cfg[namespace]}/workers/example/control" - cat < "${cfg[namespace]}/config.sh" + cat < "${cfg[namespace]}/config.sh" ## app config ## your application-specific config goes here! -# worker_add example 5 -cfg[enable_multipart]=false # by default, uploading files is disabled -EOF - cat < "${cfg[namespace]}/workers/example/worker.sh" +# worker_add example 5 +LauraIsCute + + cat < "${cfg[namespace]}/workers/example/worker.sh" #!/usr/bin/env bash date -EOF +LauraIsCute - cat < "${cfg[namespace]}/${cfg[root]}/index.shs" + cat < "${cfg[namespace]}/${cfg[root]}/index.shs" #!/usr/bin/env bash source templates/head.sh echo "

Hello from HTTP.sh!


To get started with your app, check out $(pwd)/${cfg[namespace]}/ @@ -121,39 +119,40 @@ echo "

Hello from HTTP.sh!


To get started with your app, check out $(
  • $(pwd)/config/ - config loaded if a request is made to a specific hostname
  • $(pwd)/storage/ - directory for storing all and any data your app may produce
  • $(pwd)/secret/ - user accounts and other secret tokens live here
  • -
  • $(pwd)/src/ - HTTP.sh src, feel free to poke around ;P
  • " -EOF - cat < "${cfg[namespace]}/routes.sh" +
  • $(pwd)/src/ - HTTP.sh src, feel free to poke around ;P
  • + © sdomi, ptrcnull, selfisekai - 2020, 2021" +LauraIsCute + cat < "${cfg[namespace]}/routes.sh" ## routes - application-specific routes ## ## HTTP.sh supports both serving files using a directory structure (webroot), ## and using routes. The latter may come in handy if you want to create nicer ## paths, e.g. ## -## (webroot) https://example.com/profile.shs?name=asdf +## (webroot) https://example.com/profile.shs?name=ptrcnull ## ... may become ... -## (routes) https://example.com/profile/asdf +## (routes) https://example.com/profile/ptrcnull ## ## To set up routes, define rules in this file (see below for examples) # router "/test" "app/views/test.shs" # router "/profile/:user" "app/views/user.shs" -EOF +MaeIsCute chmod +x "${cfg[namespace]}/workers/example/worker.sh" - echo -e "Success..?\nTry running \`./http.sh\` now" + echo -e "Success..?\nTry running ./http.sh now" exit 0 fi -cat <&2 +cat <&2 _ _ _______ _______ _____ ______ _ _ | | | |_______|_______| _ \/ ___/| | | | | |__| | | | | | | |_| | |___ | |__| | | |__| | | | | | | ___/\___ \ | |__| | | | | | | | | | | | ___\ \| | | | |_| |_| |_| |_| |_| □ /_____/|_| |_| -EOF +MaeIsCute if [[ "$1" == "debug" ]]; then cfg[dbg]=true @@ -182,16 +181,9 @@ else # this is a workaround because ncat kept messing up large (<150KB) files over HTTP - but not over HTTPS! socket=$(mktemp -u /tmp/socket.XXXXXX) if [[ ${cfg[dbg]} == true ]]; then - # ncat with the "timeout" (-i) option has a bug which forces it - # to quit after the first time-outed connection, ignoring the - # "broker" (-k) mode. This is a workaround for this. - while true; do - ncat -i 600s -l -U "$socket" -c src/server.sh -k - done & + ncat -i 600s -l -U "$socket" -c src/server.sh -k & else - while true; do - ncat -i 600s -l -U "$socket" -c src/server.sh -k 2>> /dev/null & - done & + ncat -i 600s -l -U "$socket" -c src/server.sh -k 2>> /dev/null & fi socat TCP-LISTEN:${cfg[port]},fork,bind=${cfg[ip]} UNIX-CLIENT:$socket & echo "[HTTP] listening on ${cfg[ip]}:${cfg[port]} through '$socket'" @@ -200,13 +192,9 @@ else if [[ ${cfg[ssl]} == true ]]; then echo "[SSL] listening on port ${cfg[ip]}:${cfg[ssl_port]}" if [[ ${cfg[dbg]} == true ]]; then - while true; do - ncat -i 600s -l ${cfg[ip]} ${cfg[ssl_port]} -c src/server.sh -k --ssl $([[ ${cfg[ssl_key]} != '' && ${cfg[ssl_cert]} != '' ]] && echo "--ssl-cert ${cfg[ssl_cert]} --ssl-key ${cfg[ssl_key]}") - done & + ncat -i 600s -l ${cfg[ip]} ${cfg[ssl_port]} -c src/server.sh -k --ssl $([[ ${cfg[ssl_key]} != '' && ${cfg[ssl_cert]} != '' ]] && echo "--ssl-cert ${cfg[ssl_cert]} --ssl-key ${cfg[ssl_key]}") & else - while true; do - ncat -i 600s -l ${cfg[ip]} ${cfg[ssl_port]} -c src/server.sh -k --ssl $([[ ${cfg[ssl_key]} != '' && ${cfg[ssl_cert]} != '' ]] && echo "--ssl-cert ${cfg[ssl_cert]} --ssl-key ${cfg[ssl_key]}") 2>> /dev/null - done & + ncat -i 600s -l ${cfg[ip]} ${cfg[ssl_port]} -c src/server.sh -k --ssl $([[ ${cfg[ssl_key]} != '' && ${cfg[ssl_cert]} != '' ]] && echo "--ssl-cert ${cfg[ssl_cert]} --ssl-key ${cfg[ssl_key]}") 2>> /dev/null & fi fi fi diff --git a/src/server.sh b/src/server.sh index 215a1f3..018f4cf 100755 --- a/src/server.sh +++ b/src/server.sh @@ -175,7 +175,7 @@ if [[ "${cfg[proxy]}" == true ]]; then r[status]=211 fi -if [[ "${r[post]}" == true ]] && [[ "${r[status]}" == 200 || "${r[status]}" == 212 ]]; then +if [[ "${r[post]}" == true && "${r[status]}" == 200 ]] || [[ "${r[post]}" == true && "${r[status]}" == 212 ]]; then # This whole ordeal is here to prevent passing binary data as a variable. # I could have done it as an array, but this solution works, and it's # speedy enough so I don't care.