1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2010 Jo-Philipp Wich
5 UHTTPD_BIN
="/usr/sbin/uhttpd"
6 PX5G_BIN
="/usr/sbin/px5g"
16 config_get val
"$cfg" "$var"
17 [ -n "$val" -o -n "$def" ] && append UHTTPD_ARGS
"$opt ${val:-$def}"
24 local days bits country state location commonname
26 config_get days
"$cfg" days
27 config_get bits
"$cfg" bits
28 config_get country
"$cfg" country
29 config_get state
"$cfg" state
30 config_get location
"$cfg" location
31 config_get commonname
"$cfg" commonname
33 [ -x "$PX5G_BIN" ] && {
34 $PX5G_BIN selfsigned
-der \
35 -days ${days:-730} -newkey rsa
:${bits:-1024} -keyout "$UHTTPD_KEY" -out "$UHTTPD_CERT" \
36 -subj /C
=${country:-DE}/ST=${state:-Saxony}/L=${location:-Leipzig}/CN=${commonname:-OpenWrt}
38 echo "WARNING: the specified certificate and key" \
39 "files do not exist and the px5g generator" \
40 "is not available, skipping SSL setup."
51 local realm
="$(uci_get system.@system[0].hostname)"
52 local listen http https
54 append_arg
"$cfg" home
"-h"
55 append_arg
"$cfg" realm
"-r" "${realm:-OpenWrt}"
56 append_arg
"$cfg" config
"-c"
57 append_arg
"$cfg" cgi_prefix
"-x"
58 append_arg
"$cfg" lua_prefix
"-l"
59 append_arg
"$cfg" lua_handler
"-L"
60 append_arg
"$cfg" script_timeout
"-t"
61 append_arg
"$cfg" network_timeout
"-T"
63 config_get http
"$cfg" listen_http
64 for listen
in $http; do
65 append UHTTPD_ARGS
"-p $listen"
68 config_get https
"$cfg" listen_https
69 config_get UHTTPD_KEY
"$cfg" key
/etc
/uhttpd.key
70 config_get UHTTPD_CERT
"$cfg" cert
/etc
/uhttpd.crt
73 [ -f "$UHTTPD_CERT" -a -f "$UHTTPD_KEY" ] ||
{
74 config_foreach generate_keys cert
77 [ -f "$UHTTPD_CERT" -a -f "$UHTTPD_KEY" ] && {
78 append_arg
"$cfg" cert
"-C"
79 append_arg
"$cfg" key
"-K"
81 for listen
in $https; do
82 append UHTTPD_ARGS
"-s $listen"
87 start-stop-daemon
-S -x $UHTTPD_BIN \
88 -p /var
/run
/uhttpd_
${cfg}.pid \
89 -m -b -- -f $UHTTPD_ARGS
96 [ -f /var
/run
/uhttpd_
${cfg}.pid
] && {
97 start-stop-daemon
-K -q -n ${UHTTPD_BIN##*/} \
98 -p /var
/run
/uhttpd_
${cfg}.pid
-s TERM
100 rm -f /var
/run
/uhttpd_
${cfg}.pid
106 config_foreach start_instance uhttpd
111 config_foreach stop_instance uhttpd