tazpanel view lib/libtazpanel @ rev 91

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