tazpanel view lib/libtazpanel @ rev 71

lib/libtazpanel: this time fix query_string_parser to handle all case in TazPanel
author Christophe Lincoln <pankso@slitaz.org>
date Tue Apr 12 01:22:50 2011 +0200 (2011-04-12)
parents 1938c9c0603b
children 26455264ec32
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 var=${var#&}
32 case "$id" in
33 '1') CASE=${var% } ;;
34 '2') WANT=${var% } ;;
35 '3') VAR_1=${var% } ;;
36 '4') VAR_2=${var% } ;;
37 esac
38 done
39 #unset IFS
40 }
42 # LOG activities
43 log() {
44 grep ^[a-zA-Z0-9] | sed s'/\.*\]//' >> $LOG_FILE
45 }
47 # Network interface status
48 interface_status() {
49 if ifconfig | grep -A 1 $i | grep -q inet; then
50 ip=`ifconfig | grep -A 1 $i | grep inet | \
51 awk '{ print $2 }' | cut -d ":" -f 2`
52 echo "<td>connected</td><td>$ip</td>"
53 else
54 echo "<td>----</td><td>----</td>"
55 fi
56 }
58 # Catch network interface (used in summary and network main page)
59 list_network_interfaces() {
60 table_start
61 cat << EOT
62 <tr id="thead">
63 <td>`gettext "Interface"`</td>
64 <td>`gettext "Name"`</td>
65 <td>`gettext "Status"`</td>
66 <td>`gettext "IP Address"`</td>
67 </tr>
68 EOT
69 for i in `ls /sys/class/net`
70 do
71 case $i in
72 eth*)
73 echo "<tr><td><a href='/network.cgi?eth'>
74 <img src='$IMAGES/ethernet.png' />$i</a></td>
75 <td>Ethernet</td> `interface_status`</tr>" ;;
76 wlan*|ath*|ra*)
77 echo "<tr><td><a href='/network.cgi?wifi'>
78 <img src='$IMAGES/wireless.png' />$i</a></td>
79 <td>Wireless</td> `interface_status`</tr>" ;;
80 lo)
81 echo "<tr><td><img src='$IMAGES/loopback.png' />$i</td>
82 <td>Loopback</td> `interface_status`</tr>" ;;
83 *)
84 continue ;;
85 esac
86 done
87 table_end
88 }
90 #
91 # xHTML 5 (header and footer skel are from the style)
92 #
94 loading_msg() {
95 cat << EOT
96 <script type="text/javascript">
97 document.write('<div id="loading"><img src="/styles/default/images/loader.gif" />$LOADING_MSG</div>');
98 </script>
99 EOT
100 }
102 xhtml_header() {
103 cat ${PANEL}$HEADER | sed s/'- %TITLE%'/"$TITLE"/
104 if [ $DEBUG == "1" ]; then
105 cat << EOT
106 <pre class='debug'>
107 QUERY_STRING="$QUERY_STRING"
108 CASE="$CASE" WANT="$WANT"
109 </pre>
110 EOT
111 fi
112 }
114 xhtml_footer() {
115 cat ${PANEL}$FOOTER
116 }
118 table_start() {
119 cat << EOT
120 <table>
121 <tbody>
122 EOT
123 }
125 table_end () {
126 cat << EOT
127 </tbody>
128 </table>
129 EOT
131 }