summaryrefslogtreecommitdiffstats
path: root/krfb/krfb_httpd/krfb_httpd
blob: ee30fd9e8a0225978349e7ed835443602ae74123 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#! /usr/bin/env bash

if [ "$1" = "--kinetd" ]; then
	# redirect stdin and stdout to the inetd socket.
	exec <&$2 >&$2
fi

read request url httptype || exit 0
url="${url/
/}"
httptype="${httptype/
/}"

if [ "x$httptype" != "x" ]; then
	line="x"
	while [ -n "$line" ]; do
		read line || exit 0
		line="${line/
/}"
	done
fi
# echo "url = $url, request = $request" >> /tmp/httpd.log
case "$url" in
/)
	# We need the size of the display for the current applet.
	size=`xdpyinfo -display :0| grep dimensions:|head -n 1|sed -e "s/.*dimensions: *//" -e "s/ pixels.*//"`
	width=`echo $size|sed -e "s/x.*//"`
	height=`echo $size|sed -e "s/.*x//"`
	# The VNC menubar is 20 pixels high ...
	height=$((height+20))

	port=`dcop kded kinetd port krfb`
	if [ "$port" == "-1" ]; then
		port=5900
	fi

	ctype="text/html"
	content="
<HTML><HEAD><TITLE>$LOGNAME's desktop</TITLE></HEAD>
<BODY>
<APPLET CODE=VncViewer.class ARCHIVE=VncViewer.jar WIDTH=$width HEIGHT=$height>
	<param name=PORT value=$port>
</APPLET>
</BODY></HTML>"
	;;
*.jar|*.class)
	# Use basename to make sure we have just a filename, not ../../...
	url="`basename "$url"`"
	ctype="application/octet-stream"
	cfile="/usr/share/vnc/classes/$url"
	content="FILE"
	;;
esac

if [ "x$httptype" != "x" ]; then
	echo "HTTP/1.0 200 OK"
	echo "Content-Type: $ctype"
	if [ "$content" == "FILE" ]; then
		clen=`wc -c "$cfile"`
	else
		clen=`echo "$content"|wc -c`
	fi
	echo "Content-Length: $clen"
	echo "Connection: close"
	echo
fi

if [ "$request" == "GET" ]; then
	if [ "$content" == "FILE" ]; then
		cat "$cfile"
	else
		echo "$content"
	fi
fi
exit 0