diff --git a/http.sh b/http.sh index 25f8617..482aeab 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]="Luna is cute <3" +cfg[auth_realm]="asdf" 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 -MaeIsCute +EOF fi source config/master.sh @@ -89,22 +89,24 @@ 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 -LauraIsCute +cfg[enable_multipart]=false # by default, uploading files is disabled +EOF - cat < "${cfg[namespace]}/workers/example/worker.sh" + cat < "${cfg[namespace]}/workers/example/worker.sh" #!/usr/bin/env bash date -LauraIsCute +EOF - 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]}/ @@ -119,40 +121,39 @@ 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
  • - © sdomi, ptrcnull, selfisekai - 2020, 2021" -LauraIsCute - cat < "${cfg[namespace]}/routes.sh" +
  • $(pwd)/src/ - HTTP.sh src, feel free to poke around ;P
  • " +EOF + 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=ptrcnull +## (webroot) https://example.com/profile.shs?name=asdf ## ... may become ... -## (routes) https://example.com/profile/ptrcnull +## (routes) https://example.com/profile/asdf ## ## 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" -MaeIsCute +EOF 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 _ _ _______ _______ _____ ______ _ _ | | | |_______|_______| _ \/ ___/| | | | | |__| | | | | | | |_| | |___ | |__| | | |__| | | | | | | ___/\___ \ | |__| | | | | | | | | | | | ___\ \| | | | |_| |_| |_| |_| |_| □ /_____/|_| |_| -MaeIsCute +EOF if [[ "$1" == "debug" ]]; then cfg[dbg]=true @@ -181,9 +182,16 @@ 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 -i 600s -l -U "$socket" -c src/server.sh -k & + # 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 & else - ncat -i 600s -l -U "$socket" -c src/server.sh -k 2>> /dev/null & + while true; do + ncat -i 600s -l -U "$socket" -c src/server.sh -k 2>> /dev/null & + done & fi socat TCP-LISTEN:${cfg[port]},fork,bind=${cfg[ip]} UNIX-CLIENT:$socket & echo "[HTTP] listening on ${cfg[ip]}:${cfg[port]} through '$socket'" @@ -192,9 +200,13 @@ else if [[ ${cfg[ssl]} == true ]]; then echo "[SSL] listening on port ${cfg[ip]}:${cfg[ssl_port]}" if [[ ${cfg[dbg]} == true ]]; then - 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]}") & + 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 & else - 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 & + 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 & fi fi fi diff --git a/src/server.sh b/src/server.sh index 018f4cf..43dad2f 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[post]}" == true && "${r[status]}" == 212 ]]; then +if [[ "{cfg[enable_multipart]}" == true ]] && [[ "${r[post]}" == true ]] && [[ "${r[status]}" == 200 || "${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.