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 2>/dev/null)"
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"
62 config_get http "$cfg" listen_http
63 for listen in $http; do
64 append UHTTPD_ARGS "-p $listen"
67 config_get https "$cfg" listen_https
68 config_get UHTTPD_KEY "$cfg" key /etc/uhttpd.key
69 config_get UHTTPD_CERT "$cfg" cert /etc/uhttpd.crt
72 [ -f "$UHTTPD_CERT" -a -f "$UHTTPD_KEY" ] || {
73 config_foreach generate_keys cert
76 [ -f "$UHTTPD_CERT" -a -f "$UHTTPD_KEY" ] && {
77 append_arg "$cfg" cert "-C"
78 append_arg "$cfg" key "-K"
80 for listen in $https; do
81 append UHTTPD_ARGS "-s $listen"
86 start-stop-daemon -S -x $UHTTPD_BIN \
87 -p /var/run/uhttpd_${cfg}.pid \
88 -m -b -- -f $UHTTPD_ARGS
95 [ -f /var/run/uhttpd_${cfg}.pid ] && {
96 start-stop-daemon -K -q -n ${UHTTPD_BIN##*/} \
97 -p /var/run/uhttpd_${cfg}.pid -s TERM
99 rm -f /var/run/uhttpd_${cfg}.pid
105 config_foreach start_instance uhttpd
110 config_foreach stop_instance uhttpd