tazpanel view index.cgi @ rev 121

settings.cgi: hide password (well... still in URL, should we use POST instead of GET ?)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Apr 15 12:38:49 2011 +0200 (2011-04-15)
parents dce3e66c3ba4
children 7855bd81abb7
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 wether 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 *\ debug\ *)
101 TITLE="- Debug"
102 xhtml_header
103 echo '<h2>HTTP Environment</h2>'
104 echo '<pre>'
105 httpinfo
106 echo '</pre>' ;;
107 *)
108 #
109 # Default xHTML content
110 #
111 xhtml_header
112 [ -n "$(GET gen_locale)" ] && new_locale=$(GET gen_locale)
113 [ -n "$(GET rdate)" ] && echo ""
114 cat << EOT
115 <div id="wrapper">
116 <h2>`gettext "Host:"` `hostname`</h2>
117 <p>`gettext "SliTaz administration and configuration Panel"`<p>
118 </div>
120 <h3>`gettext "Summary"`</h3>
121 <div id="summary">
122 <p>
123 `gettext "Uptime:"` `uptime`
124 </p>
125 <p>
126 `gettext "Memory in Mb"`
127 `free -m | grep Mem: | awk \
128 '{print "| Total:", $2, "| Used:", $3, "| Free:", $4}'`
129 </p>
130 <!-- Close summary -->
131 </div>
133 <h4>`gettext "Network status"`</h4>
134 `list_network_interfaces`
136 <h4>`gettext "Filesystem usage statistics"`</h4>
137 <pre>
138 `df -h | grep ^/dev`
139 </pre>
141 <h3>`gettext "Panel Activity"`</h3>
142 <pre id="panel-activity">
143 $(cat $LOG_FILE | tail -n 8 | sort -r | syntax_highlighter activity)
144 </pre>
146 EOT
147 ;;
148 esac
150 xhtml_footer
151 exit 0