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