tazpanel view index.cgi @ rev 76

Show Panel activity and log a few more things to test (we need date in log() and reverse output on main page)
author Christophe Lincoln <pankso@slitaz.org>
date Tue Apr 12 04:24:35 2011 +0200 (2011-04-12)
parents 1780ef64bcd5
children 25602bc63ca7
line source
1 #!/bin/sh
2 #
3 # Main CGI interface for TazPanel. In on word: KISS. Use the main css form
4 # command so we are faster and do not load unneeded functions. If necessary
5 # you can use the lib/ dir to handle external resources.
6 #
7 # Copyright (C) 2011 SliTaz GNU/Linux - GNU gpl v3
8 #
9 echo "Content-Type: text/html"
10 echo ""
12 # Common functions from libtazpanel
13 . lib/libtazpanel
14 get_config
15 query_string_parser
17 # Include gettext helper script.
18 . /usr/bin/gettext.sh
20 # Export package name for gettext.
21 TEXTDOMAIN='tazpanel'
22 export TEXTDOMAIN
24 #
25 # Things to do before displaying the page
26 #
28 case "$QUERY_STRING" in
29 panel-pass=*)
30 new=${QUERY_STRING#*=}
31 sed -i s@/:root:.*@/:root:$new@ $HTTPD_CONF ;;
32 *) continue ;;
33 esac
35 #
36 # Commands
37 #
39 case "$QUERY_STRING" in
40 file=*)
41 #
42 # Handle files (may have an edit function, we will see)
43 #
44 TITLE="- File"
45 xhtml_header
46 echo "<h2>$WANT</h2>"
47 echo '<pre>'
48 # Handle file type by extension as a Web Server does it.
49 case "$WANT" in
50 *.conf|*.lst)
51 cat $WANT | syntax_highlighter conf ;;
52 *.sh|*.cgi)
53 cat $WANT | syntax_highlighter sh ;;
54 *)
55 cat $WANT ;;
56 esac
57 echo '</pre>' ;;
58 debug*)
59 TITLE="- Debug"
60 xhtml_header
61 cat << EOT
62 <h2>QUERY_STRING</h2>
63 <pre>
64 QUERY_STRING="$QUERY_STRING"
66 Fuction: query_string_parser (<a href="?debug=test=var1=var2">test</a>)
68 CASE="$CASE"
69 WANT="$WANT"
70 VAR_1="$VAR_1"
71 VAR_2="$VAR_2"
72 </pre>
73 EOT
74 echo '<h2>HTTP Environment</h2>'
75 local var
76 local info
77 echo '<pre>'
78 for var in SERVER_SOFTWARE SERVER_NAME SERVER_PORT GATEWAY_INTERFACE \
79 AUTH_TYPE REMOTE_ADDR REMOTE_PORT HTTP_HOST HTTP_USER_AGENT \
80 HTTP_ACCEPT_LANGUAGE REQUEST_METHOD REQUEST_URI QUERY_STRING \
81 CONTENT_LENGTH CONTENT_TYPE SCRIPT_NAME SCRIPT_FILENAME PWD
82 do
83 eval info=\$$var
84 echo "$var=\"$info\""
85 done
86 echo '</pre>' ;;
87 *)
88 #
89 # Default xHTML content
90 #
91 xhtml_header
92 case "$QUERY_STRING" in
93 gen-locale=*)
94 new_locale=${QUERY_STRING#gen-locale=} ;;
95 rdate)
96 echo "" ;;
97 esac
98 cat << EOT
99 <div id="wrapper">
100 <h2>`gettext "Host:"` `hostname`</h2>
101 <p>`gettext "SliTaz administration and configuration Panel"`<p>
102 </div>
104 <h3>`gettext "Summary"`</h3>
105 <div id="summary">
106 <p>
107 `gettext "Uptime:"` `uptime`
108 </p>
109 <p>
110 `gettext "Memory in Mb"`
111 `free -m | grep Mem: | awk \
112 '{print "| Total:", $2, "| Used:", $3, "| Free:", $4}'`
113 </p>
114 <!-- Close summary -->
115 </div>
117 <h4>`gettext "Network status"`</h4>
118 `list_network_interfaces`
120 <h4>`gettext "Filesystem usage statistics"`</h4>
121 <pre>
122 `df -h | grep ^/dev`
123 </pre>
125 <h3>`gettext "Panel Activity"`</h3>
126 <pre>
127 $(cat $LOG_FILE | tail -n 6)
128 </pre>
130 <h3>`gettext "Panel settings"`</h3>
131 <form method="get" action="$SCRIPT_NAME">
132 <div>
133 `gettext "Panel password:"`
134 <input type="password" name="panel-pass"/>
135 <input type="submit" value="`gettext "Change"`" />
136 </div>
137 </form>
138 <p>
139 $(gettext "TazPanel provides a debuging mode and page:")
140 <a href='$SCRIPT_NAME?debug'>debug</a>
141 </p>
143 EOT
144 ;;
145 esac
147 xhtml_footer
148 exit 0