tazpanel view lib/libtazpanel @ rev 75
Add SHell script colored sytax as seen in boot for /etc/init.d/local.sh
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Tue Apr 12 03:52:19 2011 +0200 (2011-04-12) |
parents | e4a7503f7efd |
children | 7ac8e561d0a5 |
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 sh)
49 sed -e s"#^\#\([^']*\)#<span class='sh-comment'>\0</span>#"g \
50 -e s"#\"\([^']*\)\"#<span class='sh-val'>\0</span>#"g
51 esac
52 }
54 # LOG activities
55 log() {
56 grep ^[a-zA-Z0-9] | sed s'/\.*\]//' >> $LOG_FILE
57 }
59 # Network interface status
60 interface_status() {
61 if ifconfig | grep -A 1 $i | grep -q inet; then
62 ip=`ifconfig | grep -A 1 $i | grep inet | \
63 awk '{ print $2 }' | cut -d ":" -f 2`
64 echo "<td>connected</td><td>$ip</td>"
65 else
66 echo "<td>----</td><td>----</td>"
67 fi
68 }
70 # Catch network interface (used in summary and network main page)
71 list_network_interfaces() {
72 table_start
73 cat << EOT
74 <tr id="thead">
75 <td>`gettext "Interface"`</td>
76 <td>`gettext "Name"`</td>
77 <td>`gettext "Status"`</td>
78 <td>`gettext "IP Address"`</td>
79 </tr>
80 EOT
81 for i in `ls /sys/class/net`
82 do
83 case $i in
84 eth*)
85 echo "<tr><td><a href='/network.cgi?eth'>
86 <img src='$IMAGES/ethernet.png' />$i</a></td>
87 <td>Ethernet</td> `interface_status`</tr>" ;;
88 wlan*|ath*|ra*)
89 echo "<tr><td><a href='/network.cgi?wifi'>
90 <img src='$IMAGES/wireless.png' />$i</a></td>
91 <td>Wireless</td> `interface_status`</tr>" ;;
92 lo)
93 echo "<tr><td><img src='$IMAGES/loopback.png' />$i</td>
94 <td>Loopback</td> `interface_status`</tr>" ;;
95 *)
96 continue ;;
97 esac
98 done
99 table_end
100 }
102 #
103 # xHTML 5 (header and footer skel are from the style)
104 #
106 loading_msg() {
107 cat << EOT
108 <script type="text/javascript">
109 document.write('<div id="loading"><img src="/styles/default/images/loader.gif" />$LOADING_MSG</div>');
110 </script>
111 EOT
112 }
114 xhtml_header() {
115 cat ${PANEL}$HEADER | sed s/'- %TITLE%'/"$TITLE"/
116 if [ $DEBUG == "1" ]; then
117 cat << EOT
118 <pre class='debug'>
119 QUERY_STRING="$QUERY_STRING"
120 CASE="$CASE" WANT="$WANT" VAR_1="$VAR_1"
121 </pre>
122 EOT
123 fi
124 }
126 xhtml_footer() {
127 cat ${PANEL}$FOOTER
128 }
130 table_start() {
131 cat << EOT
132 <table>
133 <tbody>
134 EOT
135 }
137 table_end () {
138 cat << EOT
139 </tbody>
140 </table>
141 EOT
143 }