Commit 8f0d48a5 authored by Dominika Liberda's avatar Dominika Liberda 💽

ncat is bork bugfix

parent 4a2a0bb8
......@@ -3,8 +3,9 @@ trap ctrl_c INT
source config/master.sh
function ctrl_c() {
[[ $socket != '' ]] && rm $socket
pkill -P $$
echo -e "Killed all remaining processes.\nHave an awesome day!!"
echo -e "Cleaned up, exitting.\nHave an awesome day!!"
}
if [[ ! -f "$(pwd)/http.sh" ]]; then
......@@ -12,6 +13,25 @@ if [[ ! -f "$(pwd)/http.sh" ]]; then
exit 1
fi
echo "-= HTTP.sh =-"
for i in $(cat src/dependencies.required); do
which $i > /dev/null 2>&1
if [[ $? != 0 ]]; then
echo "ERROR: can't find $i"
error=true
fi
done
for i in $(cat src/dependencies.optional); do
which $i > /dev/null 2>&1
[[ $? != 0 ]] && echo "WARNING: can't find $i"
done
if [[ $error == true ]]; then
echo "Fix above dependencies, and we might just let you pass."
exit 0
fi
if [[ $1 == "init" ]]; then # will get replaced with proper parameter parsing in 1.0
mkdir -p "${cfg[namespace]}/${cfg[root]}" "${cfg[namespace]}/workers/example"
touch "${cfg[namespace]}/config.sh" "${cfg[namespace]}/workers/example/control"
......@@ -46,8 +66,6 @@ LauraIsCute
exit 0
fi
echo "HTTP.sh"
source src/worker.sh
if [[ -f "${cfg[namespace]}/config.sh" ]]; then
......@@ -55,16 +73,20 @@ if [[ -f "${cfg[namespace]}/config.sh" ]]; then
fi
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 &
# this is a workaround because ncat kept messing up large (<150KB) files over HTTP - but not over HTTPS!
socket=$(mktemp -u /tmp/XXXX.socket)
ncat -l -U "$socket" -c src/server.sh -k 2>> /dev/null &
socat TCP-LISTEN:${cfg[port]},fork,bind=${cfg[ip]} UNIX-CLIENT:$socket &
echo "[HTTP] listening on ${cfg[ip]}:${cfg[port]} through '$socket'"
#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 &
ncat -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 &
ncat -l ${cfg[ip]} ${cfg[ssl_port]} -c ./src/server.sh -k --ssl 2>> /dev/null &
fi
fi
......
bash
ncat
socat
grep
sed
mktemp
date
dd
file
......@@ -88,13 +88,12 @@ done
r[uri]=$(realpath "${cfg[namespace]}/${cfg[root]}$(echo ${r[url]} | sed -E 's/\?(.*)$//')")
[[ -d "${r[uri]}/" ]] && pwd="${r[uri]}" || pwd=$(dirname "${r[uri]}")
r[ip]="$NCAT_REMOTE_ADDR:$NCAT_REMOTE_PORT"
if [[ $NCAT_LOCAL_PORT == ${cfg[port]} ]]; then
if [[ $NCAT_LOCAL_PORT == '' ]]; then
r[proto]='http'
r[ip]="NCAT_IS_BORK"
else
r[proto]='https'
r[ip]="$NCAT_REMOTE_ADDR:$NCAT_REMOTE_PORT"
fi
echo "$(date) - IP: ${r[ip]}, PROTO: ${r[proto]}, URL: ${r[url]}, GET_data: ${get_data[@]}, POST_data: ${post_data[@]}, POST_multipart: ${post_multipart[@]}" >> "${cfg[namespace]}/${cfg[log]}"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment