+ new proxying system
parent
a7acb3ee6e
commit
46e77541cf
6
http.sh
6
http.sh
|
@ -36,9 +36,9 @@ cfg[python_enabled]=false # enable Python script evalutaion (requires Python)
|
|||
|
||||
cfg[log]='log' # filename
|
||||
|
||||
# proxy functionality is very WiP
|
||||
cfg[proxy]=false
|
||||
cfg[proxy_url]='http://example.com/'
|
||||
cfg[proxy]=false # you probably want to configure this per-url
|
||||
cfg[proxy_url]='' # regexp matching valid URLs to proxy
|
||||
cfg[proxy_param]='url' # /proxy?url=...
|
||||
|
||||
# mail handler config
|
||||
cfg[mail]=""
|
||||
|
|
|
@ -1,4 +1,28 @@
|
|||
printf "HTTP/1.0 200 OK
|
||||
${cfg[extra_headers]}\r\n\r\n"
|
||||
#!/bin/bash
|
||||
url="$(url_decode "$(url_decode "$(sed -E 's/\?/<2F><>Lun4_iS_CuTe<54>/;s/^(.*)<29><>Lun4_iS_CuTe<54>//;s/'"${cfg[proxy_param]}"'=//g' <<< "${r[url]}")")")"
|
||||
|
||||
curl ${cfg[proxy_url]}${r[url]}
|
||||
if [[ $(grep -Poh "${cfg[proxy_url]}" <<< "$url") == '' ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
host="$(sed -E 's@http(s|)://@@;s@/.*@@' <<< "$url")"
|
||||
headers="$(tr '\r' '\n' <<< "${r[req_headers]}")"
|
||||
headers+=$'\n'
|
||||
|
||||
while read line; do
|
||||
if [[ "$line" == "GET"* ]]; then
|
||||
if [[ "$url" == *"$host" ]]; then
|
||||
echo "GET / HTTP/1.1"
|
||||
else
|
||||
echo "GET /$(sed -E 's@http(s|)://@@;s@/@<40><>Lun4_iS_CuTe<54>@;s@.*<2A><>Lun4_iS_CuTe<54>@@' <<< "$url") HTTP/1.1"
|
||||
fi
|
||||
elif [[ "$line" == *"Host"* ]]; then
|
||||
echo "Host: $url" | sed -E 's@http(s|)://@@;s@/.*@@'
|
||||
else
|
||||
echo "$line"
|
||||
fi
|
||||
done <<< "$headers" | if [[ "$url" == "https"* ]]; then
|
||||
nc $host 443 --ssl -C -i 0.1 --no-shutdown
|
||||
else
|
||||
nc $host 80 -C -i 0.1 --no-shutdown
|
||||
fi
|
||||
|
|
|
@ -16,9 +16,11 @@ declare -A post_data # all POST params
|
|||
declare -A params # parsed router data
|
||||
|
||||
r[status]=210 # Mommy always said that I was special
|
||||
r[req_headers]=''
|
||||
post_length=0
|
||||
|
||||
while read -r param; do
|
||||
r[req_headers]+="$param"
|
||||
param_l="${param,,}" # lowercase
|
||||
name=''
|
||||
value=''
|
||||
|
@ -160,6 +162,8 @@ fi
|
|||
|
||||
echo "${r[url]}" >&2
|
||||
|
||||
# the app config gets loaded a second time to allow for path-specific config modification
|
||||
[[ -f "${cfg[namespace]}/config.sh" ]] && source "${cfg[namespace]}/config.sh"
|
||||
|
||||
if [[ "${cfg[auth_required]}" == true && "${r[authorized]}" != true ]]; then
|
||||
echo "Auth failed." >> ${cfg[log_misc]}
|
||||
|
@ -213,9 +217,6 @@ if [[ "${r[post]}" == true && "${r[status]}" == 200 ]]; then
|
|||
fi
|
||||
fi
|
||||
|
||||
# the app config gets loaded a second time to allow for path-specific config modification
|
||||
[[ -f "${cfg[namespace]}/config.sh" ]] && source "${cfg[namespace]}/config.sh"
|
||||
|
||||
if [[ ${r[status]} == 210 && ${cfg[autoindex]} == true ]]; then
|
||||
source "src/response/listing.sh"
|
||||
elif [[ ${r[status]} == 211 ]]; then
|
||||
|
|
Loading…
Reference in New Issue