slitaz-arm view cgi-adm/tools.cgi @ rev 135

rpi: add Audio support in CGI admin interface
author Christophe Lincoln <pankso@slitaz.org>
date Sat Apr 26 10:41:23 2014 +0200 (2014-04-26)
parents e4640054ca22
children e785c2b0ea5a
line source
1 #!/bin/sh
2 #
3 # TazBerry CGI SHell Admin tool. Fast, pure SHell, small core with
4 # plugins support. Auth is done via a HTTP server such as Busybox httpd.
5 #
6 # Copyright (C) 2012-2014 SliTaz ARM - BSD License
7 # Author: Christophe Lincoln <pankso@slitaz.org>
8 #
9 . /lib/libtaz.sh
10 . /usr/lib/slitaz/httphelper.sh
12 # Only for root
13 check_root
15 plugins="$(pwd)/plugins"
16 script="$SCRIPT_NAME"
17 data="$(pwd)/data"
19 #
20 # Functions
21 #
23 # Usage: html_header "title"
24 html_header() {
25 header
26 cat ${data}/header.html | sed s"/_TITLE_/$1/"
27 }
29 html_footer() {
30 cat << EOT
31 </section>
32 <footer id="footer">
33 &copy; $(date +%Y) <a href="http://arm.slitaz.org/">SliTaz ARM</a>
34 </footer>
35 </body>
36 </html>
37 EOT
38 }
40 # Usage: notify [hide|"Message..."]
41 notify() {
42 if [ "$1" == "hide" ]; then
43 echo "<style type='text/css'>#notify { display: none !important; }</style>"
44 else
45 echo "<div id='notify'>$@</div>"
46 fi
47 }
49 list_plugins() {
50 for p in $(ls -1 $plugins)
51 do
52 . ${plugins}/${p}/${p}.conf
53 cat << EOT
54 <div><b><a href="$script?$p">$PLUGIN</a></b></div>
55 <pre>
56 Description : $SHORT_DESC
57 Website : <a href="$WEB_SITE">${WEB_SITE#http://}</a>
58 </pre>
59 EOT
60 unset PLUGIN SHORT_DESC MAINTAINER WEB_SITE
61 done
62 }
64 # The only sys functions, everything else must go in plugins :-)
65 sys_tools() {
66 ip=$(ifconfig | fgrep -A 1 "encap:Ethernet" | fgrep "inet" | cut -d ":" -f 2)
67 #iface=$(ifconfig | fgrep "encap:Ethernet" | awk '{print $1}')
68 mem_total=$(free -m | fgrep "Mem:" | awk '{print $2}')
69 mem_used=$(free -m | fgrep "Mem:" | awk '{print $3}')
70 mem_used_pct=$(( ( ${mem_used} * 100) / ${mem_total} ))
71 cat << EOT
72 <pre>
73 Kernel : $(uname -snrm)
74 Uptime : $(uptime | awk '{print $3}' | sed s"/:/h /" | sed s"/,/min/")
75 Network IP : $(echo $ip | awk '{print $1}')
76 CPU heat : $(awk '{printf "%3.1f C\n", $1/1000}' /sys/class/thermal/thermal_zone0/temp)
77 Processes : $(ps | wc -l)
78 Memory usage : ${mem_used_pct}%
79 CPU usage : $(top -n 1 | grep ^CPU: | awk '{print $4}')
80 </pre>
82 <div id="actions">
83 <form method="get" action="$script">
84 <input type="submit" name="reboot" value="Reboot system" />
85 <input type="submit" name="halt" value="Halt system" />
86 </form>
87 </div>
88 EOT
89 }
91 #
92 # Handle plugins
93 #
94 for p in $(ls -1 plugins)
95 do
96 [ -f "$plugins/$p/$p.conf" ] && . $plugins/$p/$p.conf
97 [ -x "$plugins/$p/$p.cgi" ] && . $plugins/$p/$p.cgi
98 done
100 #
101 # Handle GET actions
102 #
104 case " $(GET) " in
105 *\ reboot\ *) reboot ;;
106 *\ halt\ *) halt ;;
107 *\ plugins\ *)
108 html_header "Plugins"
109 echo "<h1>Plugins list</h1>"
110 list_plugins
111 html_footer ;;
112 *)
113 html_header "Admin"
114 echo "<h1>System admin</h1>"
115 sys_tools
116 html_footer ;;
117 esac