tazpanel view lib/libtazpanel @ rev 74

move syntax_highlighter to libtazpanel to be used in other case than file and put colors in CSS so it themeable
author Christophe Lincoln <pankso@slitaz.org>
date Tue Apr 12 03:36:52 2011 +0200 (2011-04-12)
parents 26455264ec32
children 1780ef64bcd5
line source
1 #!/bin/sh
2 #
3 # Common functions for TazPanel CGI and cmdline interface
4 #
6 # Include gettext helper script.
7 . /usr/bin/gettext.sh
9 # Export package name for gettext.
10 TEXTDOMAIN='tazpanel'
11 export TEXTDOMAIN
13 # We need a config file first
14 get_config() {
15 CONFIG="/etc/slitaz/tazpanel.conf"
16 [ -f $CONFIG ] && . $CONFIG
17 [ -f tazpanel.conf ] && . tazpanel.conf
18 [ ! -f $PANEL/lib/libtazpanel ] && \
19 echo "No config file or libtazpanel found: $CONFIG" && \
20 exit 1
21 }
23 # TazPanel QUERY_STRING parser returns: CASE WANT VAR_1 VAR_4
24 # we use that to help get URL string variables and user names
25 query_string_parser() {
26 id=0
27 for var in $(echo "$QUERY_STRING" | sed s'@=@ @'g)
28 do
29 id=$((id + 1))
30 var=${var#&}
31 case "$id" in
32 '1') CASE=${var% } ;;
33 '2') WANT=${var% } ;;
34 '3') VAR_1=${var% } ;;
35 '4') VAR_2=${var% } ;;
36 esac
37 done
38 }
40 # Syntax highlighting for config file and SHell scripts
41 syntax_highlighter() {
42 case $1 in
43 conf)
44 sed -e s"#^\#\([^']*\)#<span class='conf-comment'>\0</span>#"g \
45 -e s"#^[A-Z]\([^']*\)=#<span class='conf-var'>\0</span>#"g \
46 -e s"#^[a-z]\([^']*\)#<span class='conf-var'>\0</span>#"g \
47 -e s"#\"\([^']*\)\"#<span class='conf-val'>\0</span>#"g ;;
48 esac
49 }
51 # LOG activities
52 log() {
53 grep ^[a-zA-Z0-9] | sed s'/\.*\]//' >> $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 cat << EOT
115 <pre class='debug'>
116 QUERY_STRING="$QUERY_STRING"
117 CASE="$CASE" WANT="$WANT" VAR_1="$VAR_1"
118 </pre>
119 EOT
120 fi
121 }
123 xhtml_footer() {
124 cat ${PANEL}$FOOTER
125 }
127 table_start() {
128 cat << EOT
129 <table>
130 <tbody>
131 EOT
132 }
134 table_end () {
135 cat << EOT
136 </tbody>
137 </table>
138 EOT
140 }