-
Notifications
You must be signed in to change notification settings - Fork 0
/
image_server-unmenu-package.conf
107 lines (106 loc) · 5.1 KB
/
image_server-unmenu-package.conf
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#UNMENU_RELEASE $Revision$ $Date$
PACKAGE_NAME unMENU Image Server
PACKAGE_DESCR This package installs a very simple and imited capability image web-server for users of unMENU.<br>
PACKAGE_DESCR This image server is used by the myMain plugin on unMENU. <br> It will be active on the port defined below. It uses the "inetd" program to manage connections.
PACKAGE_DESCR <br>It will log connections to the syslog, so expect lines similar to the example below. They are <b>not</b> an indication of a problem.<br>
PACKAGE_DESCR <b>Example syslog entry:</b><font color=gray><b>Dec 15 09:24:11 Tower bash[5228]: connect from 192.168.2.6 (192.168.2.6) (Routine)</b></font>
PACKAGE_URL none
PACKAGE_FILE image_server.sh
PACKAGE_INSTALLED /usr/local/sbin/image_server.sh
PACKAGE_DEPENDENCIES none
PACKAGE_VARIABLE Image Server Port||vPORT=8088||The image server will be active on this port. It must be a port currently unused by any other service on the unRAID server.
PACKAGE_INSTALLATION #Version: 1.0
PACKAGE_INSTALLATION cat >>/usr/local/sbin/image_server.sh << 'THE_END_OF_SCRIPT'
# For those trying to figure out what I've done here...
# the leading "M" in each of the following lines in the "here" document is needed to preserve indentation.
# They are removed by a "sed" command at the end of this script
PACKAGE_INSTALLATION M#!/bin/bash
PACKAGE_INSTALLATION M#Version: 1.0
PACKAGE_INSTALLATION M# a minimal image web-server highly reliant on inetd.
PACKAGE_INSTALLATION Mbase=/var
PACKAGE_INSTALLATION Mread request
PACKAGE_INSTALLATION M
PACKAGE_INSTALLATION Mwhile /bin/true; do
PACKAGE_INSTALLATION Mread header
PACKAGE_INSTALLATION M [ "$header" == $'\r' ] && break;
PACKAGE_INSTALLATION Mdone
PACKAGE_INSTALLATION M
PACKAGE_INSTALLATION Murl="${request#GET }"
PACKAGE_INSTALLATION Murl="${url% HTTP/*}"
PACKAGE_INSTALLATION M
PACKAGE_INSTALLATION Mcase "$url" in
PACKAGE_INSTALLATION M*../*)
PACKAGE_INSTALLATION M echo -e "HTTP/1.1 403 Forbidden\r"
PACKAGE_INSTALLATION M echo -e "Content-Type: text/html\r"
PACKAGE_INSTALLATION M echo -e "\r"
PACKAGE_INSTALLATION M echo -e "403 Permission Denied\r"
PACKAGE_INSTALLATION M echo -e "\r"
PACKAGE_INSTALLATION M exit
PACKAGE_INSTALLATION M ;;
PACKAGE_INSTALLATION M*.pdf)
PACKAGE_INSTALLATION M ctype="application/pdf"
PACKAGE_INSTALLATION M;;
PACKAGE_INSTALLATION M*.html|*.htm)
PACKAGE_INSTALLATION M ctype="text/html"
PACKAGE_INSTALLATION M;;
PACKAGE_INSTALLATION M*.txt)
PACKAGE_INSTALLATION M ctype="text/text"
PACKAGE_INSTALLATION M;;
PACKAGE_INSTALLATION M*.jpg)
PACKAGE_INSTALLATION M ctype="image/jpeg"
PACKAGE_INSTALLATION M;;
PACKAGE_INSTALLATION M*.png)
PACKAGE_INSTALLATION M ctype="image/png"
PACKAGE_INSTALLATION M;;
PACKAGE_INSTALLATION M*.gif)
PACKAGE_INSTALLATION M ctype="image/gif"
PACKAGE_INSTALLATION M;;
PACKAGE_INSTALLATION M*)
PACKAGE_INSTALLATION M echo -e "HTTP/1.1 403 Forbidden\r"
PACKAGE_INSTALLATION M echo -e "Content-Type: text/html\r"
PACKAGE_INSTALLATION M echo -e "\r"
PACKAGE_INSTALLATION M echo -e "403 Permission denied\r"
PACKAGE_INSTALLATION M echo -e "\r"
PACKAGE_INSTALLATION M exit
PACKAGE_INSTALLATION M;;
PACKAGE_INSTALLATION Mesac
PACKAGE_INSTALLATION M
PACKAGE_INSTALLATION Mfilename="$base$url"
PACKAGE_INSTALLATION Mif [ -f "$filename" ]; then
PACKAGE_INSTALLATION M echo -e "HTTP/1.1 200 OK\r"
PACKAGE_INSTALLATION M echo -e "Content-Type: $ctype\r"
PACKAGE_INSTALLATION M echo -e "\r"
PACKAGE_INSTALLATION M cat "$filename"
PACKAGE_INSTALLATION M echo -e "\r"
PACKAGE_INSTALLATION Melse
PACKAGE_INSTALLATION M echo -e "HTTP/1.1 404 Not Found\r"
PACKAGE_INSTALLATION M echo -e "Content-Type: text/html\r"
PACKAGE_INSTALLATION M echo -e "\r"
PACKAGE_INSTALLATION M echo -e "404 Not Found\r"
PACKAGE_INSTALLATION M echo -e "<br>$filename Not Found\r"
PACKAGE_INSTALLATION M echo -e "\r"
PACKAGE_INSTALLATION Mfi
PACKAGE_INSTALLATION THE_END_OF_SCRIPT
PACKAGE_INSTALLATION sed -i "s/^M//" /usr/local/sbin/image_server.sh
PACKAGE_INSTALLATION chmod 755 /usr/local/sbin/image_server.sh
PACKAGE_INSTALLATION #Add the unmenu service to /etc/services if it does not currently exist
PACKAGE_INSTALLATION grep "^unmenu" /etc/services >/dev/null 2>&1
PACKAGE_INSTALLATION if [ $? = 0 ]
PACKAGE_INSTALLATION then
PACKAGE_INSTALLATION grep -v "^unmenu" /etc/services >/tmp/services.tmp$$
PACKAGE_INSTALLATION cp /tmp/services.tmp$$ /etc/services
PACKAGE_INSTALLATION fi
PACKAGE_INSTALLATION echo -e "unmenu\t\t${vPORT-8088}/tcp" >>/etc/services
PACKAGE_INSTALLATION #Add the unmenu service to /etc/inetd.conf if it does not currently exist
PACKAGE_INSTALLATION grep "^unmenu" /etc/inetd.conf >/dev/null 2>&1
PACKAGE_INSTALLATION if [ $? = 0 ]
PACKAGE_INSTALLATION then
PACKAGE_INSTALLATION grep -v "^unmenu" /etc/inetd.conf >/tmp/inetd.conf.tmp$$
PACKAGE_INSTALLATION cp /tmp/inetd.conf.tmp$$ /etc/inetd.conf
PACKAGE_INSTALLATION fi
PACKAGE_INSTALLATION echo "unmenu stream tcp nowait nobody /usr/sbin/tcpd /bin/bash -c /usr/local/sbin/image_server.sh" >>/etc/inetd.conf
PACKAGE_INSTALLATION killall -HUP inetd
PACKAGE_VERSION_TEST grep "Version:" /usr/local/sbin/image_server.sh | awk '{print $2}'
PACKAGE_VERSION_STRING 1.0
PACKAGE_MEMORY_USAGE Small
PACKAGE_OS any