slitaz-arm view cgi-adm/tools.cgi @ rev 166
Add a small Yad Box to handle Slitaz RPi from an i486 desktop
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Sun May 04 19:10:58 2014 +0200 (2014-05-04) |
parents | e785c2b0ea5a |
children |
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"
18 cache="$(pwd)/cache"
20 #
21 # Functions
22 #
24 # Usage: html_header "title"
25 html_header() {
26 header
27 cat ${data}/header.html | sed s"/_TITLE_/$1/"
28 }
30 html_footer() {
31 cat << EOT
32 </section>
33 <footer id="footer">
34 © $(date +%Y) <a href="http://arm.slitaz.org/">SliTaz ARM</a>
35 </footer>
36 </body>
37 </html>
38 EOT
39 }
41 # Usage: notify [hide|"Message..."]
42 notify() {
43 if [ "$1" == "hide" ]; then
44 echo "<style type='text/css'>#notify { display: none !important; }</style>"
45 else
46 echo "<div id='notify'>$@</div>"
47 fi
48 }
50 list_plugins() {
51 for p in $(ls -1 $plugins)
52 do
53 . ${plugins}/${p}/${p}.conf
54 cat << EOT
55 <div><b><a href="$script?$p">$PLUGIN</a></b></div>
56 <pre>
57 Description : $SHORT_DESC
58 Website : <a href="$WEB_SITE">${WEB_SITE#http://}</a>
59 </pre>
60 EOT
61 unset PLUGIN SHORT_DESC MAINTAINER WEB_SITE
62 done
63 }
65 # The only sys functions, everything else must go in plugins :-)
66 sys_tools() {
67 ip=$(ifconfig | fgrep -A 1 "encap:Ethernet" | fgrep "inet" | cut -d ":" -f 2)
68 #iface=$(ifconfig | fgrep "encap:Ethernet" | awk '{print $1}')
69 mem_total=$(free -m | fgrep "Mem:" | awk '{print $2}')
70 mem_used=$(free -m | fgrep "Mem:" | awk '{print $3}')
71 mem_used_pct=$(( ( ${mem_used} * 100) / ${mem_total} ))
72 cat << EOT
73 <pre>
74 System time : $(date)
75 Time zone : $(cat /etc/TZ)
76 Kernel : $(uname -snrm)
77 Uptime : $(uptime | awk '{print $3}' | sed s"/:/h /" | sed s"/,/min/")
78 Network IP : $(echo $ip | awk '{print $1}')
79 CPU heat : $(awk '{printf "%3.1f C\n", $1/1000}' /sys/class/thermal/thermal_zone0/temp)
80 Processes : $(ps | wc -l)
81 Memory usage : ${mem_used_pct}%
82 CPU usage : $(top -n 1 | grep ^CPU: | awk '{print $4}')
83 </pre>
85 <div id="actions">
86 <form method="get" action="$script">
87 <input type="submit" name="reboot" value="Reboot system" />
88 <input type="submit" name="halt" value="Halt system" />
89 <input type="submit" name="rdate" value="Set system time" />
90 </form>
91 </div>
92 EOT
93 }
95 #
96 # Handle plugins
97 #
98 for p in $(ls -1 plugins)
99 do
100 [ -f "$plugins/$p/$p.conf" ] && . $plugins/$p/$p.conf
101 [ -x "$plugins/$p/$p.cgi" ] && . $plugins/$p/$p.cgi
102 done
104 #
105 # Handle GET actions
106 #
108 case " $(GET) " in
109 *\ reboot\ *) reboot ;;
110 *\ halt\ *) halt ;;
112 *\ plugins\ *)
113 html_header "Plugins"
114 echo "<h1>Plugins list</h1>"
115 list_plugins
116 html_footer ;;
118 *\ rdate\ *)
119 html_header "System time"
120 echo "<h1>System time</h1>"
121 echo "<pre>"
122 echo -n "Old date: "; date
123 rdate -s tick.greyware.com
124 echo -n "New date: "; date
125 echo "</pre>"
126 html_footer && exit 0 ;;
128 *)
129 html_header "Admin"
130 echo "<h1>System admin</h1>"
131 sys_tools
132 html_footer ;;
133 esac