tazpanel view index.cgi @ rev 267

temporary fix for editing files
author naitsirhc
date Fri Mar 09 00:40:28 2012 +0000 (2012-03-09)
parents 7e3623f26c5e
children 4f657c82beae
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 '<pre>'
152 top -n1 -b | sed \
153 -e s"#^[A-Z].*:\([^']\)#<span class='sh-comment'>\0</span>#"g \
154 -e s"#PID.*\([^']\)#<span class='top'>\0</span>#"g
155 echo '</pre>' ;;
156 *\ debug\ *)
157 TITLE="- Debug"
158 xhtml_header
159 echo '<h2>HTTP Environment</h2>'
160 echo '<pre>'
161 httpinfo
162 echo '</pre>' ;;
163 *\ report\ *)
164 TITLE="- $(gettext "System report")"
165 [ -d /var/cache/slitaz ] || mkdir -p /var/cache/slitaz
166 output=/var/cache/slitaz/sys-report.html
167 xhtml_header
168 echo "<h2>$(gettext "Reporting to:") $output</h2>"
169 echo '<pre>'
170 gettext "Creating report header... "
171 cat > $output << EOT
172 <!DOCTYPE html>
173 <html xmlns="http://www.w3.org/1999/xhtml">
174 <head>
175 <title>SliTaz system report</title>
176 <style type="text/css">
177 body { padding: 20px 60px; font-size: 13px; } h1, h2 { color: #444; }
178 pre { background: #f1f1f1; border: 1px solid #ddd;
179 padding: 10px; border-radius: 4px; }
180 span.diff-rm { color: red; }
181 span.diff-add { color: green; }
182 </style>
183 </head>
184 <body>
185 EOT
186 ok_status
187 gettext "Creating system summary... "
188 cat >> $output << EOT
189 <h1>SliTaz system report</h1>
190 Date: $(date)
191 <pre>
192 uptime : $(uptime)
193 cmdline : $(cat /proc/cmdline)
194 version : $(cat /etc/slitaz-release)
195 packages : $(ls /var/lib/tazpkg/installed | wc -l) installed
196 kernel : $(uname -r)
197 </pre>
198 EOT
199 ok_status
200 gettext "Getting hardware info... "
201 cat >> $output << EOT
202 <h2>free</h2>
203 <pre>
204 $(free)
205 </pre>
207 <h2>lspci -k</h2>
208 <pre>
209 $(lspci -k)
210 </pre>
212 <h2>lsusb</h2>
213 <pre>
214 $(lsusb)
215 </pre>
217 <h2>lsmod</h2>
218 <pre>
219 $(lsmod)
220 </pre>
222 EOT
223 ok_status
224 gettext "Getting networking info... "
225 cat >> $output << EOT
226 <h2>ifconfig -a</h2>
227 <pre>
228 $(ifconfig -a)
229 </pre>
230 <h2>route -n</h2>
231 <pre>
232 $(route -n)
233 </pre>
234 <h2>/etc/resolv.conf</h2>
235 <pre>
236 $(cat /etc/resolv.conf)
237 </pre>
238 EOT
239 ok_status
240 gettext "Getting filesystems info..."
241 cat >> $output << EOT
242 <h2>blkid</h2>
243 <pre>
244 $(blkid)
245 </pre>
246 <h2>fdisk -l</h2>
247 <pre>
248 $(fdisk -l)
249 </pre>
250 <h2>mount</h2>
251 <pre>
252 $(mount)
253 </pre>
254 <h2>df -h</h2>
255 <pre>
256 $(df -h)
257 </pre>
258 <h2>df -i</h2>
259 <pre>
260 $(df -i)
261 </pre>
262 EOT
263 ok_status
264 gettext "Getting boot logs... "
265 cat >> $output << EOT
266 <h2>$(gettext "Kernel messages")</h2>
267 <pre>
268 $(cat /var/log/dmesg.log)
269 </pre>
270 <h2>$(gettext "Boot scripts")</h2>
271 <pre>
272 $(cat /var/log/boot.log | filter_taztools_msgs)
273 </pre>
274 EOT
275 ok_status
276 gettext "Creating report footer... "
277 cat cat >> $output << EOT
278 </body>
279 </html>
280 EOT
281 ok_status
282 echo '</pre>'
283 echo "<p><a class='button' href='$SCRIPT_NAME?file=$output'>
284 $(gettext "View report")</a>"
285 gettext "This report can be attached with a bug report on: "
286 echo '<a href="http://bugs.slitaz.org/">bugs.slitaz.org</a></p>' ;;
287 *)
288 #
289 # Default xHTML content
290 #
291 xhtml_header
292 [ -n "$(GET gen_locale)" ] && new_locale=$(GET gen_locale)
293 [ -n "$(GET rdate)" ] && echo ""
294 cat << EOT
295 <div id="wrapper">
296 <h2>$(gettext "Host:") $(hostname)</h2>
297 <p>$(gettext "SliTaz administration and configuration Panel")<p>
298 </div>
299 <div id="actions">
300 <a class="button" href="$SCRIPT_NAME?terminal">
301 <img src="$IMAGES/terminal.png" />$(gettext "Terminal")</a>
302 <a class="button" href="$SCRIPT_NAME?top">
303 <img src="$IMAGES/monitor.png" />$(gettext "Process activity")</a>
304 <a class="button" href="$SCRIPT_NAME?report">
305 <img src="$IMAGES/text.png" />$(gettext "Create a report")</a>
306 </div>
308 <h3>$(gettext "Summary")</h3>
309 <div id="summary">
310 <pre>
311 $(gettext "Uptime :")$(uptime)
312 $(gettext "Memory in Mb :") $(free -m | grep Mem: | awk \
313 '{print "Total:", $2, "Used:", $3, "Free:", $4}')
314 $(gettext "Linux kernel :") $(uname -r)
315 </pre>
316 <!-- Close summary -->
317 </div>
319 <h4>$(gettext "Network status")</h4>
320 $(list_network_interfaces)
322 <h4>$(gettext "Filesystem usage statistics")</h4>
323 EOT
324 # Disk stats (management is done as hardware.cgi)
325 table_start
326 df_thead
327 df -h | grep ^/dev | while read fs size used av pct mp
328 do
329 cat << EOT
330 <tr>
331 <td><a href="hardware.cgi">
332 <img src="$IMAGES/harddisk.png" />${fs#/dev/}</a></td>
333 <td>$size</td>
334 <td>$av</td>
335 <td class="pct"><div class="pct"
336 style="width: $pct;">$used - $pct</div></td>
337 <td>$mp</td>
338 </tr>
339 EOT
340 done
341 table_end
342 cat << EOT
343 <h3>$(gettext "Panel Activity")</h3>
344 <pre id="panel-activity">
345 $(cat $LOG_FILE | tail -n 8 | sort -r | syntax_highlighter activity)
346 </pre>
348 EOT
349 ;;
350 esac
352 xhtml_footer
353 exit 0