tazpanel rev 474

settings.cgi: add tweaks to quick change terminal prompt style, and LXPanel menu button style.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Fri May 01 19:30:01 2015 +0300 (2015-05-01)
parents 12e726724a74
children de34ca9d1417
files settings.cgi styles/default/header.html
line diff
     1.1 --- a/settings.cgi	Thu Apr 30 18:37:05 2015 +0200
     1.2 +++ b/settings.cgi	Fri May 01 19:30:01 2015 +0300
     1.3 @@ -12,7 +12,6 @@
     1.4  
     1.5  . lib/libtazpanel
     1.6  get_config
     1.7 -header
     1.8  
     1.9  TITLE=$(_ 'TazPanel - Settings')
    1.10  
    1.11 @@ -95,6 +94,76 @@
    1.12  	*\ style*)
    1.13  		sed -i s/'^STYLE.*'/"STYLE=\"$(GET style)\""/ $CONFIG
    1.14  		. $CONFIG ;;
    1.15 +
    1.16 +
    1.17 +	*\ tweak\ *)
    1.18 +		HOME="$(awk -F: -vu=$REMOTE_USER '$1==u{print $6}' /etc/passwd)"
    1.19 +		[ -z "$HOME" ] && exit 0
    1.20 +
    1.21 +		case $REMOTE_USER in
    1.22 +			root) color=31; ind='#';;
    1.23 +			*)    color=32; ind='$';;
    1.24 +		esac
    1.25 +
    1.26 +		case $(GET tweak) in
    1.27 +			monochrome)
    1.28 +				# PS1='\u@\h:\w\$ '
    1.29 +				sed -i "s|^PS1=.*|PS1='\\\\u@\\\\h:\\\\w\\\\$ind '|" $HOME/.profile;;
    1.30 +			colored)
    1.31 +				# PS1='\[\e[0;32m\]\u@\h\[\e[0m\]:\[\e[0;33m\]\w\[\e[0m\]\$ '
    1.32 +				sed -i "s|^PS1=.*|PS1='\\\\\\[\\\\e\[0;${color}m\\\\\\]\\\\u@\\\\h\\\\\\[\\\\e\\[0m\\\\\\]:\\\\\\[\\\\e\\[0;33m\\\\\\]\\\\w\\\\\\[\\\\e\\[0m\\\\\\]\\\\$ind '|" $HOME/.profile;;
    1.33 +			slitaz-*)
    1.34 +				lxpanel="$HOME/.config/lxpanel"
    1.35 +				if [ ! -e "$lxpanel" ]; then
    1.36 +					mkdir -p "$lxpanel"; cp /etc/lxpanel/default /etc/lxpanel/slitaz $lxpanel
    1.37 +				fi
    1.38 +				for panel in $(find /home/tux/.config/lxpanel -type f -iname panel); do
    1.39 +					awk -vicon="/usr/share/pixmaps/$(GET tweak).png" '
    1.40 +					BEGIN{ found = "0"; }
    1.41 +					{
    1.42 +						if ($1 == "Plugin") { found = "1"; }
    1.43 +
    1.44 +						if (found == "1" && $1 == "type") {
    1.45 +							if ($3 == "menu") found = "2"; else found = "0";
    1.46 +						}
    1.47 +
    1.48 +						if (found == "2" && $1 == "Plugin") { found = "0"; }
    1.49 +
    1.50 +						if (found == "2" && index($1, "image")) {
    1.51 +							printf "        image=%s\n", icon;
    1.52 +							found = 0;
    1.53 +						} else {
    1.54 +							print;
    1.55 +						}
    1.56 +					}
    1.57 +					' $panel > $panel.new
    1.58 +					mv -f $panel.new $panel
    1.59 +				done
    1.60 +
    1.61 +				# `lxpanelctl restart` exists, but it breaks often leaving us without any panel
    1.62 +				killall lxpanel; DISPLAY=':0.0' lxpanel &
    1.63 +				;;
    1.64 +			menu-notext)
    1.65 +				dd="$HOME/.local/share/desktop-directories"
    1.66 +				mkdir -p $dd
    1.67 +				echo -e '[Desktop Entry]\nType=Directory\nName=' > $dd/SliTazMenu.directory
    1.68 +				killall lxpanel; DISPLAY=':0.0' lxpanel &
    1.69 +				;;
    1.70 +			menu-text)
    1.71 +				dd="$HOME/.local/share/desktop-directories/SliTazMenu.directory"
    1.72 +				[ -f "$dd" ] && rm "$dd"
    1.73 +				killall lxpanel; DISPLAY=':0.0' lxpanel &
    1.74 +				;;
    1.75 +		esac
    1.76 +		exit 0
    1.77 +		;;
    1.78 +
    1.79 +
    1.80 +	*\ menuIcon\ *)
    1.81 +		icon="/usr/share/pixmaps/$(GET menuIcon).png"
    1.82 +		[ ! -r $icon ] && exit 0
    1.83 +		header "Content-Type: image/png"; cat $icon; exit 0
    1.84 +		;;
    1.85  esac
    1.86  
    1.87  
    1.88 @@ -105,14 +174,16 @@
    1.89  # Default xHTML content
    1.90  #
    1.91  
    1.92 +header
    1.93  xhtml_header
    1.94 -check_root_tazpanel
    1.95  
    1.96  case " $(GET) " in
    1.97  	*\ group*)
    1.98  		#
    1.99  		# Groups management
   1.100  		#
   1.101 +		check_root_tazpanel
   1.102 +
   1.103  		cat <<EOT
   1.104  <h2 id="groups">$(_ 'Manage groups')</h2>
   1.105  
   1.106 @@ -206,6 +277,8 @@
   1.107  		#
   1.108  		# Users management
   1.109  		#
   1.110 +		check_root_tazpanel
   1.111 +
   1.112  		cat <<EOT
   1.113  <h2 id="users">$(_ 'Manage users')</h2>
   1.114  
   1.115 @@ -314,6 +387,8 @@
   1.116  		#
   1.117  		# Choose locale
   1.118  		#
   1.119 +		check_root_tazpanel
   1.120 +
   1.121  		LOADING_MSG="$(_ 'Please wait...')"; loading_msg
   1.122  
   1.123  		cur_loc=$(locale | grep LANG | cut -d= -f2)
   1.124 @@ -388,10 +463,123 @@
   1.125  		;;
   1.126  
   1.127  
   1.128 +	*\ tweaks\ *)
   1.129 +		#
   1.130 +		# Small tweaks for user
   1.131 +		#
   1.132 +
   1.133 +		user="$REMOTE_USER"; host="$(hostname)"
   1.134 +		HOME="$(awk -F: -vu=$user '$1==u{print $6}' /etc/passwd)"
   1.135 +		font="${TERM_FONT:-monospace}"; palette=$(echo $TERM_PALETTE | tr A-Z a-z)
   1.136 +		case $user in
   1.137 +			root) color=31; ind="#";;
   1.138 +			*)    color=32; ind="$";;
   1.139 +		esac
   1.140 +
   1.141 +		prompt_bw="$user@$host:/usr/bin$ind"
   1.142 +		prompt_c="<span class=\"color$color\">$user@$host</span>:<span class=\"color33\">/usr/bin</span>$ind"
   1.143 +		cursor="<span class=\"color47\">_</span>"
   1.144 +		cat <<EOT
   1.145 +<script type="text/javascript">
   1.146 +function tweak(tweakName) {
   1.147 +	// Send request to the server
   1.148 +	var hiddenImg = document.createElement('IMG');
   1.149 +	hiddenImg.src = "settings.cgi?tweak=" + tweakName;
   1.150 +}
   1.151 +</script>
   1.152 +
   1.153 +<section>
   1.154 +	<header>$(_ 'Small quick tweaks for user %s' "$user")</header>
   1.155 +
   1.156 +	<fieldset><legend>$(_ 'Terminal prompt')</legend>
   1.157 +		<table class="wide">
   1.158 +			<tr>
   1.159 +				<td>
   1.160 +					<label>
   1.161 +						<input type="radio" name="termPrompt" onclick="tweak('monochrome')"/>
   1.162 +						$(_ 'Monochrome')
   1.163 +					</label>
   1.164 +					<pre class="term $palette" style="font-family: '$font'; height: 5rem;">
   1.165 +$prompt_bw uname -r<br/>$(uname -r)<br/>$prompt_bw date<br/>$(date)<br/>$prompt_bw $cursor
   1.166 +</pre>
   1.167 +				</td>
   1.168 +				<td>
   1.169 +					<label>
   1.170 +						<input type="radio" name="termPrompt" onclick="tweak('colored')"/>
   1.171 +						$(_ 'Colored')
   1.172 +					</label>
   1.173 +					<pre class="term $palette" style="font-family: '$font'; height: 5rem;">
   1.174 +$prompt_c uname -r<br/>$(uname -r)<br/>$prompt_c date<br/>$(date)<br/>$prompt_c $cursor
   1.175 +</pre>
   1.176 +				</td>
   1.177 +			</tr>
   1.178 +		</table>
   1.179 +
   1.180 +		<p>$(_ 'Manual edit: %s' "<a data-icon=\"conf\" href="index.cgi?file=$HOME/.profile">~/.profile</a>")<br/>
   1.181 +$(_ 'To take effect: log out and log in to system or execute command in the terminal:')</p>
   1.182 +
   1.183 +		<pre>. ~/.profile</pre>
   1.184 +	</fieldset>
   1.185 +
   1.186 +	<br/>
   1.187 +
   1.188 +	<fieldset>
   1.189 +		<legend>$(_ 'Menu button appearance')</legend>
   1.190 +		<table class="wide">
   1.191 +			<tr>
   1.192 +				<td style="vertical-align: top">
   1.193 +					<fieldset>
   1.194 +						<legend>$(_ 'Icon:')</legend>
   1.195 +						<label>
   1.196 +							<input type="radio" name="menuIcon" onclick="tweak('slitaz-menu-empty')"/>
   1.197 +							$(_ 'Do not show')
   1.198 +						</label><br/>
   1.199 +						<label>
   1.200 +							<input type="radio" name="menuIcon" onclick="tweak('slitaz-button-red')"/>
   1.201 +							<img src="?menuIcon=slitaz-button-red"/>
   1.202 +						</label><br/>
   1.203 +						<label>
   1.204 +							<input type="radio" name="menuIcon" onclick="tweak('slitaz-menu')"/>
   1.205 +							<img src="?menuIcon=slitaz-menu"/>
   1.206 +						</label><br/>
   1.207 +						<label>
   1.208 +							<input type="radio" name="menuIcon" onclick="tweak('slitaz-button')"/>
   1.209 +							<img src="?menuIcon=slitaz-button"/>
   1.210 +						</label>
   1.211 +					</fieldset>
   1.212 +				</td>
   1.213 +				<td style="vertical-align: top">
   1.214 +					<fieldset>
   1.215 +						<legend>$(_ 'Text:')</legend>
   1.216 +						<label>
   1.217 +							<input type="radio" name="menuText" onclick="tweak('menu-notext')"/>
   1.218 +							$(_ 'Do not show')
   1.219 +						</label><br/>
   1.220 +						<label>
   1.221 +							<input type="radio" name="menuText" onclick="tweak('menu-text')"/>
   1.222 +							$(_ 'Show text')
   1.223 +						</label>
   1.224 +					</fieldset>
   1.225 +				</td>
   1.226 +			</tr>
   1.227 +		</table>
   1.228 +		<p>$(_ 'Manual edit: %s' \
   1.229 +			"<a data-icon=\"conf\" href=\"index.cgi?file=$HOME/.local/share/desktop-directories/SliTazMenu.directory\">~/.local/share/desktop-directories/SliTazMenu.directory</a>
   1.230 +			$(
   1.231 +				find $HOME/.config/lxpanel -type f -name panel | awk -vh="$HOME" \
   1.232 +				'{ printf "<a data-icon=\"conf\" href=\"index.cgi?file=%s\">%s</a> ", $1, gensub(h, "~", "")}'
   1.233 +			)")</p>
   1.234 +	</fieldset>
   1.235 +</section>
   1.236 +EOT
   1.237 +		;;
   1.238 +
   1.239 +
   1.240  	*)
   1.241  		#
   1.242  		# Default system settings page
   1.243  		#
   1.244 +		check_root_tazpanel
   1.245  
   1.246  		cat <<EOT
   1.247  <h2>$(_ 'System settings')</h2>
     2.1 --- a/styles/default/header.html	Thu Apr 30 18:37:05 2015 +0200
     2.2 +++ b/styles/default/header.html	Fri May 01 19:30:01 2015 +0300
     2.3 @@ -78,9 +78,10 @@
     2.4    <li tabindex="5">
     2.5     <span>$(_ 'Settings')</span>
     2.6     <menu>
     2.7 -    <li><a data-icon="info"  href="settings.cgi" data-root>$(_ 'Summary')</a></li>
     2.8 -    <li><a data-icon="user"  href="settings.cgi?users" data-root>$(_ 'Users')</a></li>
     2.9 -    <li><a data-icon="group" href="settings.cgi?groups" data-root>$(_ 'Groups')</a></li>
    2.10 +    <li><a data-icon="info"     href="settings.cgi" data-root>$(_ 'Summary')</a></li>
    2.11 +    <li><a data-icon="user"     href="settings.cgi?users" data-root>$(_ 'Users')</a></li>
    2.12 +    <li><a data-icon="group"    href="settings.cgi?groups" data-root>$(_ 'Groups')</a></li>
    2.13 +    <li><a data-icon="settings" href="settings.cgi?tweaks">$(_ 'Tweaks')</a></li>
    2.14      $(for i in menu.d/settings/* ; do [ -f $i ] && sh $i menu $i ; done)
    2.15     </menu>
    2.16    </li>