mirror of
https://github.com/motioneye-project/motioneyeos.git
synced 2025-07-29 06:06:32 +00:00
dehydrated-dumb-httpd: use socat
This commit is contained in:
parent
10ce67c0ac
commit
b08f8cfcdb
@ -3,25 +3,24 @@
|
|||||||
CHALLENGE="$1"
|
CHALLENGE="$1"
|
||||||
PORT=80
|
PORT=80
|
||||||
LIFETIME=10
|
LIFETIME=10
|
||||||
|
TMP_RESPONSE="/tmp/dehydrated-response"
|
||||||
|
LOG="/var/log/dehydrated-dumb-httpd.log"
|
||||||
|
|
||||||
if [[ -z "${CHALLENGE}" ]]; then
|
if [[ -z "${CHALLENGE}" ]]; then
|
||||||
echo "Usage $0 <challenge>"
|
echo "Usage $0 <challenge>"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
function make_response() {
|
{
|
||||||
echo -en "HTTP/1.1 200 OK\r\n"
|
echo -en "HTTP/1.1 200 OK\r\n"
|
||||||
echo -en "Content-Length: ${#CHALLENGE}\r\n"
|
echo -en "Content-Length: ${#CHALLENGE}\r\n"
|
||||||
echo -en "Content-Type: text/plain\r\n"
|
echo -en "Content-Type: text/plain\r\n"
|
||||||
echo -en "Connection: close\r\n\r\n${CHALLENGE}"
|
echo -en "Connection: close\r\n\r\n${CHALLENGE}"
|
||||||
}
|
} > "${TMP_RESPONSE}"
|
||||||
|
|
||||||
start_time=$(date +%s)
|
echo "Dumb httpd started" > ${LOG}
|
||||||
echo "Dumb httpd started"
|
socat -d TCP4-LISTEN:80,reuseaddr,fork EXEC:"/bin/cat ${TMP_RESPONSE}" &>>${LOG} &
|
||||||
while true; do
|
pid=$!
|
||||||
make_response | nc -l -w "${LIFETIME}" -p ${PORT} >/dev/null
|
sleep ${LIFETIME}
|
||||||
if (( $(date +%s) - ${start_time} > ${LIFETIME} )); then
|
kill ${pid}
|
||||||
break
|
echo "Dumb httpd exit" >> ${LOG}
|
||||||
fi
|
|
||||||
done
|
|
||||||
echo "Dumb httpd exit"
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user