tazpanel view index.cgi @ rev 160

en:html: tiny edits
author Paul Issott <paul@slitaz.org>
date Wed Apr 20 20:17:46 2011 +0100 (2011-04-20)
parents 4911d9797833
children 6e757e629f77
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>
127 <div id="actions">
128 <a class="button" href="$SCRIPT_NAME?top">$(gettext "Process activity")</a>
129 </div>
131 <h3>$(gettext "Summary")</h3>
132 <div id="summary">
133 <p>
134 $(gettext "Uptime:") $(uptime)
135 </p>
136 <p>
137 $(gettext "Memory in Mb")
138 $(free -m | grep Mem: | awk \
139 '{print "| Total:", $2, "| Used:", $3, "| Free:", $4}')
140 </p>
141 <!-- Close summary -->
142 </div>
144 <h4>$(gettext "Network status")</h4>
145 $(list_network_interfaces)
147 <h4>$(gettext "Filesystem usage statistics")</h4>
148 EOT
149 # Disk stats (management is done as hardware.cgi)
150 table_start
151 df_thead
152 df -h | grep ^/dev | while read fs size used av pct mp
153 do
154 cat << EOT
155 <tr>
156 <td><a href="hardware.cgi">
157 <img src="$IMAGES/harddisk.png" />$fs</a></td>
158 <td>$size</td>
159 <td>$av</td>
160 <td class="pct"><div class="pct"
161 style="width: $pct;">$used - $pct</div></td>
162 <td>$mp</td>
163 </tr>
164 EOT
165 done
166 table_end
167 cat << EOT
168 <h3>$(gettext "Panel Activity")</h3>
169 <pre id="panel-activity">
170 $(cat $LOG_FILE | tail -n 8 | sort -r | syntax_highlighter activity)
171 </pre>
173 EOT
174 ;;
175 esac
177 xhtml_footer
178 exit 0