rewrote the logging system using ncat's env variables; added bind IP to config; now you can host only HTTPS (as opposed to HTTP/HTTP+HTTPS); bump version

merge-requests/2/head
Dominika 2020-09-18 11:11:14 +02:00
parent fa7435d235
commit f7b8b441fb
3 changed files with 32 additions and 32 deletions

View File

@ -1,6 +1,9 @@
declare -A cfg
cfg[port]=1337
cfg[ip]=127.0.0.1 # IP address to bind to - use 0.0.0.0 to bind to all
cfg[http]=true # enables/disables listening on HTTP
cfg[port]=1337 # HTTP port
cfg[root]='webroot/'
cfg[index]='index.shs'
@ -9,23 +12,22 @@ cfg[autoindex]=true
cfg[auth_required]=false
cfg[auth_realm]="Laura is cute <3"
cfg[ssl]=false
cfg[ssl]=false # enables/disables listening on HTTPS
cfg[ssl_port]=8443
cfg[ssl_cert]=''
cfg[ssl_key]=''
cfg[extension]='shs'
cfg[extra_headers]='server: HTTP.sh/0.91 (devel)'
cfg[extra_headers]='server: HTTP.sh/0.92 (devel)'
cfg[title]='ddd defies development'
cfg[title]='HTTP.sh 0.92'
cfg[php_enabled]=false
cfg[python_enabled]=false
cfg[php_enabled]=false # enable PHP script evalutaion (requires PHP)
cfg[python_enabled]=false # enable Python script evalutaion (requires Python)
# by default, those logs are placed in the main directory - change it to /var/log/_name_ for production
cfg[log_http]='log_http'
cfg[log_https]='log_https'
cfg[log_misc]='log'
# by default, this log file is placed in the main directory - change it to /var/log/_name_ for production
cfg[log]='log'
# proxy functionality is very WiP
cfg[proxy]=false
cfg[proxy_url]='http://example.com/'

24
http.sh
View File

@ -15,16 +15,18 @@ fi
source config/master.sh
echo "HTTP.sh"
if [[ ${cfg[ssl]} == true ]]; then
echo "listening on port ${cfg[port]} (HTTP) and ${cfg[ssl_port]} (HTTPS)"
ncat -v -l -p ${cfg[port]} -c ./src/server.sh -k 2>> ${cfg[log_http]} &
if [[ ${cfg[ssl_key]} != '' && ${cfg[ssl_cert]} != '' ]]; then
ncat -v -l -p ${cfg[ssl_port]} -c ./src/server.sh -k --ssl --ssl-cert ${cfg[ssl_cert]} --ssl-key ${cfg[ssl_key]} 2>> ${cfg[log_https]}
else
ncat -v -l -p ${cfg[ssl_port]} -c ./src/server.sh -k --ssl 2>> ${cfg[log_https]}
fi
else
echo "listening on port ${cfg[port]} (HTTP)"
ncat -v -l -p ${cfg[port]} -c ./src/server.sh -k 2>> ${cfg[log_http]}
if [[ ${cfg[http]} == true ]]; then
echo "[HTTP] listening on ${cfg[ip]}:${cfg[port]}"
ncat -v -l ${cfg[ip]} ${cfg[port]} -c ./src/server.sh -k 2>> /dev/null &
fi
if [[ ${cfg[ssl]} == true ]]; then
echo "[SSL] listening on port ${cfg[ip]}:${cfg[ssl_port]}"
if [[ ${cfg[ssl_key]} != '' && ${cfg[ssl_cert]} != '' ]]; then
ncat -v -l ${cfg[ip]} ${cfg[ssl_port]} -c ./src/server.sh -k --ssl --ssl-cert ${cfg[ssl_cert]} --ssl-key ${cfg[ssl_key]} 2>> /dev/null &
else
ncat -v -l ${cfg[ip]} ${cfg[ssl_port]} -c ./src/server.sh -k --ssl 2>> /dev/null &
fi
fi
wait

View File

@ -72,11 +72,11 @@ while read param; do
# below shamelessly copied from GET, should be moved to a function
data=$(echo ${r[url]} | sed -E 's/^(.*)\?//;s/\&/ /g')
if [[ $data != ${r[url]} ]]; then
declare -A get_data
declare -A post_data
for i in $data; do
name=$(echo $i | sed -E 's/\=(.*)$//')
value=$(echo $i | sed "s/$name\=//")
get_data[$name]=$value
post_data[$name]=$value
done
fi
@ -87,19 +87,15 @@ r[uri]=$(realpath ${cfg[root]}$(echo ${r[url]} | sed -E 's/\?(.*)$//'))
[[ -d "${r[uri]}/" ]] && pwd="${r[uri]}" || pwd=$(dirname "${r[uri]}")
echo "---" >> ${cfg[log_misc]}
echo "$(date)" >> ${cfg[log_misc]}
if [[ $(tail -n 1 ${cfg[log_http]}) == $(cat /tmp/lasthttp) ]]; then
r[ip]=$(tail -n 1 ${cfg[log_https]} | sed -s 's/Ncat: Connection from //')
r[ip]="$NCAT_REMOTE_ADDR:$NCAT_REMOTE_PORT"
if [[ $NCAT_LOCAL_PORT == ${cfg[port]} ]]; then
r[proto]='http'
echo "HTTPS IP: ${r[ip]}" >> ${cfg[log_misc]}
else
r[ip]=$(tail -n 1 ${cfg[log_http]} | sed -s 's/Ncat: Connection from //')
r[proto]='https'
echo "HTTP IP: ${r[ip]}" >> ${cfg[log_misc]}
fi
echo "URL: ${r[url]}, GET_data: ${get_data[@]}, POST_data: ${post_data[@]}, POST_multipart: ${post_multipart[@]}" >> ${cfg[log_misc]}
tail -n 1 ${cfg[log_http]} > /tmp/lasthttp
echo "$(date) - IP: ${r[ip]}, PROTO: ${r[proto]}, URL: ${r[url]}, GET_data: ${get_data[@]}, POST_data: ${post_data[@]}, POST_multipart: ${post_multipart[@]}" >> ${cfg[log]}
if [[ ${r[status]} != 101 ]]; then