slitaz-tools diff oldstuff/gtkdialog/sshbox @ rev 813

Current state, features stabilized and open for bugfixes and translations.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Mon Sep 09 03:27:04 2013 +0300 (2013-09-09)
parents 29fe613b2eb6
children 491239328786
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/oldstuff/gtkdialog/sshbox	Mon Sep 09 03:27:04 2013 +0300
     1.3 @@ -0,0 +1,498 @@
     1.4 +#! /bin/sh
     1.5 +# 
     1.6 +# Gtkdialog box interface for SSH connections.
     1.7 +#
     1.8 +# Manage profile in .prf files store in $HOME/.sshbox 
     1.9 +# (c) 2009 SliTaz GNU/Linux - GNU gpl v3
    1.10 +#
    1.11 +
    1.12 +
    1.13 +# Create config directory and init default var
    1.14 +export VERSION=0.2
    1.15 +export PROGNAME="SSHBox"
    1.16 +export PROG="$0"
    1.17 +export CONFIG_DIR=$HOME/.config/sshbox
    1.18 +export TEMP=/tmp/$(basename $PROG).out
    1.19 +
    1.20 +# Create $CONFIG_DIR if it doesn't exist.
    1.21 +[ -d $HOME/$CONFIG_DIR/session ] || mkdir -p $CONFIG_DIR/session
    1.22 +
    1.23 +# Set locale message if message file exists and $LANG is set.
    1.24 +# Default: English 
    1.25 +if [ -f /usr/share/locale/${LANG%%_*}/LC_MESSAGES/sshbox.msg ]; then
    1.26 +	. /usr/share/locale/${LANG%%_*}/LC_MESSAGES/sshbox.msg 
    1.27 +fi
    1.28 +
    1.29 +##
    1.30 +# Function
    1.31 +##
    1.32 +add_session(){
    1.33 +	export GTK_ADD_PROFILE="
    1.34 +		<window title=\"${TITLE_ADD_PROFILE:-Add new session}\" icon-name=\"sunny\">
    1.35 +			<vbox>
    1.36 +			<hbox>
    1.37 +				<text>
    1.38 +					<label>\"${LBL_SESSION:-Session}:\"</label>
    1.39 +				</text>
    1.40 +				<entry>
    1.41 +					<variable>SESSION</variable>
    1.42 +				</entry>
    1.43 +				</hbox>
    1.44 +				<hbox>
    1.45 +				<text>
    1.46 +					<label>\"${LBL_HOSTNAME:-Hostname}:\"</label>
    1.47 +				</text>
    1.48 +				<entry>
    1.49 +					<variable>SSH_HOST</variable>
    1.50 +				</entry>
    1.51 +
    1.52 +				</hbox>
    1.53 +				<hbox>
    1.54 +				<text>
    1.55 +					<default>22</default>
    1.56 +					<label>\"${LBL_PORT-Port}:\"</label>
    1.57 +				</text>
    1.58 +				<entry width_chars=\"5\" max-length=\"5\">
    1.59 +				<default>22</default>
    1.60 +					<variable>SSH_PORT</variable>
    1.61 +				</entry>
    1.62 +				</hbox>
    1.63 +				<hbox>
    1.64 +				<text>
    1.65 +					<label>\"${LBL_USERNAME-Username}:\"</label>
    1.66 +				</text>
    1.67 +				<entry>
    1.68 +					<variable>SSH_USER</variable>
    1.69 +				</entry>
    1.70 +				</hbox>
    1.71 +			<hbox>
    1.72 +			<button>
    1.73 +				<label>${BTN_SAVE:-Save}</label>
    1.74 +				<input file icon=\"gtk-floppy\"></input>
    1.75 +				<action>$PROG save_session $SESSION</action>
    1.76 +				<action>refresh:USER_HOST</action>
    1.77 +				<action type=\"exit\">Exit</action>
    1.78 +			</button>
    1.79 +				<button cancel></button>
    1.80 +			</hbox>
    1.81 +				</vbox>
    1.82 +		</window>
    1.83 +	"
    1.84 +	gtkdialog  --center --program=GTK_ADD_PROFILE
    1.85 +}
    1.86 +
    1.87 +gtk_manage_session(){
    1.88 +	
    1.89 +	# Read the config file if it exists
    1.90 +	[ -f "$CONFIG_DIR/session/$SESSION.conf" ] && . "$CONFIG_DIR/session/$SESSION.conf"
    1.91 +	
    1.92 +	export GTK_MANAGE_SESSION="
    1.93 +		<window title=\"${TITLE_GTK_MANAGE:-Session} $SESSION\" icon-name=\"gnome-control-center\">
    1.94 +		<vbox>
    1.95 +					<hbox>
    1.96 +				<text>
    1.97 +					<label>\"${LBL_HOSTNAME:-Hostname}:\"</label>
    1.98 +				</text>
    1.99 +				<entry>
   1.100 +					<input>\"echo $HOSTNAME\"</input>
   1.101 +					<variable>SSH_HOST</variable>
   1.102 +				</entry>
   1.103 +			</hbox>
   1.104 +			<hbox>
   1.105 +				<text>
   1.106 +					<default>22</default>
   1.107 +					<label>\"${LBL_PORT-Port}:\"</label>
   1.108 +				</text>
   1.109 +				<entry width_chars=\"5\" max-length=\"5\">
   1.110 +					<input>\"echo $PORT\"</input>
   1.111 +					<variable>SSH_PORT</variable>
   1.112 +				</entry>
   1.113 +			</hbox>
   1.114 +			<hbox>
   1.115 +					<text>
   1.116 +						<label>\"${LBL_USERNAME-Username}:\"</label>
   1.117 +					</text>
   1.118 +					<entry>
   1.119 +						<input>\"echo $USER\"</input>
   1.120 +						<variable>SSH_USER</variable>
   1.121 +					</entry>
   1.122 +			</hbox>
   1.123 +			
   1.124 +		<hbox>
   1.125 +			<button>
   1.126 +				<label>${BTN_DELETE:-Delete}</label>
   1.127 +				<input file icon=\"gtk-delete\"></input>
   1.128 +				<action>$PROG delete_session $SESSION</action>
   1.129 +			</button>
   1.130 +			<button>
   1.131 +				<label>${BTN_SAVE:-Modify}</label>
   1.132 +				<input file icon=\"gtk-floppy\"></input>
   1.133 +				<action>$PROG save_session</action>
   1.134 +			</button>
   1.135 +			<button>
   1.136 +				<label>${BTN_CONNECT:-Connect}</label>
   1.137 +				<input file icon=\"gtk-connect\"></input>
   1.138 +				<action>$PROG ssh_connect</action>
   1.139 +			</button>
   1.140 +			<button cancel></button>
   1.141 +		</hbox>
   1.142 +		</vbox>
   1.143 +		</window>
   1.144 +	"
   1.145 +	gtkdialog --center --program=GTK_MANAGE_SESSION
   1.146 +}
   1.147 +
   1.148 +
   1.149 +# Display SettingsBox.
   1.150 +gtk_settings(){
   1.151 +	read_settings
   1.152 +	export GTK_SETTINGS="
   1.153 +		<window title=\"${TITLE_GTK_SETTINGS:-Properties}\" icon-name=\"gnome-control-center\">
   1.154 +			<vbox>
   1.155 +				<hbox>
   1.156 +					<text use-markup=\"true\">
   1.157 +						<label>\"${TXT_TERM:-Terminal}: \"</label>
   1.158 +					</text>
   1.159 +					<entry>
   1.160 +						<input>echo $XTERM</input>
   1.161 +						<variable>XTERM</variable>
   1.162 +					</entry>
   1.163 +					</hbox>
   1.164 +					<hbox>
   1.165 +						<text use-markup=\"true\">
   1.166 +							<label>\"${TXT_SSH_CLIENT:-SSH Client}: \"</label>
   1.167 +						</text>
   1.168 +						<entry>
   1.169 +							<input>echo $SSH_CLIENT</input>
   1.170 +							<variable>SSH_CLIENT</variable>
   1.171 +						</entry>
   1.172 +					</hbox>
   1.173 +					<hbox>
   1.174 +						<button ok></button>
   1.175 +						<button cancel></button>
   1.176 +					</hbox>
   1.177 +				</vbox>
   1.178 +				</window>
   1.179 +		"
   1.180 +		gtkdialog --center --program=GTK_SETTINGS > /tmp/_out_
   1.181 +		
   1.182 +		. /tmp/_out_
   1.183 +		
   1.184 +		if [ "$EXIT" == "OK" ]; then
   1.185 +			save_settings
   1.186 +		fi
   1.187 +}
   1.188 +
   1.189 +gtk_gen_key(){
   1.190 +		# Gen private key with dropbearkey
   1.191 +		#
   1.192 +		export GTK_GEN_KEY="
   1.193 +		<window title=\"${TITLE_GTK_MANAGE:-Session} $SESSION\" icon-name=\"gnome-control-center\">
   1.194 +		<vbox>
   1.195 +			<hbox>
   1.196 +				
   1.197 +			</hbox>
   1.198 +			<hbox>
   1.199 +			<button>
   1.200 +				<label>${BTN_CONNECT:-Connect}</label>
   1.201 +				<input file icon=\"gtk-connect\"></input>
   1.202 +				<action>$PROG ssh_connect</action>
   1.203 +			</button>
   1.204 +			<button cancel></button>
   1.205 +			</hbox>
   1.206 +		</vbox>
   1.207 +		"
   1.208 +}
   1.209 +
   1.210 +ssh_genkey(){
   1.211 +	echo "nop"
   1.212 +}
   1.213 +
   1.214 +list_ssh_key(){
   1.215 +	
   1.216 +	# dropbearkey -y -f foo_dss  | awk '/ssh-(dss|rsa)/ { print $3 "|" $1}'
   1.217 +
   1.218 +	for i in ${HOME}/.ssh/*.priv
   1.219 +	do
   1.220 +		[ -f $i ] && echo $(basename $i .priv)
   1.221 +	done
   1.222 +}
   1.223 +
   1.224 +list_host(){
   1.225 +	if [ -f $HOME/.ssh/known_hosts ]; then
   1.226 +		for i in "$(cat $HOME/.ssh/known_hosts)"; do echo "$i"| awk '{print $1}';done
   1.227 +	fi
   1.228 +}
   1.229 +
   1.230 +delete_host(){
   1.231 +	cp $HOME/.ssh/known_hosts /tmp/f.tmp && \
   1.232 +	awk -v host=$KNOWN_HOST 'match($0,host) == 0 {print $0}' /tmp/f.tmp > $HOME/.ssh/known_hosts
   1.233 +}
   1.234 +
   1.235 +quick_add_session(){
   1.236 +			export GTK_QUICK_ADD="
   1.237 +				<window title=\"${TITLE_QUICK_ADD:-Enter session name}\" icon-name=\"gtk-dialog-question\">
   1.238 +				<vbox>
   1.239 +					<hbox>
   1.240 +					<text>
   1.241 +						<label>\"${TXT_SESSION_NAME:-Session}:\"</label>
   1.242 +					</text>
   1.243 +					<entry>
   1.244 +						<variable>SESSION</variable>
   1.245 +					</entry>
   1.246 +					</hbox>
   1.247 +					<hbox>
   1.248 +					<button>
   1.249 +						<label>${BTN_SAVE:-Save}</label>
   1.250 +						<input file icon=\"gtk-apply\"></input>
   1.251 +						<action type=\"exit\">OK</action>
   1.252 +					</button>
   1.253 +					<button cancel></button>
   1.254 +					</hbox>
   1.255 +				</vbox>
   1.256 +				</window>
   1.257 +		"
   1.258 +		gtkdialog  --center --program=GTK_QUICK_ADD > ${TEMP} 
   1.259 +		
   1.260 +		if ( grep -q  'EXIT="OK"' $TEMP ); then
   1.261 +				. $TEMP
   1.262 +				echo "HOSTNAME=${SSH_HOST}" > ${CONFIG_DIR}/session/${SESSION}.conf
   1.263 +				echo "USER=${SSH_USER}" >> ${CONFIG_DIR}/session/${SESSION}.conf
   1.264 +				echo "PORT=${SSH_PORT}" >> ${CONFIG_DIR}/session/${SESSION}.conf
   1.265 +		fi
   1.266 +}
   1.267 +
   1.268 +edit_session(){
   1.269 +	echo "nop"
   1.270 +}
   1.271 +
   1.272 +save_session(){
   1.273 +	echo "HOSTNAME=${SSH_HOST}" > ${CONFIG_DIR}/session/${SESSION}.conf
   1.274 +	echo "USER=${SSH_USER}" >> ${CONFIG_DIR}/session/${SESSION}.conf
   1.275 +	echo "PORT=${SSH_PORT}" >> ${CONFIG_DIR}/session/${SESSION}.conf
   1.276 +}
   1.277 +
   1.278 +delete_session(){
   1.279 +	rm -f ${CONFIG_DIR}/session/${SESSION}.conf
   1.280 +}
   1.281 +
   1.282 +list_sessions(){
   1.283 +	
   1.284 +	for i in ${CONFIG_DIR}/session/*.conf
   1.285 +	do
   1.286 +		[ -f $i ] && echo "$(basename $i .conf)" | awk '{print"gtk-network|", $0}'
   1.287 +	done
   1.288 +}
   1.289 +
   1.290 +read_settings(){
   1.291 +	# Read user settings.
   1.292 +	# Init default settings if don't exist
   1.293 +	if [ -f ${CONFIG_DIR}/sshbox.conf ]; then
   1.294 +		. ${CONFIG_DIR}/sshbox.conf
   1.295 +	else
   1.296 +		echo "XTERM=xterm" > ${CONFIG_DIR}/sshbox.conf
   1.297 +		echo "SSH_CLIENT=ssh" >> ${CONFIG_DIR}/sshbox.conf
   1.298 +	fi
   1.299 +	export XTERM SSH_CLIENT 
   1.300 +}
   1.301 +
   1.302 +read_last_connection(){	
   1.303 +	# Read last connection
   1.304 +	[ -f $CONFIG_DIR/last ] &&  . $CONFIG_DIR/last
   1.305 +}	
   1.306 +
   1.307 +save_settings(){
   1.308 +	# Save user settings in user.pref.
   1.309 +	echo "XTERM=${XTERM:-xterm}" > $CONFIG_DIR/sshbox.conf
   1.310 +	echo "SSH_CLIENT=${SSH_CLIENT:-/usr/bin/ssh}" >> $CONFIG_DIR/sshbox.conf
   1.311 +}
   1.312 +
   1.313 +ssh_connect(){
   1.314 +	
   1.315 +	read_settings
   1.316 +	
   1.317 +	# TODO: Move this to another place
   1.318 +	# Save last used profile and start ssh connection
   1.319 +	echo "HOSTNAME=$SSH_HOST" > $CONFIG_DIR/last
   1.320 +	echo "USERNAME=$SSH_USER" >> $CONFIG_DIR/last
   1.321 +	echo "KEY=$SSH_KEY" >> $CONFIG_DIR/last
   1.322 +	
   1.323 +	$SSH_OPTIONS=""
   1.324 +	
   1.325 +	[ ! -z $SSH_PORT ] && SSH_OPTION="-p $SSH_PORT"
   1.326 +	
   1.327 +	# set terminal options
   1.328 +	if [ "$XTERM" ==  "sakura" ]; then
   1.329 +		OPTION="--title $SSH_USER@$SSH_HOST"
   1.330 +	else 
   1.331 +		OPTION="-T $SSH_USER@$SSH_HOST"
   1.332 +	fi
   1.333 +	
   1.334 +	exec $XTERM $OPTION -e "$SSH_CLIENT $SSH_OPTIONS $SSH_USER@$SSH_HOST" &
   1.335 +}
   1.336 +
   1.337 +gtk_about(){
   1.338 +		export GTK_ABOUT="
   1.339 +				<window title=\"${TITLE_ABOUT:-About} the $PROGNAMENAME\" icon-name=\"sunny\">
   1.340 +				<vbox>
   1.341 +					<pixmap>
   1.342 +						<input file stock=\"gtk-network\"></input>
   1.343 +					</pixmap>
   1.344 +					<text use-markup=\"true\">
   1.345 +					<label>\"<b>SSHBox v$VERSION</b>\"</label>
   1.346 +					</text>
   1.347 +					<text wrap=\"true\" width-chars=\"40\" use-markup=\"true\">
   1.348 +						<label>\"
   1.349 +Gtkdialog box interface for SSH connections.
   1.350 +
   1.351 +		SliTaz GNU/Linux - GPL v3
   1.352 +						\"
   1.353 +						</label>
   1.354 +					</text>
   1.355 +					<hbox><button ok></button></hbox>
   1.356 +				</vbox>
   1.357 +				</window>
   1.358 +		"
   1.359 +		gtkdialog  --center --program=GTK_ABOUT 
   1.360 +}
   1.361 +
   1.362 +main_dialog(){
   1.363 +	
   1.364 +	read_settings
   1.365 +	read_last_connection
   1.366 +	
   1.367 +export MAIN_DIALOG=" \
   1.368 +<window title=\"SSHBox\" icon-name=\"gtk-network\" resizable=^\"false\">
   1.369 + <vbox>  
   1.370 +	<hbox homogeneous=\"true\">
   1.371 +	<text  width-chars=\"60\">
   1.372 +		<label>\"\"</label>
   1.373 +	</text>
   1.374 +	</hbox>
   1.375 +	<notebook labels=\"${TITLE_MAIN:-Main}|${TITLE_SESSION:-Sessions}|${TITLE_HOST:-Host key}\">
   1.376 +	
   1.377 +	<vbox>  
   1.378 +		<hbox spacing=\"43\">
   1.379 +			<text use-markup=\"true\" >
   1.380 +				<label>\"${TXT_HOST:-Host}:\"</label>
   1.381 +			</text>
   1.382 +			<entry>
   1.383 +				<default>\"$HOSTNAME\"</default>
   1.384 +				<variable>SSH_HOST</variable>
   1.385 +			</entry>
   1.386 +		</hbox>
   1.387 +		<hbox>
   1.388 +			<text use-markup=\"true\">
   1.389 +				<label>\"${TXT_USER:-Username}:\"</label>
   1.390 +			</text>
   1.391 +			<entry>
   1.392 +				<default>\"$USERNAME\"</default>
   1.393 +				<variable>SSH_USER</variable>
   1.394 +			</entry>
   1.395 +		</hbox>
   1.396 +		<hbox  spacing=\"20\">
   1.397 +			<text use-markup=\"true\">
   1.398 +				<label>\"${TXT_KEY:-SSH Key}:\"</label>
   1.399 +			</text>
   1.400 +			<entry>
   1.401 +				<default>\"\"</default>
   1.402 +				<variable>SSH_KEY</variable>
   1.403 +			</entry>
   1.404 +		</hbox>
   1.405 +		<hbox>
   1.406 +		<button>
   1.407 +			<label>${BTN_ADD:-Save session}</label>
   1.408 +			<input file icon=\"gtk-save\"></input>
   1.409 +			<action>$PROG quick_add_session</action>
   1.410 +			<action>refresh:SESSION</action>
   1.411 +		</button>
   1.412 +		<button>
   1.413 +			<label>${BTN_CONNECT:-Connect}</label>
   1.414 +			<input file icon=\"gtk-connect\"></input>
   1.415 +			<action>$PROG ssh_connect</action>
   1.416 +		</button>
   1.417 +		</hbox>
   1.418 +	</vbox>
   1.419 +	
   1.420 +	<vbox>
   1.421 +		<hbox>
   1.422 +			<tree headers_visible=\"false\" exported_column=\"0\">
   1.423 +				<width>200</width><height>150</height>
   1.424 +				<label>\"\"</label>
   1.425 +				<variable>SESSION</variable>
   1.426 +				<input stock_column=\"0\">$PROG list_sessions</input>
   1.427 +				<action>$PROG gtk_manage_session $SESSION</action>
   1.428 +				<action>refresh:SESSION</action>
   1.429 +			</tree>
   1.430 +		</hbox>
   1.431 +		<hbox>
   1.432 +			<text width-chars=\"45\">
   1.433 +				<label>
   1.434 +\"
   1.435 +Double click on session name to manage SSH session.
   1.436 +\"
   1.437 +				</label>
   1.438 +			</text>
   1.439 +		<button>
   1.440 +			<label>${BTN_ADD_SESSION:-Add session}</label>
   1.441 +			<input file icon=\"gtk-add\"></input>
   1.442 +			<action>$PROG add_session</action>
   1.443 +			<action>refresh:SESSION</action>
   1.444 +		</button>
   1.445 +		</hbox>
   1.446 +	</vbox>
   1.447 +	
   1.448 +	<vbox>
   1.449 +		<hbox>
   1.450 +			<tree headers_visible=\"false\" exported_column=\"0\">
   1.451 +				<width>200</width><height>150</height>
   1.452 +				<label>\"\"</label>
   1.453 +				<variable>KNOWN_HOST</variable>
   1.454 +				<input>$PROG list_host</input>
   1.455 +				<action>$PROG delete_host $KNOWN_HOST</action>
   1.456 +				<action>refresh:KNOWN_HOST</action>
   1.457 +			</tree>
   1.458 +		</hbox>
   1.459 +		<hbox>
   1.460 +			<text width-chars=\"60\">
   1.461 +				<label>
   1.462 +\"Double click on host to remove it.\"
   1.463 +				</label>
   1.464 +			</text>
   1.465 +		</hbox>
   1.466 +	</vbox>
   1.467 +	</notebook> 
   1.468 +	 <hbox>
   1.469 +		<button>
   1.470 +			<label>${BTN_ABOUT:-About}</label>
   1.471 +			<input file icon=\"gtk-about\"></input>
   1.472 +			<action>$PROG gtk_about $PROGNAME</action>
   1.473 +		</button>
   1.474 +		<button>
   1.475 +			<label>${BTN_SETTINGS:-Settings}</label>
   1.476 +			<input file icon=\"gtk-preferences\"></input>
   1.477 +			<action>$0 gtk_settings</action>
   1.478 +		</button>
   1.479 +	 	<button>
   1.480 +			<label>${BTN_Exit:-Exit}</label>
   1.481 +			<input file icon=\"exit\"></input>
   1.482 +			<action type=\"exit\">Exit</action>
   1.483 +		</button>
   1.484 +	</hbox>
   1.485 + </vbox>
   1.486 +</window>
   1.487 +"
   1.488 +	gtkdialog --center --program=MAIN_DIALOG
   1.489 +}
   1.490 +
   1.491 +
   1.492 +
   1.493 +case $1 in 
   1.494 +	*_*)
   1.495 +		$1 ;;
   1.496 +	*)
   1.497 +		main_dialog	;;
   1.498 +esac
   1.499 +		
   1.500 +
   1.501 +