tazpanel diff hardware.cgi @ rev 309

libtazpanel: fix httpdhelper path
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri May 11 18:03:45 2012 +0200 (2012-05-11)
parents 72e9955ebdff
children 3e9acc16f728
line diff
     1.1 --- a/hardware.cgi	Wed Apr 11 20:12:41 2012 +0300
     1.2 +++ b/hardware.cgi	Fri May 11 18:03:45 2012 +0200
     1.3 @@ -18,73 +18,72 @@
     1.4  
     1.5  case " $(GET) " in
     1.6  	*\ print\ *)
     1.7 -		echo "TODO" ;;
     1.8 +		xhtml_header
     1.9 +		echo "<h2>TODO</h2>" ;;
    1.10  	*\ detect\ *)
    1.11  		# Front end for Tazhw
    1.12  		# TODO: Add button to detect webcam, etc. Like in tazhw box.
    1.13  		xhtml_header
    1.14 -				cat << EOT
    1.15 +		cat << EOT
    1.16  <div id="wrapper">
    1.17 -	<h2>$(gettext "Detect hardware")</h2>
    1.18 -	<p>$(gettext "Detect PCI and USB hardware")</p>
    1.19 +	<h2>$(gettext 'Detect hardware')</h2>
    1.20 +	<p>$(gettext 'Detect PCI and USB hardware')</p>
    1.21  </div>
    1.22 +
    1.23 +<pre>$(tazhw detect-pci | syntax_highlighter sh)</pre>
    1.24 +
    1.25 +<pre>$(tazhw detect-usb | syntax_highlighter sh)</pre>
    1.26  EOT
    1.27 -		echo '<pre>'
    1.28 -		tazhw detect-pci
    1.29 -		echo '</pre>'
    1.30 -		echo '<pre>'
    1.31 -		tazhw detect-usb
    1.32 -		echo '</pre>' ;;
    1.33 +		;;
    1.34  	*\ modules\ *|*\ modinfo\ *)
    1.35  		xhtml_header
    1.36  		cat << EOT
    1.37  <div id="wrapper">
    1.38 -	<h2>`gettext "Kernel modules"`</h2>
    1.39 -<div class="float-right">
    1.40 -	<form method="get" action="$SCRIPT_NAME">
    1.41 -		<input type="hidden" name="modules" />
    1.42 -		<input type="text" name="search" />
    1.43 -	</form>
    1.44 -</div>
    1.45 -	<p>$(gettext "Manage, search or get information about the Linux kernel modules")</p>
    1.46 +	<h2>$(gettext 'Kernel modules')</h2>
    1.47 +	<div class="float-right">
    1.48 +		<form method="get" action="$SCRIPT_NAME">
    1.49 +			<input type="hidden" name="modules" />
    1.50 +			<input type="search" placeholder="$(gettext 'Modules search')" name="search" />
    1.51 +		</form>
    1.52 +	</div>
    1.53 +	<p>$(gettext 'Manage, search or get information about the Linux kernel modules')</p>
    1.54  </div>
    1.55  EOT
    1.56  		# Request may be modinfo output that we want in the page itself
    1.57 -		if [ -n "$(GET modinfo)" ]; then
    1.58 -			echo '<strong>'
    1.59 -			gettext "Detailed information for module: "; echo "$(GET modinfo)"
    1.60 -			echo '</strong>'
    1.61 -			echo '<pre>'
    1.62 -			modinfo $(GET modinfo)
    1.63 -			echo '</pre>'
    1.64 +		get_modinfo="$(GET modinfo)"
    1.65 +		if [ -n "$get_modinfo" ]; then
    1.66 +			cat << EOT
    1.67 +<strong>$(eval_gettext 'Detailed information for module: $get_modinfo')</strong>
    1.68 +
    1.69 +<pre>$(modinfo $get_modinfo)</pre>
    1.70 +EOT
    1.71  		fi
    1.72  		if [ -n "$(GET modprobe)" ]; then
    1.73 -			echo '<pre>'
    1.74 -			modprobe -v $(GET modprobe)
    1.75 -			echo '</pre>'
    1.76 +			echo "<pre>$(modprobe -v $(GET modprobe))</pre>"
    1.77  		fi
    1.78  		if [ -n "$(GET rmmod)" ]; then
    1.79  			echo "Removing"
    1.80  			rmmod -w $(GET rmmod)
    1.81  		fi
    1.82 -		if [ -n "$(GET search)" ]; then
    1.83 -			gettext "Matching result(s) for: "; echo "$(GET search)"
    1.84 +		get_search="$(GET search)"
    1.85 +		if [ -n "$get_search" ]; then
    1.86 +			eval_gettext 'Matching result(s) for: $get_search'
    1.87  			echo '<pre>'
    1.88  			modprobe -l | grep "$(GET search)" | while read line
    1.89  			do
    1.90  				name=$(basename $line)
    1.91  				mod=${name%.ko.gz}
    1.92 -				echo "Module    : <a href='$SCRIPT_NAME?modinfo=$mod'>$mod</a> "
    1.93 +				echo "$(gettext 'Module:') <a href='$SCRIPT_NAME?modinfo=$mod'>$mod</a>"
    1.94  			done
    1.95  			echo '</pre>'
    1.96  		fi
    1.97  		cat << EOT
    1.98 -	`table_start`
    1.99 +	$(table_start)
   1.100  		<tr class="thead">
   1.101 -			<td>`gettext "Module"`</td>
   1.102 -			<td>`gettext "Size"`</td>
   1.103 -			<td>`gettext "Used"`</td>
   1.104 -			<td>`gettext "by"`</td>
   1.105 +			<td>$(gettext 'Module')</td>
   1.106 +			<td>$(gettext 'Size')</td>
   1.107 +			<td>$(gettext 'Used')</td>
   1.108 +			<td>$(gettext 'by')</td>
   1.109  		</tr>
   1.110  EOT
   1.111  		# Get the list of modules and link to modinfo
   1.112 @@ -95,7 +94,7 @@
   1.113  			<td><a href="$SCRIPT_NAME?modinfo=$MOD">$MOD</a></td>
   1.114  			<td>$SIZE</td>
   1.115  			<td>$USED</td>
   1.116 -			<td>`echo $BY | sed s/","/" "/g`</td>
   1.117 +			<td>$(echo $BY | sed s/","/" "/g)</td>
   1.118  		</tr>
   1.119  EOT
   1.120  		done
   1.121 @@ -110,14 +109,14 @@
   1.122  		xhtml_header
   1.123  		cat << EOT
   1.124  <div id="wrapper">
   1.125 -	<h2>`gettext "Drivers &amp; Devices"`</h2>
   1.126 -	<p>`gettext "Manage your computer hardware`</p>
   1.127 +	<h2>$(gettext 'Drivers &amp; Devices')</h2>
   1.128 +	<p>$(gettext 'Manage your computer hardware')</p>
   1.129  </div>
   1.130  <div>
   1.131  	<a class="button" href="$SCRIPT_NAME?modules">
   1.132 -		<img src="$IMAGES/tux.png" />Kernel modules</a>
   1.133 +		<img src="$IMAGES/tux.png" />$(gettext 'Kernel modules')</a>
   1.134  	<a class="button" href="$SCRIPT_NAME?detect">
   1.135 -		<img src="$IMAGES/monitor.png" />Detect PCI/USB</a>
   1.136 +		<img src="$IMAGES/monitor.png" />$(gettext 'Detect PCI/USB')</a>
   1.137  </div>
   1.138  
   1.139  <div id="wrapper">
   1.140 @@ -130,36 +129,46 @@
   1.141  				remain=$(sed '/remaining capacity/!d;s/[^0-9]*\([0-9]*\).*/\1/' < $dev/state)
   1.142  				rate=$(sed '/present rate/!d;s/[^0-9]*\([0-9]*\).*/\1/' < $dev/state)
   1.143  				full=$(sed '/last full capacity/!d;s/[^0-9]*\([0-9]*\).*/\1/' < $dev/info)
   1.144 -				# FIXME
   1.145 -				#remtime=$(( ($remain * 60) / $rate ))
   1.146 -				#rempct=$(( ($remain * 100) / $full ))
   1.147 +				warning=$(sed '/design capacity warning/!d;s/[^0-9]*\([0-9]*\).*/\1/' < $dev/info)
   1.148 +				low=$(sed '/design capacity low/!d;s/[^0-9]*\([0-9]*\).*/\1/' < $dev/info)
   1.149 +				state=$(sed '/charging state/!d;s/\([^:]*:[ ]\+\)\([a-z]\+\)/\2/' < $dev/state)
   1.150 +
   1.151 +				rempct=$(( $remain * 100 / $full ))
   1.152  				cat << EOT
   1.153  <tr>
   1.154  	<td><img src="$IMAGES/battery.png" />
   1.155 -		Battery $(grep "^battery type" $dev/info | sed 's/.*: *//')
   1.156 +		$(gettext 'Battery') $(grep "^battery type" $dev/info | sed 's/.*: *//')
   1.157  		$(grep "^design capacity:" $dev/info | sed 's/.*: *//') </td>
   1.158 -	<td>health  $(( (100*$full)/$design))%</td>
   1.159 +	<td>$(gettext 'health') $(( (100*$full)/$design))%</td>
   1.160 +	<td class="meter"><meter min="0" max="$full" value="$remain" low="$low"
   1.161 +		high="$warning" optimum="$full"></meter>
   1.162 +		<span>
   1.163  EOT
   1.164 -				if grep -qis discharging $dev/state; then
   1.165 -					cat <<EOT
   1.166 -	<td class="pct"><div class="pct"
   1.167 -		style="width: $rempct%;">charge&nbsp;$rempct%&nbsp;-&nbsp;$(printf "%d:%02d" $(($remtime/60)) $(($remtime%60)))</div></td>
   1.168 -EOT
   1.169 -				else
   1.170 -					cat <<EOT
   1.171 -	<td class="pct"><div class="pct"
   1.172 -		style="width: $rempct%;">recharging&nbsp;$rempct%</div></td>
   1.173 -EOT
   1.174 -				fi
   1.175 +				case "$state" in
   1.176 +				"discharging")
   1.177 +					remtime=$(( $remain * 60 / $rate ))
   1.178 +					remtimef=$(printf "%d:%02d" $(($remtime/60)) $(($remtime%60)))
   1.179 +					eval_gettext 'Discharging $rempct% - $remtimef' ;;
   1.180 +				"charging")
   1.181 +					remtime=$(( ($full - $remain) * 60 / $rate ))
   1.182 +					remtimef=$(printf "%d:%02d" $(($remtime/60)) $(($remtime%60)))
   1.183 +					eval_gettext 'Charging $rempct% - $remtimef' ;;
   1.184 +				"charged")
   1.185 +					gettext 'Charged 100%' ;;
   1.186 +				esac
   1.187 +				echo '</span></td></tr>'
   1.188  			done
   1.189  			echo "</table>"
   1.190  		fi
   1.191 +
   1.192  		if [ -n "$(ls /sys/devices/virtual/thermal/*/temp 2> /dev/null)" ]; then
   1.193 -			echo "Temperature: "
   1.194 +			echo -n '<p>'; gettext 'Temperature:'
   1.195  			for temp in /sys/devices/virtual/thermal/*/temp; do
   1.196  				awk '{ print $1/1000 }' < $temp
   1.197  			done
   1.198 +			echo '</p>'
   1.199  		fi
   1.200 +
   1.201  		if [ -n "$(ls /sys/devices/virtual/backlight/*/brightness 2> /dev/null)" ]; then
   1.202  			cat <<EOT
   1.203  <form method="get" action="$SCRIPT_NAME">
   1.204 @@ -168,7 +177,7 @@
   1.205  				name=$(echo $dev | sed 's|.*/backlight/\([^/]*\).*|\1|')
   1.206  				cat <<EOT
   1.207  <input type="hidden" name="dev" value="$name" />
   1.208 -$(gettext "Brightness") \
   1.209 +$(gettext 'Brightness') \
   1.210  $(sed 's/.*\.//;s/_*$//' < /sys/devices/virtual/backlight/$name/device/path):
   1.211  <select name="brightness" onchange="submit();">
   1.212  EOT
   1.213 @@ -190,46 +199,67 @@
   1.214  		cat << EOT
   1.215  </div>
   1.216  
   1.217 -<h3>$(gettext "Filesystem usage statistics")</h3>
   1.218 +<h3>$(gettext 'Filesystem usage statistics')</h3>
   1.219  <pre>
   1.220  EOT
   1.221  		fdisk -l | fgrep Disk
   1.222  		echo '</pre>'
   1.223 +
   1.224 +
   1.225  		#
   1.226 -		# Disk stats and management (mount, umount, heck)
   1.227 +		# Disk stats and management (mount, umount, check)
   1.228  		#
   1.229 -		table_start
   1.230 +		cat << EOT
   1.231 +<table class="zebra">
   1.232 +EOT
   1.233  		df_thead
   1.234 +		echo '<tbody>'
   1.235  		df -h | grep ^/dev | while read fs size used av pct mp
   1.236  		do
   1.237  				cat << EOT
   1.238  <tr>
   1.239  	<td><img src="$IMAGES/harddisk.png" />${fs#/dev/}</td>
   1.240 +	<td>$(blkid -o value $fs | head -n1)</td>
   1.241 +	<td>$(blkid -o value $fs | tail -n1)</td>
   1.242  	<td>$size</td>
   1.243  	<td>$av</td>
   1.244 -	<td class="pct"><div class="pct"
   1.245 -		style="width: $pct;">$used&nbsp;-&nbsp;$pct</div></td>
   1.246 +	<td class="meter"><meter min="0" max="100" value="${pct%%%}" low="70"
   1.247 +	high="90" optimum="10"></meter>
   1.248 +		<span>$used - $pct</span>
   1.249 +	</td>
   1.250  	<td>$mp</td>
   1.251  </tr>
   1.252  EOT
   1.253  		done
   1.254 -		table_end
   1.255 -		echo "<h3>$(gettext "System memory")</h3>"
   1.256 -		echo '<pre>'
   1.257 +		cat << EOT
   1.258 +</tbody>
   1.259 +</table>
   1.260 +
   1.261 +EOT
   1.262 +
   1.263 +
   1.264 +		cat << EOT
   1.265 +<h3>$(gettext 'System memory')</h3>
   1.266 +<pre>
   1.267 +EOT
   1.268  		free -m | sed \
   1.269  			-e s"#total.*\([^']\)#<span class='top'>\0</span>#"g \
   1.270  			-e s"#^[A-Z-].*:\([^']\)#<span class='sh-comment'>\0</span>#"g
   1.271 -		echo '</pre>'
   1.272 -		echo '<h3>lspci</h3>'
   1.273 -		echo '<pre>'
   1.274 +		cat << EOT
   1.275 +</pre>
   1.276 +
   1.277 +<h3>lspci</h3>
   1.278 +<pre>
   1.279 +EOT
   1.280  			lspci -k | sed \
   1.281  			 -e s"#^[0-9].*\([^']\)#<span class='diff-at'>\0</span>#" \
   1.282  			 -e s"#use: \(.*\)#use: <span class='diff-rm'>\1</span>#"
   1.283 -		echo '</pre>'
   1.284 -		echo '<h3>lsusb</h3>'
   1.285 -		echo '<pre>'
   1.286 -			lsusb
   1.287 -		echo '</pre>'
   1.288 +		cat << EOT
   1.289 +</pre>
   1.290 +
   1.291 +<h3>lsusb</h3>
   1.292 +<pre>$(lsusb)</pre>
   1.293 +EOT
   1.294  		;;
   1.295  esac
   1.296