1
0
mirror of https://github.com/EliasKotlyar/Xiaomi-Dafang-Hacks.git synced 2025-09-03 13:12:44 +02:00

Add web server control script (#1714)

This commit is contained in:
timstanley1985
2021-03-21 19:06:38 +00:00
committed by GitHub
parent a163f4456d
commit 7aa86b916f
6 changed files with 56 additions and 17 deletions

View File

@@ -0,0 +1,2 @@
#!/bin/sh
/system/sdcard/controlscripts/lighttpd

View File

@@ -1,5 +1,5 @@
server.document-root = "/system/sdcard/www"
server.pid-file = "/run/lighttpd.pid"
server.port = 80
# uncomment to allow more exotic hostnames e.g. with underscores

View File

@@ -0,0 +1,51 @@
#!/bin/sh
PIDFILE="/run/lighttpd.pid"
## Create a certificate for the webserver
if [ ! -f /system/sdcard/config/lighttpd.pem ]; then
export OPENSSL_CONF=/system/sdcard/config/openssl.cnf
/system/sdcard/bin/openssl req -new -x509 -keyout /system/sdcard/config/lighttpd.pem -out /system/sdcard/config/lighttpd.pem -days 365 -nodes -subj "/C=DE/ST=Bavaria/L=Munich/O=.../OU=.../CN=.../emailAddress=..."
chmod 400 /system/sdcard/config/lighttpd.pem
echo "Created new certificate for webserver"
fi
status()
{
pid="$(cat "$PIDFILE" 2>/dev/null)"
if [ "$pid" ]; then
# Prints PID: $pid if exists and returns 0(no error) else returns 1(error condition)
kill -0 "$pid" >/dev/null && echo "PID: $pid" || return 1
fi
}
start()
{
if [ "$(status)" != "" ]; then
echo "A web server is already running, please stop it or reboot"
else
echo "Starting web server..."
if [ ! -f /system/sdcard/config/lighttpd.conf ]; then
cp /system/sdcard/config/lighttpd.conf.dist /system/sdcard/config/lighttpd.conf
fi
/system/sdcard/bin/lighttpd -f /system/sdcard/config/lighttpd.conf
fi
}
stop()
{
pid="$(cat "$PIDFILE" 2>/dev/null)"
if [ "$pid" ]; then
sleep 1
kill "$pid"
rm "$PIDFILE" 1> /dev/null 2>&1
fi
}
if [ $# -eq 0 ]; then
start
else
case $1 in start|stop|status)
$1
;;
esac
fi

View File

@@ -197,21 +197,6 @@ else
insmod /system/sdcard/driver/sensor_jxf23.ko data_interface=2 pwdn_gpio=-1 reset_gpio=18 sensor_gpio_func=0
fi
## Create a certificate for the webserver
if [ ! -f $CONFIGPATH/lighttpd.pem ]; then
export OPENSSL_CONF=$CONFIGPATH/openssl.cnf
/system/sdcard/bin/openssl req -new -x509 -keyout $CONFIGPATH/lighttpd.pem -out $CONFIGPATH/lighttpd.pem -days 365 -nodes -subj "/C=DE/ST=Bavaria/L=Munich/O=.../OU=.../CN=.../emailAddress=..."
chmod 400 $CONFIGPATH/lighttpd.pem
echo "Created new certificate for webserver" >> $LOGPATH
fi
## Start Webserver:
if [ ! -f $CONFIGPATH/lighttpd.conf ]; then
cp $CONFIGPATH/lighttpd.conf.dist $CONFIGPATH/lighttpd.conf
fi
lighttpd_status=$(/system/sdcard/bin/lighttpd -f /system/sdcard/config/lighttpd.conf)
echo "lighttpd: $lighttpd_status" >> $LOGPATH
## Copy autonight configuration:
if [ ! -f $CONFIGPATH/autonight.conf ]; then
cp $CONFIGPATH/autonight.conf.dist $CONFIGPATH/autonight.conf

View File

@@ -13,7 +13,7 @@ echo ""
if [ -n "$F_cmd" ]; then
case "$F_cmd" in
get_services)
services="auto-night-detection debug-on-osd ftp_server mdns-responder mqtt-control mqtt-status onvif-srvd recording rtsp sound-on-startup dropbear telegram-bot timelapse"
services="auto-night-detection debug-on-osd ftp_server mdns-responder mqtt-control mqtt-status onvif-srvd recording rtsp sound-on-startup dropbear telegram-bot timelapse lighttpd"
for service in $services ; do
echo "${service}#:#$(test -f /run/${service}.pid && echo 'started' || echo 'stopped')#:#$(test -f /system/sdcard/config/autostart/${service} && echo 'true' || echo 'false')#:#false"
done

View File

@@ -281,6 +281,7 @@ var serviceFriendlyNames = {
"sound-on-startup": "Play Startup Sound",
"telegram-bot": "Telegram Bot",
"timelapse": "Timelapse",
"lighttpd": "Web server",
};
//Function get config