tazpanel annotate index.cgi @ rev 311

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