summaryrefslogtreecommitdiff
path: root/package/busybox/files/httpd
blob: f7e166d0ad06cbe31774ac82d4242e5457ca9cb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/sh /etc/rc.common
# Copyright (C) 2006 OpenWrt.org

START=50
HTTPD_BIN="/usr/sbin/httpd"

system_config() {
	local cfg="$1"

	config_get hostname "$cfg" hostname
}

httpd_config() {
	local cfg="$1"
	local c_file port realm home

	config_get c_file "$cfg" c_file
	[ -n "$c_file" -a -f "$c_file" ] && append args "-c \"$c_file\""
	config_get port "$cfg" port
	append args "-p ${port:-80}"
	config_get home "$cfg" home
	home="${home:-/www}"
	[ -d "$home" ] || return 1
	append args "-h \"$home\""
	config_get realm "$cfg" realm
	realm="${realm:-$hostname}"
	append args "-r \"$realm\""
	eval "$HTTPD_BIN $args"
}

start() {
	[ -x "$HTTPD_BIN" ] || return 1

	unset hostname
	config_load system
	config_foreach system_config system
	hostname="${hostname:-OpenWrt}"

	unset args
	config_load httpd
	[ "$?" != "0" ] && {
		uci_set_default httpd <<EOF
config 'httpd'
	option 'port' '80'
	option 'home' '/www'
EOF
		config_load httpd
	}
	config_foreach httpd_config httpd
}

stop() {
	killall httpd
}