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}"
27 config_get_bool val
"$cfg" "$var" "$def"
28 [ "$val" = 1 ] && append UHTTPD_ARGS
"$opt"
35 local days bits country state location commonname
37 config_get days
"$cfg" days
38 config_get bits
"$cfg" bits
39 config_get country
"$cfg" country
40 config_get state
"$cfg" state
41 config_get location
"$cfg" location
42 config_get commonname
"$cfg" commonname
44 [ -x "$PX5G_BIN" ] && {
45 $PX5G_BIN selfsigned
-der \
46 -days ${days:-730} -newkey rsa
:${bits:-1024} -keyout "$UHTTPD_KEY" -out "$UHTTPD_CERT" \
47 -subj /C
=${country:-DE}/ST=${state:-Saxony}/L=${location:-Leipzig}/CN=${commonname:-OpenWrt}
58 local realm
="$(uci_get system.@system[0].hostname)"
59 local listen http https interpreter path
61 append_arg
"$cfg" home
"-h"
62 append_arg
"$cfg" realm
"-r" "${realm:-OpenWrt}"
63 append_arg
"$cfg" config
"-c"
64 append_arg
"$cfg" cgi_prefix
"-x"
65 append_arg
"$cfg" lua_prefix
"-l"
66 append_arg
"$cfg" lua_handler
"-L"
67 append_arg
"$cfg" script_timeout
"-t"
68 append_arg
"$cfg" network_timeout
"-T"
69 append_arg
"$cfg" tcp_keepalive
"-A"
70 append_arg
"$cfg" error_page
"-E"
71 append_arg
"$cfg" index_page
"-I"
73 append_bool
"$cfg" no_symlinks
"-S" 0
74 append_bool
"$cfg" no_dirlists
"-D" 0
75 append_bool
"$cfg" rfc1918_filter
"-R" 0
77 config_get http
"$cfg" listen_http
78 for listen
in $http; do
79 append UHTTPD_ARGS
"-p $listen"
82 config_get interpreter
"$cfg" interpreter
83 for path
in $interpreter; do
84 append UHTTPD_ARGS
"-i $path"
87 config_get https
"$cfg" listen_https
88 config_get UHTTPD_KEY
"$cfg" key
/etc
/uhttpd.key
89 config_get UHTTPD_CERT
"$cfg" cert
/etc
/uhttpd.crt
92 [ -f "$UHTTPD_CERT" -a -f "$UHTTPD_KEY" ] ||
{
93 config_foreach generate_keys cert
96 [ -f "$UHTTPD_CERT" -a -f "$UHTTPD_KEY" ] && {
97 append_arg
"$cfg" cert
"-C"
98 append_arg
"$cfg" key
"-K"
100 for listen
in $https; do
101 append UHTTPD_ARGS
"-s $listen"
106 start-stop-daemon
-S -x $UHTTPD_BIN \
107 -p /var
/run
/uhttpd_
${cfg}.pid \
108 -m -b -- -f $UHTTPD_ARGS
115 [ -f /var
/run
/uhttpd_
${cfg}.pid
] && {
116 start-stop-daemon
-K -q -n ${UHTTPD_BIN##*/} \
117 -p /var
/run
/uhttpd_
${cfg}.pid
-s TERM
119 rm -f /var
/run
/uhttpd_
${cfg}.pid
125 config_foreach start_instance uhttpd
130 config_foreach stop_instance uhttpd