tazpanel rev 344

hardware.cgi: add mount / umount
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Feb 02 14:06:54 2013 +0100 (2013-02-02)
parents 2983cb632d9f
children d0818093bbc6
files hardware.cgi
line diff
     1.1 --- a/hardware.cgi	Sat Feb 02 12:18:44 2013 +0100
     1.2 +++ b/hardware.cgi	Sat Feb 02 14:06:54 2013 +0100
     1.3 @@ -12,6 +12,26 @@
     1.4  
     1.5  TITLE=$(gettext 'TazPanel - Hardware')
     1.6  
     1.7 +ktoh()
     1.8 +{
     1.9 +	k=$1
    1.10 +	if [ $k -lt 1024 ]; then
    1.11 +		echo ${k}K
    1.12 +		return
    1.13 +	fi
    1.14 +	k=$((($k+512)/1024))
    1.15 +	if [ $k -lt 1024 ]; then
    1.16 +		echo ${k}M
    1.17 +		return
    1.18 +	fi
    1.19 +	k=$((($k+512)/1024))
    1.20 +	if [ $k -lt 1024 ]; then
    1.21 +		echo ${k}G
    1.22 +		return
    1.23 +	fi
    1.24 +	k=$((($k+512)/1024))
    1.25 +	echo ${k}T
    1.26 +}
    1.27  #
    1.28  # Commands
    1.29  #
    1.30 @@ -209,7 +229,17 @@
    1.31  		#
    1.32  		# Disk stats and management (mount, umount, check)
    1.33  		#
    1.34 +		device=$(GET device)
    1.35 +		case "$device" in
    1.36 +		*[\;\`\&\|\$]*) ;;
    1.37 +		mount\ *)
    1.38 +			$device $(GET mountpoint);;
    1.39 +		umount\ *|swapon\ *|swapoff\ *)
    1.40 +			$device ;;
    1.41 +		esac
    1.42  		cat << EOT
    1.43 +<a name="mount">
    1.44 +<form method="get" action="$SCRIPT_NAME#mount">
    1.45  <table class="zebra outbox">
    1.46  EOT
    1.47  		df_thead
    1.48 @@ -224,11 +254,25 @@
    1.49  			av=$4
    1.50  			pct=$5
    1.51  			mp=$6
    1.52 +			action="mount"
    1.53 +			[ -n "$mp" ] && action="umount"
    1.54 +			type=$(blkid $fs | sed '/TYPE=/!d;s/.*TYPE="\([^"]*\).*/\1/')
    1.55 +			[ "$type" == "swap" ] && action="swapon"
    1.56 +			if grep -q "^$fs " /proc/swaps; then
    1.57 +				action="swapoff"
    1.58 +				set -- $(grep "^$fs " /proc/swaps)
    1.59 +				size=$(ktoh $3)
    1.60 +				used=$(ktoh $4)
    1.61 +				av=$(ktoh $(($3-$4)))
    1.62 +				pct=$(((100*$4)/$3))%
    1.63 +				mp=swap
    1.64 +			fi
    1.65  			cat << EOT
    1.66  <tr>
    1.67 -	<td><img src="$IMAGES/harddisk.png" />${fs#/dev/}</td>
    1.68 +	<td><input type="radio" name="device" value="$action $fs" />
    1.69 +	    <img src="$IMAGES/harddisk.png" />${fs#/dev/}</td>
    1.70  	<td>$(blkid $fs | sed '/LABEL=/!d;s/.*LABEL="\([^"]*\).*/\1/')</td>
    1.71 -	<td>$(blkid $fs | sed '/TYPE=/!d;s/.*TYPE="\([^"]*\).*/\1/')</td>
    1.72 +	<td>$type</td>
    1.73  	<td>$size</td>
    1.74  	<td>$av</td>
    1.75  EOT
    1.76 @@ -246,13 +290,16 @@
    1.77  		fi
    1.78  		cat << EOT
    1.79  	<td>$mp</td>
    1.80 +	<td>$(blkid $fs | sed '/UUID=/!d;s/.*UUID="\([^"]*\).*/\1/')</td>
    1.81  </tr>
    1.82  EOT
    1.83  		done
    1.84  		cat << EOT
    1.85  </tbody>
    1.86  </table>
    1.87 -
    1.88 +<input type="submit" value="mount / umount" /> -
    1.89 +new mount point <input type=text" name="mountpoint" value="/media/usbdisk" />
    1.90 +</form>
    1.91  EOT
    1.92  
    1.93