tazpanel diff powersaving.cgi @ rev 501

*.cgi: Implement TazPanel title and sub-title; hardware.cgi: fix and improve modules search; index.cgi: complex code using awk was prevented 'make pot' to collect all messages, fix terminal history removing; tazpanel.js: disable buttons when no packages selected (pkgs.cgi: up / search / category lists); network.cgi: complex comment was prevented 'make pot' to collect all messages; powersaving.cgi: starting development; *.po: rebuild; tazpanel.ttf: add messages icons, so remove all the style/png images and change libtazpanel; *.css: title and sub-title, messages icons; test.cgi: add new icons.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Mon Jun 08 04:32:19 2015 +0300 (2015-06-08)
parents
children d7b7403d5f2a
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/powersaving.cgi	Mon Jun 08 04:32:19 2015 +0300
     1.3 @@ -0,0 +1,168 @@
     1.4 +#!/bin/sh
     1.5 +#
     1.6 +# Hardware / power saving
     1.7 +#
     1.8 +# Copyright (C) 2011-2015 SliTaz GNU/Linux - BSD License
     1.9 +#
    1.10 +
    1.11 +# Common functions from libtazpanel
    1.12 +. lib/libtazpanel
    1.13 +get_config
    1.14 +header
    1.15 +
    1.16 +TITLE=$(_ 'Hardware')
    1.17 +
    1.18 +xhtml_header "$(_ 'Power saving')"
    1.19 +
    1.20 +## DPMS ##
    1.21 +cat <<EOT
    1.22 +<section>
    1.23 +	<header>
    1.24 +		<span data-icon="display">DPMS (Display Power Management Signaling)</span>
    1.25 +	</header>
    1.26 +
    1.27 +	<div>$(_ "DPMS enables power saving behaviour of monitors when the computer is not in use.")</div>
    1.28 +	<form method="post" class="wide">
    1.29 +		<input type="hidden" name="powersaving" value="set"/>
    1.30 +EOT
    1.31 +
    1.32 +monitor_conf='/etc/X11/xorg.conf.d/50-Monitor.conf'
    1.33 +if [ ! -s "$monitor_conf" ]; then
    1.34 +	# Config is absent, so create it
    1.35 +	cat > "$monitor_conf" <<EOT
    1.36 +Section "Monitor"
    1.37 +	Identifier   "Monitor0"
    1.38 +	VendorName   "Monitor Vendor"
    1.39 +	ModelName    "Monitor Model"
    1.40 +	Option "DPMS" "true"
    1.41 +EndSection
    1.42 +EOT
    1.43 +fi
    1.44 +
    1.45 +cat <<EOT
    1.46 +		<table class="wide zebra">
    1.47 +			<thead>
    1.48 +				<tr><td>$(_ 'Identifier')</td>
    1.49 +					<td>$(_ 'Vendor name')</td>
    1.50 +					<td>$(_ 'Model name')</td>
    1.51 +					<td>$(_ 'DPMS enabled')</td>
    1.52 +				</tr>
    1.53 +			</thead>
    1.54 +EOT
    1.55 +
    1.56 +awk -F\" '{
    1.57 +	if ($1 ~ /^Section/) { I = V = M = D = ""; }
    1.58 +	if ($1 ~ /Identifier/) { I = $2; }
    1.59 +	if ($1 ~ /VendorName/) { V = $2; }
    1.60 +	if ($1 ~ /ModelName/)  { M = $2; }
    1.61 +	if ($1 ~ /Option/ && $2 ~ /DPMS/) { D = $4; }
    1.62 +	if ($1 ~ /EndSection/) {
    1.63 +		if (D == "false") { D = ""; } else { D = "checked"; }
    1.64 +		printf "<tr><td data-icon=\"display\">%s</td><td>%s</td><td>%s</td><td>", I, V, M;
    1.65 +		printf "<label><input type=\"checkbox\" name=\"%s\" %s/>DPMS</label>", I, D;
    1.66 +		printf "</td></tr>\n";
    1.67 +	}
    1.68 +}' $monitor_conf
    1.69 +
    1.70 +layout_conf='/etc/X11/xorg.conf.d/10-ServerLayout.conf'
    1.71 +
    1.72 +cat <<EOT
    1.73 +		</table>
    1.74 +		<input type="hidden" name="ids" value="$(
    1.75 +			awk -F\" '$1 ~ /Identifier/ { printf "%s ", $2; }' $monitor_conf)"/>
    1.76 +
    1.77 +		<table>
    1.78 +			<tr><td>
    1.79 +					<fieldset>
    1.80 +						<legend>$(_ 'DPMS times (in minutes):')</legend>
    1.81 +						<table>
    1.82 +							<tr><td>Standby Time</td>
    1.83 +								<td><input type="number" name="StandbyTime" value="10"/></td></tr>
    1.84 +							<tr><td>Suspend Time</td>
    1.85 +								<td><input type="number" name="SuspendTime" value="20"/></td></tr>
    1.86 +							<tr><td>Off Time</td>
    1.87 +								<td><input type="number" name="OffTime"     value="30"/></td></tr>
    1.88 +						</table>
    1.89 +					</fieldset>
    1.90 +				</td>
    1.91 +				<td style="vertical-align: top">
    1.92 +					<fieldset>
    1.93 +						<legend>$(_ 'Manual edit')</legend>
    1.94 +						<a data-icon="conf" href="index.cgi?file=$monitor_conf">$(basename $monitor_conf)</a><br/>
    1.95 +						<a data-icon="conf" href="index.cgi?file=$layout_conf">$(basename $layout_conf)</a>
    1.96 +					</fieldset>
    1.97 +					<pre>$(for i in $(POST); do echo "$i: " $(POST $i); done)</pre>
    1.98 +				</td>
    1.99 +			</tr>
   1.100 +		</table>
   1.101 +		<footer>
   1.102 +			<button type="submit" data-icon="ok">$(_ 'Change')</button>
   1.103 +		</footer>
   1.104 +	</form>
   1.105 +</section>
   1.106 +EOT
   1.107 +
   1.108 +
   1.109 +## CPU ##
   1.110 +
   1.111 +cpu=$(awk -F: '$1 ~ "model name" {
   1.112 +	gsub(/\(TM\)/,"™",$2); gsub(/\(R\)/,"®",$2);
   1.113 +	split($2,c,"@");
   1.114 +	print "<span data-icon=\"cpu\">" c[1] "</span>";
   1.115 +}' /proc/cpuinfo)
   1.116 +multiplier=$(echo "$cpu" | wc -l)
   1.117 +[ "$multiplier" -ne 1 ] && cpu="$multiplier × $(echo "$cpu" | head -n1)"
   1.118 +
   1.119 +freq=$(awk -F: 'BEGIN{N=0}$1~"MHz"{printf "%d:<b>%s</b>MHz ",N,$2; N++}' /proc/cpuinfo)
   1.120 +
   1.121 +cat <<EOT
   1.122 +<section>
   1.123 +	<header><span data-icon="cpu">$(_ 'CPU')</span></header>
   1.124 +
   1.125 +	<div>$(_ "CPU frequency scaling enables the operating system to scale the \
   1.126 +CPU frequency up or down in order to save power. CPU frequencies can be scaled \
   1.127 +automatically depending on the system load, in responce to ACPI events, or \
   1.128 +manually by userspace programs.")</div>
   1.129 +
   1.130 +	<table class="wide zebra">
   1.131 +		<tr><td>$(_ 'Model name')</td><td>$cpu</td></tr>
   1.132 +		<tr><td>$(_ 'Current frequency')</td><td>$freq</td></tr>
   1.133 +		<tr><td>$(_ 'Current driver')</td><td>$(cat '/sys/devices/system/cpu/cpu0/cpufreq/scaling_driver')
   1.134 +		<tr><td>$(_ 'Current governor')</td><td>$(cat '/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor')
   1.135 +	</table>
   1.136 +</section>
   1.137 +EOT
   1.138 +
   1.139 +# As of Kernel 3.4, the native CPU module is loaded automatically.
   1.140 +if [ -d "/lib/modules/$(uname -r)/kernel/drivers/cpufreq" ]; then
   1.141 +	cd /lib/modules/$(uname -r)/kernel/drivers/cpufreq
   1.142 +	cat <<EOT
   1.143 +<section>
   1.144 +	<header>$(_ 'Kernel modules')</header>
   1.145 +	<table class="wide zebra summary">
   1.146 +		<thead>
   1.147 +			<tr><td>$(_ 'Module')</td>
   1.148 +				<td>$(_ 'Description')</td>
   1.149 +			</tr>
   1.150 +		</thead>
   1.151 +EOT
   1.152 +	lsmod="$(lsmod | awk '{printf "%s " $1}') "
   1.153 +
   1.154 +	for module in $(ls | grep -v 'mperf\|speedstep-lib'); do
   1.155 +		module="${module%.ko.xz}"; module="${module//-/_}"
   1.156 +		if echo $lsmod | grep -q " $module "; then icon='ok'; else icon='cancel'; fi
   1.157 +		echo "<tr><td><span data-icon=\"$icon\">$module</span></td><td>"
   1.158 +		modinfo $module | awk -F: '$1=="description"{
   1.159 +			gsub(/\(TM\)/,"™",$2); gsub(/\(R\)/,"®",$2);
   1.160 +			gsub(/VIA|C7|Cyrix|MediaGX|NatSemi|Geode|Transmeta|Crusoe|Efficeon|Pentium™ 4|Xeon™|AMD|K6-2\+|K6-3\+|K7|Athlon 64|Opteron|Intel/,"<b>&</b>",$2);
   1.161 +			print $2}'
   1.162 +		echo "</td></tr>"
   1.163 +	done
   1.164 +	cat <<EOT
   1.165 +	</table>
   1.166 +</section>
   1.167 +EOT
   1.168 +fi
   1.169 +
   1.170 +xhtml_footer
   1.171 +exit 0