Showing posts with label rdesktop. Show all posts
Showing posts with label rdesktop. Show all posts

Thursday, March 5, 2015

How-To: Rdesktop over (HTTP) Proxy

How to connect to a remote desktop host via an HTTP Proxy

In this example we will use, once again, socat. Here is how to connect to a Terminal Server which can be reach only behind an HTTP Proxy.

First, make sure that your $http_proxy environment variable is set properly.

Add the following function to your ~/.bashrc:

function rdesktop_proxy () {
 
 if [ $# -lt 1 ]; then
  echo "usage: $0 <hostname/ip>"
  return
 fi

 HOST=$1
 PROXY_HOST=$(echo $http_proxy | sed 's,http:,,;s,/,,g' | cut -d: -f1)
 PROXY_PORT=$(echo $http_proxy | sed 's,http:,,;s,/,,g' | cut -d: -f2)

 socat TCP4-LISTEN:51515,bind=127.0.0.1,reuseaddr PROXY:$PROXY_HOST:$HOST:3389,proxyport=$PROXY_PORT &

 /usr/local/bin/xfreerdp +clipboard +home-drive "/t:$1" /v:127.0.0.1:51515 "${@:2}"
}

Then re-source your shell:

source ~/.bashrc

And you can just type:

rdesktop_proxy my.rdpdomain.com /u:John

The example above use the xfreerdp client, but you can adjust it to use your favourite RDP client, you get the idea.

Thursday, March 13, 2014

Automatic rdesktop logon (Linux)

So when you want to test the connection to multiple Windows boxes from your Linux workstation, you have to go through this boring process every time:

- Bring up the rdesktop session
- Type in the user name
- Type in the password
- Hit OK

To automatise this, you can obviously go with:
rdesktop 10.1.1.10 -u Username -p Password

And this will work. But if you have to accept a legal notice prior to being able to type in your creds, you'll notice that the password on the command line won't work. Not easy to script. Also you would have noticed that copy/pasting in the password fields is disabled.

Here is how to automate this using xdotool. Add this function to the end of your ~/.bashrc:
function rdesktop_autologin()
{
 if [ $# != 3 ]; then
  echo "usage: $0 <hostname/ip> <username> <password>"
  return
 fi
 
 IP=$1
 USER=$2
 PASS=$3

 Xaxis=$(xdpyinfo | grep dimensions | awk '{print $2}' | cut -dx -f1)
 Yaxis=$(xdpyinfo | grep dimensions | awk '{print $2}' | cut -dx -f2)
 MaxRes=$Xaxis"x"$(($Yaxis-50))

 /usr/bin/rdesktop -T "$IP" "$IP" -g $MaxRes -u "$USER" -r disk:home=${HOME} -r disk:tmp=/tmp -r clipboard:PRIMARYCLIPBOARD -D -K &
 sleep 3

 WINDOWID=$(xwininfo  -root -tree | grep rdesktop | grep "$IP" | awk '{print $1}')

 if [ "$WINDOWID" == "" ]; then
  echo no window found
  exit
 fi

 echo attaching to $WINDOWID...
 xdotool windowactivate $WINDOWID
 xdotool windowfocus $WINDOWID
 sleep 1

 xdotool key "Return"
 xdotool key "Return"
 xdotool type "$PASS"
 xdotool key "Return"
}

And then just run:
source ~/.bashrc
rdesktop_autologin 10.1.1.10 Username Password
It makes my life so easier. That said, legal notices are here to be read. Heh.

Monday, February 24, 2014

Linux rdesktop fullscreen script

Under Linux with Gnome for example, you might want to rdesktop into a windows host and go full screen. However then it’s a real pain to reduce the window and switch between running apps, so you end up trying to find out the most appropriate resolution for your rdesktop session.

Here is a shell script to detect the screen dimensions, excluding the window manager’s top and bottom bars, and remove the rdesktop window decorations. Also it will map your /tmp and /home/user into the remote desktop session.

Adjust the number of pixels to exclude according to your configuration. I found the value 50 appropriate for a standard gnome-shell in classic mode, each of the bars being 25px.
#!/bin/bash
Xaxis=$(xdpyinfo | grep dimensions | awk '{print $2}' | cut -dx -f1)
Yaxis=$(xdpyinfo | grep dimensions | awk '{print $2}' | cut -dx -f2)
MaxRes=$Xaxis"x"$(($Yaxis-50))
rdesktop $1 -5 -u "$2" -g $MaxRes -r disk:home=${HOME} -r disk:tmp=/tmp -r clipboard:PRIMARYCLIPBOARD -D -K
And then you can run:
sh rdesktop.sh 192.168.0.10 MyUsername
Now go create a launcher for that.