tazpanel view index.cgi @ rev 32

add doc/ with index.cgi to generate translated help and doc + use absolute path in xHTML and config
author Christophe Lincoln <pankso@slitaz.org>
date Tue Apr 05 05:51:38 2011 +0200 (2011-04-05)
parents 253219c1f9fe
children fa59528e8bdf
line source
1 #!/bin/sh
2 #
3 # Main CGI interface for TazPanel. In on word: KISS. Use the main cas form
4 # command so we are faster and dont load unneeded function. If nececarry
5 # you can use the lib/ dir to handle external resources.
6 #
7 echo "Content-Type: text/html"
8 echo ""
10 # Common functions from libtazpanel
11 . lib/libtazpanel
12 get_config
14 # Include gettext helper script.
15 . /usr/bin/gettext.sh
17 # Export package name for gettext.
18 TEXTDOMAIN='tazpanel-cgi'
19 export TEXTDOMAIN
21 # Network interface status
22 interface_status() {
23 if ifconfig | grep -A 1 $i | grep -q inet; then
24 ip=`ifconfig | grep -A 1 $i | grep inet | \
25 awk '{ print $2 }' | cut -d ":" -f 2`
26 echo "<td>connected</td><td>$ip</td>"
27 else
28 echo "<td>----</td><td>----</td>"
29 fi
30 }
32 # Catch network interface (network is splited this function and above
33 # must go in lib/libtazpanel
34 list_network_interfaces() {
35 table_start
36 cat << EOT
37 <tr id="thead">
38 <td>`gettext "Interface"`</td>
39 <td>`gettext "Name"`</td>
40 <td>`gettext "Statut"`</td>
41 <td>`gettext "IP Address"`</td>
42 </tr>
43 EOT
44 for i in `ls /sys/class/net`
45 do
46 case $i in
47 eth*)
48 echo "<tr><td><img src='$IMAGES/ethernet.png' />$i</td>
49 <td>Ethernet</td> `interface_status`</tr>" ;;
50 wlan*|ath*|ra*)
51 echo "<tr><td><img src='$IMAGES/wireless.png' />$i</td>
52 <td>Wireless</td> `interface_status`</tr>" ;;
53 lo)
54 echo "<tr><td><img src='$IMAGES/loopback.png' />$i</td>
55 <td>Loopback</td> `interface_status`</tr>" ;;
56 *)
57 continue ;;
58 esac
59 done
60 table_end
61 }
63 #
64 # Commands
65 #
67 case "$QUERY_STRING" in
68 boot)
69 #
70 # Everything until user login
71 #
72 TITLE="- Boot"
73 xhtml_header
74 cat << EOT
75 <div id="wrapper">
76 <h2>`gettext "Boot &amp; startup"`</h2>
77 <p>
78 `gettext "Everything that appends before user login."`
79 </p>
80 </div>
82 <h3>`gettext "Kernel cmdline"`</h3>
83 <pre>
84 `cat /proc/cmdline`
85 </pre>
86 EOT
87 ;;
88 users|user=*)
89 #
90 # Manage system user accounts
91 #
92 TITLE="- Users"
93 xhtml_header
94 cmdline=`echo ${QUERY_STRING#user*=} | sed s'/&/ /g'`
95 # Parse cmdline
96 for opt in $cmdline
97 do
98 case $opt in
99 adduser=*)
100 user=${opt#adduser=}
101 cmd=adduser ;;
102 deluser=*)
103 user=${opt#deluser=}
104 deluser $user ;;
105 passwd=*)
106 pass=${opt#passwd=} ;;
107 esac
108 done
109 case "$cmd" in
110 adduser)
111 echo "$user"
112 echo $pass
113 adduser -D $user
114 echo "$pass" | chpasswd
115 for g in audio cdrom floppy video
116 do
117 addgroup $user $g
118 done ;;
119 *) continue ;;
120 esac
121 cat << EOT
122 <div id="wrapper">
123 <h2>`gettext "Manage users"`</h2>
124 <p>`gettext "Manage human users on your SliTaz system"`</p>
125 </div>
126 <form method="get" action="$SCRIPT_NAME">
127 EOT
128 table_start
129 cat << EOT
130 <tr id="thead">
131 <td>`gettext "Login"`</td>
132 <td>`gettext "User ID"`</td>
133 <td>`gettext "Name"`</td>
134 <td>`gettext "Home"`</td>
135 <td>`gettext "SHell"`</td>
136 </tr>
137 EOT
138 for i in `cat /etc/passwd | cut -d ":" -f 1`
139 do
140 if [ -d /home/$i ]; then
141 login=$i
142 uid=`cat /etc/passwd | grep $i | cut -d ":" -f 3`
143 gid=`cat /etc/passwd | grep $i | cut -d ":" -f 4`
144 name=`cat /etc/passwd | grep $i | cut -d ":" -f 5 | \
145 sed s/,,,//`
146 home=`cat /etc/passwd | grep $i | cut -d ":" -f 6`
147 shell=`cat /etc/passwd | grep $i | cut -d ":" -f 7`
148 echo '<tr>'
149 echo "<td><input type='hidden' name='user' />
150 <input type='checkbox' name='deluser' value='$login' />
151 <img src='$IMAGES/user.png' />$login</td>"
152 echo "<td>$uid:$gid</td>"
153 echo "<td>$name</td>"
154 echo "<td>$home</td>"
155 echo "<td>$shell</td>"
156 echo '</tr>'
157 fi
158 done
159 table_end
160 cat << EOT
161 <div>
162 <input type="submit" value="`gettext "Delete selected user"`" />
163 </div>
164 </form>
166 <h3>`gettext "Add a new user"`</h3>
167 <form method="get" action="$SCRIPT_NAME">
168 <input type="hidden" name="user" />
169 <p>`gettext "User login:"`</p>
170 <p><input type="text" name="adduser" size="30" /></p>
171 <p>`gettext "User password:"`</p>
172 <p><input type="password" name="passwd" size="30" /></p>
173 <input type="submit" value="`gettext "Create user"`" />
174 </form>
175 EOT
176 ;;
177 network)
178 #
179 # Network configuration
180 #
181 TITLE="- Network"
182 xhtml_header
183 cat << EOT
184 <div id="wrapper">
185 <h2>`gettext "Networking`</h2>
186 <p>`gettext "Manage network connection and services`</p>
187 </div>
189 `list_network_interfaces`
191 <h3>Output of: ifconfig -a</h3>
192 <pre>
193 `ifconfig -a`
194 </pre>
195 EOT
196 ;;
197 hardware)
198 #
199 # Hardware drivers, devices, filesystem, screen
200 #
201 TITLE="- Hardware"
202 xhtml_header
203 cat << EOT
204 <div id="wrapper">
205 <h2>`gettext "Drivers &amp; Devices"`</h2>
206 <p>`gettext "Manage your computer hardware`</p>
207 </div>
208 EOT
209 echo '<pre>'
210 fdisk -l | fgrep Disk
211 echo '</pre>'
212 echo '<pre>'
213 df -h | grep ^/dev
214 echo '</pre>'
215 echo '<pre>'
216 lspci
217 echo '</pre>'
218 ;;
219 *)
220 #
221 # Default xHTML content
222 #
223 xhtml_header
224 cat << EOT
225 <div id="wrapper">
226 <h2>`gettext "Host:"` `hostname`</h2>
227 <p>`gettext "SliTaz administration et configuration Panel"`<p>
228 </div>
230 <h3>`gettext "Summary"`</h3>
231 <div id="summary">
233 <p>
234 `gettext "Uptime:"` `uptime`
235 </p>
236 <p>
237 `gettext "Memory in Mb"`
238 `free -m | grep Mem: | awk \
239 '{print "| Total:", $2, "| Used:", $3, "| Free:", $4}'`
240 </p>
241 <p>
242 `gettext "Filesystem usage statistics:"`
243 </p>
244 <pre>
245 `df -h | grep ^/dev`
246 </pre>
248 `list_network_interfaces`
250 <!-- Close summary -->
251 </div>
252 EOT
253 ;;
254 esac
256 xhtml_footer
257 exit 0