166 lines
4.1 KiB
Bash
Executable File
166 lines
4.1 KiB
Bash
Executable File
#!/bin/sh
|
|
# /etc/bewan/lib/web_server_config
|
|
# library of thttpd used to manage it
|
|
# HTTP_ID must be set
|
|
|
|
local LIGHTY_CONF_DIR=/var/bewan/lighty
|
|
local LIGHTY_TPL=/etc/bewan/lighttpd/lighttpd.conf.tpl
|
|
local LIGHTY_SED=${LIGHTY_CONF_DIR}/lighttpd.sed.${HTTP_ID}
|
|
local LIGHTY_CONF=${LIGHTY_CONF_DIR}/lighttpd.conf_${HTTP_ID}
|
|
|
|
check_http() {
|
|
if [ ! -f /sbin/lighttpd ] || [ "$HTTP_ID" = '' ]; then
|
|
ARG=nothing
|
|
return
|
|
fi
|
|
local httpdev='HttpServer_'$HTTP_ID
|
|
local http_en; eval http_en=\${$httpdev'_Enable':-0}
|
|
|
|
local srv; eval srv=\${$httpdev'_Service':-}
|
|
local srv_en; eval srv_en=\${'Services_'$srv'_Enable':-0}
|
|
|
|
local enable="test x$http_en = x1 -a x$srv_en = x1"
|
|
local active="base_exist_daemon $daemon"
|
|
base_check_arg "$enable" "$active"
|
|
}
|
|
|
|
#stop()
|
|
stop_http() {
|
|
local pid="`cat /var/run/$daemon.pid 2>/dev/null`"
|
|
base_kill_daemon "$daemon" "$pid"
|
|
}
|
|
|
|
|
|
# start
|
|
start_http() {
|
|
local port rootdir server bind nice realm pidfile listen debug
|
|
local http='HttpServer_'$HTTP_ID
|
|
|
|
eval rootdir=\${$http'_RootDir'}
|
|
|
|
if [ "$rootdir" = '' ]; then
|
|
base_log "$INITD/http : RootDir is empty !"
|
|
return
|
|
fi
|
|
|
|
eval port=\${$http'_ListenPort'}
|
|
eval bind=\${$http'_BindLocal'}
|
|
eval realm=\${$http'_AuthRealm'}
|
|
eval debug=\${$http'_Debug'}
|
|
|
|
pidfile=/var/run/$daemon.pid
|
|
|
|
if [ "$bind" = 1 ]; then
|
|
listen="server.bind=\"127.0.0.1\""
|
|
else
|
|
listen="#server.bind=\"127.0.0.1\""
|
|
fi
|
|
if [ -f "$rootdir/.htpasswd" ] || [ -h "$rootdir/.htpasswd" ] || [ -e '/lib/libwebauth.so' ]; then
|
|
[ "$realm" = '' ] && realm=$Device_Hostname
|
|
fi
|
|
|
|
# check if log needs to go in syslog (default)
|
|
|
|
|
|
local req_hdr req_hdl rsp_hdr rsp_hdl accesslog uselog
|
|
case "$debug" in
|
|
"1")
|
|
req_hdr="disable"
|
|
req_hdl="disable"
|
|
rsp_hdr="disable"
|
|
rsp_hdl="disable"
|
|
accesslog="enable"
|
|
uselog="enable"
|
|
;;
|
|
"2")
|
|
req_hdr="enable"
|
|
req_hdl="disable"
|
|
rsp_hdr="enable"
|
|
rsp_hdl="disable"
|
|
accesslog="enable"
|
|
uselog="enable"
|
|
;;
|
|
"3")
|
|
req_hdr="enable"
|
|
req_hdl="enable"
|
|
rsp_hdr="enable"
|
|
rsp_hdl="enable"
|
|
accesslog="enable"
|
|
uselog="enable"
|
|
;;
|
|
*)
|
|
req_hdr="disable"
|
|
req_hdl="disable"
|
|
rsp_hdr="disable"
|
|
rsp_hdl="disable"
|
|
accesslog="disable"
|
|
uselog="enable"
|
|
;;
|
|
esac
|
|
|
|
build_conf_file
|
|
|
|
local cmd="/sbin/lighttpd -f ${LIGHTY_CONF} -m /lib -D"
|
|
base_add_daemon "$daemon" "$cmd"
|
|
}
|
|
|
|
build_conf_file(){
|
|
mkdir -p ${LIGHTY_CONF_DIR}
|
|
mkdir -p ${LIGHTY_CONF_DIR}/conf.d
|
|
|
|
rootdir_ex=$(echo $rootdir | sed -e 's/\//\\\//g')
|
|
pidfile_ex=$(echo $pidfile | sed -e 's/\//\\\//g')
|
|
cat > ${LIGHTY_SED} <<EOF
|
|
s/<port\/>/${port}/g
|
|
s/<pidfile\/>/${pidfile_ex}/g
|
|
s/<doc_root\/>/${rootdir_ex}/g
|
|
s/<realm\/>/${realm}/g
|
|
s/<serverbind\/>/$listen/g
|
|
s/<srv_idx\/>/$HTTP_ID/g
|
|
s/<req-hdl\/>/$req_hdl/g
|
|
s/<req-hdr\/>/$req_hdr/g
|
|
s/<rsp-hdl\/>/$rsp_hdl/g
|
|
s/<rsp-hdr\/>/$rsp_hdr/g
|
|
s/<uselog\/>/$uselog/g
|
|
s/<accesslog\/>/$accesslog/g
|
|
EOF
|
|
|
|
sed -f ${LIGHTY_SED} ${LIGHTY_TPL} > ${LIGHTY_CONF}
|
|
[ -f ${LIGHTY_SED} ] && rm -rf ${LIGHTY_SED}
|
|
# build aliases
|
|
find /etc/bewan/http.alias.d/ -name "*.alias" -exec \
|
|
sed 's/^\([^:]*\):\(.*\)$/alias.url+=("\/\1\" => server.document-root + "\/cgi-bin\/\2")/g' /etc/bewan/http.alias.d > ${LIGHTY_CONF_DIR}/conf.d/alias.conf {} \;
|
|
echo "include_shell \"find ${LIGHTY_CONF_DIR}/conf.d -name '*.conf' -exec cat {} \;\"" >> ${LIGHTY_CONF}
|
|
|
|
|
|
# Alacn, 2018-01-28
|
|
# require authentication for firmware upload
|
|
cat > ${LIGHTY_CONF_DIR}/conf.d/firmware.conf <<EOF
|
|
server.modules += ( "mod_auth" )
|
|
auth.backend = "plain"
|
|
auth.backend.plain.userfile = "/var/bewan/webuser.d/.iad_admin"
|
|
auth.require = (
|
|
"/firmware.cgi" => (
|
|
"method" => "digest",
|
|
"realm" => "Auth Required",
|
|
"require" => "valid-user"
|
|
),
|
|
"/cgi-bin/firmware.cgi" => (
|
|
"method" => "digest",
|
|
"realm" => "Auth Required",
|
|
"require" => "valid-user"
|
|
),
|
|
"/pt_BR/admin/firmware.htm" => (
|
|
"method" => "digest",
|
|
"realm" => "Auth Required",
|
|
"require" => "valid-user"
|
|
),
|
|
"/en_US/admin/firmware.htm" => (
|
|
"method" => "digest",
|
|
"realm" => "Auth Required",
|
|
"require" => "valid-user"
|
|
)
|
|
)
|
|
EOF
|
|
}
|