tazpanel diff tazpkg.cgi @ rev 10

Add configuration page in tazpkg.cgi
author Christophe Lincoln <pankso@slitaz.org>
date Sat Apr 02 21:32:50 2011 +0200 (2011-04-02)
parents dfcc3f322885
children 4c1174a446ee
line diff
     1.1 --- a/tazpkg.cgi	Sat Apr 02 17:35:09 2011 +0200
     1.2 +++ b/tazpkg.cgi	Sat Apr 02 21:32:50 2011 +0200
     1.3 @@ -24,7 +24,9 @@
     1.4  cat $HEADER | sed s'/%TITLE%/Tazpkg/'
     1.5  
     1.6  # DEBUG mode
     1.7 -[ $DEBUG == "1" ] && echo "<p class='debug'>$REQUEST_METHOD ${QUERY_STRING}</p>"
     1.8 +if [ $DEBUG == "1" ]; then
     1.9 +	echo "<p class='debug'>$REQUEST_METHOD ${QUERY_STRING}</p>"
    1.10 +fi
    1.11  
    1.12  # We need packages information for list and search
    1.13  parse_packages_desc() {
    1.14 @@ -70,6 +72,17 @@
    1.15  	cat $LOCALSTATE/blocked-packages.list | wc -l
    1.16  }
    1.17  
    1.18 +# Parse mirrors list to be able to have an icon an remove link
    1.19 +list_mirrors() {
    1.20 +	cat $LOCALSTATE/mirrors | while read line
    1.21 +	do
    1.22 +		cat << EOT
    1.23 +<li><a href="$SCRIPT_NAME?config=rm-mirror=$line"><img
    1.24 +	src="$IMAGES/clear.png" /></a><a href="$line">$line</a></li>
    1.25 +EOT
    1.26 +	done
    1.27 +}
    1.28 +
    1.29  #
    1.30  # xHTML functions
    1.31  #
    1.32 @@ -79,8 +92,9 @@
    1.33  <div class="search">
    1.34  <form method="get" action="$SCRIPT_NAME">
    1.35  	<p>
    1.36 -		`gettext "Search":`
    1.37 +		
    1.38  		<input type="text" name="search" size="20">
    1.39 +		<input type="submit" value="`gettext "Search"`">
    1.40  	</p>
    1.41  </form>
    1.42  </div>
    1.43 @@ -114,7 +128,8 @@
    1.44  	<a href='$SCRIPT_NAME?list'>`gettext "My packages"`</a> |
    1.45  	<a href='$SCRIPT_NAME?list-all'>`gettext "All packages"`</a> |
    1.46  	<a href='$SCRIPT_NAME?recharge'>`gettext "Recharge"`</a> |
    1.47 -	<a href='$SCRIPT_NAME?upgradeable'>`gettext "Upgradeable"`</a>
    1.48 +	<a href='$SCRIPT_NAME?upgradeable'>`gettext "Upgradeable"`</a> |
    1.49 +	<a href='$SCRIPT_NAME?config'>`gettext "Configuration"`</a>
    1.50  </div>
    1.51  EOT
    1.52  }
    1.53 @@ -233,7 +248,7 @@
    1.54  <div id="actions">
    1.55  	<p>`gettext "Recharge lists will check for new or updated packages"`</p>
    1.56  </div>	
    1.57 -<pre>
    1.58 +<pre class="pre_main">
    1.59  EOT
    1.60  		gettext "Recharging the packages list... please wait"; echo
    1.61  		tazpkg recharge | filter_tazpkg_msgs
    1.62 @@ -275,11 +290,13 @@
    1.63  <p>
    1.64  EOT
    1.65  		gettext "Performing task on packages"
    1.66 -		[ $DEBUG == "1" ] && echo "<p class='debug'>cmd: $cmd</p><p>pkgs: $pkgs </p>"
    1.67  		echo '</p></div>'
    1.68 +		echo '<pre class="pre_main">'
    1.69 +		gettext "Executing $cmd for:$pkgs"
    1.70 +		echo '</pre>'
    1.71  		for pkg in $pkgs
    1.72  		do
    1.73 -			echo '<pre class="nomargin">'
    1.74 +			echo '<pre>'
    1.75  			echo 'y' | tazpkg $cmd $pkg $opt 2>/dev/null | filter_tazpkg_msgs
    1.76  			echo '</pre>'
    1.77  		done ;;
    1.78 @@ -289,14 +306,15 @@
    1.79  		sub_block
    1.80  		. $INSTALLED/$pkg/receipt
    1.81  		cat << EOT
    1.82 -<h2>`gettext "Upgradeable packages"`</h2>
    1.83 +<h2>`gettext "Package info"`</h2>
    1.84  <div id="actions">
    1.85 -	<p>`gettext "Detailled information on:" $PACKAGE`</p>
    1.86 +	<p>`gettext "Detailled information on:"` $PACKAGE</p>
    1.87  </div>
    1.88 -<pre>
    1.89 +<pre class="pre_main">
    1.90  Name        : $PACKAGE
    1.91  Version     : $VERSION
    1.92  Description : $SHORT_DESC
    1.93 +Maintainer  : $MAINTAINER
    1.94  Depends     : `for i in $DEPENDS; do echo -n \
    1.95  	"<a href="$SCRIPT_NAME?info=$i">$i</a> "; done`
    1.96  Website     : <a href="$WEB_SITE">$WEB_SITE</a>
    1.97 @@ -310,21 +328,73 @@
    1.98  </pre>
    1.99  EOT
   1.100  		;;
   1.101 +	config*)
   1.102 +		# Tazpkg configuration page
   1.103 +		cmd=${QUERY_STRING#*=}
   1.104 +		case "$cmd" in
   1.105 +			clean)
   1.106 +				rm -rf /var/cache/tazpkg/* ;;
   1.107 +			add-mirror*=http*|add-mirror*=ftp*)
   1.108 +				# Decode url
   1.109 +				mirror=`httpd -d ${cmd#*=}`
   1.110 +				echo "$mirror" >> $LOCALSTATE/mirrors ;;
   1.111 +			rm-mirror=http://*|rm-mirror=ftp://*)
   1.112 +				mirror=${QUERY_STRING#*=rm-mirror=}
   1.113 +				sed -i -e "s@$mirror@@" -e '/^$/d' $LOCALSTATE/mirrors ;;
   1.114 +		esac
   1.115 +		cache_files=`find /var/cache/tazpkg -name *.tazpkg | wc -l`
   1.116 +		cache_size=`du -sh /var/cache/tazpkg`
   1.117 +		sub_block
   1.118 +		cat << EOT
   1.119 +<h2>`gettext "Configuration"`</h2>
   1.120 +<div>
   1.121 +	<p>`gettext "Tazpkg configuration and settings"`</p>
   1.122 +</div>
   1.123 +<div>
   1.124 +	<h3>`gettext "Package in cache"`</h3>
   1.125 +	<form method="get" action="$SCRIPT_NAME">
   1.126 +	<p>
   1.127 +		`gettext "Packages in the cache:"` $cache_files ($cache_size)
   1.128 +		<input type="hidden" name="config" value="clean" />
   1.129 +		<input type="submit" value="Clean" />
   1.130 +	</p>
   1.131 +	</form>
   1.132 +</div>
   1.133 +<h3>`gettext "Current mirror list"`</h3>
   1.134 +<div class="box">
   1.135 +	<ul>
   1.136 +		`list_mirrors`
   1.137 +	</ul>
   1.138 +</div>
   1.139 +<form method="get" action="$SCRIPT_NAME">
   1.140 +	<p>
   1.141 +		<input type="hidden" name="config" value="add-mirror" />
   1.142 +		<input type="text" name="mirror" size="60">
   1.143 +		<input type="submit" value="Add mirror" />
   1.144 +	</p>
   1.145 +</form>
   1.146 +EOT
   1.147 +		 ;;
   1.148  	*)
   1.149  		# Default to summary
   1.150 -		
   1.151 +		search_form
   1.152  		sub_block
   1.153 -		search_form
   1.154  		cat << EOT
   1.155  <h2>`gettext "Summary"`</h2>
   1.156  <div id="actions">
   1.157  	<p>`gettext "Overview of all installed and mirrored packages"`</p>
   1.158  </div>
   1.159 -<pre>
   1.160 +<pre class="pre_main">
   1.161  `packages_summary`
   1.162  </pre>
   1.163 +<h3>`gettext "Latest log entries"`</h3>
   1.164 +<pre>
   1.165 +`tail -n 6 /var/log/tazpkg.log | fgrep "-" | \
   1.166 +	awk '{print $1, $2, $3, $4, $5, $6, $7}'`
   1.167 +</pre>
   1.168 +
   1.169  EOT
   1.170 -		echo "" ;;
   1.171 +		;;
   1.172  esac
   1.173  
   1.174  # xHTML 5 footer