slitaz-tools rev 364

Add: sshbox (again).
author Eric Joseph-Alexandre <erjo@slitaz.org>
date Sat Jun 27 11:26:25 2009 +0200 (2009-06-27)
parents 4a5c5e759915
children 6192ed1f3eb4
files rootfs/usr/share/applications/sshbox.desktop tinyutils/sshbox tinyutils/tazx
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/rootfs/usr/share/applications/sshbox.desktop	Sat Jun 27 11:26:25 2009 +0200
     1.3 @@ -0,0 +1,12 @@
     1.4 +[Desktop Entry]
     1.5 +Encoding=UTF-8
     1.6 +Name=SSHBox 
     1.7 +Name[fr]=SSHBox
     1.8 +Name=Scpbox Secure Shell
     1.9 +Name[fr]=SSHBox Shell sécurisé
    1.10 +Comment=Upload or download files with scp
    1.11 +Comment[fr]=Connexion distante sécurisée
    1.12 +Exec=sshbox
    1.13 +Icon=gtk-network
    1.14 +Type=Application
    1.15 +Categories=Application;Network;
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/tinyutils/sshbox	Sat Jun 27 11:26:25 2009 +0200
     2.3 @@ -0,0 +1,498 @@
     2.4 +#! /bin/sh
     2.5 +# 
     2.6 +# Gtkdialog box interafce for SSH connexions.
     2.7 +#
     2.8 +# Manage profile in .prf files store in $HOME/.sshbox 
     2.9 +# (c) 2009 SliTaz GNU/Linux - GNU gpl v3
    2.10 +#
    2.11 +
    2.12 +
    2.13 +# Create config directory and init default var
    2.14 +export VERSION=0.2
    2.15 +export PROGNAME="SSHBox"
    2.16 +export PROG="$0"
    2.17 +export CONFIG_DIR=$HOME/.config/sshbox
    2.18 +export TEMP=/tmp/$(basename $PROG).out
    2.19 +
    2.20 +# Create $CONFIG_DIR if it doesn't exist.
    2.21 +[ -d $HOME/$CONFIG_DIR/session ] || mkdir -p $CONFIG_DIR/session
    2.22 +
    2.23 +# Set locale message if message file exist and $LANG is set.
    2.24 +# Default: English 
    2.25 +if [ -f /usr/share/locale/${LANG%%_*}/LC_MESSAGES/sshbox.msg ]; then
    2.26 +	. /usr/share/locale/${LANG%%_*}/LC_MESSAGES/sshbox.msg 
    2.27 +fi
    2.28 +
    2.29 +##
    2.30 +# Function
    2.31 +##
    2.32 +add_session(){
    2.33 +	export GTK_ADD_PROFILE="
    2.34 +		<window title=\"${TITLE_ADD_PROFILE:-Add new session}\" icon-name=\"sunny\">
    2.35 +			<vbox>
    2.36 +			<hbox>
    2.37 +				<text>
    2.38 +					<label>\"${LBL_SESSION:-Session}:\"</label>
    2.39 +				</text>
    2.40 +				<entry>
    2.41 +					<variable>SESSION</variable>
    2.42 +				</entry>
    2.43 +				</hbox>
    2.44 +				<hbox>
    2.45 +				<text>
    2.46 +					<label>\"${LBL_HOSTNAME:-Hostname}:\"</label>
    2.47 +				</text>
    2.48 +				<entry>
    2.49 +					<variable>SSH_HOST</variable>
    2.50 +				</entry>
    2.51 +
    2.52 +				</hbox>
    2.53 +				<hbox>
    2.54 +				<text>
    2.55 +					<default>22</default>
    2.56 +					<label>\"${LBL_PORT-Port}:\"</label>
    2.57 +				</text>
    2.58 +				<entry width_chars=\"5\" max-length=\"5\">
    2.59 +				<default>22</default>
    2.60 +					<variable>SSH_PORT</variable>
    2.61 +				</entry>
    2.62 +				</hbox>
    2.63 +				<hbox>
    2.64 +				<text>
    2.65 +					<label>\"${LBL_USERNAME-Username}:\"</label>
    2.66 +				</text>
    2.67 +				<entry>
    2.68 +					<variable>SSH_USER</variable>
    2.69 +				</entry>
    2.70 +				</hbox>
    2.71 +			<hbox>
    2.72 +			<button>
    2.73 +				<label>${BTN_SAVE:-Save}</label>
    2.74 +				<input file icon=\"gtk-floppy\"></input>
    2.75 +				<action>$PROG save_session $SESSION</action>
    2.76 +				<action>refresh:USER_HOST</action>
    2.77 +				<action type=\"exit\">Exit</action>
    2.78 +			</button>
    2.79 +				<button cancel></button>
    2.80 +			</hbox>
    2.81 +				</vbox>
    2.82 +		</window>
    2.83 +	"
    2.84 +	gtkdialog  --center --program=GTK_ADD_PROFILE
    2.85 +}
    2.86 +
    2.87 +gtk_manage_session(){
    2.88 +	
    2.89 +	# Read th config file if exist
    2.90 +	[ -f "$CONFIG_DIR/session/$SESSION.conf" ] && . "$CONFIG_DIR/session/$SESSION.conf"
    2.91 +	
    2.92 +	export GTK_MANAGE_SESSION="
    2.93 +		<window title=\"${TITLE_GTK_MANAGE:-Session} $SESSION\" icon-name=\"gnome-control-center\">
    2.94 +		<vbox>
    2.95 +					<hbox>
    2.96 +				<text>
    2.97 +					<label>\"${LBL_HOSTNAME:-Hostname}:\"</label>
    2.98 +				</text>
    2.99 +				<entry>
   2.100 +					<input>\"echo $HOSTNAME\"</input>
   2.101 +					<variable>SSH_HOST</variable>
   2.102 +				</entry>
   2.103 +			</hbox>
   2.104 +			<hbox>
   2.105 +				<text>
   2.106 +					<default>22</default>
   2.107 +					<label>\"${LBL_PORT-Port}:\"</label>
   2.108 +				</text>
   2.109 +				<entry width_chars=\"5\" max-length=\"5\">
   2.110 +					<input>\"echo $PORT\"</input>
   2.111 +					<variable>SSH_PORT</variable>
   2.112 +				</entry>
   2.113 +			</hbox>
   2.114 +			<hbox>
   2.115 +					<text>
   2.116 +						<label>\"${LBL_USERNAME-Username}:\"</label>
   2.117 +					</text>
   2.118 +					<entry>
   2.119 +						<input>\"echo $USER\"</input>
   2.120 +						<variable>SSH_USER</variable>
   2.121 +					</entry>
   2.122 +			</hbox>
   2.123 +			
   2.124 +		<hbox>
   2.125 +			<button>
   2.126 +				<label>${BTN_DELETE:-Delete}</label>
   2.127 +				<input file icon=\"gtk-delete\"></input>
   2.128 +				<action>$PROG delete_session $SESSION</action>
   2.129 +			</button>
   2.130 +			<button>
   2.131 +				<label>${BTN_SAVE:-Modify}</label>
   2.132 +				<input file icon=\"gtk-floppy\"></input>
   2.133 +				<action>$PROG save_session</action>
   2.134 +			</button>
   2.135 +			<button>
   2.136 +				<label>${BTN_CONNECT:-Connect}</label>
   2.137 +				<input file icon=\"gtk-connect\"></input>
   2.138 +				<action>$PROG ssh_connect</action>
   2.139 +			</button>
   2.140 +			<button cancel></button>
   2.141 +		</hbox>
   2.142 +		</vbox>
   2.143 +		</window>
   2.144 +	"
   2.145 +	gtkdialog --center --program=GTK_MANAGE_SESSION
   2.146 +}
   2.147 +
   2.148 +
   2.149 +# Display SettingsBox.
   2.150 +gtk_settings(){
   2.151 +	read_settings
   2.152 +	export GTK_SETTINGS="
   2.153 +		<window title=\"${TITLE_GTK_SETTINGS:-Properties}\" icon-name=\"gnome-control-center\">
   2.154 +			<vbox>
   2.155 +				<hbox>
   2.156 +					<text use-markup=\"true\">
   2.157 +						<label>\"${TXT_TERM:-Terminal}: \"</label>
   2.158 +					</text>
   2.159 +					<entry>
   2.160 +						<input>echo $XTERM</input>
   2.161 +						<variable>XTERM</variable>
   2.162 +					</entry>
   2.163 +					</hbox>
   2.164 +					<hbox>
   2.165 +						<text use-markup=\"true\">
   2.166 +							<label>\"${TXT_SSH_CLIENT:-SSH Client}: \"</label>
   2.167 +						</text>
   2.168 +						<entry>
   2.169 +							<input>echo $SSH_CLIENT</input>
   2.170 +							<variable>SSH_CLIENT</variable>
   2.171 +						</entry>
   2.172 +					</hbox>
   2.173 +					<hbox>
   2.174 +						<button ok></button>
   2.175 +						<button cancel></button>
   2.176 +					</hbox>
   2.177 +				</vbox>
   2.178 +				</window>
   2.179 +		"
   2.180 +		gtkdialog --center --program=GTK_SETTINGS > /tmp/_out_
   2.181 +		
   2.182 +		. /tmp/_out_
   2.183 +		
   2.184 +		if [ "$EXIT" == "OK" ]; then
   2.185 +			save_settings
   2.186 +		fi
   2.187 +}
   2.188 +
   2.189 +gtk_gen_key(){
   2.190 +		# Gen private key with dropbearkey
   2.191 +		#
   2.192 +		export GTK_GEN_KEY="
   2.193 +		<window title=\"${TITLE_GTK_MANAGE:-Session} $SESSION\" icon-name=\"gnome-control-center\">
   2.194 +		<vbox>
   2.195 +			<hbox>
   2.196 +				
   2.197 +			</hbox>
   2.198 +			<hbox>
   2.199 +			<button>
   2.200 +				<label>${BTN_CONNECT:-Connect}</label>
   2.201 +				<input file icon=\"gtk-connect\"></input>
   2.202 +				<action>$PROG ssh_connect</action>
   2.203 +			</button>
   2.204 +			<button cancel></button>
   2.205 +			</hbox>
   2.206 +		</vbox>
   2.207 +		"
   2.208 +}
   2.209 +
   2.210 +ssh_genkey(){
   2.211 +	echo "nop"
   2.212 +}
   2.213 +
   2.214 +list_ssh_key(){
   2.215 +	
   2.216 +	# dropbearkey -y -f foo_dss  | awk '/ssh-(dss|rsa)/ { print $3 "|" $1}'
   2.217 +
   2.218 +	for i in ${HOME}/.ssh/*.priv
   2.219 +	do
   2.220 +		[ -f $i ] && echo $(basename $i .priv)
   2.221 +	done
   2.222 +}
   2.223 +
   2.224 +list_host(){
   2.225 +	if [ -f $HOME/.ssh/known_hosts ]; then
   2.226 +		for i in "$(cat $HOME/.ssh/known_hosts)"; do echo "$i"| awk '{print $1}';done
   2.227 +	fi
   2.228 +}
   2.229 +
   2.230 +delete_host(){
   2.231 +	cp $HOME/.ssh/known_hosts /tmp/f.tmp && \
   2.232 +	awk -v host=$KNOWN_HOST 'match($0,host) == 0 {print $0}' /tmp/f.tmp > $HOME/.ssh/known_hosts
   2.233 +}
   2.234 +
   2.235 +quick_add_session(){
   2.236 +			export GTK_QUICK_ADD="
   2.237 +				<window title=\"${TITLE_QUICK_ADD:-Enter session name}\" icon-name=\"gtk-dialog-question\">
   2.238 +				<vbox>
   2.239 +					<hbox>
   2.240 +					<text>
   2.241 +						<label>\"${TXT_SESSION_NAME:-Session}:\"</label>
   2.242 +					</text>
   2.243 +					<entry>
   2.244 +						<variable>SESSION</variable>
   2.245 +					</entry>
   2.246 +					</hbox>
   2.247 +					<hbox>
   2.248 +					<button>
   2.249 +						<label>${BTN_SAVE:-Save}</label>
   2.250 +						<input file icon=\"gtk-apply\"></input>
   2.251 +						<action type=\"exit\">OK</action>
   2.252 +					</button>
   2.253 +					<button cancel></button>
   2.254 +					</hbox>
   2.255 +				</vbox>
   2.256 +				</window>
   2.257 +		"
   2.258 +		gtkdialog  --center --program=GTK_QUICK_ADD > ${TEMP} 
   2.259 +		
   2.260 +		if ( grep -q  'EXIT="OK"' $TEMP ); then
   2.261 +				. $TEMP
   2.262 +				echo "HOSTNAME=${SSH_HOST}" > ${CONFIG_DIR}/session/${SESSION}.conf
   2.263 +				echo "USER=${SSH_USER}" >> ${CONFIG_DIR}/session/${SESSION}.conf
   2.264 +				echo "PORT=${SSH_PORT}" >> ${CONFIG_DIR}/session/${SESSION}.conf
   2.265 +		fi
   2.266 +}
   2.267 +
   2.268 +edit_session(){
   2.269 +	echo "nop"
   2.270 +}
   2.271 +
   2.272 +save_session(){
   2.273 +	echo "HOSTNAME=${SSH_HOST}" > ${CONFIG_DIR}/session/${SESSION}.conf
   2.274 +	echo "USER=${SSH_USER}" >> ${CONFIG_DIR}/session/${SESSION}.conf
   2.275 +	echo "PORT=${SSH_PORT}" >> ${CONFIG_DIR}/session/${SESSION}.conf
   2.276 +}
   2.277 +
   2.278 +delete_session(){
   2.279 +	rm -f ${CONFIG_DIR}/session/${SESSION}.conf
   2.280 +}
   2.281 +
   2.282 +list_sessions(){
   2.283 +	
   2.284 +	for i in ${CONFIG_DIR}/session/*.conf
   2.285 +	do
   2.286 +		[ -f $i ] && echo "$(basename $i .conf)" | awk '{print"gtk-network|", $0}'
   2.287 +	done
   2.288 +}
   2.289 +
   2.290 +read_settings(){
   2.291 +	# Read user settings.
   2.292 +	# Init default settings if don't exist
   2.293 +	if [ -f ${CONFIG_DIR}/sshbox.conf ]; then
   2.294 +		. ${CONFIG_DIR}/sshbox.conf
   2.295 +	else
   2.296 +		echo "XTERM=xterm" > ${CONFIG_DIR}/sshbox.conf
   2.297 +		echo "SSH_CLIENT=ssh" >> ${CONFIG_DIR}/sshbox.conf
   2.298 +	fi
   2.299 +	export XTERM SSH_CLIENT 
   2.300 +}
   2.301 +
   2.302 +read_last_connection(){	
   2.303 +	#Read last connexion
   2.304 +	[ -f $CONFIG_DIR/last ] &&  . $CONFIG_DIR/last
   2.305 +}	
   2.306 +
   2.307 +save_settings(){
   2.308 +	# Save user settings in user.pref.
   2.309 +	echo "XTERM=${XTERM:-xterm}" > $CONFIG_DIR/sshbox.conf
   2.310 +	echo "SSH_CLIENT=${SSH_CLIENT:-/usr/bin/ssh}" >> $CONFIG_DIR/sshbox.conf
   2.311 +}
   2.312 +
   2.313 +ssh_connect(){
   2.314 +	
   2.315 +	read_settings
   2.316 +	
   2.317 +	#TODO: Move this to another place
   2.318 +	# Save last used profile and start ssh connection
   2.319 +	echo "HOSTNAME=$SSH_HOST" > $CONFIG_DIR/last
   2.320 +	echo "USERNAME=$SSH_USER" >> $CONFIG_DIR/last
   2.321 +	echo "KEY=$SSH_KEY" >> $CONFIG_DIR/last
   2.322 +	
   2.323 +	$SSH_OPTIONS=""
   2.324 +	
   2.325 +	[ ! -z $SSH_PORT ] && SSH_OPTION="-p $SSH_PORT"
   2.326 +	
   2.327 +	#  set terminal options
   2.328 +	if [ "$XTERM" ==  "sakura" ]; then
   2.329 +		OPTION="--title $SSH_USER@$SSH_HOST"
   2.330 +	else 
   2.331 +		OPTION="-T $SSH_USER@$SSH_HOST"
   2.332 +	fi
   2.333 +	
   2.334 +	exec $XTERM $OPTION -e "$SSH_CLIENT $SSH_OPTIONS $SSH_USER@$SSH_HOST" &
   2.335 +}
   2.336 +
   2.337 +gtk_about(){
   2.338 +		export GTK_ABOUT="
   2.339 +				<window title=\"${TITLE_ABOUT:-About} de $PROGNAMENAME\" icon-name=\"sunny\">
   2.340 +				<vbox>
   2.341 +					<pixmap>
   2.342 +						<input file stock=\"gtk-network\"></input>
   2.343 +					</pixmap>
   2.344 +					<text use-markup=\"true\">
   2.345 +					<label>\"<b>SSHBox v$VERSION</b>\"</label>
   2.346 +					</text>
   2.347 +					<text wrap=\"true\" width-chars=\"40\" use-markup=\"true\">
   2.348 +						<label>\"
   2.349 +Gtkdialog box interface for SSH connexions.
   2.350 +
   2.351 +		SliTaz GNU/Linux - GPL v3
   2.352 +						\"
   2.353 +						</label>
   2.354 +					</text>
   2.355 +					<hbox><button ok></button></hbox>
   2.356 +				</vbox>
   2.357 +				</window>
   2.358 +		"
   2.359 +		gtkdialog  --center --program=GTK_ABOUT 
   2.360 +}
   2.361 +
   2.362 +main_dialog(){
   2.363 +	
   2.364 +	read_settings
   2.365 +	read_last_connection
   2.366 +	
   2.367 +export MAIN_DIALOG=" \
   2.368 +<window title=\"SSHBox\" icon-name=\"gtk-network\" resizable=^\"false\">
   2.369 + <vbox>  
   2.370 +	<hbox homogeneous=\"true\">
   2.371 +	<text  width-chars=\"60\">
   2.372 +		<label>\"\"</label>
   2.373 +	</text>
   2.374 +	</hbox>
   2.375 +	<notebook labels=\"${TITLE_MAIN:-Main}|${TITLE_SESSION:-Sessions}|${TITLE_HOST:-Host key}\">
   2.376 +	
   2.377 +	<vbox>  
   2.378 +		<hbox spacing=\"43\">
   2.379 +			<text use-markup=\"true\" >
   2.380 +				<label>\"${TXT_HOST:-Host}:\"</label>
   2.381 +			</text>
   2.382 +			<entry>
   2.383 +				<default>\"$HOSTNAME\"</default>
   2.384 +				<variable>SSH_HOST</variable>
   2.385 +			</entry>
   2.386 +		</hbox>
   2.387 +		<hbox>
   2.388 +			<text use-markup=\"true\">
   2.389 +				<label>\"${TXT_USER:-Username}:\"</label>
   2.390 +			</text>
   2.391 +			<entry>
   2.392 +				<default>\"$USERNAME\"</default>
   2.393 +				<variable>SSH_USER</variable>
   2.394 +			</entry>
   2.395 +		</hbox>
   2.396 +		<hbox  spacing=\"20\">
   2.397 +			<text use-markup=\"true\">
   2.398 +				<label>\"${TXT_KEY:-SSH Key}:\"</label>
   2.399 +			</text>
   2.400 +			<entry>
   2.401 +				<default>\"\"</default>
   2.402 +				<variable>SSH_KEY</variable>
   2.403 +			</entry>
   2.404 +		</hbox>
   2.405 +		<hbox>
   2.406 +		<button>
   2.407 +			<label>${BTN_ADD:-Save session}</label>
   2.408 +			<input file icon=\"gtk-save\"></input>
   2.409 +			<action>$PROG quick_add_session</action>
   2.410 +			<action>refresh:SESSION</action>
   2.411 +		</button>
   2.412 +		<button>
   2.413 +			<label>${BTN_CONNECT:-Connect}</label>
   2.414 +			<input file icon=\"gtk-connect\"></input>
   2.415 +			<action>$PROG ssh_connect</action>
   2.416 +		</button>
   2.417 +		</hbox>
   2.418 +	</vbox>
   2.419 +	
   2.420 +	<vbox>
   2.421 +		<hbox>
   2.422 +			<tree headers_visible=\"false\" exported_column=\"0\">
   2.423 +				<width>200</width><height>150</height>
   2.424 +				<label>\"\"</label>
   2.425 +				<variable>SESSION</variable>
   2.426 +				<input stock_column=\"0\">$PROG list_sessions</input>
   2.427 +				<action>$PROG gtk_manage_session $SESSION</action>
   2.428 +				<action>refresh:SESSION</action>
   2.429 +			</tree>
   2.430 +		</hbox>
   2.431 +		<hbox>
   2.432 +			<text width-chars=\"45\">
   2.433 +				<label>
   2.434 +\"
   2.435 +Double click on session name to manage SSH session.
   2.436 +\"
   2.437 +				</label>
   2.438 +			</text>
   2.439 +		<button>
   2.440 +			<label>${BTN_ADD_SESSION:-Add session}</label>
   2.441 +			<input file icon=\"gtk-add\"></input>
   2.442 +			<action>$PROG add_session</action>
   2.443 +			<action>refresh:SESSION</action>
   2.444 +		</button>
   2.445 +		</hbox>
   2.446 +	</vbox>
   2.447 +	
   2.448 +	<vbox>
   2.449 +		<hbox>
   2.450 +			<tree headers_visible=\"false\" exported_column=\"0\">
   2.451 +				<width>200</width><height>150</height>
   2.452 +				<label>\"\"</label>
   2.453 +				<variable>KNOWN_HOST</variable>
   2.454 +				<input>$PROG list_host</input>
   2.455 +				<action>$PROG delete_host $KNOWN_HOST</action>
   2.456 +				<action>refresh:KNOWN_HOST</action>
   2.457 +			</tree>
   2.458 +		</hbox>
   2.459 +		<hbox>
   2.460 +			<text width-chars=\"60\">
   2.461 +				<label>
   2.462 +\"Double click on host to remove it.\"
   2.463 +				</label>
   2.464 +			</text>
   2.465 +		</hbox>
   2.466 +	</vbox>
   2.467 +	</notebook> 
   2.468 +	 <hbox>
   2.469 +		<button>
   2.470 +			<label>${BTN_ABOUT:-About}</label>
   2.471 +			<input file icon=\"gtk-about\"></input>
   2.472 +			<action>$PROG gtk_about $PROGNAME</action>
   2.473 +		</button>
   2.474 +		<button>
   2.475 +			<label>${BTN_SETTINGS:-Settings}</label>
   2.476 +			<input file icon=\"gtk-preferences\"></input>
   2.477 +			<action>$0 gtk_settings</action>
   2.478 +		</button>
   2.479 +	 	<button>
   2.480 +			<label>${BTN_Exit:-Exit}</label>
   2.481 +			<input file icon=\"exit\"></input>
   2.482 +			<action type=\"exit\">Exit</action>
   2.483 +		</button>
   2.484 +	</hbox>
   2.485 + </vbox>
   2.486 +</window>
   2.487 +"
   2.488 +	gtkdialog --center --program=MAIN_DIALOG
   2.489 +}
   2.490 +
   2.491 +
   2.492 +
   2.493 +case $1 in 
   2.494 +	*_*)
   2.495 +		$1 ;;
   2.496 +	*)
   2.497 +		main_dialog	;;
   2.498 +esac
   2.499 +		
   2.500 +
   2.501 +
     3.1 --- a/tinyutils/tazx	Sun Jun 21 01:14:46 2009 +0000
     3.2 +++ b/tinyutils/tazx	Sat Jun 27 11:26:25 2009 +0200
     3.3 @@ -148,7 +148,6 @@
     3.4  	$(Xvesa -listmodes 2>&1 | grep ^0x | awk '{ printf "%s %s\n",$2,$3 }' | sort -nr | grep x[1-2][4-6]) \
     3.5  	"xterm" "800x600x16" \
     3.6  	"xorg" "Installer Xorg" \
     3.7 -	"wm" "Choose Window Manager" \
     3.8  	"quit" "Quitter" \
     3.9  	2>&1 1>&3`
    3.10  	retval=$?