tazpanel view lib/libtazpanel @ rev 76

Show Panel activity and log a few more things to test (we need date in log() and reverse output on main page)
author Christophe Lincoln <pankso@slitaz.org>
date Tue Apr 12 04:24:35 2011 +0200 (2011-04-12)
parents 1780ef64bcd5
children 25602bc63ca7
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 var=${var#&}
31 case "$id" in
32 '1') CASE=${var% } ;;
33 '2') WANT=${var% } ;;
34 '3') VAR_1=${var% } ;;
35 '4') VAR_2=${var% } ;;
36 esac
37 done
38 }
40 # Syntax highlighting for config file and SHell scripts
41 # HTML entities: -e 's|&|\&amp;|g' -e 's|<|\&lt;|g' -e 's|>|\&gt;|g'
42 syntax_highlighter() {
43 case $1 in
44 conf)
45 sed -e s"#^\#\([^']*\)#<span class='conf-comment'>\0</span>#"g \
46 -e s"#^[A-Z]\([^']*\)=#<span class='conf-var'>\0</span>#"g \
47 -e s"#^[a-z]\([^']*\)#<span class='conf-var'>\0</span>#"g \
48 -e s"#\"\([^']*\)\"#<span class='conf-val'>\0</span>#"g ;;
49 sh)
50 sed -e s"#^\#\([^']*\)#<span class='sh-comment'>\0</span>#"g \
51 -e s"#\"\([^']*\)\"#<span class='sh-val'>\0</span>#"g
52 esac
53 }
55 # LOG activities
56 log() {
57 grep ^[a-zA-Z0-9] | sed s'/\.*\]//' >> $LOG_FILE
58 }
60 # Network interface status
61 interface_status() {
62 if ifconfig | grep -A 1 $i | grep -q inet; then
63 ip=`ifconfig | grep -A 1 $i | grep inet | \
64 awk '{ print $2 }' | cut -d ":" -f 2`
65 echo "<td>connected</td><td>$ip</td>"
66 else
67 echo "<td>----</td><td>----</td>"
68 fi
69 }
71 # Catch network interface (used in summary and network main page)
72 list_network_interfaces() {
73 table_start
74 cat << EOT
75 <tr id="thead">
76 <td>`gettext "Interface"`</td>
77 <td>`gettext "Name"`</td>
78 <td>`gettext "Status"`</td>
79 <td>`gettext "IP Address"`</td>
80 </tr>
81 EOT
82 for i in `ls /sys/class/net`
83 do
84 case $i in
85 eth*)
86 echo "<tr><td><a href='/network.cgi?eth'>
87 <img src='$IMAGES/ethernet.png' />$i</a></td>
88 <td>Ethernet</td> `interface_status`</tr>" ;;
89 wlan*|ath*|ra*)
90 echo "<tr><td><a href='/network.cgi?wifi'>
91 <img src='$IMAGES/wireless.png' />$i</a></td>
92 <td>Wireless</td> `interface_status`</tr>" ;;
93 lo)
94 echo "<tr><td><img src='$IMAGES/loopback.png' />$i</td>
95 <td>Loopback</td> `interface_status`</tr>" ;;
96 *)
97 continue ;;
98 esac
99 done
100 table_end
101 }
103 #
104 # xHTML 5 (header and footer skel are from the style)
105 #
107 loading_msg() {
108 cat << EOT
109 <script type="text/javascript">
110 document.write('<div id="loading"><img src="/styles/default/images/loader.gif" />$LOADING_MSG</div>');
111 </script>
112 EOT
113 }
115 xhtml_header() {
116 cat ${PANEL}$HEADER | sed s/'- %TITLE%'/"$TITLE"/
117 if [ $DEBUG == "1" ]; then
118 cat << EOT
119 <pre class='debug'>
120 QUERY_STRING="$QUERY_STRING"
121 CASE="$CASE" WANT="$WANT" VAR_1="$VAR_1"
122 </pre>
123 EOT
124 fi
125 }
127 xhtml_footer() {
128 cat ${PANEL}$FOOTER
129 }
131 table_start() {
132 cat << EOT
133 <table>
134 <tbody>
135 EOT
136 }
138 table_end () {
139 cat << EOT
140 </tbody>
141 </table>
142 EOT
144 }