tazpanel view index.cgi @ rev 211

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