Commit 03f39e3d authored by Dominika Liberda's avatar Dominika Liberda 💽

Added r[ip], r[proto] and IP logging

parent 09008f78
......@@ -21,3 +21,8 @@ cfg[title]='ddd defies development'
cfg[php_enabled]=true
cfg[python_enabled]=true
# 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'
......@@ -11,14 +11,14 @@ echo "HTTP.sh"
if [[ ${cfg[ssl]} == true ]]; then
echo "listening on port ${cfg[port]} (HTTP) and ${cfg[ssl_port]} (HTTPS)"
ncat -l -p ${cfg[port]} -c ./src/server.sh -k &
ncat -v -l -p ${cfg[port]} -c ./src/server.sh -k 2>> ${cfg[log_http]} &
if [[ ${cfg[ssl_key]} != '' && ${cfg[ssl_cert]} != '' ]]; then
ncat -l -p ${cfg[ssl_port]} -c ./src/server.sh -k --ssl --ssl-cert ${cfg[ssl_cert]} --ssl-key ${cfg[ssl_key]}
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 -l -p ${cfg[ssl_port]} -c ./src/server.sh -k --ssl
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 -l -p ${cfg[port]} -c ./src/server.sh -k
ncat -v -l -p ${cfg[port]} -c ./src/server.sh -k 2>> ${cfg[log_http]}
fi
......@@ -23,7 +23,6 @@ function register() {
# login(username, password)
function login() {
local username=$(echo -ne $(echo "$1" | sed -E 's/%/\\x/g'))
echo $1 $username > /dev/stderr
IFS=':'
local user=($(grep "$username:" secret/users.dat))
unset IFS
......@@ -42,7 +41,6 @@ function login() {
# login_simple(base64)
function login_simple() {
local data=$(echo $3 | base64 -d)
echo $3 > /dev/stderr
local password=$(echo $data | sed -E 's/^(.*)\://')
local login=$(echo $data | sed -E 's/\:(.*)$//')
......@@ -51,7 +49,6 @@ function login_simple() {
unset IFS
if [[ $(echo -n $password${user[2]} | sha256sum | cut -c 1-64 ) == ${user[1]} ]]; then
r[authorized]=true
echo "nay" > /dev/stderr
else
r[authorized]=false
fi
......
......@@ -15,7 +15,6 @@
function get_mime() {
local file=$@
local mime=$(file --mime-type -b $file)
echo $file $mime > /dev/stderr
if [[ $file == *".htm" || $file == *".html" ]]; then
content_type="text/html"
return 0
......
......@@ -86,12 +86,21 @@ done
r[uri]=$(realpath ${cfg[root]}$(echo ${r[url]} | sed -E 's/\?(.*)$//'))
[[ -d "${r[uri]}/" ]] && pwd="${r[uri]}" || pwd=$(dirname "${r[uri]}")
# shitty logging
echo "-------------" >> log
echo $(date) >> log
echo "URL: ${r[url]}, GET_data: ${get_data[@]}, POST_data: ${post_data[@]}, POST_multipart: ${post_multipart[@]}" >> log
echo ${r[uri]} > /dev/stderr
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[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
if [[ ${r[status]} != 101 ]]; then
if [[ -a ${r[uri]} && ! -r ${r[uri]} ]]; then
......@@ -113,7 +122,7 @@ if [[ ${r[status]} != 101 ]]; then
fi
if [[ ${cfg[auth_required]} == true && ${r[authorized]} != true ]]; then
echo "Auth failed." >> log
echo "Auth failed." >> ${cfg[log_misc]}
r[status]=401
fi
......
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