| [5876] | 1 | #!/bin/sh /etc/rc.common |
|---|
| 2 | # Copyright (C) 2010 Jo-Philipp Wich |
|---|
| 3 | |
|---|
| 4 | START=50 |
|---|
| 5 | UHTTPD_BIN="/usr/sbin/uhttpd" |
|---|
| 6 | UHTTPD_ARGS="" |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | append_listen_http() { |
|---|
| 10 | append UHTTPD_ARGS "-p $1" |
|---|
| 11 | } |
|---|
| 12 | |
|---|
| 13 | append_listen_https() { |
|---|
| 14 | append UHTTPD_ARGS "-s $1" |
|---|
| 15 | } |
|---|
| 16 | |
|---|
| 17 | append_arg() { |
|---|
| 18 | local cfg="$1" |
|---|
| 19 | local var="$2" |
|---|
| 20 | local opt="$3" |
|---|
| [5896] | 21 | local def="$4" |
|---|
| [5876] | 22 | local val |
|---|
| 23 | |
|---|
| 24 | config_get val "$cfg" "$var" |
|---|
| [5896] | 25 | [ -n "$val" -o -n "$def" ] && append UHTTPD_ARGS "$opt ${val:-$def}" |
|---|
| [5876] | 26 | } |
|---|
| 27 | |
|---|
| 28 | start_instance() |
|---|
| 29 | { |
|---|
| 30 | UHTTPD_ARGS="" |
|---|
| 31 | |
|---|
| 32 | local cfg="$1" |
|---|
| [5896] | 33 | local realm="$(uci get system.@system[0].hostname 2>/dev/null)" |
|---|
| [5876] | 34 | local ssl |
|---|
| 35 | |
|---|
| 36 | append_arg "$cfg" home "-h" |
|---|
| [5896] | 37 | append_arg "$cfg" realm "-r" "${realm:-OpenWrt}" |
|---|
| 38 | append_arg "$cfg" config "-c" |
|---|
| 39 | append_arg "$cfg" cgi_prefix "-x" |
|---|
| [5876] | 40 | append_arg "$cfg" lua_prefix "-l" |
|---|
| 41 | append_arg "$cfg" lua_handler "-L" |
|---|
| 42 | |
|---|
| 43 | config_list_foreach "$cfg" listen_http \ |
|---|
| 44 | append_listen_http |
|---|
| 45 | |
|---|
| 46 | config_get ssl "$cfg" listen_https |
|---|
| 47 | [ -n "$ssl" ] && { |
|---|
| 48 | append_arg "$cfg" cert "-C" |
|---|
| 49 | append_arg "$cfg" key "-K" |
|---|
| 50 | |
|---|
| 51 | config_list_foreach "$cfg" listen_https \ |
|---|
| 52 | append_listen_https |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | start-stop-daemon -S -x $UHTTPD_BIN \ |
|---|
| 56 | -p /var/run/uhttpd_${cfg}.pid \ |
|---|
| 57 | -m -b -- -f $UHTTPD_ARGS |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | stop_instance() |
|---|
| 61 | { |
|---|
| 62 | local cfg="$1" |
|---|
| 63 | |
|---|
| 64 | [ -f /var/run/uhttpd_${cfg}.pid ] && { |
|---|
| 65 | start-stop-daemon -K -q -n ${UHTTPD_BIN##*/} \ |
|---|
| 66 | -p /var/run/uhttpd_${cfg}.pid -s TERM |
|---|
| 67 | |
|---|
| 68 | rm -f /var/run/uhttpd_${cfg}.pid |
|---|
| 69 | } |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | start() { |
|---|
| 73 | config_load uhttpd |
|---|
| 74 | config_foreach start_instance uhttpd |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | stop() { |
|---|
| 78 | config_load uhttpd |
|---|
| 79 | config_foreach stop_instance uhttpd |
|---|
| 80 | } |
|---|