tazpanel view lib/libtazpanel @ rev 51

Implement daemons management
author Christophe Lincoln <pankso@slitaz.org>
date Sat Apr 09 05:45:44 2011 +0200 (2011-04-09)
parents cf15cb2ff715
children cb8779b378d4
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 # LOG activities
31 log() {
32 grep ^[a-zA-Z0-9] | sed s'/\.*\]//' >> $LOG_FILE
33 }
35 # Network interface status
36 interface_status() {
37 if ifconfig | grep -A 1 $i | grep -q inet; then
38 ip=`ifconfig | grep -A 1 $i | grep inet | \
39 awk '{ print $2 }' | cut -d ":" -f 2`
40 echo "<td>connected</td><td>$ip</td>"
41 else
42 echo "<td>----</td><td>----</td>"
43 fi
44 }
46 # Catch network interface (used in summary and network main page)
47 list_network_interfaces() {
48 table_start
49 cat << EOT
50 <tr id="thead">
51 <td>`gettext "Interface"`</td>
52 <td>`gettext "Name"`</td>
53 <td>`gettext "Status"`</td>
54 <td>`gettext "IP Address"`</td>
55 </tr>
56 EOT
57 for i in `ls /sys/class/net`
58 do
59 case $i in
60 eth*)
61 echo "<tr><td><a href='/network.cgi?eth'>
62 <img src='$IMAGES/ethernet.png' />$i</a></td>
63 <td>Ethernet</td> `interface_status`</tr>" ;;
64 wlan*|ath*|ra*)
65 echo "<tr><td><a href='/network.cgi?wifi'>
66 <img src='$IMAGES/wireless.png' />$i</a></td>
67 <td>Wireless</td> `interface_status`</tr>" ;;
68 lo)
69 echo "<tr><td><img src='$IMAGES/loopback.png' />$i</td>
70 <td>Loopback</td> `interface_status`</tr>" ;;
71 *)
72 continue ;;
73 esac
74 done
75 table_end
76 }
78 #
79 # xHTML 5 (header and footer skel are from the style)
80 #
82 loading_msg() {
83 cat << EOT
84 <script type="text/javascript">
85 document.write('<div id="loading"><img src="/styles/default/images/loader.gif" />$LOADING_MSG</div>');
86 </script>
87 EOT
88 }
90 xhtml_header() {
91 cat ${PANEL}$HEADER | sed s/'- %TITLE%'/"$TITLE"/
92 }
94 xhtml_footer() {
95 cat ${PANEL}$FOOTER
96 }
98 table_start() {
99 cat << EOT
100 <table>
101 <tbody>
102 EOT
103 }
105 table_end () {
106 cat << EOT
107 </tbody>
108 </table>
109 EOT
111 }