SimpleRemoteURLServer

By admin
I have a long standing setup where I read my email on

one
CARDINAL

of our

Linux
PRODUCT

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
CARDINAL

of

two
CARDINAL

options; either I forwarded X over

SSH
ORG

and used

Firefox
ORG

‘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
PRODUCT

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
ORG

‘s off to some server, runs the program for the client end, and then reads lines from the

SSH
ORG

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
CARDINAL

programs combined are under

120
CARDINAL

lines of

Python
ORG

, 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
DATE

that

Firefox
ORG

only supports

D-Bus
ORG

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
DATE

. 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
ORG

connection is cut or something goes wrong with the other end.)