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

cgi-adm: move time setiing to core and misc fixes
author Christophe Lincoln <pankso@slitaz.org>
date Sat Apr 26 12:06:42 2014 +0200 (2014-04-26)
parents c10b9b20b9a5
children fae61a8c31e0
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 System time : $(date)
74 Time zone : $(cat /etc/TZ)
75 Kernel : $(uname -snrm)
76 Uptime : $(uptime | awk '{print $3}' | sed s"/:/h /" | sed s"/,/min/")
77 Network IP : $(echo $ip | awk '{print $1}')
78 CPU heat : $(awk '{printf "%3.1f C\n", $1/1000}' /sys/class/thermal/thermal_zone0/temp)
79 Processes : $(ps | wc -l)
80 Memory usage : ${mem_used_pct}%
81 CPU usage : $(top -n 1 | grep ^CPU: | awk '{print $4}')
82 </pre>
84 <div id="actions">
85 <form method="get" action="$script">
86 <input type="submit" name="reboot" value="Reboot system" />
87 <input type="submit" name="halt" value="Halt system" />
88 <input type="submit" name="rdate" value="Set system time" />
89 </form>
90 </div>
91 EOT
92 }
94 #
95 # Handle plugins
96 #
97 for p in $(ls -1 plugins)
98 do
99 [ -f "$plugins/$p/$p.conf" ] && . $plugins/$p/$p.conf
100 [ -x "$plugins/$p/$p.cgi" ] && . $plugins/$p/$p.cgi
101 done
103 #
104 # Handle GET actions
105 #
107 case " $(GET) " in
108 *\ reboot\ *) reboot ;;
109 *\ halt\ *) halt ;;
111 *\ plugins\ *)
112 html_header "Plugins"
113 echo "<h1>Plugins list</h1>"
114 list_plugins
115 html_footer ;;
117 *\ rdate\ *)
118 html_header "System time"
119 echo "<h1>System time</h1>"
120 echo "<pre>"
121 echo -n "Old date: "; date
122 rdate -s tick.greyware.com
123 echo -n "New date: "; date
124 echo "</pre>"
125 html_footer && exit 0 ;;
127 *)
128 html_header "Admin"
129 echo "<h1>System admin</h1>"
130 sys_tools
131 html_footer ;;
132 esac