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