tazpanel view index.cgi @ rev 153

hardware.cgi and index.cgi better output of df and prepare for disk management
author Christophe Lincoln <pankso@slitaz.org>
date Mon Apr 18 04:48:51 2011 +0200 (2011-04-18)
parents 29a4a55db6e3
children 4911d9797833
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
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 TITLE="- File"
60 xhtml_header
61 file="$(GET file)"
62 echo "<h2>$file</h2>"
63 if [ "$(GET action)" == "edit" ]; then
64 cat <<EOT
65 <form method="post" action="$SCRIPT_NAME?file=$file">
66 <img src="$IMAGES/edit.png" />
67 <input type="submit" value="`gettext "Save"`">
68 <textarea name="content" rows="30" style="width: 100%;">
69 $(cat $file)
70 </textarea>
71 </form>
72 EOT
73 elif [ "$(GET action)" == "diff" ]; then
74 echo '<pre id="diff">'
75 file_is_modified $file diff | syntax_highlighter diff
76 echo '</pre>'
77 else
78 [ -n "$(POST content)" ] &&
79 sed "s/`echo -en '\r'` /\n/g" > $file <<EOT
80 $(POST content)
81 EOT
82 cat <<EOT
83 <div id="actions">
84 <a class="button" href='$SCRIPT_NAME?file=$file&action=edit'>
85 <img src="$IMAGES/edit.png" />`gettext "Edit"`</a>
86 EOT
87 file_is_modified $file button
88 echo -e "</div>\n<pre>"
89 # Handle file type by extension as a Web Server does it.
90 case "$file" in
91 *.conf|*.lst)
92 syntax_highlighter conf ;;
93 *.sh|*.cgi)
94 syntax_highlighter sh ;;
95 *)
96 cat ;;
97 esac < $file
98 echo '</pre>'
99 fi ;;
100 *\ top\ *)
101 TITLE="- $(gettext "Process activity")"
102 xhtml_header
103 echo '<pre>'
104 top -n1 -b | sed \
105 -e s"#^[A-Z].*:\([^']\)#<span class='sh-comment'>\0</span>#"g \
106 -e s"#PID.*\([^']\)#<span class='top'>\0</span>#"g
107 echo '</pre>' ;;
108 *\ debug\ *)
109 TITLE="- Debug"
110 xhtml_header
111 echo '<h2>HTTP Environment</h2>'
112 echo '<pre>'
113 httpinfo
114 echo '</pre>' ;;
115 *)
116 #
117 # Default xHTML content
118 #
119 xhtml_header
120 [ -n "$(GET gen_locale)" ] && new_locale=$(GET gen_locale)
121 [ -n "$(GET rdate)" ] && echo ""
122 cat << EOT
123 <div id="wrapper">
124 <h2>`gettext "Host:"` `hostname`</h2>
125 <p>`gettext "SliTaz administration and configuration Panel"`<p>
126 </div>
128 <h3>`gettext "Summary"`</h3>
129 <div id="summary">
130 <p>
131 `gettext "Uptime:"` `uptime`
132 <a class="button" href="$SCRIPT_NAME?top">
133 <img src="$IMAGES/recharge.png" />`gettext "Process activity"`</a>
134 </p>
135 <p>
136 `gettext "Memory in Mb"`
137 `free -m | grep Mem: | awk \
138 '{print "| Total:", $2, "| Used:", $3, "| Free:", $4}'`
139 </p>
140 <!-- Close summary -->
141 </div>
143 <h4>`gettext "Network status"`</h4>
144 `list_network_interfaces`
145 EOT
146 # Disk stats (management is done is hardwar.cgi)
147 table_start
148 df_thead
149 df -h | grep ^/dev | while read fs size used av pct mp
150 do
151 cat << EOT
152 <tr>
153 <td><a href="hardware.cgi">
154 <img src="$IMAGES/harddisk.png" />$fs</a></td>
155 <td>$size</td>
156 <td>$av</td>
157 <td class="pct"><div class="pct"
158 style="width: $pct;">$used - $pct</div></td>
159 <td>$mp</td>
160 </tr>
161 EOT
162 done
163 table_end
164 cat << EOT
165 <h3>$(gettext "Panel Activity")</h3>
166 <pre id="panel-activity">
167 $(cat $LOG_FILE | tail -n 8 | sort -r | syntax_highlighter activity)
168 </pre>
170 EOT
171 ;;
172 esac
174 xhtml_footer
175 exit 0