tazpanel view index.cgi @ rev 288

live: make live usb into tazpanle, new input and button style
author Christophe Lincoln <pankso@slitaz.org>
date Mon Apr 02 11:22:06 2012 +0200 (2012-04-02)
parents 4f657c82beae
children 72e9955ebdff
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 - BSD License
8 #
10 # Common functions from libtazpanel
11 . lib/libtazpanel
12 get_config
13 header
15 # Check whether a configuration file has been modified after installation
16 file_is_modified()
17 {
18 grep -l " $1$" $INSTALLED/*/md5sum | while read file; do
20 # Found, but can we do diff ?
21 [ "$(grep -h " $1$" $file)" != "$(md5sum $1)" ] || break
22 org=$(dirname $file)/volatile.cpio.gz
23 zcat $org 2>/dev/null | cpio -t 2>/dev/null | \
24 grep -q "^${1#/}$" || break
26 case "$2" in
27 diff)
28 tmp=/tmp/tazpanel$$
29 mkdir -p $tmp
30 ( cd $tmp ; zcat $org | cpio -id ${1#/} )
31 diff -u $tmp$1 $1 | sed "s|$tmp||"
32 rm -rf $tmp ;;
33 button)
34 cat <<EOT
35 <a class="button" href='$SCRIPT_NAME?file=$1&action=diff'>
36 <img src="$IMAGES/help.png" />`gettext "Differences"`</a>
37 EOT
38 esac
39 break
40 done
41 }
43 #
44 # Things to do before displaying the page
45 #
47 [ -n "$(GET panel_pass)" ] &&
48 sed -i s@/:root:.*@/:root:$(GET panel_pass)@ $HTTPD_CONF
50 #
51 # Commands
52 #
54 case " $(GET) " in
55 *\ file\ *)
56 #
57 # Handle files
58 #
59 file="$(GET file)"
60 case $file in
61 *.html)
62 cat $file && exit 0 ;;
63 *)
64 TITLE="- File"
65 xhtml_header
66 echo "<h2>$file</h2>" ;;
67 esac
68 if [ "$(GET action)" == "edit" ]; then
69 cat <<EOT
70 <form method="post" action="$SCRIPT_NAME?file=$file">
71 <img src="$IMAGES/edit.png" />
72 <input type="submit" value="`gettext "Save"`">
73 <a class="button" href='$SCRIPT_NAME?file=$file&action=diff'>
74 <img src="$IMAGES/help.png" />`gettext "Differences"`</a>
75 <textarea name="content" rows="30" style="width: 100%;">
76 $(cat $file)
77 </textarea>
78 </form>
79 EOT
80 #The space before textarea gets muddled when the form is submitted.
81 #It prevents anything else from getting messed up
82 elif [ "$(GET action)" == "diff" ]; then
83 echo '<pre id="diff">'
84 file_is_modified $file diff | syntax_highlighter diff
85 echo '</pre>'
86 else
87 [ -n "$(POST content)" ] &&
88 sed "s/`echo -en '\r'` /\n/g" > $file <<EOT
89 $(POST content)
90 EOT
91 cat <<EOT
92 <div id="actions">
93 <a class="button" href='$SCRIPT_NAME?file=$file&action=edit'>
94 <img src="$IMAGES/edit.png" />`gettext "Edit"`</a>
95 EOT
96 file_is_modified $file button
97 echo -e "</div>\n<pre>"
98 # Handle file type by extension as a Web Server does it.
99 case "$file" in
100 *.conf|*.lst)
101 syntax_highlighter conf ;;
102 *.sh|*.cgi)
103 syntax_highlighter sh ;;
104 *)
105 cat ;;
106 esac < $file
107 echo '</pre>'
108 fi ;;
109 *\ terminal\ *|*\ cmd\ *)
110 # Cmdline terminal.
111 commands='cat du help ls ping pwd who wget'
112 cmd=$(GET cmd)
113 TITLE="- $(gettext "Terminal")"
114 xhtml_header
115 cat << EOT
116 <form method="get" action="$SCRIPT_NAME">
117 <div class="box">
118 root@$(hostname):~# <input type="text" name="cmd" style="width: 80%;" />
119 </div>
120 </form>
121 EOT
122 echo '<pre id="terminal">'
123 # Allow only a few commands for the moment.
124 case "$cmd" in
125 usage|help)
126 gettext "Small terminal emulator, commands options are supported."
127 echo ""
128 gettext "Commands:"; echo " $commands" ;;
129 wget*)
130 dl=/var/cache/downloads
131 [ ! -d "$dl" ] && mkdir -p $dl
132 gettext "Downloading to:"; echo " $dl"
133 cd $dl && $cmd ;;
134 du*|ls*|ping*|pwd|who)
135 $cmd ;;
136 cat*)
137 # Cmd must be used with an arg.
138 arg=$(echo $cmd | awk '{print $2}')
139 [ "$arg" == "" ] && echo -n "$cmd " && \
140 gettext "needs an argument $arg" && exit 0
141 $cmd ;;
142 *)
143 [ "$cmd" == "" ] || \
144 gettext "Unknown command: $cmd"
145 gettext "Commands:"; echo " $commands" ;;
146 esac
147 echo '</pre>' ;;
148 *\ top\ *)
149 TITLE="- $(gettext "Process activity")"
150 xhtml_header
151 echo `gettext "Refresh: "` $(GET refresh)
152 echo '<br/>
153 <form method="get">
154 <input type="hidden" name="top"/>
155 <input type="submit" name="refresh" value="1s"/>
156 <input type="submit" name="refresh" value="5s"/>
157 <input type="submit" name="refresh" value="10s"/>
158 <input type="submit" value="none"/>
159 </form> '
160 [ -n $(GET refresh) ] &&
161 echo '<meta http-equiv="refresh" content="' $(GET refresh) '">' | sed "s/s //"
163 echo '<pre>'
164 top -n1 -b | sed \
165 -e s"#^[A-Z].*:\([^']\)#<span class='sh-comment'>\0</span>#"g \
166 -e s"#PID.*\([^']\)#<span class='top'>\0</span>#"g
167 echo '</pre>' ;;
168 *\ debug\ *)
169 TITLE="- Debug"
170 xhtml_header
171 echo '<h2>HTTP Environment</h2>'
172 echo '<pre>'
173 httpinfo
174 echo '</pre>' ;;
175 *\ report\ *)
176 TITLE="- $(gettext "System report")"
177 [ -d /var/cache/slitaz ] || mkdir -p /var/cache/slitaz
178 output=/var/cache/slitaz/sys-report.html
179 xhtml_header
180 echo "<h2>$(gettext "Reporting to:") $output</h2>"
181 echo '<pre>'
182 gettext "Creating report header... "
183 cat > $output << EOT
184 <!DOCTYPE html>
185 <html xmlns="http://www.w3.org/1999/xhtml">
186 <head>
187 <title>SliTaz system report</title>
188 <style type="text/css">
189 body { padding: 20px 60px; font-size: 13px; } h1, h2 { color: #444; }
190 pre { background: #f1f1f1; border: 1px solid #ddd;
191 padding: 10px; border-radius: 4px; }
192 span.diff-rm { color: red; }
193 span.diff-add { color: green; }
194 </style>
195 </head>
196 <body>
197 EOT
198 ok_status
199 gettext "Creating system summary... "
200 cat >> $output << EOT
201 <h1>SliTaz system report</h1>
202 Date: $(date)
203 <pre>
204 uptime : $(uptime)
205 cmdline : $(cat /proc/cmdline)
206 version : $(cat /etc/slitaz-release)
207 packages : $(ls /var/lib/tazpkg/installed | wc -l) installed
208 kernel : $(uname -r)
209 </pre>
210 EOT
211 ok_status
212 gettext "Getting hardware info... "
213 cat >> $output << EOT
214 <h2>free</h2>
215 <pre>
216 $(free)
217 </pre>
219 <h2>lspci -k</h2>
220 <pre>
221 $(lspci -k)
222 </pre>
224 <h2>lsusb</h2>
225 <pre>
226 $(lsusb)
227 </pre>
229 <h2>lsmod</h2>
230 <pre>
231 $(lsmod)
232 </pre>
234 EOT
235 ok_status
236 gettext "Getting networking info... "
237 cat >> $output << EOT
238 <h2>ifconfig -a</h2>
239 <pre>
240 $(ifconfig -a)
241 </pre>
242 <h2>route -n</h2>
243 <pre>
244 $(route -n)
245 </pre>
246 <h2>/etc/resolv.conf</h2>
247 <pre>
248 $(cat /etc/resolv.conf)
249 </pre>
250 EOT
251 ok_status
252 gettext "Getting filesystems info..."
253 cat >> $output << EOT
254 <h2>blkid</h2>
255 <pre>
256 $(blkid)
257 </pre>
258 <h2>fdisk -l</h2>
259 <pre>
260 $(fdisk -l)
261 </pre>
262 <h2>mount</h2>
263 <pre>
264 $(mount)
265 </pre>
266 <h2>df -h</h2>
267 <pre>
268 $(df -h)
269 </pre>
270 <h2>df -i</h2>
271 <pre>
272 $(df -i)
273 </pre>
274 EOT
275 ok_status
276 gettext "Getting boot logs... "
277 cat >> $output << EOT
278 <h2>$(gettext "Kernel messages")</h2>
279 <pre>
280 $(cat /var/log/dmesg.log)
281 </pre>
282 <h2>$(gettext "Boot scripts")</h2>
283 <pre>
284 $(cat /var/log/boot.log | filter_taztools_msgs)
285 </pre>
286 EOT
287 ok_status
288 gettext "Creating report footer... "
289 cat cat >> $output << EOT
290 </body>
291 </html>
292 EOT
293 ok_status
294 echo '</pre>'
295 echo "<p><a class='button' href='$SCRIPT_NAME?file=$output'>
296 $(gettext "View report")</a>"
297 gettext "This report can be attached with a bug report on: "
298 echo '<a href="http://bugs.slitaz.org/">bugs.slitaz.org</a></p>' ;;
299 *)
300 #
301 # Default xHTML content
302 #
303 xhtml_header
304 [ -n "$(GET gen_locale)" ] && new_locale=$(GET gen_locale)
305 [ -n "$(GET rdate)" ] && echo ""
306 cat << EOT
307 <div id="wrapper">
308 <h2>$(gettext "Host:") $(hostname)</h2>
309 <p>$(gettext "SliTaz administration and configuration Panel")<p>
310 </div>
311 <div id="actions">
312 <a class="button" href="$SCRIPT_NAME?terminal">
313 <img src="$IMAGES/terminal.png" />$(gettext "Terminal")</a>
314 <a class="button" href="$SCRIPT_NAME?top">
315 <img src="$IMAGES/monitor.png" />$(gettext "Process activity")</a>
316 <a class="button" href="$SCRIPT_NAME?report">
317 <img src="$IMAGES/text.png" />$(gettext "Create a report")</a>
318 </div>
320 <h3>$(gettext "Summary")</h3>
321 <div id="summary">
322 <pre>
323 $(gettext "Uptime :")$(uptime)
324 $(gettext "Memory in Mb :") $(free -m | grep Mem: | awk \
325 '{print "Total:", $2, "Used:", $3, "Free:", $4}')
326 $(gettext "Linux kernel :") $(uname -r)
327 </pre>
328 <!-- Close summary -->
329 </div>
331 <h4>$(gettext "Network status")</h4>
332 $(list_network_interfaces)
334 <h4>$(gettext "Filesystem usage statistics")</h4>
335 EOT
336 # Disk stats (management is done as hardware.cgi)
337 table_start
338 df_thead
339 df -h | grep ^/dev | while read fs size used av pct mp
340 do
341 cat << EOT
342 <tr>
343 <td><a href="hardware.cgi">
344 <img src="$IMAGES/harddisk.png" />${fs#/dev/}</a></td>
345 <td>$size</td>
346 <td>$av</td>
347 <td class="pct"><div class="pct"
348 style="width: $pct;">$used - $pct</div></td>
349 <td>$mp</td>
350 </tr>
351 EOT
352 done
353 table_end
354 cat << EOT
355 <h3>$(gettext "Panel Activity")</h3>
356 <pre id="panel-activity">
357 $(cat $LOG_FILE | tail -n 8 | sort -r | syntax_highlighter activity)
358 </pre>
360 EOT
361 ;;
362 esac
364 xhtml_footer
365 exit 0