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"
10 append UHTTPD_ARGS "-p $1"
13 append_listen_https() {
14 append UHTTPD_ARGS "-s $1"
24 config_get val "$cfg" "$var"
25 [ -n "$val" -o -n "$def" ] && append UHTTPD_ARGS "$opt ${val:-$def}"
32 local days bits country state location commonname
34 config_get days "$cfg" days
35 config_get bits "$cfg" bits
36 config_get country "$cfg" country
37 config_get state "$cfg" state
38 config_get location "$cfg" location
39 config_get commonname "$cfg" commonname
41 [ -x "$PX5G_BIN" ] && {
42 $PX5G_BIN selfsigned -der \
43 -days ${days:-730} -newkey rsa:${bits:-1024} -keyout "$UHTTPD_KEY" -out "$UHTTPD_CERT" \
44 -subj /C=${country:-DE}/ST=${state:-Saxony}/L=${location:-Leipzig}/CN=${commonname:-OpenWrt}
46 echo "WARNING: the specified certificate and key" \
47 "files do not exist and the px5g generator" \
48 "is not available, skipping SSL setup."
59 local realm="$(uci get system.@system[0].hostname 2>/dev/null)"
62 append_arg "$cfg" home "-h"
63 append_arg "$cfg" realm "-r" "${realm:-OpenWrt}"
64 append_arg "$cfg" config "-c"
65 append_arg "$cfg" cgi_prefix "-x"
66 append_arg "$cfg" lua_prefix "-l"
67 append_arg "$cfg" lua_handler "-L"
69 config_list_foreach "$cfg" listen_http \
72 config_get ssl "$cfg" listen_https
73 config_get UHTTPD_KEY "$cfg" key /etc/uhttpd.key
74 config_get UHTTPD_CERT "$cfg" cert /etc/uhttpd.crt
77 [ -f "$UHTTPD_CERT" -a -f "$UHTTPD_KEY" ] || {
78 config_foreach generate_keys cert
81 [ -f "$UHTTPD_CERT" -a -f "$UHTTPD_KEY" ] && {
82 append_arg "$cfg" cert "-C"
83 append_arg "$cfg" key "-K"
85 config_list_foreach "$cfg" listen_https \
90 start-stop-daemon -S -x $UHTTPD_BIN \
91 -p /var/run/uhttpd_${cfg}.pid \
92 -m -b -- -f $UHTTPD_ARGS
99 [ -f /var/run/uhttpd_${cfg}.pid ] && {
100 start-stop-daemon -K -q -n ${UHTTPD_BIN##*/} \
101 -p /var/run/uhttpd_${cfg}.pid -s TERM
103 rm -f /var/run/uhttpd_${cfg}.pid
109 config_foreach start_instance uhttpd
114 config_foreach stop_instance uhttpd