tazpanel view index.cgi @ rev 92

pkgs.cgi: add block/unblock buttons
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Apr 14 17:48:18 2011 +0200 (2011-04-14)
parents b5df231d1010
children 4b09b20ce287
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 - GNU gpl v3
8 #
10 # Common functions from libtazpanel
11 . lib/libtazpanel
12 get_config
13 header
15 # Include gettext helper script.
16 . /usr/bin/gettext.sh
18 # Export package name for gettext.
19 TEXTDOMAIN='tazpanel'
20 export TEXTDOMAIN
22 # Check wether a configuration file has been modified after installation
23 file_is_modified()
24 {
25 grep -l " $1$" $INSTALLED/*/md5sum | while read file; do
27 # Found, but can we do diff ?
28 [ "$(grep -h " $1$" $file)" != "$(md5sum $1)" ] || break
29 org=$(dirname $file)/volatile.cpio.gz
30 zcat $org 2>/dev/null | cpio -t 2>/dev/null | \
31 grep -q "^${1#/}$" || break
33 case "$2" in
34 diff)
35 tmp=/tmp/tazpanel$$
36 mkdir -p $tmp
37 ( cd $tmp ; zcat $org | cpio -id ${1#/} )
38 diff -u $tmp$1 $1
39 rm -rf $tmp ;;
40 button)
41 cat <<EOT
42 <a class="button" href='/index.cgi?file=$1&action=diff'>
43 <img src="/styles/default/images/help.png" />`gettext "Differences"`</a>
44 EOT
45 esac
46 done
47 }
49 #
50 # Things to do before displaying the page
51 #
53 [ -n "$(GET panel_pass)" ] &&
54 sed -i s@/:root:.*@/:root:$(GET panel_pass)@ $HTTPD_CONF
56 #
57 # Commands
58 #
60 case " $(GET) " in
61 *\ file\ *)
62 #
63 # Handle files
64 #
65 TITLE="- File"
66 xhtml_header
67 file="$(GET file)"
68 echo "<h2>$file</h2>"
69 if [ "$(GET action)" == "edit" ]; then
70 cat <<EOT
71 <form method="post" action="/index.cgi?file=$file">
72 <img src="/styles/default/images/edit.png" />
73 <input type="submit" value="`gettext "Save"`">
74 <textarea name="content" rows="30" style="width: 100%;">
75 $(cat $file)
76 </textarea>
77 </form>
78 EOT
79 elif [ "$(GET action)" == "diff" ]; then
80 echo '<pre id="diff">'
81 file_is_modified $file diff | syntax_highlighter diff
82 echo '</pre>'
83 else
84 [ -n "$(POST content)" ] &&
85 sed "s/`echo -en '\r'` /\n/g" > $file <<EOT
86 $(POST content)
87 EOT
88 cat <<EOT
89 <div id="actions">
90 <a class="button" href='/index.cgi?file=$file&action=edit'>
91 <img src="/styles/default/images/edit.png" />`gettext "Edit"`</a>
92 EOT
93 file_is_modified $file button
94 echo -e "</div>\n<pre>"
95 # Handle file type by extension as a Web Server does it.
96 case "$file" in
97 *.conf|*.lst)
98 syntax_highlighter conf ;;
99 *.sh|*.cgi)
100 syntax_highlighter sh ;;
101 *)
102 cat ;;
103 esac < $file
104 echo '</pre>'
105 fi ;;
106 *\ debug\ *)
107 TITLE="- Debug"
108 xhtml_header
109 echo '<h2>HTTP Environment</h2>'
110 echo '<pre>'
111 httpinfo
112 echo '</pre>' ;;
113 *)
114 #
115 # Default xHTML content
116 #
117 xhtml_header
118 [ -n "$(GET gen_locale)" ] && new_locale=$(GET gen_locale)
119 [ -n "$(GET rdate)" ] && echo ""
120 cat << EOT
121 <div id="wrapper">
122 <h2>`gettext "Host:"` `hostname`</h2>
123 <p>`gettext "SliTaz administration and configuration Panel"`<p>
124 </div>
126 <h3>`gettext "Summary"`</h3>
127 <div id="summary">
128 <p>
129 `gettext "Uptime:"` `uptime`
130 </p>
131 <p>
132 `gettext "Memory in Mb"`
133 `free -m | grep Mem: | awk \
134 '{print "| Total:", $2, "| Used:", $3, "| Free:", $4}'`
135 </p>
136 <!-- Close summary -->
137 </div>
139 <h4>`gettext "Network status"`</h4>
140 `list_network_interfaces`
142 <h4>`gettext "Filesystem usage statistics"`</h4>
143 <pre>
144 `df -h | grep ^/dev`
145 </pre>
147 <h3>`gettext "Panel Activity"`</h3>
148 <pre>
149 $(cat $LOG_FILE | tail -n 6)
150 </pre>
152 <h3>`gettext "Panel settings"`</h3>
153 <form method="get" action="$SCRIPT_NAME">
154 <div>
155 `gettext "Panel password:"`
156 <input type="password" name="panel_pass"/>
157 <input type="submit" value="`gettext "Change"`" />
158 </div>
159 </form>
160 <p>
161 $(gettext "TazPanel provides a debuging mode and page:")
162 <a href='$SCRIPT_NAME?debug'>debug</a>
163 </p>
165 EOT
166 ;;
167 esac
169 xhtml_footer
170 exit 0