tazpanel view lib/libtazpanel @ rev 49

Update all page with latest functions such as debug, bunch of fixes and adding support for deamons
author Christophe Lincoln <pankso@slitaz.org>
date Sat Apr 09 00:22:23 2011 +0200 (2011-04-09)
parents 56d55a9dcc9c
children a7f0d1a1ed2e
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 # DEBUG mode
24 debug_info() {
25 if [ $DEBUG == "1" ]; then
26 echo "<div class='debug'>$REQUEST_METHOD ${QUERY_STRING}</div>"
27 fi
28 }
30 # Network interface status
31 interface_status() {
32 if ifconfig | grep -A 1 $i | grep -q inet; then
33 ip=`ifconfig | grep -A 1 $i | grep inet | \
34 awk '{ print $2 }' | cut -d ":" -f 2`
35 echo "<td>connected</td><td>$ip</td>"
36 else
37 echo "<td>----</td><td>----</td>"
38 fi
39 }
41 # Catch network interface (used in summary and network main page)
42 list_network_interfaces() {
43 table_start
44 cat << EOT
45 <tr id="thead">
46 <td>`gettext "Interface"`</td>
47 <td>`gettext "Name"`</td>
48 <td>`gettext "Status"`</td>
49 <td>`gettext "IP Address"`</td>
50 </tr>
51 EOT
52 for i in `ls /sys/class/net`
53 do
54 case $i in
55 eth*)
56 echo "<tr><td><a href='/network.cgi?eth'>
57 <img src='$IMAGES/ethernet.png' />$i</a></td>
58 <td>Ethernet</td> `interface_status`</tr>" ;;
59 wlan*|ath*|ra*)
60 echo "<tr><td><a href='/network.cgi?wifi'>
61 <img src='$IMAGES/wireless.png' />$i</a></td>
62 <td>Wireless</td> `interface_status`</tr>" ;;
63 lo)
64 echo "<tr><td><img src='$IMAGES/loopback.png' />$i</td>
65 <td>Loopback</td> `interface_status`</tr>" ;;
66 *)
67 continue ;;
68 esac
69 done
70 table_end
71 }
73 #
74 # xHTML 5 (header and footer skel are from the style)
75 #
77 loading_msg() {
78 cat << EOT
79 <script type="text/javascript">
80 document.write('<div id="loading"><img src="/styles/default/images/loader.gif" />$LOADING_MSG</div>');
81 </script>
82 EOT
83 }
85 xhtml_header() {
86 cat ${PANEL}$HEADER | sed s/'- %TITLE%'/"$TITLE"/
87 }
89 xhtml_footer() {
90 cat ${PANEL}$FOOTER
91 }
93 table_start() {
94 cat << EOT
95 <table>
96 <tbody>
97 EOT
98 }
100 table_end () {
101 cat << EOT
102 </tbody>
103 </table>
104 EOT
106 }