tazpanel view index.cgi @ rev 205

Tiny edits
author Paul Issott <paul@slitaz.org>
date Sun Aug 14 10:49:10 2011 +0100 (2011-08-14)
parents 4a4d48fb6190
children 57c5ebe79e05
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
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 <textarea name="content" rows="30" style="width: 100%;">
74 $(cat $file)
75 </textarea>
76 </form>
77 EOT
78 elif [ "$(GET action)" == "diff" ]; then
79 echo '<pre id="diff">'
80 file_is_modified $file diff | syntax_highlighter diff
81 echo '</pre>'
82 else
83 [ -n "$(POST content)" ] &&
84 sed "s/`echo -en '\r'` /\n/g" > $file <<EOT
85 $(POST content)
86 EOT
87 cat <<EOT
88 <div id="actions">
89 <a class="button" href='$SCRIPT_NAME?file=$file&action=edit'>
90 <img src="$IMAGES/edit.png" />`gettext "Edit"`</a>
91 EOT
92 file_is_modified $file button
93 echo -e "</div>\n<pre>"
94 # Handle file type by extension as a Web Server does it.
95 case "$file" in
96 *.conf|*.lst)
97 syntax_highlighter conf ;;
98 *.sh|*.cgi)
99 syntax_highlighter sh ;;
100 *)
101 cat ;;
102 esac < $file
103 echo '</pre>'
104 fi ;;
105 *\ terminal\ *|*\ cmd\ *)
106 # Cmdline terminal.
107 commands='cat du help ls ping pwd who wget'
108 cmd=$(GET cmd)
109 TITLE="- $(gettext "Terminal")"
110 xhtml_header
111 cat << EOT
112 <form method="get" action="$SCRIPT_NAME">
113 <div class="box">
114 root@$(hostname):~# <input type="text" name="cmd" style="width: 80%;" />
115 </div>
116 </form>
117 EOT
118 echo '<pre id="terminal">'
119 # Allow only a few commands for the moment.
120 case "$cmd" in
121 usage|help)
122 gettext "Small terminal emulator, commands options are supported."
123 echo ""
124 gettext "Commands:"; echo " $commands" ;;
125 wget*)
126 dl=/var/cache/downloads
127 [ ! -d "$dl" ] && mkdir -p $dl
128 gettext "Downloading to:"; echo " $dl"
129 cd $dl && $cmd ;;
130 du*|ls*|ping*|pwd|who)
131 $cmd ;;
132 cat*)
133 # Cmd must be used with an arg.
134 arg=$(echo $cmd | awk '{print $2}')
135 [ "$arg" == "" ] && echo -n "$cmd " && \
136 gettext "needs an argument $arg" && exit 0
137 $cmd ;;
138 *)
139 [ "$cmd" == "" ] || \
140 gettext "Unknown command: $cmd"
141 gettext "Commands:"; echo " $commands" ;;
142 esac
143 echo '</pre>' ;;
144 *\ top\ *)
145 TITLE="- $(gettext "Process activity")"
146 xhtml_header
147 echo '<pre>'
148 top -n1 -b | sed \
149 -e s"#^[A-Z].*:\([^']\)#<span class='sh-comment'>\0</span>#"g \
150 -e s"#PID.*\([^']\)#<span class='top'>\0</span>#"g
151 echo '</pre>' ;;
152 *\ debug\ *)
153 TITLE="- Debug"
154 xhtml_header
155 echo '<h2>HTTP Environment</h2>'
156 echo '<pre>'
157 httpinfo
158 echo '</pre>' ;;
159 *\ report\ *)
160 TITLE="- $(gettext "System report")"
161 [ -d /var/cache/slitaz ] || mkdir -p /var/cache/slitaz
162 output=/var/cache/slitaz/sys-report.html
163 xhtml_header
164 echo "<h2>$(gettext "Reporting to:") $output</h2>"
165 echo '<pre>'
166 gettext "Creating report header... "
167 cat > $output << EOT
168 <!DOCTYPE html>
169 <html xmlns="http://www.w3.org/1999/xhtml">
170 <head>
171 <title>SliTaz system report</title>
172 <style type="text/css">
173 body { padding: 20px 60px; font-size: 13px; } h1, h2 { color: #444; }
174 pre { background: #f1f1f1; border: 1px solid #ddd;
175 padding: 10px; border-radius: 4px; }
176 span.diff-rm { color: red; }
177 span.diff-add { color: green; }
178 </style>
179 </head>
180 <body>
181 EOT
182 ok_status
183 gettext "Creating system summary... "
184 cat >> $output << EOT
185 <h1>SliTaz system report</h1>
186 Date: $(date)
187 <pre>
188 uptime : $(uptime)
189 cmdline : $(cat /proc/cmdline)
190 version : $(cat /etc/slitaz-release)
191 packages : $(ls /var/lib/tazpkg/installed | wc -l) installed
192 kernel : $(uname -r)
193 </pre>
194 EOT
195 ok_status
196 gettext "Getting hardware info... "
197 cat >> $output << EOT
198 <h2>free</h2>
199 <pre>
200 $(free)
201 </pre>
203 <h2>lspci -k</h2>
204 <pre>
205 $(lspci -k)
206 </pre>
208 <h2>lsusb</h2>
209 <pre>
210 $(lsusb)
211 </pre>
213 <h2>lsmod</h2>
214 <pre>
215 $(lsmod)
216 </pre>
218 EOT
219 ok_status
220 gettext "Getting networking info... "
221 cat >> $output << EOT
222 <h2>ifconfig -a</h2>
223 <pre>
224 $(ifconfig -a)
225 </pre>
226 <h2>route -n</h2>
227 <pre>
228 $(route -n)
229 </pre>
230 <h2>/etc/resolv.conf</h2>
231 <pre>
232 $(cat /etc/resolv.conf)
233 </pre>
234 EOT
235 ok_status
236 gettext "Getting filesystems info..."
237 cat >> $output << EOT
238 <h2>blkid</h2>
239 <pre>
240 $(blkid)
241 </pre>
242 <h2>fdisk -l</h2>
243 <pre>
244 $(fdisk -l)
245 </pre>
246 <h2>mount</h2>
247 <pre>
248 $(mount)
249 </pre>
250 <h2>df -h</h2>
251 <pre>
252 $(df -h)
253 </pre>
254 <h2>df -i</h2>
255 <pre>
256 $(df -i)
257 </pre>
258 EOT
259 ok_status
260 gettext "Getting boot logs... "
261 cat >> $output << EOT
262 <h2>$(gettext "Kernel messages")</h2>
263 <pre>
264 $(cat /var/log/dmesg.log)
265 </pre>
266 <h2>$(gettext "Boot scripts")</h2>
267 <pre>
268 $(cat /var/log/boot.log | filter_taztools_msgs)
269 </pre>
270 EOT
271 ok_status
272 gettext "Creating report footer... "
273 cat cat >> $output << EOT
274 </body>
275 </html>
276 EOT
277 ok_status
278 echo '</pre>'
279 echo "<p><a class='button' href='$SCRIPT_NAME?file=$output'>
280 $(gettext "View report")</a>"
281 gettext "This report can be attached with a bug report on: "
282 echo '<a href="http://bugs.slitaz.org/">bugs.slitaz.org</a></p>' ;;
283 *)
284 #
285 # Default xHTML content
286 #
287 xhtml_header
288 [ -n "$(GET gen_locale)" ] && new_locale=$(GET gen_locale)
289 [ -n "$(GET rdate)" ] && echo ""
290 cat << EOT
291 <div id="wrapper">
292 <h2>$(gettext "Host:") $(hostname)</h2>
293 <p>$(gettext "SliTaz administration and configuration Panel")<p>
294 </div>
295 <div id="actions">
296 <a class="button" href="$SCRIPT_NAME?terminal">
297 <img src="$IMAGES/terminal.png" />$(gettext "Terminal")</a>
298 <a class="button" href="$SCRIPT_NAME?top">
299 <img src="$IMAGES/monitor.png" />$(gettext "Process activity")</a>
300 <a class="button" href="$SCRIPT_NAME?report">
301 <img src="$IMAGES/text.png" />$(gettext "Create a report")</a>
302 </div>
304 <h3>$(gettext "Summary")</h3>
305 <div id="summary">
306 <pre>
307 $(gettext "Uptime :")$(uptime)
308 $(gettext "Memory in Mb :") $(free -m | grep Mem: | awk \
309 '{print "Total:", $2, "Used:", $3, "Free:", $4}')
310 $(gettext "Linux kernel :") $(uname -r)
311 </pre>
312 <!-- Close summary -->
313 </div>
315 <h4>$(gettext "Network status")</h4>
316 $(list_network_interfaces)
318 <h4>$(gettext "Filesystem usage statistics")</h4>
319 EOT
320 # Disk stats (management is done as hardware.cgi)
321 table_start
322 df_thead
323 df -h | grep ^/dev | while read fs size used av pct mp
324 do
325 cat << EOT
326 <tr>
327 <td><a href="hardware.cgi">
328 <img src="$IMAGES/harddisk.png" />${fs#/dev/}</a></td>
329 <td>$size</td>
330 <td>$av</td>
331 <td class="pct"><div class="pct"
332 style="width: $pct;">$used - $pct</div></td>
333 <td>$mp</td>
334 </tr>
335 EOT
336 done
337 table_end
338 cat << EOT
339 <h3>$(gettext "Panel Activity")</h3>
340 <pre id="panel-activity">
341 $(cat $LOG_FILE | tail -n 8 | sort -r | syntax_highlighter activity)
342 </pre>
344 EOT
345 ;;
346 esac
348 xhtml_footer
349 exit 0