tazpanel view lib/libtazpanel @ rev 311

change 'zebra' table styles to use in scrollable tables
author Aleksej Bobylev <al.bobylev@gmail.com>
date Thu May 17 14:02:41 2012 +0300 (2012-05-17)
parents 4074126a8eb0
children 01e1839f6450
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/lib/slitaz/httphelper
9 # Disk usage warnings in percents
10 DU_WARN="70"
11 DU_CRIT="90"
13 # I18n
14 . /etc/locale.conf
15 . /usr/bin/gettext.sh
16 TEXTDOMAIN='tazpanel'
17 export TEXTDOMAIN LANG LC_ALL
19 # We need a config file first
20 get_config() {
21 CONFIG="/etc/slitaz/tazpanel.conf"
22 [ -f data/tazpanel.conf ] && CONFIG="data/tazpanel.conf"
23 [ -f "$CONFIG" ] && . $CONFIG
24 [ ! -f "$PANEL/lib/libtazpanel" ] && \
25 echo "No config file or libtazpanel found: $CONFIG" && \
26 exit 1
27 }
29 # Display < > &
30 htmlize() {
31 sed -e 's|\&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g'
32 }
34 # Syntax highlighting for config file and SHell scripts
35 syntax_highlighter() {
36 case $1 in
37 conf)
38 htmlize | sed \
39 -e s"#^\#\([^']*\)#<span class='conf-comment'>\0</span>#"g \
40 -e s"#^[A-Z]\([^']*\)=#<span class='conf-var'>\0</span>#"g \
41 -e s"#^[a-z]\([^']*\)#<span class='conf-var'>\0</span>#"g \
42 -e s"#\"\([^']*\)\"#<span class='conf-val'>\0</span>#"g ;;
43 sh)
44 htmlize | sed \
45 -e s"#^\#\([^']*\)#<span class='sh-comment'>\0</span>#"g \
46 -e s"#\"\([^']*\)\"#<span class='sh-val'>\0</span>#"g ;;
47 diff)
48 htmlize | sed \
49 -e s"#^-\(.*\).#<span class='diff-rm'>\0</span>#"g \
50 -e s"#^+\(.*\).#<span class='diff-add'>\0</span>#"g \
51 -e s"#@@\(.*\)@@#<span class='diff-at'>@@\1@@</span>#"g ;;
52 activity)
53 sed -e s"#^\([^']*:\)#<span class='activity-log'>\0</span>#"g ;;
54 kernel)
55 htmlize | sed \
56 -e "s|\([^0-9]\)\(0x[0-9a-f]\+\)|\1<span class='kernel-hex'>\2</span>|g" \
57 -e "s|^\([^(,\[]\+: \)|<span class='kernel-id'>\0</span>|g" \
58 -e "s|\(\[[^ ]\+\]\)|<span class='kernel-id2'>\0</span>|g" ;;
60 esac
61 }
63 # Remove status and ESC char from tazpkg/tazlito commands output
64 filter_taztools_msgs() {
65 sed -e s'/\[^Gm]*.//g' \
66 -e ':a;s/^\(.\{1,68\}\)\(\[ [A-Za-z]* \]\)/\1 \2/;ta' \
67 -e 's#\[ OK \]#[ <span class="diff-add">OK</span> ]#' \
68 -e 's#\[ Failed \]#[ <span class="diff-rm">Failed</span> ]#'
69 }
71 # LOG activities
72 log() {
73 date=$(date "+%Y-%m-%d %H:%M")
74 filter_taztools_msgs | \
75 sed s"#[^']*#$date : \0#" >> $LOG_FILE
76 }
78 ok_status() {
79 echo "[<span class='diff-add'> OK </span>]"
80 }
82 # Network interface status
83 interface_status() {
84 if ifconfig | grep -A 1 $i | grep -q inet; then
85 ip=`ifconfig | grep -A 1 $i | grep inet | \
86 awk '{ print $2 }' | cut -d ":" -f 2`
87 echo "<td>$(gettext 'connected')</td><td>$ip</td>"
88 echo "<td><a href='/network.cgi?scan=$ip'>"
89 echo "<img src='$IMAGES/recharge.png' /></a></td>"
90 else
91 echo "<td>----</td><td>----</td><td></td>"
92 fi
93 }
95 # Catch network interface (used in summary and network main page)
96 list_network_interfaces() {
97 cat << EOT
98 <table class="zebra outbox">
99 <thead>
100 <tr>
101 <td>$(gettext 'Interface')</td>
102 <td>$(gettext 'Name')</td>
103 <td>$(gettext 'Status')</td>
104 <td>$(gettext 'IP Address')</td>
105 <td>$(gettext 'Scan ports')</td>
106 </tr>
107 </thead>
108 <tbody>
109 EOT
110 for i in `ls /sys/class/net`
111 do
112 case $i in
113 eth*)
114 echo " <tr><td><a href='/network.cgi?eth'>
115 <img src='$IMAGES/ethernet.png' />$i</a></td>
116 <td>Ethernet</td> $(interface_status)</tr>" ;;
117 wlan*|ath*|ra*)
118 echo " <tr><td><a href='/network.cgi?wifi'>
119 <img src='$IMAGES/wireless.png' />$i</a></td>
120 <td>Wireless</td> $(interface_status)</tr>" ;;
121 lo)
122 echo " <tr><td><img src='$IMAGES/loopback.png' />$i</td>
123 <td>Loopback</td> $(interface_status)</tr>" ;;
124 *)
125 continue ;;
126 esac
127 done
128 cat << EOT
129 </tbody>
130 </table>
131 EOT
132 }
134 # Get the list of panel styles
135 list_styles() {
136 for style in $PANEL/styles/*
137 do
138 style=$(basename $style)
139 echo "<option value='$style'>$style</option>"
140 done
141 }
143 # Get the list of system locales
144 list_locales() {
145 for locale in $(find /usr/share/i18n/locales -type f -name "[a-z][a-z]_[A-Z][A-Z]")
146 do
147 echo "<option value='$locale'>$locale</option>"
148 done
149 }
151 # Get the list of console keymaps
152 list_keymaps() {
153 for keymap in /usr/share/kmap/*.kmap
154 do
155 basename $keymap .kmap | sed "s|.*|<option value='&'>&</option>|"
156 done
157 }
159 #
160 # xHTML 5 (header and footer skel are from the style)
161 #
163 loading_msg() {
164 cat << EOT
165 <script type="text/javascript">
166 document.write('<div id="loading"><img src="/styles/default/images/loader.gif" />$LOADING_MSG</div>');
167 </script>
168 EOT
169 }
171 xhtml_header() {
172 . ${PANEL}$HEADER
173 if [ $DEBUG == "1" ]; then
174 local i
175 local j
176 local x
177 args=""
178 for x in GET POST COOKIE ; do
179 for i in $($x) ; do
180 if [ $($x $i count) -gt 1 ]; then
181 for j in $(seq 1 $($x $i count)); do
182 args="$args $x($i,$j)='$($x $i $j)'"
183 done
184 else
185 args="$args $x($i)='$($x $i)'"
186 fi
187 done
188 done
189 for i in $(FILE); do
190 for j in name size type tmpname ; do
191 args="$args FILE($i,$j)=$(FILE $i $j)"
192 done
193 done
194 cat << EOT
195 <pre class='debug'>
196 QUERY_STRING="$QUERY_STRING"$args
197 </pre>
198 EOT
199 fi
200 }
202 xhtml_footer() {
203 . ${PANEL}$FOOTER
204 }
206 table_start() {
207 echo '<table>'
208 }
210 table_end() {
211 echo '</table>'
212 }
214 df_thead() {
215 cat << EOT
216 <thead>
217 <tr>
218 <td>$(gettext 'Disk')</td>
219 <td>$(gettext 'Label')</td>
220 <td>$(gettext 'Type')</td>
221 <td>$(gettext 'Size')</td>
222 <td>$(gettext 'Available')</td>
223 <td>$(gettext 'Used')</td>
224 <td>$(gettext 'Mount point')</td>
225 </tr>
226 </thead>
227 EOT
228 }