tazpanel rev 363

hardware.cgi: display lspci and lsusb as table, with separate page for every item
author Aleksej Bobylev <al.bobylev@gmail.com>
date Sun Jun 23 16:55:26 2013 +0300 (2013-06-23)
parents 8ec43100e75e
children 4a8f56bb08cb
files hardware.cgi lib/libtazpanel styles/default/style.css
line diff
     1.1 --- a/hardware.cgi	Wed Jun 12 20:38:55 2013 +0000
     1.2 +++ b/hardware.cgi	Sun Jun 23 16:55:26 2013 +0300
     1.3 @@ -16,22 +16,52 @@
     1.4  {
     1.5  	k=$1
     1.6  	if [ $k -lt 1024 ]; then
     1.7 -		echo ${k}K
     1.8 +		eval_gettext '${k}K'
     1.9  		return
    1.10  	fi
    1.11  	k=$((($k+512)/1024))
    1.12  	if [ $k -lt 1024 ]; then
    1.13 -		echo ${k}M
    1.14 +		eval_gettext '${k}M'
    1.15  		return
    1.16  	fi
    1.17  	k=$((($k+512)/1024))
    1.18  	if [ $k -lt 1024 ]; then
    1.19 -		echo ${k}G
    1.20 +		eval_gettext '${k}G'
    1.21  		return
    1.22  	fi
    1.23  	k=$((($k+512)/1024))
    1.24 -	echo ${k}T
    1.25 +	eval_gettext '${k}T'
    1.26  }
    1.27 +
    1.28 +lsusb_table()
    1.29 +{
    1.30 +	cat << EOT
    1.31 +<table class="zebra outbox">
    1.32 +<thead><tr><td>Bus</td><td>Device</td><td>ID</td><td>Name</td></thead>
    1.33 +<tbody>
    1.34 +EOT
    1.35 +	lsusb | sed 's|^Bus \([0-9]*\)|<tr><td>\1</td>|;
    1.36 +			s|</td> Device \([0-9]*\):|</td><td>\1</td>|;
    1.37 +			s|</td> ID \([^:]*:[^ ]*\)|</td><td><a href="?lsusb=\1">\1</a></td>|;
    1.38 +			s| |<td>|2;
    1.39 +			s|.*$|\0</td></tr>|'
    1.40 +	echo "</tbody></table>"
    1.41 +}
    1.42 +
    1.43 +lspci_table()
    1.44 +{
    1.45 +	cat << EOT
    1.46 +<table class="zebra outbox">
    1.47 +<thead><tr><td>Slot</td><td>Device</td><td>Name</td></thead>
    1.48 +<tbody>
    1.49 +EOT
    1.50 +	lspci | sed 's| |</td><td>|;
    1.51 +			s|: |</td><td>|;
    1.52 +			s|^\([^<]*\)|<a href="?lspci=\1">\1</a>|;
    1.53 +			s|^.*$|<tr><td>\0</td></tr>|'
    1.54 +	echo "</tbody></table>"
    1.55 +}
    1.56 +
    1.57  #
    1.58  # Commands
    1.59  #
    1.60 @@ -119,6 +149,34 @@
    1.61  EOT
    1.62  		done
    1.63  		table_end ;;
    1.64 +	*\ lsusb\ *)
    1.65 +		xhtml_header
    1.66 +		vidpid="$(GET lsusb)"
    1.67 +		cat << EOT
    1.68 +<div id="wrapper">
    1.69 +	<h2>$(eval_gettext 'Information for USB Device $vidpid')</h2>
    1.70 +	<p>$(gettext 'Detailed information about specified device.')</p>
    1.71 +EOT
    1.72 +		lsusb_table
    1.73 +		cat << EOT
    1.74 +</div>
    1.75 +<pre>$(lsusb -vd $vidpid | syntax_highlighter lsusb)</pre>
    1.76 +EOT
    1.77 +		;;
    1.78 +	*\ lspci\ *)
    1.79 +		xhtml_header
    1.80 +		slot="$(GET lspci)"
    1.81 +		cat << EOT
    1.82 +<div id="wrapper">
    1.83 +	<h2>$(eval_gettext 'Information for PCI Device $slot')</h2>
    1.84 +	<p>$(gettext 'Detailed information about specified device.')</p>
    1.85 +EOT
    1.86 +		lspci_table
    1.87 +		cat << EOT
    1.88 +</div>
    1.89 +<pre>$(lspci -vs $slot | syntax_highlighter lspci)</pre>
    1.90 +EOT
    1.91 +		;;
    1.92  	*)
    1.93  		[ -n "$(GET brightness)" ] &&
    1.94  		echo -n $(GET brightness) > /sys/devices/virtual/backlight/$(GET dev)/brightness
    1.95 @@ -139,7 +197,6 @@
    1.96  		<img src="$IMAGES/monitor.png" />$(gettext 'Detect PCI/USB')</a>
    1.97  </div>
    1.98  
    1.99 -<div id="wrapper">
   1.100  EOT
   1.101  		if [ -n "$(ls /proc/acpi/battery/*/info 2> /dev/null)" ]; then
   1.102  			echo "<table>"
   1.103 @@ -217,14 +274,14 @@
   1.104  EOT
   1.105  		fi
   1.106  		cat << EOT
   1.107 -</div>
   1.108  
   1.109 -<a name="disk">
   1.110 -<h3>$(gettext 'Filesystem usage statistics')</h3>
   1.111 +
   1.112 +<h3 id="disk">$(gettext 'Filesystem usage statistics')</h3>
   1.113 +
   1.114  <pre>
   1.115 +$(fdisk -l | fgrep Disk)
   1.116 +</pre>
   1.117  EOT
   1.118 -		fdisk -l | fgrep Disk
   1.119 -		echo '</pre>'
   1.120  
   1.121  
   1.122  		#
   1.123 @@ -239,9 +296,8 @@
   1.124  			$device ;;
   1.125  		esac
   1.126  		cat << EOT
   1.127 -<a name="mount">
   1.128  <form method="get" action="$SCRIPT_NAME#mount">
   1.129 -<table class="zebra outbox">
   1.130 +<table id="mount" class="zebra outbox nowrap">
   1.131  EOT
   1.132  		df_thead
   1.133  		echo '<tbody>'
   1.134 @@ -286,7 +342,7 @@
   1.135  EOT
   1.136  		else
   1.137  			cat << EOT
   1.138 -	<td></td>
   1.139 +	<td> </td>
   1.140  EOT
   1.141  		fi
   1.142  		cat << EOT
   1.143 @@ -301,38 +357,43 @@
   1.144  <input type="submit" value="mount / umount" /> -
   1.145  new mount point <input type=text" name="mountpoint" value="/media/usbdisk" />
   1.146  </form>
   1.147 +
   1.148 +
   1.149  <h3>$(gettext 'Filesystems table')</h3>
   1.150 -<pre>
   1.151 -$(grep -v ^# /etc/fstab | syntax_highlighter conf)
   1.152 -</pre>
   1.153 +EOT
   1.154 +
   1.155 +grep -v '^#' /etc/fstab | awk 'BEGIN{print "<table class=\"zebra outbox\">\
   1.156 +	<thead><tr><td>spec</td><td>file</td><td>vfstype</td><td>mntops</td><td>\
   1.157 +	freq</td><td>passno</td></thead><tbody>"}{print "<tr><td>"$1"</td><td>"$2\
   1.158 +	"</td><td>"$3"</td><td>"$4"</td><td>"$5"</td><td>"$6"</td></tr>"}
   1.159 +	END{print "</tbody></table>"}'
   1.160 +
   1.161 +		cat << EOT
   1.162  <a class="button" href="index.cgi?file=/etc/fstab&action=edit">
   1.163  	<img src="$IMAGES/edit.png" />$(gettext 'Manual Edit')</a>
   1.164 +
   1.165 +
   1.166 +<h3>$(gettext 'System memory')</h3>
   1.167  EOT
   1.168  
   1.169 +echo "<table class=\"zebra outbox\"><thead><tr><td>&nbsp;</td><td>total</td>\
   1.170 +<td>used</td><td>free</td><td>shared</td><td>buffers</td></tr></thead><tbody>"
   1.171 +freem=$(free -m)
   1.172 +echo "$freem" | grep Mem: | awk '{print "<tr><td>"$1"</td><td>"$2"</td><td>"$3\
   1.173 +	"</td><td>"$4"</td><td>"$5"</td><td>"$6"</td></tr>"}'
   1.174 +echo "$freem" | grep buffers: | awk '{print "<tr><td>"$1 $2"</td><td>&nbsp;</td>\
   1.175 +	<td>"$3"</td><td>"$4"</td><td>&nbsp;</td><td>&nbsp;</td></tr>"}'
   1.176 +echo "$freem" | grep Swap: | awk '{print "<tr><td>"$1"</td><td>"$2"</td><td>"$3\
   1.177 +	"</td><td>"$4"</td><td>&nbsp;</td><td>&nbsp;</td></tr></tbody></table>"}'
   1.178  
   1.179  		cat << EOT
   1.180 -<h3>$(gettext 'System memory')</h3>
   1.181 -<pre>
   1.182 -EOT
   1.183 -		free -m | sed \
   1.184 -			-e s"#total.*\([^']\)#<span class='top'>\0</span>#"g \
   1.185 -			-e s"#^[A-Z-].*:\([^']\)#<span class='sh-comment'>\0</span>#"g
   1.186 -		cat << EOT
   1.187 -</pre>
   1.188 -
   1.189  <h3>lspci</h3>
   1.190 -<pre>
   1.191 -EOT
   1.192 -			lspci -k | sed \
   1.193 -			 -e s"#^[0-9].*\([^']\)#<span class='diff-at'>\0</span>#" \
   1.194 -			 -e s"#use: \(.*\)#use: <span class='diff-rm'>\1</span>#"
   1.195 -		cat << EOT
   1.196 -</pre>
   1.197 +$(lspci_table)
   1.198  
   1.199  <h3>lsusb</h3>
   1.200 -<pre>$(lsusb)</pre>
   1.201 +$(lsusb_table)
   1.202  EOT
   1.203 -		;;
   1.204 +			;;
   1.205  esac
   1.206  
   1.207  xhtml_footer
     2.1 --- a/lib/libtazpanel	Wed Jun 12 20:38:55 2013 +0000
     2.2 +++ b/lib/libtazpanel	Sun Jun 23 16:55:26 2013 +0300
     2.3 @@ -56,6 +56,14 @@
     2.4  				-e "s|\([^0-9]\)\(0x[0-9a-f]\+\)|\1<span class='kernel-hex'>\2</span>|g" \
     2.5  				-e "s|^\([^(,\[]\+: \)|<span class='kernel-id'>\0</span>|g" \
     2.6  				-e "s|\(\[[^ ]\+\]\)|<span class='kernel-id2'>\0</span>|g" ;;
     2.7 +		lsusb)
     2.8 +			htmlize | sed \
     2.9 +				-e 's|^[^:]*:[ x0-9a-f^:]*$|<span class="lsusb-t">\0</span>|g' \
    2.10 +				-e 's|^Bus.*$|<span class="lsusb-h">\0</span>|g' ;;
    2.11 +		lspci)
    2.12 +			htmlize | sed \
    2.13 +				-e 's|^[0-9a-f].*$|<span class="lspci-t">\0</span>|g' \
    2.14 +				-e 's|^	\([^:]*:\)|	<span class="lspci-h">\1</span>|g' ;;
    2.15  
    2.16  	esac
    2.17  }
     3.1 --- a/styles/default/style.css	Wed Jun 12 20:38:55 2013 +0000
     3.2 +++ b/styles/default/style.css	Sun Jun 23 16:55:26 2013 +0300
     3.3 @@ -291,6 +291,8 @@
     3.4  span.kernel-hex { color: #18A423; }
     3.5  span.kernel-id { color: #287FC7; }
     3.6  span.kernel-id2 { color: #843523; }
     3.7 +span.lsusb-h, span.lspci-h { color: #800; font-weight: bold; }
     3.8 +span.lsusb-t, span.lspci-t { color: #448; font-weight: bold; }
     3.9  
    3.10  /* Misc */
    3.11