tazpanel view lib/libtazpanel @ rev 89
Remove list-style in box
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Thu Apr 14 04:32:43 2011 +0200 (2011-04-14) |
parents | 7ac8e561d0a5 |
children | 783e2405d384 |
line source
1 #!/bin/sh
2 #
3 # Common functions for TazPanel CGI and cmdline interface
4 #
6 # Get parameters with GET, POST and FILE functions
7 . /usr/bin/httpd_helper.sh
9 # Include gettext helper script.
10 . /usr/bin/gettext.sh
12 # Export package name for gettext.
13 TEXTDOMAIN='tazpanel'
14 export TEXTDOMAIN
16 # We need a config file first
17 get_config() {
18 CONFIG="/etc/slitaz/tazpanel.conf"
19 [ -f $CONFIG ] && . $CONFIG
20 [ -f tazpanel.conf ] && . tazpanel.conf
21 [ ! -f $PANEL/lib/libtazpanel ] && \
22 echo "No config file or libtazpanel found: $CONFIG" && \
23 exit 1
24 }
26 # Syntax highlighting for config file and SHell scripts
27 # HTML entities: -e 's|&|\&|g' -e 's|<|\<|g' -e 's|>|\>|g'
28 syntax_highlighter() {
29 case $1 in
30 conf)
31 sed -e s"#^\#\([^']*\)#<span class='conf-comment'>\0</span>#"g \
32 -e s"#^[A-Z]\([^']*\)=#<span class='conf-var'>\0</span>#"g \
33 -e s"#^[a-z]\([^']*\)#<span class='conf-var'>\0</span>#"g \
34 -e s"#\"\([^']*\)\"#<span class='conf-val'>\0</span>#"g ;;
35 sh)
36 sed -e s"#^\#\([^']*\)#<span class='sh-comment'>\0</span>#"g \
37 -e s"#\"\([^']*\)\"#<span class='sh-val'>\0</span>#"g
38 esac
39 }
41 # LOG activities
42 log() {
43 grep ^[a-zA-Z0-9] | sed s'/\.*\]//' >> $LOG_FILE
44 }
46 # Network interface status
47 interface_status() {
48 if ifconfig | grep -A 1 $i | grep -q inet; then
49 ip=`ifconfig | grep -A 1 $i | grep inet | \
50 awk '{ print $2 }' | cut -d ":" -f 2`
51 echo "<td>connected</td><td>$ip</td>"
52 else
53 echo "<td>----</td><td>----</td>"
54 fi
55 }
57 # Catch network interface (used in summary and network main page)
58 list_network_interfaces() {
59 table_start
60 cat << EOT
61 <tr id="thead">
62 <td>`gettext "Interface"`</td>
63 <td>`gettext "Name"`</td>
64 <td>`gettext "Status"`</td>
65 <td>`gettext "IP Address"`</td>
66 </tr>
67 EOT
68 for i in `ls /sys/class/net`
69 do
70 case $i in
71 eth*)
72 echo "<tr><td><a href='/network.cgi?eth'>
73 <img src='$IMAGES/ethernet.png' />$i</a></td>
74 <td>Ethernet</td> `interface_status`</tr>" ;;
75 wlan*|ath*|ra*)
76 echo "<tr><td><a href='/network.cgi?wifi'>
77 <img src='$IMAGES/wireless.png' />$i</a></td>
78 <td>Wireless</td> `interface_status`</tr>" ;;
79 lo)
80 echo "<tr><td><img src='$IMAGES/loopback.png' />$i</td>
81 <td>Loopback</td> `interface_status`</tr>" ;;
82 *)
83 continue ;;
84 esac
85 done
86 table_end
87 }
89 #
90 # xHTML 5 (header and footer skel are from the style)
91 #
93 loading_msg() {
94 cat << EOT
95 <script type="text/javascript">
96 document.write('<div id="loading"><img src="/styles/default/images/loader.gif" />$LOADING_MSG</div>');
97 </script>
98 EOT
99 }
101 xhtml_header() {
102 cat ${PANEL}$HEADER | sed s/'- %TITLE%'/"$TITLE"/
103 if [ $DEBUG == "1" ]; then
104 local i
105 local j
106 local x
107 args=""
108 for x in GET POST COOKIE ; do
109 for i in $($x) ; do
110 if [ $($x $i count) -gt 1 ]; then
111 for j in $(seq 1 $($x $i count)); do
112 args="$args $x($i,$j)='$($x $i $j)'"
113 done
114 else
115 args="$args $x($i)='$($x $i)'"
116 fi
117 done
118 done
119 for i in $(FILE); do
120 for j in name size type tmpname ; do
121 args="$args FILE($i,$j)=$(FILE $i $j)"
122 done
123 done
124 cat << EOT
125 <pre class='debug'>
126 QUERY_STRING="$QUERY_STRING"$args
127 </pre>
128 EOT
129 fi
130 }
132 xhtml_footer() {
133 cat ${PANEL}$FOOTER
134 }
136 table_start() {
137 cat << EOT
138 <table>
139 <tbody>
140 EOT
141 }
143 table_end () {
144 cat << EOT
145 </tbody>
146 </table>
147 EOT
149 }