# HG changeset patch # User Christophe Lincoln # Date 1394898139 -3600 # Node ID d3376f27881867e66560cd66ea2d524753b8a949 # Parent 2d1f132ea8bfa6c22af90d8e3d02d2705fe46731 Add CGI SHell toolkit for ARM devices diff -r 2d1f132ea8bf -r d3376f278818 cgi-adm/data/header.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cgi-adm/data/header.html Sat Mar 15 16:42:19 2014 +0100 @@ -0,0 +1,18 @@ + + + + + SliTaz ARM - _TITLE_ + + + + +
+ + +
+ +
diff -r 2d1f132ea8bf -r d3376f278818 cgi-adm/data/logo.png Binary file cgi-adm/data/logo.png has changed diff -r 2d1f132ea8bf -r d3376f278818 cgi-adm/data/style.css --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cgi-adm/data/style.css Sat Mar 15 16:42:19 2014 +0100 @@ -0,0 +1,86 @@ +/* SliTaz RPi CSS */ + +html { height: 102%; } +body { margin: 0; font-size: 90%; } +h1 { color: #4d4d4d; } +h2 { color: #666; font-size: 120%; } +a:hover { text-decoration: none; } +li { list-style-type: square; color: #4d4d4d; } +pre, textarea { + font-size: 100%; + background: #eee; + padding: 10px; + overflow: hidden; +} +textarea { + width: 100%; height: 320px; + border: 2px solid #ccc; + padding: 5px; + overflow: auto; +} + +/* Header and navigation */ + +header { + background: #222; height: 40px; border-bottom: 4px solid #afafaf; +} + +#nav { float: left; margin: 0; padding: 12px 0 0 45px; } +#nav a { font-size: 90%; color: #fff; text-decoration: none; + font-weight: bold; padding: 0 4px; } +#nav a:hover { color: #afafaf;} + +/* Logo */ + +#logo { + background: url(logo.png) no-repeat left; + position: absolute; float: left; + left: 5px; top: 0px; width: 40px; height: 40px; +} + +/* Content */ + +#content { margin: 4%; text-align: justify; } + +input[type="submit"], select { + color: #444444; + border: 1px solid #afafaf; + padding: 4px; + margin: 4px 0px; + font-size: 14px; + line-height: 1.2em; + background-image: -webkit-linear-gradient(#FAFAFA, #F4F4F4 40%, #E5E5E5); + background-image: -moz-linear-gradient(#FAFAFA, #F4F4F4 40%, #E5E5E5); + -webkit-appearance: none; + -webkit-padding-end: 12px; + -webkit-padding-start: 6px; +} +input[type="submit"] { + -webkit-box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.1); + -moz-box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.1); + box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.1); +} +input[type="text"] { + border: 1px solid #afafaf; + padding: 4px; + min-width: 360px; +} + +input[type="submit"]:hover, select:hover { + background-color: #ddd; + border: 1px solid #999; +} + +pre, input[type="submit"], input[type="text"], textarea { + border-radius: 4px; +} + +/* Footer */ + +#footer { + text-align: center; + font-size: 84%; + border-top: 1px dotted #ddd; + padding: 40px; +} +#footer, #footer a { color: #888888; } diff -r 2d1f132ea8bf -r d3376f278818 cgi-adm/index.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cgi-adm/index.html Sat Mar 15 16:42:19 2014 +0100 @@ -0,0 +1,5 @@ + + + + + diff -r 2d1f132ea8bf -r d3376f278818 cgi-adm/plugins/editor/editor.cgi --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cgi-adm/plugins/editor/editor.cgi Sat Mar 15 16:42:19 2014 +0100 @@ -0,0 +1,57 @@ +#!/bin/sh +# +# TazBerry CGI Plugin - Editor +# + +case " $(GET) " in + *\ editor\ *) + case " $(GET) " in + *\ file\ *) + file=$(GET file) + html_header "Editor" + echo "

Editor: $file

" + cat << EOT +
+
+ + + + +
+
+EOT + ;; + + *\ save\ *) + html_header "Editor" + echo "

Editor

" + echo '
'
+					echo "Saving file : $(GET save)"
+					sed "s/$(echo -en '\r') /\n/g" > $(GET save) << EOT
+$(GET content)
+EOT
+					echo "File size   : $(du -h $(GET save) | awk '{print $1}')"
+					echo '
' + echo "

Editor

" + if [ -d "$cache" ]; then + echo "" >> ${cache}/editor.log + fi ;; + + *) + html_header "Editor" + echo "

Editor

" + cat << EOT +
+
+ + + +
+
+EOT + ;; + esac + + html_footer + exit 0 ;; +esac diff -r 2d1f132ea8bf -r d3376f278818 cgi-adm/plugins/editor/editor.conf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cgi-adm/plugins/editor/editor.conf Sat Mar 15 16:42:19 2014 +0100 @@ -0,0 +1,6 @@ +# SliTaz ARM CGI Plugin configuration + +PLUGIN="Simple editor" +SHORT_DESC="Small and fast text editor" +MAINTAINER="devel@slitaz.org" +WEB_SITE="http://arm.slitaz.org/" diff -r 2d1f132ea8bf -r d3376f278818 cgi-adm/plugins/skel/skel.cgi --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cgi-adm/plugins/skel/skel.cgi Sat Mar 15 16:42:19 2014 +0100 @@ -0,0 +1,15 @@ +#!/bin/sh +# +# TazBerry CGI Plugin - Skeleton +# + +if [ "$(GET skel)" ]; then + html_header "Skel" + echo "

Plugin Skel

