tazpanel annotate index.cgi @ rev 312

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