tazpanel view lib/libtazpanel @ rev 45

Better loading integration and clean up code in pkgs.cgi
author Christophe Lincoln <pankso@slitaz.org>
date Fri Apr 08 03:26:38 2011 +0200 (2011-04-08)
parents 13b1019d68d8
children 56d55a9dcc9c
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 # Network interface status
24 interface_status() {
25 if ifconfig | grep -A 1 $i | grep -q inet; then
26 ip=`ifconfig | grep -A 1 $i | grep inet | \
27 awk '{ print $2 }' | cut -d ":" -f 2`
28 echo "<td>connected</td><td>$ip</td>"
29 else
30 echo "<td>----</td><td>----</td>"
31 fi
32 }
34 # Catch network interface (used in summary and network main page)
35 list_network_interfaces() {
36 table_start
37 cat << EOT
38 <tr id="thead">
39 <td>`gettext "Interface"`</td>
40 <td>`gettext "Name"`</td>
41 <td>`gettext "Status"`</td>
42 <td>`gettext "IP Address"`</td>
43 </tr>
44 EOT
45 for i in `ls /sys/class/net`
46 do
47 case $i in
48 eth*)
49 echo "<tr><td><a href='/network.cgi?eth'>
50 <img src='$IMAGES/ethernet.png' />$i</a></td>
51 <td>Ethernet</td> `interface_status`</tr>" ;;
52 wlan*|ath*|ra*)
53 echo "<tr><td><a href='/network.cgi?wifi'>
54 <img src='$IMAGES/wireless.png' />$i</a></td>
55 <td>Wireless</td> `interface_status`</tr>" ;;
56 lo)
57 echo "<tr><td><img src='$IMAGES/loopback.png' />$i</td>
58 <td>Loopback</td> `interface_status`</tr>" ;;
59 *)
60 continue ;;
61 esac
62 done
63 table_end
64 }
66 #
67 # xHTML 5 (header and footer skel are from the style)
68 #
70 loading_msg() {
71 cat << EOT
72 <script type="text/javascript">
73 document.write('<div id="loading"><img src="/styles/default/images/loader.gif" />$LOADING_MSG</div>');
74 </script>
75 EOT
76 }
78 xhtml_header() {
79 cat ${PANEL}$HEADER | sed s/'- %TITLE%'/"$TITLE"/
80 }
82 xhtml_footer() {
83 cat ${PANEL}$FOOTER
84 }
86 table_start() {
87 cat << EOT
88 <table>
89 <tbody>
90 EOT
91 }
93 table_end () {
94 cat << EOT
95 </tbody>
96 </table>
97 <a href="#header">`gettext "Go up"`</a>
98 EOT
100 }