slitaz-arm view cgi-adm/tools.cgi @ rev 69
Fixes to sat-rpi release/install.sh and rpi-desktop packages list
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Mon Mar 17 22:26:48 2014 +0100 (2014-03-17) |
parents | |
children | 817a5e031220 |
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 © $(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">$p</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 </pre>
72 <pre>
73 Filesystem Size Used Available Use% Mounted on
74 --------------------------------------------------------------------------------
75 $(df -h | grep ^/dev)
76 </pre>
78 <div id="actions">
79 <form method="get" action="$script">
80 <input type="submit" name="reboot" value="Reboot system" />
81 <input type="submit" name="halt" value="Halt system" />
82 </form>
83 </div>
85 EOT
86 }
88 #
89 # Handle plugins
90 #
91 for p in $(ls -1 plugins)
92 do
93 [ -f "$plugins/$p/$p.conf" ] && . $plugins/$p/$p.conf
94 [ -x "$plugins/$p/$p.cgi" ] && . $plugins/$p/$p.cgi
95 done
97 #
98 # Handle GET actions
99 #
101 case " $(GET) " in
102 *\ reboot\ *) reboot ;;
103 *\ halt\ *) halt ;;
104 *\ plugins\ *)
105 html_header "Plugins"
106 echo "<h1>Plugins list</h1>"
107 list_plugins
108 html_footer ;;
109 *)
110 html_header "Admin"
111 echo "<h1>System admin</h1>"
112 sys_tools
113 html_footer ;;
114 esac