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

Improve tazberry, prepa for running post_install on first boot
author Christophe Lincoln <pankso@slitaz.org>
date Fri Apr 04 19:04:15 2014 +0200 (2014-04-04)
parents 817a5e031220
children e4640054ca22
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 list_plugins() {
41 for p in $(ls -1 $plugins)
42 do
43 . ${plugins}/${p}/${p}.conf
44 cat << EOT
45 <div><b><a href="$script?$p">$PLUGIN</a></b></div>
46 <pre>
47 Description : $SHORT_DESC
48 Website : <a href="$WEB_SITE">${WEB_SITE#http://}</a>
49 </pre>
50 EOT
51 unset PLUGIN SHORT_DESC MAINTAINER WEB_SITE
52 done
53 }
55 # The only sys functions, everything else must go in plugins :-)
56 sys_tools() {
57 ip=$(ifconfig | fgrep -A 1 "encap:Ethernet" | fgrep "inet" | cut -d ":" -f 2)
58 #iface=$(ifconfig | fgrep "encap:Ethernet" | awk '{print $1}')
59 mem_total=$(free -m | fgrep "Mem:" | awk '{print $2}')
60 mem_used=$(free -m | fgrep "Mem:" | awk '{print $3}')
61 mem_used_pct=$(( ( ${mem_used} * 100) / ${mem_total} ))
62 cat << EOT
63 <pre>
64 Kernel : $(uname -snrm)
65 Uptime : $(uptime | awk '{print $3}' | sed s"/:/h /" | sed s"/,/min/")
66 Network IP : $(echo $ip | awk '{print $1}')
67 CPU heat : $(awk '{printf "%3.1f C\n", $1/1000}' /sys/class/thermal/thermal_zone0/temp)
68 Processes : $(ps | wc -l)
69 Memory usage : ${mem_used_pct}%
70 CPU usage : $(top -n 1 | fgrep CPU: | awk '{print $4}')
71 </pre>
73 <div id="actions">
74 <form method="get" action="$script">
75 <input type="submit" name="reboot" value="Reboot system" />
76 <input type="submit" name="halt" value="Halt system" />
77 </form>
78 </div>
79 EOT
80 }
82 #
83 # Handle plugins
84 #
85 for p in $(ls -1 plugins)
86 do
87 [ -f "$plugins/$p/$p.conf" ] && . $plugins/$p/$p.conf
88 [ -x "$plugins/$p/$p.cgi" ] && . $plugins/$p/$p.cgi
89 done
91 #
92 # Handle GET actions
93 #
95 case " $(GET) " in
96 *\ reboot\ *) reboot ;;
97 *\ halt\ *) halt ;;
98 *\ plugins\ *)
99 html_header "Plugins"
100 echo "<h1>Plugins list</h1>"
101 list_plugins
102 html_footer ;;
103 *)
104 html_header "Admin"
105 echo "<h1>System admin</h1>"
106 sys_tools
107 html_footer ;;
108 esac