slitaz-arm rev 59

Add CGI SHell toolkit for ARM devices
author Christophe Lincoln <pankso@slitaz.org>
date Sat Mar 15 16:42:19 2014 +0100 (2014-03-15)
parents 2d1f132ea8bf
children 1b4800da5288
files cgi-adm/data/header.html cgi-adm/data/logo.png cgi-adm/data/style.css cgi-adm/index.html cgi-adm/plugins/editor/editor.cgi cgi-adm/plugins/editor/editor.conf cgi-adm/plugins/skel/skel.cgi cgi-adm/plugins/skel/skel.conf cgi-adm/tools.cgi rpi/cgi-adm/data/header.html rpi/cgi-adm/data/logo.png rpi/cgi-adm/plugins/rpi_boot/rpi_boot.cgi rpi/cgi-adm/plugins/rpi_boot/rpi_boot.conf
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/cgi-adm/data/header.html	Sat Mar 15 16:42:19 2014 +0100
     1.3 @@ -0,0 +1,18 @@
     1.4 +<!DOCTYPE html>
     1.5 +<html lang="en">
     1.6 +<head>
     1.7 +	<meta charset="utf-8" />
     1.8 +	<title>SliTaz ARM - _TITLE_</title>
     1.9 +	<link rel="stylesheet" type="text/css" href="data/style.css" />
    1.10 +</head>
    1.11 +<body>
    1.12 +
    1.13 +<header>
    1.14 +	<div id="logo"></div>
    1.15 +	<nav id="nav">
    1.16 +		<a href="tools.cgi">System</a>
    1.17 +		<a href="tools.cgi?plugins">Plugins</a>
    1.18 +	</nav>
    1.19 +</header>
    1.20 +
    1.21 +<section id="content">
     2.1 Binary file cgi-adm/data/logo.png has changed
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/cgi-adm/data/style.css	Sat Mar 15 16:42:19 2014 +0100
     3.3 @@ -0,0 +1,86 @@
     3.4 +/* SliTaz RPi CSS */
     3.5 +
     3.6 +html { height: 102%; }
     3.7 +body { margin: 0; font-size: 90%; }
     3.8 +h1 { color: #4d4d4d; }
     3.9 +h2 { color: #666; font-size: 120%; }
    3.10 +a:hover { text-decoration: none; }
    3.11 +li { list-style-type: square; color: #4d4d4d; }
    3.12 +pre, textarea {
    3.13 +	font-size: 100%;
    3.14 +	background: #eee;
    3.15 +	padding: 10px;
    3.16 +	overflow: hidden; 
    3.17 +}
    3.18 +textarea {
    3.19 +	width: 100%; height: 320px; 
    3.20 +	border: 2px solid #ccc; 
    3.21 +	padding: 5px;
    3.22 +	overflow: auto;
    3.23 +}
    3.24 +
    3.25 +/* Header and navigation */
    3.26 +
    3.27 +header {
    3.28 +	background: #222; height: 40px; border-bottom: 4px solid #afafaf;
    3.29 +}
    3.30 +
    3.31 +#nav { float: left; margin: 0; padding: 12px 0 0 45px; }
    3.32 +#nav a { font-size: 90%; color: #fff; text-decoration: none;
    3.33 +	font-weight: bold; padding: 0 4px; }
    3.34 +#nav a:hover { color: #afafaf;}
    3.35 +
    3.36 +/* Logo */
    3.37 +
    3.38 +#logo {
    3.39 +	background: url(logo.png) no-repeat left;
    3.40 +	position: absolute; float: left; 
    3.41 +	left: 5px; top: 0px; width: 40px; height: 40px;
    3.42 +}
    3.43 +
    3.44 +/* Content */
    3.45 +
    3.46 +#content { margin: 4%; text-align: justify; }
    3.47 +
    3.48 +input[type="submit"], select {
    3.49 +	color: #444444;
    3.50 +	border: 1px solid #afafaf;
    3.51 +	padding: 4px;
    3.52 +	margin: 4px 0px;
    3.53 +	font-size: 14px;
    3.54 +	line-height: 1.2em;
    3.55 +	background-image: -webkit-linear-gradient(#FAFAFA, #F4F4F4 40%, #E5E5E5);
    3.56 +	background-image: -moz-linear-gradient(#FAFAFA, #F4F4F4 40%, #E5E5E5);
    3.57 +	-webkit-appearance: none;
    3.58 +	-webkit-padding-end: 12px;
    3.59 +	-webkit-padding-start: 6px;
    3.60 +}
    3.61 +input[type="submit"] {
    3.62 +	-webkit-box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.1);
    3.63 +	-moz-box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.1);
    3.64 +	box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.1);
    3.65 +}
    3.66 +input[type="text"] { 
    3.67 +	border: 1px solid #afafaf;
    3.68 +	padding: 4px;
    3.69 +	min-width: 360px;
    3.70 +}
    3.71 +
    3.72 +input[type="submit"]:hover, select:hover {
    3.73 +	background-color: #ddd;
    3.74 +	border: 1px solid #999;
    3.75 +}
    3.76 +
    3.77 +pre, input[type="submit"], input[type="text"], textarea {
    3.78 +	border-radius: 4px;
    3.79 +}
    3.80 +
    3.81 +/* Footer */
    3.82 +
    3.83 +#footer {
    3.84 +	text-align: center;
    3.85 +	font-size: 84%;
    3.86 +	border-top: 1px dotted #ddd;
    3.87 +	padding: 40px;
    3.88 +}
    3.89 +#footer, #footer a { color: #888888; }
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/cgi-adm/index.html	Sat Mar 15 16:42:19 2014 +0100
     4.3 @@ -0,0 +1,5 @@
     4.4 +<html>
     4.5 +	<head>
     4.6 +		<meta http-equiv="refresh" content="0; URL=tools.cgi">
     4.7 +	</head>
     4.8 +</html> 
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/cgi-adm/plugins/editor/editor.cgi	Sat Mar 15 16:42:19 2014 +0100
     5.3 @@ -0,0 +1,57 @@
     5.4 +#!/bin/sh
     5.5 +#
     5.6 +# TazBerry CGI Plugin - Editor
     5.7 +#
     5.8 +
     5.9 +case " $(GET) " in
    5.10 +		*\ editor\ *)
    5.11 +			case " $(GET) " in
    5.12 +				*\ file\ *)
    5.13 +					file=$(GET file)
    5.14 +					html_header "Editor"
    5.15 +					echo "<h1>Editor: $file</h1>"
    5.16 +					cat << EOT
    5.17 +<div id="actions">
    5.18 +	<form method="get" action="$script">
    5.19 +		<input type="hidden" name="editor" />
    5.20 +		<input type="hidden" name="save" value="$file" />
    5.21 +		<textarea name="content">$(cat "$file" 2>/dev/null)</textarea>
    5.22 +		<input type="submit" value="Save file" />
    5.23 +	</form>
    5.24 +</div>
    5.25 +EOT
    5.26 +					;;
    5.27 +				
    5.28 +				*\ save\ *)
    5.29 +					html_header "Editor"
    5.30 +					echo "<h1>Editor</h1>"
    5.31 +					echo '<pre>'
    5.32 +					echo "Saving file : $(GET save)"
    5.33 +					sed "s/$(echo -en '\r') /\n/g" > $(GET save) << EOT
    5.34 +$(GET content)
    5.35 +EOT
    5.36 +					echo "File size   : $(du -h $(GET save) | awk '{print $1}')"
    5.37 +					echo '</pre>'
    5.38 +					echo "<p><a href='$script?editor'>Editor</a></p>"
    5.39 +					if [ -d "$cache" ]; then
    5.40 +						echo "" >> ${cache}/editor.log
    5.41 +					fi ;;
    5.42 +				
    5.43 +				*)
    5.44 +					html_header "Editor"
    5.45 +					echo "<h1>Editor</h1>"
    5.46 +					cat << EOT
    5.47 +<div id="actions">
    5.48 +	<form method="get" action="$script">
    5.49 +		<input type="hidden" name="editor" />
    5.50 +		<input type="text" name="file" value="$file" placeholder="File path" />
    5.51 +		<input type="submit" value="View or edit" />
    5.52 +	</form>
    5.53 +</div>
    5.54 +EOT
    5.55 +					;;
    5.56 +			esac
    5.57 +			
    5.58 +		html_footer
    5.59 +		exit 0 ;;
    5.60 +esac
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/cgi-adm/plugins/editor/editor.conf	Sat Mar 15 16:42:19 2014 +0100
     6.3 @@ -0,0 +1,6 @@
     6.4 +# SliTaz ARM CGI Plugin configuration
     6.5 +
     6.6 +PLUGIN="Simple editor"
     6.7 +SHORT_DESC="Small and fast text editor"
     6.8 +MAINTAINER="devel@slitaz.org"
     6.9 +WEB_SITE="http://arm.slitaz.org/"
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/cgi-adm/plugins/skel/skel.cgi	Sat Mar 15 16:42:19 2014 +0100
     7.3 @@ -0,0 +1,15 @@
     7.4 +#!/bin/sh
     7.5 +#
     7.6 +# TazBerry CGI Plugin - Skeleton
     7.7 +#
     7.8 +
     7.9 +if [ "$(GET skel)" ]; then
    7.10 +	html_header "Skel"
    7.11 +	echo "<h1>Plugin Skel</h1>"
    7.12 +	
    7.13 +	# Let's code!
    7.14 +	date
    7.15 +	
    7.16 +	html_footer
    7.17 +	exit 0
    7.18 +fi
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/cgi-adm/plugins/skel/skel.conf	Sat Mar 15 16:42:19 2014 +0100
     8.3 @@ -0,0 +1,6 @@
     8.4 +# TazBerry CGI Plugin configuration
     8.5 +
     8.6 +PLUGIN="Plugin Skeleton"
     8.7 +SHORT_DESC="Example plugin for SliTaz ARM CGI admin tool"
     8.8 +MAINTAINER="devel@slitaz.org"
     8.9 +WEB_SITE="http://arm.slitaz.org/"
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/cgi-adm/tools.cgi	Sat Mar 15 16:42:19 2014 +0100
     9.3 @@ -0,0 +1,114 @@
     9.4 +#!/bin/sh
     9.5 +#
     9.6 +# TazBerry CGI SHell Admin tool. Fast, pure SHell, small core with
     9.7 +# plugins support. Auth is done via a HTTP server such as Busybox httpd.
     9.8 +#
     9.9 +# Copyright (C) 2012-2014 SliTaz ARM - BSD License
    9.10 +# Author: Christophe Lincoln <pankso@slitaz.org>
    9.11 +#
    9.12 +. /lib/libtaz.sh
    9.13 +. /usr/lib/slitaz/httphelper.sh
    9.14 +
    9.15 +# Only for root
    9.16 +check_root
    9.17 +
    9.18 +plugins="$(pwd)/plugins"
    9.19 +script="$SCRIPT_NAME"
    9.20 +data="$(pwd)/data"
    9.21 +
    9.22 +#
    9.23 +# Functions
    9.24 +#
    9.25 +
    9.26 +# Usage: html_header "title"
    9.27 +html_header() {
    9.28 +	header
    9.29 +	cat ${data}/header.html | sed s"/_TITLE_/$1/"
    9.30 +}
    9.31 +
    9.32 +html_footer() {
    9.33 +	cat << EOT
    9.34 +</section>
    9.35 +<footer id="footer">
    9.36 +	&copy; $(date +%Y) <a href="http://arm.slitaz.org/">SliTaz ARM</a>
    9.37 +</footer>
    9.38 +</body>
    9.39 +</html>
    9.40 +EOT
    9.41 +}
    9.42 +
    9.43 +list_plugins() {
    9.44 +	for p in $(ls -1 $plugins)
    9.45 +	do
    9.46 +		. ${plugins}/${p}/${p}.conf
    9.47 +	cat << EOT
    9.48 +<div><b><a href="$script?$p">$p</a></b></div>
    9.49 +<pre>
    9.50 +Description : $SHORT_DESC
    9.51 +Website     : <a href="$WEB_SITE">${WEB_SITE#http://}</a>
    9.52 +</pre>
    9.53 +EOT
    9.54 +		unset PLUGIN SHORT_DESC MAINTAINER WEB_SITE
    9.55 +	done
    9.56 +}
    9.57 +
    9.58 +# The only sys functions, everything else must go in plugins :-)
    9.59 +sys_tools() {
    9.60 +	ip=$(ifconfig | fgrep -A 1 "encap:Ethernet" | fgrep "inet" | cut -d ":" -f 2)
    9.61 +	#iface=$(ifconfig | fgrep "encap:Ethernet" | awk '{print $1}')
    9.62 +	mem_total=$(free -m | fgrep "Mem:" | awk '{print $2}')
    9.63 +	mem_used=$(free -m | fgrep "Mem:" | awk '{print $3}')
    9.64 +	mem_used_pct=$(( ( ${mem_used} * 100) / ${mem_total} ))
    9.65 +	cat << EOT
    9.66 +<pre>
    9.67 +Kernel       : $(uname -snrm)
    9.68 +Uptime       : $(uptime | awk '{print $3}' | sed s"/:/h /" | sed s"/,/min/")
    9.69 +Network IP   : $(echo $ip | awk '{print $1}')
    9.70 +CPU heat     : $(awk '{printf "%3.1f C\n", $1/1000}' /sys/class/thermal/thermal_zone0/temp)
    9.71 +Processes    : $(ps | wc -l)
    9.72 +Memory usage : ${mem_used_pct}%
    9.73 +</pre>
    9.74 +
    9.75 +<pre>
    9.76 +Filesystem                Size      Used Available Use% Mounted on
    9.77 +--------------------------------------------------------------------------------
    9.78 +$(df -h | grep ^/dev)
    9.79 +</pre>
    9.80 +
    9.81 +<div id="actions">
    9.82 +	<form method="get" action="$script">
    9.83 +		<input type="submit" name="reboot" value="Reboot system" />
    9.84 +		<input type="submit" name="halt" value="Halt system" />
    9.85 +	</form>
    9.86 +</div>
    9.87 +
    9.88 +EOT
    9.89 +}
    9.90 +
    9.91 +#
    9.92 +# Handle plugins
    9.93 +#
    9.94 +for p in $(ls -1 plugins)
    9.95 +do
    9.96 +	[ -f "$plugins/$p/$p.conf" ] && . $plugins/$p/$p.conf
    9.97 +	[ -x "$plugins/$p/$p.cgi" ] && . $plugins/$p/$p.cgi
    9.98 +done
    9.99 +
   9.100 +#
   9.101 +# Handle GET actions
   9.102 +#
   9.103 +
   9.104 +case " $(GET) " in
   9.105 +	*\ reboot\ *) reboot ;;
   9.106 +	*\ halt\ *) halt ;;
   9.107 +	*\ plugins\ *)
   9.108 +		html_header "Plugins"
   9.109 +		echo "<h1>Plugins list</h1>"
   9.110 +		list_plugins
   9.111 +		html_footer ;;
   9.112 +	*)
   9.113 +		html_header "Admin"
   9.114 +		echo "<h1>System admin</h1>"
   9.115 +		sys_tools
   9.116 +		html_footer ;;
   9.117 +esac
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/rpi/cgi-adm/data/header.html	Sat Mar 15 16:42:19 2014 +0100
    10.3 @@ -0,0 +1,19 @@
    10.4 +<!DOCTYPE html>
    10.5 +<html lang="en">
    10.6 +<head>
    10.7 +	<meta charset="utf-8" />
    10.8 +	<title>TazBerry - _TITLE_</title>
    10.9 +	<link rel="stylesheet" type="text/css" href="data/style.css" />
   10.10 +</head>
   10.11 +<body>
   10.12 +
   10.13 +<header>
   10.14 +	<div id="logo"></div>
   10.15 +	<nav id="nav">
   10.16 +		<a href="tools.cgi">TazBerry</a>
   10.17 +		<a href="tools.cgi?plugins">Plugins</a>
   10.18 +		<a href="tools.cgi?rpi_boot">Boot</a>
   10.19 +	</nav>
   10.20 +</header>
   10.21 +
   10.22 +<section id="content">
    11.1 Binary file rpi/cgi-adm/data/logo.png has changed
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/rpi/cgi-adm/plugins/rpi_boot/rpi_boot.cgi	Sat Mar 15 16:42:19 2014 +0100
    12.3 @@ -0,0 +1,36 @@
    12.4 +#!/bin/sh
    12.5 +#
    12.6 +# TazBerry CGI Plugin - Skeleton
    12.7 +#
    12.8 +
    12.9 +if [ "$(GET rpi_boot)" ]; then
   12.10 +	html_header "Boot"
   12.11 +	echo "<h1>SliTaz RPi Boot</h1>"
   12.12 +	
   12.13 +	cat << EOT
   12.14 +<p>
   12.15 +	The Raspberry Pi use 2 config files to boot. The default SliTaz RPi 
   12.16 +	Linux kernel image is: /boot/kernel.img
   12.17 +</p>
   12.18 +
   12.19 +<pre>
   12.20 +
   12.21 +Kernel boot parameters
   12.22 +--------------------------------------------------------------------------------
   12.23 +$(cat /boot/cmdline.txt 2>/dev/null)
   12.24 +
   12.25 +
   12.26 +RPi configuration file
   12.27 +--------------------------------------------------------------------------------
   12.28 +$(cat /boot/config.txt 2>/dev/null)
   12.29 +
   12.30 +
   12.31 +Boot files
   12.32 +--------------------------------------------------------------------------------
   12.33 +$(ls -1 /boot)
   12.34 +</pre>
   12.35 +EOT
   12.36 +	
   12.37 +	html_footer
   12.38 +	exit 0
   12.39 +fi
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/rpi/cgi-adm/plugins/rpi_boot/rpi_boot.conf	Sat Mar 15 16:42:19 2014 +0100
    13.3 @@ -0,0 +1,6 @@
    13.4 +# TazBerry CGI Plugin configuration
    13.5 +
    13.6 +PLUGIN="RPi Boot"
    13.7 +SHORT_DESC="Raspberry Pi boot time configs"
    13.8 +MAINTAINER="pankso@slitaz.org"
    13.9 +WEB_SITE="http://arm.slitaz.org/rpi/"