tazpanel view index.cgi @ rev 297

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