tazpanel view lib/libtazpanel @ rev 161

Add report creation (to help debbuging)
author Christophe Lincoln <pankso@slitaz.org>
date Thu Apr 21 17:21:12 2011 +0200 (2011-04-21)
parents ed55f0e369b3
children ebf9e3bf4313
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 # I18n
10 . /usr/bin/gettext.sh
11 TEXTDOMAIN='tazpanel'
12 export TEXTDOMAIN
14 # We need a config file first
15 get_config() {
16 CONFIG="/etc/slitaz/tazpanel.conf"
17 [ -f data/tazpanel.conf ] && CONFIG="data/tazpanel.conf"
18 [ -f "$CONFIG" ] && . $CONFIG
19 [ ! -f "$PANEL/lib/libtazpanel" ] && \
20 echo "No config file or libtazpanel found: $CONFIG" && \
21 exit 1
22 }
24 # Syntax highlighting for config file and SHell scripts
25 # HTML entities: -e 's|&|\&amp;|g' -e 's|<|\&lt;|g' -e 's|>|\&gt;|g'
26 syntax_highlighter() {
27 case $1 in
28 conf)
29 sed -e s"#^\#\([^']*\)#<span class='conf-comment'>\0</span>#"g \
30 -e s"#^[A-Z]\([^']*\)=#<span class='conf-var'>\0</span>#"g \
31 -e s"#^[a-z]\([^']*\)#<span class='conf-var'>\0</span>#"g \
32 -e s"#\"\([^']*\)\"#<span class='conf-val'>\0</span>#"g ;;
33 sh)
34 sed -e s"#^\#\([^']*\)#<span class='sh-comment'>\0</span>#"g \
35 -e s"#\"\([^']*\)\"#<span class='sh-val'>\0</span>#"g ;;
36 diff)
37 sed -e 's|&|\&amp;|g' -e 's|<|\&lt;|g' -e 's|>|\&gt;|g' \
38 -e s"#^-\([^']*\).#<span class='diff-rm'>\0</span>#"g \
39 -e s"#^+\([^']*\).#<span class='diff-add'>\0</span>#"g \
40 -e s"#@@\([^']*\)@@#<span class='diff-at'>@@\1@@</span>#"g ;;
41 activity)
42 sed s"#^\([^']*:\)#<span class='activity-log''>\0</span>#"g ;;
43 esac
44 }
46 # Remove status and ESC char from tazpkg/tazlito commands output
47 filter_taztools_msgs() {
48 grep ^[a-zA-Z0-9] | sed \
49 -e s'/\[^Gm]*.//g' \
50 -e s'@OK@<span class="diff-add">OK</span>@'
51 }
53 # LOG activities
54 log() {
55 date=$(date "+%Y-%m-%d %H:%M")
56 filter_taztools_msgs | \
57 sed s"#[^']*#$date : \0#" >> $LOG_FILE
58 }
60 ok_status() {
61 echo "[<span class='diff-add'> OK </span>]"
62 }
64 # Network interface status
65 interface_status() {
66 if ifconfig | grep -A 1 $i | grep -q inet; then
67 ip=`ifconfig | grep -A 1 $i | grep inet | \
68 awk '{ print $2 }' | cut -d ":" -f 2`
69 echo "<td>connected</td><td>$ip</td>"
70 echo "<td><a href='/network.cgi?scan=$ip'>"
71 echo "<img src='$IMAGES/recharge.png' /></a></td>"
72 else
73 echo "<td>----</td><td>----</td><td></td>"
74 fi
75 }
77 # Catch network interface (used in summary and network main page)
78 list_network_interfaces() {
79 table_start
80 cat << EOT
81 <tr id="thead">
82 <td>`gettext "Interface"`</td>
83 <td>`gettext "Name"`</td>
84 <td>`gettext "Status"`</td>
85 <td>`gettext "IP Address"`</td>
86 <td>`gettext "Scan ports"`</td>
87 </tr>
88 EOT
89 for i in `ls /sys/class/net`
90 do
91 case $i in
92 eth*)
93 echo "<tr><td><a href='/network.cgi?eth'>
94 <img src='$IMAGES/ethernet.png' />$i</a></td>
95 <td>Ethernet</td> $(interface_status)</tr>" ;;
96 wlan*|ath*|ra*)
97 echo "<tr><td><a href='/network.cgi?wifi'>
98 <img src='$IMAGES/wireless.png' />$i</a></td>
99 <td>Wireless</td> $(interface_status)</tr>" ;;
100 lo)
101 echo "<tr><td><img src='$IMAGES/loopback.png' />$i</td>
102 <td>Loopback</td> $(interface_status)</tr>" ;;
103 *)
104 continue ;;
105 esac
106 done
107 table_end
108 }
110 #
111 # xHTML 5 (header and footer skel are from the style)
112 #
114 loading_msg() {
115 cat << EOT
116 <script type="text/javascript">
117 document.write('<div id="loading"><img src="/styles/default/images/loader.gif" />$LOADING_MSG</div>');
118 </script>
119 EOT
120 }
122 xhtml_header() {
123 cat ${PANEL}$HEADER | sed s/'- %TITLE%'/"$TITLE"/
124 if [ $DEBUG == "1" ]; then
125 local i
126 local j
127 local x
128 args=""
129 for x in GET POST COOKIE ; do
130 for i in $($x) ; do
131 if [ $($x $i count) -gt 1 ]; then
132 for j in $(seq 1 $($x $i count)); do
133 args="$args $x($i,$j)='$($x $i $j)'"
134 done
135 else
136 args="$args $x($i)='$($x $i)'"
137 fi
138 done
139 done
140 for i in $(FILE); do
141 for j in name size type tmpname ; do
142 args="$args FILE($i,$j)=$(FILE $i $j)"
143 done
144 done
145 cat << EOT
146 <pre class='debug'>
147 QUERY_STRING="$QUERY_STRING"$args
148 </pre>
149 EOT
150 fi
151 }
153 xhtml_footer() {
154 cat ${PANEL}$FOOTER
155 }
157 table_start() {
158 cat << EOT
159 <table>
160 <tbody>
161 EOT
162 }
164 table_end () {
165 cat << EOT
166 </tbody>
167 </table>
168 EOT
170 }
172 df_thead() {
173 cat << EOT
174 <thead>
175 <tr>
176 <td>$(gettext "Filesystem")</td>
177 <td>$(gettext "Size")</td>
178 <td>$(gettext "Available")</td>
179 <td>$(gettext "Used")</td>
180 <td>$(gettext "Mount point")</td>
181 </tr>
182 </thead>
183 EOT
184 }