tazpanel view lib/libtazpanel @ rev 67
remove debug_info and put code in header
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Tue Apr 12 02:47:00 2011 +0200 (2011-04-12) |
parents | 294029941298 |
children | 26811cbf12d8 |
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 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 # LOG activities
40 log() {
41 grep ^[a-zA-Z0-9] | sed s'/\.*\]//' >> $LOG_FILE
42 }
44 # Network interface status
45 interface_status() {
46 if ifconfig | grep -A 1 $i | grep -q inet; then
47 ip=`ifconfig | grep -A 1 $i | grep inet | \
48 awk '{ print $2 }' | cut -d ":" -f 2`
49 echo "<td>connected</td><td>$ip</td>"
50 else
51 echo "<td>----</td><td>----</td>"
52 fi
53 }
55 # Catch network interface (used in summary and network main page)
56 list_network_interfaces() {
57 table_start
58 cat << EOT
59 <tr id="thead">
60 <td>`gettext "Interface"`</td>
61 <td>`gettext "Name"`</td>
62 <td>`gettext "Status"`</td>
63 <td>`gettext "IP Address"`</td>
64 </tr>
65 EOT
66 for i in `ls /sys/class/net`
67 do
68 case $i in
69 eth*)
70 echo "<tr><td><a href='/network.cgi?eth'>
71 <img src='$IMAGES/ethernet.png' />$i</a></td>
72 <td>Ethernet</td> `interface_status`</tr>" ;;
73 wlan*|ath*|ra*)
74 echo "<tr><td><a href='/network.cgi?wifi'>
75 <img src='$IMAGES/wireless.png' />$i</a></td>
76 <td>Wireless</td> `interface_status`</tr>" ;;
77 lo)
78 echo "<tr><td><img src='$IMAGES/loopback.png' />$i</td>
79 <td>Loopback</td> `interface_status`</tr>" ;;
80 *)
81 continue ;;
82 esac
83 done
84 table_end
85 }
87 #
88 # xHTML 5 (header and footer skel are from the style)
89 #
91 loading_msg() {
92 cat << EOT
93 <script type="text/javascript">
94 document.write('<div id="loading"><img src="/styles/default/images/loader.gif" />$LOADING_MSG</div>');
95 </script>
96 EOT
97 }
99 xhtml_header() {
100 cat ${PANEL}$HEADER | sed s/'- %TITLE%'/"$TITLE"/
101 if [ $DEBUG == "1" ]; then
102 echo "<div class='debug'>$REQUEST_METHOD ${QUERY_STRING}</div>"
103 fi
104 }
106 xhtml_footer() {
107 cat ${PANEL}$FOOTER
108 }
110 table_start() {
111 cat << EOT
112 <table>
113 <tbody>
114 EOT
115 }
117 table_end () {
118 cat << EOT
119 </tbody>
120 </table>
121 EOT
123 }