tazpanel view index.cgi @ rev 31

index.cgi: Add support for network connection detection and listing + up po/*
author Christophe Lincoln <pankso@slitaz.org>
date Tue Apr 05 05:10:57 2011 +0200 (2011-04-05)
parents f82057fcce3f
children b4e001e85045
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>"
29 fi
30 }
32 # Catch network interface
33 list_network_interfaces() {
34 table_start
35 cat << EOT
36 <tr id="thead">
37 <td>`gettext "Interface"`</td>
38 <td>`gettext "Name"`</td>
39 <td>`gettext "Statut"`</td>
40 <td>`gettext "IP Address"`</td>
41 </tr>
42 EOT
43 for i in `ls /sys/class/net`
44 do
45 case $i in
46 eth*)
47 echo "<tr><td><img src='$IMAGES/ethernet.png' />$i</td>
48 <td>Ethernet</td> `interface_status`</tr>" ;;
49 wlan*|ath*|ra*)
50 echo "<tr><td><img src='$IMAGES/wireless.png' />$i</td>
51 <td>Wireless</td> `interface_status`</tr>" ;;
52 lo)
53 echo "<tr><td><img src='$IMAGES/loopback.png' />$i</td>
54 <td>Loopback</td> `interface_status`</tr>" ;;
55 *)
56 continue ;;
57 esac
58 done
59 table_end
60 }
62 #
63 # Commands
64 #
66 case "$QUERY_STRING" in
67 boot)
68 #
69 # Everything until user login
70 #
71 TITLE="- Boot"
72 xhtml_header
73 cat << EOT
74 <div id="wrapper">
75 <h2>`gettext "Boot &amp; startup"`</h2>
76 <p>
77 `gettext "Everything that appends before user login."`
78 </p>
79 </div>
81 <h3>`gettext "Kernel cmdline"`</h3>
82 <pre>
83 `cat /proc/cmdline`
84 </pre>
85 EOT
86 ;;
87 users|user=*)
88 #
89 # Manage system user accounts
90 #
91 TITLE="- Users"
92 xhtml_header
93 cmdline=`echo ${QUERY_STRING#user*=} | sed s'/&/ /g'`
94 # Parse cmdline
95 for opt in $cmdline
96 do
97 case $opt in
98 adduser=*)
99 user=${opt#adduser=}
100 cmd=adduser ;;
101 deluser=*)
102 user=${opt#deluser=}
103 deluser $user ;;
104 passwd=*)
105 pass=${opt#passwd=} ;;
106 esac
107 done
108 case "$cmd" in
109 adduser)
110 echo "$user"
111 echo $pass
112 adduser -D $user
113 echo "$pass" | chpasswd
114 for g in audio cdrom floppy video
115 do
116 addgroup $user $g
117 done ;;
118 *) continue ;;
119 esac
120 cat << EOT
121 <div id="wrapper">
122 <h2>`gettext "Manage users"`</h2>
123 <p>`gettext "Manage human users on your SliTaz system"`</p>
124 </div>
125 <form method="get" action="$SCRIPT_NAME">
126 EOT
127 table_start
128 cat << EOT
129 <tr id="thead">
130 <td>`gettext "Login"`</td>
131 <td>`gettext "User ID"`</td>
132 <td>`gettext "Name"`</td>
133 <td>`gettext "Home"`</td>
134 <td>`gettext "SHell"`</td>
135 </tr>
136 EOT
137 for i in `cat /etc/passwd | cut -d ":" -f 1`
138 do
139 if [ -d /home/$i ]; then
140 login=$i
141 uid=`cat /etc/passwd | grep $i | cut -d ":" -f 3`
142 gid=`cat /etc/passwd | grep $i | cut -d ":" -f 4`
143 name=`cat /etc/passwd | grep $i | cut -d ":" -f 5 | \
144 sed s/,,,//`
145 home=`cat /etc/passwd | grep $i | cut -d ":" -f 6`
146 shell=`cat /etc/passwd | grep $i | cut -d ":" -f 7`
147 echo '<tr>'
148 echo "<td><input type='hidden' name='user' />
149 <input type='checkbox' name='deluser' value='$login' />
150 <img src='$IMAGES/user.png' />$login</td>"
151 echo "<td>$uid:$gid</td>"
152 echo "<td>$name</td>"
153 echo "<td>$home</td>"
154 echo "<td>$shell</td>"
155 echo '</tr>'
156 fi
157 done
158 table_end
159 cat << EOT
160 <div>
161 <input type="submit" value="`gettext "Delete selected user"`" />
162 </div>
163 </form>
165 <h3>`gettext "Add a new user"`</h3>
166 <form method="get" action="$SCRIPT_NAME">
167 <input type="hidden" name="user" />
168 <p>`gettext "User login:"`</p>
169 <p><input type="text" name="adduser" size="30" /></p>
170 <p>`gettext "User password:"`</p>
171 <p><input type="password" name="passwd" size="30" /></p>
172 <input type="submit" value="`gettext "Create user"`" />
173 </form>
174 EOT
175 ;;
176 network)
177 #
178 # Network configuration
179 #
180 TITLE="- Network"
181 xhtml_header
182 cat << EOT
183 <div id="wrapper">
184 <h2>`gettext "Networking`</h2>
185 <p>`gettext "Manage network connection and services`</p>
186 </div>
188 `list_network_interfaces`
190 <h3>Output of: ifconfig -a</h3>
191 <pre>
192 `ifconfig -a`
193 </pre>
194 EOT
195 ;;
196 hardware)
197 #
198 # Hardware drivers, devices, filesystem, screen
199 #
200 TITLE="- Hardware"
201 xhtml_header
202 cat << EOT
203 <div id="wrapper">
204 <h2>`gettext "Drivers &amp; Devices"`</h2>
205 <p>`gettext "Manage your computer hardware`</p>
206 </div>
207 EOT
208 echo '<pre>'
209 fdisk -l | fgrep Disk
210 echo '</pre>'
211 echo '<pre>'
212 df -h | grep ^/dev
213 echo '</pre>'
214 echo '<pre>'
215 lspci
216 echo '</pre>'
217 ;;
218 *)
219 #
220 # Default xHTML content
221 #
222 xhtml_header
223 cat << EOT
224 <div id="wrapper">
225 <h2>`gettext "Host:"` `hostname`</h2>
226 <p>`gettext "SliTaz administration et configuration Panel"`<p>
227 </div>
229 <h3>`gettext "Summary"`</h3>
230 <div id="summary">
232 <p>
233 `gettext "Uptime:"` `uptime`
234 </p>
235 <p>
236 `gettext "Memory in Mb"`
237 `free -m | grep Mem: | awk \
238 '{print "| Total:", $2, "| Used:", $3, "| Free:", $4}'`
239 </p>
240 <p>
241 `gettext "Filesystem usage statistics:"`
242 </p>
243 <pre>
244 `df -h | grep ^/dev`
245 </pre>
247 `list_network_interfaces`
249 <!-- Close summary -->
250 </div>
251 EOT
252 ;;
253 esac
255 xhtml_footer
256 exit 0