tazpanel view index.cgi @ rev 166

index.cgi: add status colors in report
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Apr 22 11:46:37 2011 +0200 (2011-04-22)
parents 3a6f2e0ddaea
children dbb91ac456b7
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 *\ top\ *)
106 TITLE="- $(gettext "Process activity")"
107 xhtml_header
108 echo '<pre>'
109 top -n1 -b | sed \
110 -e s"#^[A-Z].*:\([^']\)#<span class='sh-comment'>\0</span>#"g \
111 -e s"#PID.*\([^']\)#<span class='top'>\0</span>#"g
112 echo '</pre>' ;;
113 *\ debug\ *)
114 TITLE="- Debug"
115 xhtml_header
116 echo '<h2>HTTP Environment</h2>'
117 echo '<pre>'
118 httpinfo
119 echo '</pre>' ;;
120 *\ report\ *)
121 TITLE="- $(gettext "System report")"
122 [ -d /var/cache/slitaz ] || mkdir -p /var/cache/slitaz
123 output=/var/cache/slitaz/sys-report.html
124 xhtml_header
125 echo "<h2>$(gettext "Reporting to:") $output</h2>"
126 echo '<pre>'
127 gettext "Creating report header... "
128 cat > $output << EOT
129 <!DOCTYPE html>
130 <html xmlns="http://www.w3.org/1999/xhtml">
131 <head>
132 <title>SliTaz system report</title>
133 <style type="text/css">
134 body { padding: 20px 60px; font-size: 13px; } h1, h2 { color: #444; }
135 pre { background: #f1f1f1; border: 1px solid #ddd;
136 padding: 10px; border-radius: 4px; }
137 span.diff-rm { color: red; }
138 span.diff-add { color: green; }
139 </style>
140 </head>
141 <body>
142 EOT
143 ok_status
144 gettext "Creating system summary... "
145 cat >> $output << EOT
146 <h1>SliTaz system report</h1>
147 Date: $(date)
148 <pre>
149 uptime : $(uptime)
150 cmdline : $(cat /proc/cmdline)
151 version : $(cat /etc/slitaz-release)
152 packages : $(ls /var/lib/tazpkg/installed | wc -l) installed
153 kernel : $(uname -r)
154 </pre>
155 EOT
156 ok_status
157 gettext "Getting hardware info... "
158 cat >> $output << EOT
159 <h2>free</h2>
160 <pre>
161 $(free)
162 </pre>
164 <h2>lspci -k</h2>
165 <pre>
166 $(lspci -k)
167 </pre>
169 <h2>lsusb</h2>
170 <pre>
171 $(lsusb)
172 </pre>
174 <h2>lsmod</h2>
175 <pre>
176 $(lsmod)
177 </pre>
179 EOT
180 ok_status
181 gettext "Getting networking info... "
182 cat >> $output << EOT
183 <h2>ifconfig -a</h2>
184 <pre>
185 $(ifconfig -a)
186 </pre>
187 <h2>route -n</h2>
188 <pre>
189 $(route -n)
190 </pre>
191 <h2>/etc/resolv.conf</h2>
192 <pre>
193 $(cat /etc/resolv.conf)
194 </pre>
195 EOT
196 ok_status
197 gettext "Getting filesystems info..."
198 cat >> $output << EOT
199 <h2>blkid</h2>
200 <pre>
201 $(blkid)
202 </pre>
203 <h2>fdisk -l</h2>
204 <pre>
205 $(fdisk -l)
206 </pre>
207 <h2>mount</h2>
208 <pre>
209 $(mount)
210 </pre>
211 <h2>df -h</h2>
212 <pre>
213 $(df -h)
214 </pre>
215 <h2>df -i</h2>
216 <pre>
217 $(df -i)
218 </pre>
219 EOT
220 ok_status
221 gettext "Getting boot logs... "
222 cat >> $output << EOT
223 <h2>$(gettext "Kernel messages")</h2>
224 <pre>
225 $(cat /var/log/dmesg.log)
226 </pre>
227 <h2>$(gettext "Boot scripts")</h2>
228 <pre>
229 $(cat /var/log/boot.log | filter_taztools_msgs)
230 </pre>
231 EOT
232 ok_status
233 gettext "Creating report footer... "
234 cat cat >> $output << EOT
235 </body>
236 </html>
237 EOT
238 ok_status
239 echo '</pre>'
240 echo "<p><a class='button' href='$SCRIPT_NAME?file=$output'>
241 $(gettext "View report")</a>"
242 gettext "This report can be attached with a bug report on: "
243 echo '<a href="http://bugs.slitaz.org/">bugs.slitaz.org</a></p>' ;;
244 *)
245 #
246 # Default xHTML content
247 #
248 xhtml_header
249 [ -n "$(GET gen_locale)" ] && new_locale=$(GET gen_locale)
250 [ -n "$(GET rdate)" ] && echo ""
251 cat << EOT
252 <div id="wrapper">
253 <h2>$(gettext "Host:") $(hostname)</h2>
254 <p>$(gettext "SliTaz administration and configuration Panel")<p>
255 </div>
256 <div id="actions">
257 <a class="button" href="$SCRIPT_NAME?top">
258 <img src="$IMAGES/monitor.png" />$(gettext "Process activity")</a>
259 <a class="button" href="$SCRIPT_NAME?report">
260 <img src="$IMAGES/text.png" />$(gettext "Create a report")</a>
261 </div>
263 <h3>$(gettext "Summary")</h3>
264 <div id="summary">
265 <pre>
266 $(gettext "Uptime :")$(uptime)
267 $(gettext "Memory in Mb :") $(free -m | grep Mem: | awk \
268 '{print "Total:", $2, "Used:", $3, "Free:", $4}')
269 $(gettext "Linux kernel :") $(uname -r)
270 </pre>
271 <!-- Close summary -->
272 </div>
274 <h4>$(gettext "Network status")</h4>
275 $(list_network_interfaces)
277 <h4>$(gettext "Filesystem usage statistics")</h4>
278 EOT
279 # Disk stats (management is done as hardware.cgi)
280 table_start
281 df_thead
282 df -h | grep ^/dev | while read fs size used av pct mp
283 do
284 cat << EOT
285 <tr>
286 <td><a href="hardware.cgi">
287 <img src="$IMAGES/harddisk.png" />$fs</a></td>
288 <td>$size</td>
289 <td>$av</td>
290 <td class="pct"><div class="pct"
291 style="width: $pct;">$used - $pct</div></td>
292 <td>$mp</td>
293 </tr>
294 EOT
295 done
296 table_end
297 cat << EOT
298 <h3>$(gettext "Panel Activity")</h3>
299 <pre id="panel-activity">
300 $(cat $LOG_FILE | tail -n 8 | sort -r | syntax_highlighter activity)
301 </pre>
303 EOT
304 ;;
305 esac
307 xhtml_footer
308 exit 0