" + + # Let's code! + date + + html_footer + exit 0 +fi diff -r 2d1f132ea8bf -r d3376f278818 cgi-adm/plugins/skel/skel.conf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cgi-adm/plugins/skel/skel.conf Sat Mar 15 16:42:19 2014 +0100 @@ -0,0 +1,6 @@ +# TazBerry CGI Plugin configuration + +PLUGIN="Plugin Skeleton" +SHORT_DESC="Example plugin for SliTaz ARM CGI admin tool" +MAINTAINER="devel@slitaz.org" +WEB_SITE="http://arm.slitaz.org/" diff -r 2d1f132ea8bf -r d3376f278818 cgi-adm/tools.cgi --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cgi-adm/tools.cgi Sat Mar 15 16:42:19 2014 +0100 @@ -0,0 +1,114 @@ +#!/bin/sh +# +# TazBerry CGI SHell Admin tool. Fast, pure SHell, small core with +# plugins support. Auth is done via a HTTP server such as Busybox httpd. +# +# Copyright (C) 2012-2014 SliTaz ARM - BSD License +# Author: Christophe Lincoln +# +. /lib/libtaz.sh +. /usr/lib/slitaz/httphelper.sh + +# Only for root +check_root + +plugins="$(pwd)/plugins" +script="$SCRIPT_NAME" +data="$(pwd)/data" + +# +# Functions +# + +# Usage: html_header "title" +html_header() { + header + cat ${data}/header.html | sed s"/_TITLE_/$1/" +} + +html_footer() { + cat << EOT +
+ + + +EOT +} + +list_plugins() { + for p in $(ls -1 $plugins) + do + . ${plugins}/${p}/${p}.conf + cat << EOT +
$p
+
+Description : $SHORT_DESC
+Website     : ${WEB_SITE#http://}
+
+EOT + unset PLUGIN SHORT_DESC MAINTAINER WEB_SITE + done +} + +# The only sys functions, everything else must go in plugins :-) +sys_tools() { + ip=$(ifconfig | fgrep -A 1 "encap:Ethernet" | fgrep "inet" | cut -d ":" -f 2) + #iface=$(ifconfig | fgrep "encap:Ethernet" | awk '{print $1}') + mem_total=$(free -m | fgrep "Mem:" | awk '{print $2}') + mem_used=$(free -m | fgrep "Mem:" | awk '{print $3}') + mem_used_pct=$(( ( ${mem_used} * 100) / ${mem_total} )) + cat << EOT +
+Kernel       : $(uname -snrm)
+Uptime       : $(uptime | awk '{print $3}' | sed s"/:/h /" | sed s"/,/min/")
+Network IP   : $(echo $ip | awk '{print $1}')
+CPU heat     : $(awk '{printf "%3.1f C\n", $1/1000}' /sys/class/thermal/thermal_zone0/temp)
+Processes    : $(ps | wc -l)
+Memory usage : ${mem_used_pct}%
+
+ +
+Filesystem                Size      Used Available Use% Mounted on
+--------------------------------------------------------------------------------
+$(df -h | grep ^/dev)
+
+ +
+
+ + +
+
+ +EOT +} + +# +# Handle plugins +# +for p in $(ls -1 plugins) +do + [ -f "$plugins/$p/$p.conf" ] && . $plugins/$p/$p.conf + [ -x "$plugins/$p/$p.cgi" ] && . $plugins/$p/$p.cgi +done + +# +# Handle GET actions +# + +case " $(GET) " in + *\ reboot\ *) reboot ;; + *\ halt\ *) halt ;; + *\ plugins\ *) + html_header "Plugins" + echo "

Plugins list

" + list_plugins + html_footer ;; + *) + html_header "Admin" + echo "

System admin

" + sys_tools + html_footer ;; +esac diff -r 2d1f132ea8bf -r d3376f278818 rpi/cgi-adm/data/header.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rpi/cgi-adm/data/header.html Sat Mar 15 16:42:19 2014 +0100 @@ -0,0 +1,19 @@ + + + + + TazBerry - _TITLE_ + + + + +
+ + +
+ +
diff -r 2d1f132ea8bf -r d3376f278818 rpi/cgi-adm/data/logo.png Binary file rpi/cgi-adm/data/logo.png has changed diff -r 2d1f132ea8bf -r d3376f278818 rpi/cgi-adm/plugins/rpi_boot/rpi_boot.cgi --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rpi/cgi-adm/plugins/rpi_boot/rpi_boot.cgi Sat Mar 15 16:42:19 2014 +0100 @@ -0,0 +1,36 @@ +#!/bin/sh +# +# TazBerry CGI Plugin - Skeleton +# + +if [ "$(GET rpi_boot)" ]; then + html_header "Boot" + echo "

SliTaz RPi Boot

" + + cat << EOT +

+ The Raspberry Pi use 2 config files to boot. The default SliTaz RPi + Linux kernel image is: /boot/kernel.img +

+ +
+
+Kernel boot parameters
+--------------------------------------------------------------------------------
+$(cat /boot/cmdline.txt 2>/dev/null)
+
+
+RPi configuration file
+--------------------------------------------------------------------------------
+$(cat /boot/config.txt 2>/dev/null)
+
+
+Boot files
+--------------------------------------------------------------------------------
+$(ls -1 /boot)
+
+EOT + + html_footer + exit 0 +fi diff -r 2d1f132ea8bf -r d3376f278818 rpi/cgi-adm/plugins/rpi_boot/rpi_boot.conf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rpi/cgi-adm/plugins/rpi_boot/rpi_boot.conf Sat Mar 15 16:42:19 2014 +0100 @@ -0,0 +1,6 @@ +# TazBerry CGI Plugin configuration + +PLUGIN="RPi Boot" +SHORT_DESC="Raspberry Pi boot time configs" +MAINTAINER="pankso@slitaz.org" +WEB_SITE="http://arm.slitaz.org/rpi/"