tazpanel view lib/libtazpanel @ rev 96
Fix log (forgor date var)
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Thu Apr 14 20:13:49 2011 +0200 (2011-04-14) |
parents | 932073e74883 |
children | 1f6667794d15 |
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 diff)
39 sed -e 's|&|\&|g' -e 's|<|\<|g' -e 's|>|\>|g' \
40 -e s"#^-\([^']*\).#<span style='color: red;'>\0</span>#"g \
41 -e s"#^+\([^']*\).#<span style='color: green;'>\0</span>#"g \
42 -e s"#@@\([^']*\)@@#<span style='color: blue;'>@@\1@@</span>#"g ;;
43 esac
44 }
46 # LOG activities
47 log() {
48 date=$(date "+%Y-%m-%d %H:%M")
49 grep ^[a-zA-Z0-9] | sed s'/\.*\]//' | \
50 sed s"#[^']*#$date : \0#" >> $LOG_FILE
51 }
53 # Network interface status
54 interface_status() {
55 if ifconfig | grep -A 1 $i | grep -q inet; then
56 ip=`ifconfig | grep -A 1 $i | grep inet | \
57 awk '{ print $2 }' | cut -d ":" -f 2`
58 echo "<td>connected</td><td>$ip</td>"
59 else
60 echo "<td>----</td><td>----</td>"
61 fi
62 }
64 # Catch network interface (used in summary and network main page)
65 list_network_interfaces() {
66 table_start
67 cat << EOT
68 <tr id="thead">
69 <td>`gettext "Interface"`</td>
70 <td>`gettext "Name"`</td>
71 <td>`gettext "Status"`</td>
72 <td>`gettext "IP Address"`</td>
73 </tr>
74 EOT
75 for i in `ls /sys/class/net`
76 do
77 case $i in
78 eth*)
79 echo "<tr><td><a href='/network.cgi?eth'>
80 <img src='$IMAGES/ethernet.png' />$i</a></td>
81 <td>Ethernet</td> `interface_status`</tr>" ;;
82 wlan*|ath*|ra*)
83 echo "<tr><td><a href='/network.cgi?wifi'>
84 <img src='$IMAGES/wireless.png' />$i</a></td>
85 <td>Wireless</td> `interface_status`</tr>" ;;
86 lo)
87 echo "<tr><td><img src='$IMAGES/loopback.png' />$i</td>
88 <td>Loopback</td> `interface_status`</tr>" ;;
89 *)
90 continue ;;
91 esac
92 done
93 table_end
94 }
96 #
97 # xHTML 5 (header and footer skel are from the style)
98 #
100 loading_msg() {
101 cat << EOT
102 <script type="text/javascript">
103 document.write('<div id="loading"><img src="/styles/default/images/loader.gif" />$LOADING_MSG</div>');
104 </script>
105 EOT
106 }
108 xhtml_header() {
109 cat ${PANEL}$HEADER | sed s/'- %TITLE%'/"$TITLE"/
110 if [ $DEBUG == "1" ]; then
111 local i
112 local j
113 local x
114 args=""
115 for x in GET POST COOKIE ; do
116 for i in $($x) ; do
117 if [ $($x $i count) -gt 1 ]; then
118 for j in $(seq 1 $($x $i count)); do
119 args="$args $x($i,$j)='$($x $i $j)'"
120 done
121 else
122 args="$args $x($i)='$($x $i)'"
123 fi
124 done
125 done
126 for i in $(FILE); do
127 for j in name size type tmpname ; do
128 args="$args FILE($i,$j)=$(FILE $i $j)"
129 done
130 done
131 cat << EOT
132 <pre class='debug'>
133 QUERY_STRING="$QUERY_STRING"$args
134 </pre>
135 EOT
136 fi
137 }
139 xhtml_footer() {
140 cat ${PANEL}$FOOTER
141 }
143 table_start() {
144 cat << EOT
145 <table>
146 <tbody>
147 EOT
148 }
150 table_end () {
151 cat << EOT
152 </tbody>
153 </table>
154 EOT
156 }