1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2010 Jo-Philipp Wich
9 UHTTPD_BIN
="/usr/sbin/uhttpd"
10 PX5G_BIN
="/usr/sbin/px5g"
19 config_get val
"$cfg" "$var"
20 [ -n "$val" -o -n "$def" ] && append UHTTPD_ARGS
"$opt ${val:-$def}"
30 config_get_bool val
"$cfg" "$var" "$def"
31 [ "$val" = 1 ] && append UHTTPD_ARGS
"$opt"
38 local days bits country state location commonname
40 config_get days
"$cfg" days
41 config_get bits
"$cfg" bits
42 config_get country
"$cfg" country
43 config_get state
"$cfg" state
44 config_get location
"$cfg" location
45 config_get commonname
"$cfg" commonname
47 [ -x "$PX5G_BIN" ] && {
48 $PX5G_BIN selfsigned
-der \
49 -days ${days:-730} -newkey rsa
:${bits:-1024} -keyout "$UHTTPD_KEY" -out "$UHTTPD_CERT" \
50 -subj /C
="${country:-DE}"/ST="${state:-Saxony}"/L="${location:-Leipzig}"/CN="${commonname:-OpenWrt}"
61 local realm
="$(uci_get system.@system[0].hostname)"
62 local listen http https interpreter path
64 append_arg
"$cfg" home
"-h"
65 append_arg
"$cfg" realm
"-r" "${realm:-OpenWrt}"
66 append_arg
"$cfg" config
"-c"
67 append_arg
"$cfg" cgi_prefix
"-x"
68 append_arg
"$cfg" lua_prefix
"-l"
69 append_arg
"$cfg" lua_handler
"-L"
70 append_arg
"$cfg" script_timeout
"-t"
71 append_arg
"$cfg" network_timeout
"-T"
72 append_arg
"$cfg" tcp_keepalive
"-A"
73 append_arg
"$cfg" error_page
"-E"
74 append_arg
"$cfg" index_page
"-I"
76 append_bool
"$cfg" no_symlinks
"-S" 0
77 append_bool
"$cfg" no_dirlists
"-D" 0
78 append_bool
"$cfg" rfc1918_filter
"-R" 0
80 config_get http
"$cfg" listen_http
81 for listen
in $http; do
82 append UHTTPD_ARGS
"-p $listen"
85 config_get interpreter
"$cfg" interpreter
86 for path
in $interpreter; do
87 append UHTTPD_ARGS
"-i $path"
90 config_get https
"$cfg" listen_https
91 config_get UHTTPD_KEY
"$cfg" key
/etc
/uhttpd.key
92 config_get UHTTPD_CERT
"$cfg" cert
/etc
/uhttpd.crt
95 [ -f "$UHTTPD_CERT" -a -f "$UHTTPD_KEY" ] ||
{
96 config_foreach generate_keys cert
99 [ -f "$UHTTPD_CERT" -a -f "$UHTTPD_KEY" ] && {
100 append_arg
"$cfg" cert
"-C"
101 append_arg
"$cfg" key
"-K"
103 for listen
in $https; do
104 append UHTTPD_ARGS
"-s $listen"
109 SERVICE_PID_FILE
=/var
/run
/uhttpd_
${cfg}.pid
110 service_start
$UHTTPD_BIN -f $UHTTPD_ARGS
117 SERVICE_PID_FILE
=/var
/run
/uhttpd_
${cfg}.pid
118 service_stop
$UHTTPD_BIN
123 config_foreach start_instance uhttpd
128 config_foreach stop_instance uhttpd