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