tazpanel view index.cgi @ rev 100

index.cgi: use $SCRIPT_NAME
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Apr 14 21:27:07 2011 +0200 (2011-04-14)
parents 3eb6d92c32f1
children b898c9887a62
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='$SCRIPT_NAME?file=$1&action=diff'>
43 <img src="$IMAGES/help.png" />`gettext "Differences"`</a>
44 EOT
45 esac
46 break
47 done
48 }
50 #
51 # Things to do before displaying the page
52 #
54 [ -n "$(GET panel_pass)" ] &&
55 sed -i s@/:root:.*@/:root:$(GET panel_pass)@ $HTTPD_CONF
57 #
58 # Commands
59 #
61 case " $(GET) " in
62 *\ file\ *)
63 #
64 # Handle files
65 #
66 TITLE="- File"
67 xhtml_header
68 file="$(GET file)"
69 echo "<h2>$file</h2>"
70 if [ "$(GET action)" == "edit" ]; then
71 cat <<EOT
72 <form method="post" action="$SCRIPT_NAME?file=$file">
73 <img src="$IMAGES/edit.png" />
74 <input type="submit" value="`gettext "Save"`">
75 <textarea name="content" rows="30" style="width: 100%;">
76 $(cat $file)
77 </textarea>
78 </form>
79 EOT
80 elif [ "$(GET action)" == "diff" ]; then
81 echo '<pre id="diff">'
82 file_is_modified $file diff | syntax_highlighter diff
83 echo '</pre>'
84 else
85 [ -n "$(POST content)" ] &&
86 sed "s/`echo -en '\r'` /\n/g" > $file <<EOT
87 $(POST content)
88 EOT
89 cat <<EOT
90 <div id="actions">
91 <a class="button" href='$SCRIPT_NAME?file=$file&action=edit'>
92 <img src="$IMAGES/edit.png" />`gettext "Edit"`</a>
93 EOT
94 file_is_modified $file button
95 echo -e "</div>\n<pre>"
96 # Handle file type by extension as a Web Server does it.
97 case "$file" in
98 *.conf|*.lst)
99 syntax_highlighter conf ;;
100 *.sh|*.cgi)
101 syntax_highlighter sh ;;
102 *)
103 cat ;;
104 esac < $file
105 echo '</pre>'
106 fi ;;
107 *\ debug\ *)
108 TITLE="- Debug"
109 xhtml_header
110 echo '<h2>HTTP Environment</h2>'
111 echo '<pre>'
112 httpinfo
113 echo '</pre>' ;;
114 *)
115 #
116 # Default xHTML content
117 #
118 xhtml_header
119 [ -n "$(GET gen_locale)" ] && new_locale=$(GET gen_locale)
120 [ -n "$(GET rdate)" ] && echo ""
121 cat << EOT
122 <div id="wrapper">
123 <h2>`gettext "Host:"` `hostname`</h2>
124 <p>`gettext "SliTaz administration and configuration Panel"`<p>
125 </div>
127 <h3>`gettext "Summary"`</h3>
128 <div id="summary">
129 <p>
130 `gettext "Uptime:"` `uptime`
131 </p>
132 <p>
133 `gettext "Memory in Mb"`
134 `free -m | grep Mem: | awk \
135 '{print "| Total:", $2, "| Used:", $3, "| Free:", $4}'`
136 </p>
137 <!-- Close summary -->
138 </div>
140 <h4>`gettext "Network status"`</h4>
141 `list_network_interfaces`
143 <h4>`gettext "Filesystem usage statistics"`</h4>
144 <pre>
145 `df -h | grep ^/dev`
146 </pre>
148 <h3>`gettext "Panel Activity"`</h3>
149 <pre>
150 $(cat $LOG_FILE | tail -n 6)
151 </pre>
153 <h3>`gettext "Panel settings"`</h3>
154 <form method="get" action="$SCRIPT_NAME">
155 <div>
156 `gettext "Panel password:"`
157 <input type="password" name="panel_pass"/>
158 <input type="submit" value="`gettext "Change"`" />
159 </div>
160 </form>
161 <p>
162 $(gettext "TazPanel provides a debuging mode and page:")
163 <a href='$SCRIPT_NAME?debug'>debug</a>
164 </p>
166 EOT
167 ;;
168 esac
170 xhtml_footer
171 exit 0