1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2010 Jo-Philipp Wich
8 UHTTPD_BIN
="/usr/sbin/uhttpd"
9 PX5G_BIN
="/usr/sbin/px5g"
18 config_get val
"$cfg" "$var"
19 [ -n "$val" -o -n "$def" ] && procd_append_param
command "$opt" "${val:-$def}"
29 config_get_bool val
"$cfg" "$var" "$def"
30 [ "$val" = 1 ] && procd_append_param
command "$opt"
37 local days bits country state location commonname
39 config_get days
"$cfg" days
40 config_get bits
"$cfg" bits
41 config_get country
"$cfg" country
42 config_get state
"$cfg" state
43 config_get location
"$cfg" location
44 config_get commonname
"$cfg" commonname
46 [ -x "$PX5G_BIN" ] && {
47 $PX5G_BIN selfsigned
-der \
48 -days ${days:-730} -newkey rsa
:${bits:-1024} -keyout "$UHTTPD_KEY" -out "$UHTTPD_CERT" \
49 -subj /C
="${country:-DE}"/ST="${state:-Saxony}"/L="${location:-Leipzig}"/CN="${commonname:-OpenWrt}"
59 local realm
="$(uci_get system.@system[0].hostname)"
60 local listen http https interpreter indexes path handler
63 procd_set_param respawn
64 procd_set_param stderr
1
65 procd_set_param
command "$UHTTPD_BIN" -f
67 append_arg
"$cfg" home
"-h"
68 append_arg
"$cfg" realm
"-r" "${realm:-OpenWrt}"
69 append_arg
"$cfg" config
"-c"
70 append_arg
"$cfg" cgi_prefix
"-x"
71 [ -f /usr
/lib
/uhttpd_lua.so
] && {
72 config_get handler
"$cfg" lua_handler
73 [ -f "$handler" ] && append_arg
"$cfg" lua_prefix
"-l" && {
74 procd_append_param
command "-L" "$handler"
77 [ -f /usr
/lib
/uhttpd_ubus.so
] && {
78 append_arg
"$cfg" ubus_prefix
"-u"
79 append_arg
"$cfg" ubus_socket
"-U"
81 append_arg
"$cfg" script_timeout
"-t"
82 append_arg
"$cfg" network_timeout
"-T"
83 append_arg
"$cfg" http_keepalive
"-k"
84 append_arg
"$cfg" tcp_keepalive
"-A"
85 append_arg
"$cfg" error_page
"-E"
86 append_arg
"$cfg" max_requests
"-n" 3
87 append_arg
"$cfg" max_connections
"-N"
89 append_bool
"$cfg" no_ubusauth
"-a" 0
90 append_bool
"$cfg" no_symlinks
"-S" 0
91 append_bool
"$cfg" no_dirlists
"-D" 0
92 append_bool
"$cfg" rfc1918_filter
"-R" 0
94 config_get http
"$cfg" listen_http
95 for listen
in $http; do
96 procd_append_param
command -p "$listen"
99 config_get interpreter
"$cfg" interpreter
100 for path
in $interpreter; do
101 procd_append_param
command -i "$path"
104 config_get indexes
"$cfg" index_page
105 for path
in $indexes; do
106 procd_append_param
command -I "$path"
109 config_get https
"$cfg" listen_https
110 config_get UHTTPD_KEY
"$cfg" key
/etc
/uhttpd.key
111 config_get UHTTPD_CERT
"$cfg" cert
/etc
/uhttpd.crt
113 [ -f /lib
/libustream-ssl.so
] && [ -n "$https" ] && {
114 [ -f "$UHTTPD_CERT" -a -f "$UHTTPD_KEY" ] ||
{
115 config_foreach generate_keys cert
118 [ -f "$UHTTPD_CERT" -a -f "$UHTTPD_KEY" ] && {
119 append_arg
"$cfg" cert
"-C"
120 append_arg
"$cfg" key
"-K"
122 for listen
in $https; do
123 procd_append_param
command -s "$listen"
130 # Check if daemon is running, if not then
131 # re-execute in foreground to display error.
132 # sleep 1 && service_check $UHTTPD_BIN || \
133 # $UHTTPD_BIN -f $UHTTPD_ARGS
138 procd_add_reload_trigger
"uhttpd"
143 config_foreach start_instance uhttpd