tazpanel view lib/libtazpanel @ rev 53

Add a debug page and a QUERY_STRING parser so we can use names CASE WANT VAR_1 VAR_2
author Christophe Lincoln <pankso@slitaz.org>
date Sun Apr 10 21:28:13 2011 +0200 (2011-04-10)
parents a7f0d1a1ed2e
children 294029941298
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 ruturns: CASE WANT VAR_1 VAR_4
24 # we use that to help getting URL string variable an use names
25 query_string_parser() {
26 id=0
27 for var in $(echo "$QUERY_STRING" | sed s'@=@ @'g)
28 do
29 id=$((id + 1))
30 case "$id" in
31 '1') CASE=${var% } ;;
32 '2') WANT=${var% } ;;
33 '3') VAR_1=${var% } ;;
34 '4') VAR_2=${var% } ;;
35 esac
36 done
37 }
39 # DEBUG mode
40 debug_info() {
41 if [ $DEBUG == "1" ]; then
42 echo "<div class='debug'>$REQUEST_METHOD ${QUERY_STRING}</div>"
43 fi
44 }
46 # LOG activities
47 log() {
48 grep ^[a-zA-Z0-9] | sed s'/\.*\]//' >> $LOG_FILE
49 }
51 # Network interface status
52 interface_status() {
53 if ifconfig | grep -A 1 $i | grep -q inet; then
54 ip=`ifconfig | grep -A 1 $i | grep inet | \
55 awk '{ print $2 }' | cut -d ":" -f 2`
56 echo "<td>connected</td><td>$ip</td>"
57 else
58 echo "<td>----</td><td>----</td>"
59 fi
60 }
62 # Catch network interface (used in summary and network main page)
63 list_network_interfaces() {
64 table_start
65 cat << EOT
66 <tr id="thead">
67 <td>`gettext "Interface"`</td>
68 <td>`gettext "Name"`</td>
69 <td>`gettext "Status"`</td>
70 <td>`gettext "IP Address"`</td>
71 </tr>
72 EOT
73 for i in `ls /sys/class/net`
74 do
75 case $i in
76 eth*)
77 echo "<tr><td><a href='/network.cgi?eth'>
78 <img src='$IMAGES/ethernet.png' />$i</a></td>
79 <td>Ethernet</td> `interface_status`</tr>" ;;
80 wlan*|ath*|ra*)
81 echo "<tr><td><a href='/network.cgi?wifi'>
82 <img src='$IMAGES/wireless.png' />$i</a></td>
83 <td>Wireless</td> `interface_status`</tr>" ;;
84 lo)
85 echo "<tr><td><img src='$IMAGES/loopback.png' />$i</td>
86 <td>Loopback</td> `interface_status`</tr>" ;;
87 *)
88 continue ;;
89 esac
90 done
91 table_end
92 }
94 #
95 # xHTML 5 (header and footer skel are from the style)
96 #
98 loading_msg() {
99 cat << EOT
100 <script type="text/javascript">
101 document.write('<div id="loading"><img src="/styles/default/images/loader.gif" />$LOADING_MSG</div>');
102 </script>
103 EOT
104 }
106 xhtml_header() {
107 cat ${PANEL}$HEADER | sed s/'- %TITLE%'/"$TITLE"/
108 }
110 xhtml_footer() {
111 cat ${PANEL}$FOOTER
112 }
114 table_start() {
115 cat << EOT
116 <table>
117 <tbody>
118 EOT
119 }
121 table_end () {
122 cat << EOT
123 </tbody>
124 </table>
125 EOT
127 }