tazpanel annotate index.cgi @ rev 207

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