Wandering Thoughts archives


My (new) simple system to open URLs on my desktop from remote Linux machines

I have a long standing setup where I read my email on one of our Linux login servers, instead of on my desktop. Email can include URLs that I want to open, so I need some way of opening these URLs in my desktop browser. For a long time this has been through one of two options; either I forwarded X over SSH and used Firefox's X-based remote control, or I was operating purely with text and selected the URLs in the terminal to use with my tools to open URLs in various browsers.

(Many local terminal programs can recognize URLs in text and open them for you, but I still use xterm, which doesn't try to do this.)

Firefox has been moving away from its X11 based remote control for some time, although it's not dead yet. However, recently opening URLs using the X based protocol over my DSL link got much slower (probably because of increased latency) so I decided I was going to hack together something very crude as a substitute. The result is a very simple 'pass URLs to the remote end' pair of programs that run over a SSH connection.

The 'client' end runs on the remote server. It listens on an abstract Unix domain socket, and when it gets a connection it verifies the UID that's talking to it (using Python code I already had lying around), reads a block of input from it, and prints it to standard output. The 'server' end runs on my desktop. It SSH's off to some server, runs the program for the client end, and then reads lines from the SSH connection, verifies that they are plausible URLs, and uses my existing (local) remote control scripts to open the URL. On the remote server, I use a shell script wrapping a netcat-like program I wrote to talk to the client end.

(Using an abstract Unix socket avoids a whole lot of yak shaving around managing the socket file, because an abstract socket goes away when the program that has it open exits. I do need a special client program that can talk to abstract Unix sockets, but I happened to have that lying around already.)

Including minimal comments, the two programs combined are under 120 lines of Python, and the most complicated bits were code I already had sitting around. The result is quite speedy; URLs now open more or less immediately. Although my local end is using X based remote control, it doesn't have to, so I'm insulated against the day that Firefox only supports D-Bus remote control.

(And the whole thing doesn't need me to forward X over SSH to the remote server; I could in theory open URLs this way even in remote sessions without X forwarding, although right now I think all of the programs involved would try to do other things if there was no graphical display.)

Opening URLs over remote X forwarding wasn't a fast thing even before the recent changes to my home Internet connection, so this would have been a little quality of life improvement for years. Given how simple it turned out to be, I wish I'd done it sooner.

Sidebar: Some more usage and implementation details

Right now I don't have a clever way of running the 'server' end on my local desktop; instead I open up a local xterm, manually run the server program (which sits there and doesn't go into the background or do anything clever), and iconify the window. If something goes wrong with my SSH connection or the programs, I'll re-run the server.

(There's various code to try to make sure that each end will exit if the SSH connection is cut or something goes wrong with the other end.)

On the remote end, the name of the socket includes both the login name of the person running it and the SSH client IP (taken from the $SSH_CLIENT environment variable). I include the latter because someday I may want or need to run this on both my home desktop and my office desktop at the same time, and I would like to make sure that I open URLs in the right display.

sysadmin/SimpleRemoteURLServer written at 22:11:06; Add Comment

Page tools: See As Normal.
Login: Password:
Atom Syndication: Recent Pages, Recent Comments.

This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.