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