tazpanel view lib/libtazpanel @ rev 69
Fix query_string_parser used from a form (&)
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Tue Apr 12 02:55:40 2011 +0200 (2011-04-12) |
parents | 95dc2475f4ae |
children | 1938c9c0603b |
line source
1 #!/bin/sh
2 #
3 # Common functions for TazPanel CGI and cmdline interface
4 #
6 # Include gettext helper script.
7 . /usr/bin/gettext.sh
9 # Export package name for gettext.
10 TEXTDOMAIN='tazpanel'
11 export TEXTDOMAIN
13 # We need a config file first
14 get_config() {
15 CONFIG="/etc/slitaz/tazpanel.conf"
16 [ -f $CONFIG ] && . $CONFIG
17 [ -f tazpanel.conf ] && . tazpanel.conf
18 [ ! -f $PANEL/lib/libtazpanel ] && \
19 echo "No config file or libtazpanel found: $CONFIG" && \
20 exit 1
21 }
23 # TazPanel QUERY_STRING parser returns: CASE WANT VAR_1 VAR_4
24 # we use that to help get URL string variables and user names
25 query_string_parser() {
26 id=0
27 IFS="&"
28 for var in $(echo "$QUERY_STRING" | sed s'@=@ @'g)
29 do
30 id=$((id + 1))
31 case "$id" in
32 '1') CASE=${var% } ;;
33 '2') WANT=${var% } ;;
34 '3') VAR_1=${var% } ;;
35 '4') VAR_2=${var% } ;;
36 esac
37 done
38 unset IFS
39 }
41 # LOG activities
42 log() {
43 grep ^[a-zA-Z0-9] | sed s'/\.*\]//' >> $LOG_FILE
44 }
46 # Network interface status
47 interface_status() {
48 if ifconfig | grep -A 1 $i | grep -q inet; then
49 ip=`ifconfig | grep -A 1 $i | grep inet | \
50 awk '{ print $2 }' | cut -d ":" -f 2`
51 echo "<td>connected</td><td>$ip</td>"
52 else
53 echo "<td>----</td><td>----</td>"
54 fi
55 }
57 # Catch network interface (used in summary and network main page)
58 list_network_interfaces() {
59 table_start
60 cat << EOT
61 <tr id="thead">
62 <td>`gettext "Interface"`</td>
63 <td>`gettext "Name"`</td>
64 <td>`gettext "Status"`</td>
65 <td>`gettext "IP Address"`</td>
66 </tr>
67 EOT
68 for i in `ls /sys/class/net`
69 do
70 case $i in
71 eth*)
72 echo "<tr><td><a href='/network.cgi?eth'>
73 <img src='$IMAGES/ethernet.png' />$i</a></td>
74 <td>Ethernet</td> `interface_status`</tr>" ;;
75 wlan*|ath*|ra*)
76 echo "<tr><td><a href='/network.cgi?wifi'>
77 <img src='$IMAGES/wireless.png' />$i</a></td>
78 <td>Wireless</td> `interface_status`</tr>" ;;
79 lo)
80 echo "<tr><td><img src='$IMAGES/loopback.png' />$i</td>
81 <td>Loopback</td> `interface_status`</tr>" ;;
82 *)
83 continue ;;
84 esac
85 done
86 table_end
87 }
89 #
90 # xHTML 5 (header and footer skel are from the style)
91 #
93 loading_msg() {
94 cat << EOT
95 <script type="text/javascript">
96 document.write('<div id="loading"><img src="/styles/default/images/loader.gif" />$LOADING_MSG</div>');
97 </script>
98 EOT
99 }
101 xhtml_header() {
102 cat ${PANEL}$HEADER | sed s/'- %TITLE%'/"$TITLE"/
103 if [ $DEBUG == "1" ]; then
104 echo "<div class='debug'>$CASE $WANT $REQUEST_METHOD ${QUERY_STRING}</div>"
105 fi
106 }
108 xhtml_footer() {
109 cat ${PANEL}$FOOTER
110 }
112 table_start() {
113 cat << EOT
114 <table>
115 <tbody>
116 EOT
117 }
119 table_end () {
120 cat << EOT
121 </tbody>
122 </table>
123 EOT
125 }