Thursday, 4 February 2010

Accessing your Intranet via Privoxy

At our workplace we have several webpages that are filtered by IP. If you don't want to use VPNs, then you can access them easily via a ssh tunnel and privoxy.

This is actually quite easy. Just install privoxy in the machine inside the local network (with Ubuntu this is already pre-packaged for you, so just run Synaptic Package Manager and install it). It is normally configured to run automatically after every reboot, and that is just fine. It is also configured to listen in the 8118 port.

So now, if we are outside our local network, we can create a ssh tunnel. We can do this with a config file like this:

$ cat .ssh/config
Host work
HostName vaso.myinstitute.org
User myuser

#Privoxy
LocalForward 8118 localhost:8118


With this in place, when we do "ssh work" from outside our network, we will connect to vaso.myinstitute.org and at the same time we will create a tunnel in which all requests to local port 8118 will in fact be redirected to port 8118 in vaso.myinstitute.org (where privoxy is running).

Now in the PC outside the local network, just get Firefox with FoxyProxy (some details to configure this are in previous post:BBC iPlayer Overseas) and create a proxy configuration for Privoxy, where the IP address is 127.0.0.1 and the port 8118. When you activate this configuration (if you have the ssh tunnel in place), all your traffic will be as if inside the local network.

BBC iPlayer Overseas

I'm quite fond of the BBC, but I'm currently located outside the UK, which means that by default I cannot use their BBC iPlayer. The following steps solve this. I assume you have Unbuntu Karmic (64 bits), although for other distributions the steps should be similar.

* As a browser we will be using Firefox, since it has a very nice Proxy manager (FoxyProxy), which makes things easier.

* First, we follow the option two in http://www.torproject.org/docs/debian.html.en to add the Tor repositories. Tor is an anonymizer, which will help to pretend that we are located in the UK.

* Then, via the Synaptic Package Manager we should install FoxyProxy, vidalia and tor.

* We want to have control as to when Tor will be running, so we run the following to avoid it starting automatically after each reboot

sudo update-rc.d tor disable

* When we want to start Tor, we use Vidalia, which will give us an easy way to start/stop tor.

* Once Tor is started (Vidalia will tell you "Connected to the Tor network!"), it is time to try if it's working fine with Firefox/FoxyProxy

* In the FoxyProxy options (clicking in the status bar of Firefox), go to File->Tor Wizard, and configure a new Tor proxy (without Privoxy, default port). In the URL Patterns tab, you can write URL patterns that you need to anonymize, for the moment make sure it has *torcheck*

* Then, from the FoxyProxy options in the status bar (click with right button), select the one that says "Use proxies based on their pre-defined patterns...", and visit: http://torcheck.xenobite.eu/index.php (if all went well you should see the message: Your IP is identified to be a Tor-EXIT.)

* Now, we want a bit more control, and we want to make sure that the exit node in Tor is based in the UK. For this, we should edit the file .vidalia/torrc in your home directory and add:

StrictExitNodes 1
exitnodes {GB}


(you can get the country codes needed in the "View the Network" option with Vidalia).

* Stop/start Tor from within Vidalia. Recheck with http://torcheck.xenobite.eu/index.php and now you should get a UK IP address.

* So now for the BBC... Add as patterns for the Tor FoxyProxy (perhaps not all are necessary, should recheck):

http://www.bbc.co.uk/iplayer/episode/*
http://www.bbc.co.uk/mediaselector/4/js/download/*
http://www.bbc.co.uk/mediaselector/4/mtis/stream*


* Now go to http://www.bbc.co.uk/iplayer/, and select any of the TV programmes in there. If it tells you "Currently BBC iPlayer TV programmes are available to play in the UK only" you have done something wrong. If the message is not displayed, but you don't see anything, perhaps is a Flash Issue. With my versions of Ubuntu (9.10, 64bits), Firefox (3.5.7) and Flash (Shockwave Flash 10.1 d51) this was solved by selecting "None" (no visual effects) in System->Preferences->Appearance->Visual Effects.

* Now get a beer and enjoy the BBC programmes...

Monday, 21 December 2009

3D animation creation service

Through something completely unrelated I found the xtranormal webpage, which lets you create simple 3D animations in a very easy way. In a minute you can create something really simple (for example: a greetings message). Creating a personalized cartoon for the kids goes now into the TO DO list...

Saturday, 19 December 2009

Backing up with rdiff-backup remotely

For some time I wanted to make a decent setting to create daily backups of my different computers, but somehow kept delaying it... Not any more...

In the end, it is actually pretty easy to set up (though I still need to verify that doing it automatically instead of manually does not give me any trouble).

I basically mount a remote directory in my local tree with sshfs

sshfs remote_machine:/net/angelv/BACKUPS /BACKUPS/NAS/ -o workaround=rename

The -o workaround=rename is important, as previously I was having trouble doing this sort of backup through sshfs (see this).

Once this is in place, having daily incremental backups is as easy as putting in my cron:

0 2 * * * rdiff-backup /home/angelv /BACKUPS/NAS/VASO.HOME.BACKUP
0 3 * * * rdiff-backup --remove-older-than 4W /BACKUPS/NAS/VASO.HOME.BACKUP

See more examples.

Friday, 18 December 2009

Missing libraries libstdc++5 in Ubuntu 9.10 when installing Intel Compiler

The installation script (for 64 bits) complains about libstdc++5 not being present, and it cannot be found in the default repositories. Installing the one for the previous Ubuntu version works fine. The details can be found, for example, in here.

After that, if you want to run the debugger, you also need to install the 64 bits version of libstdc++5, which can be installed automatically (all dependencies should be met) with GDebi, after downloading the package from here.

Thursday, 17 December 2009

Photo Mosaic creation tips

Related to my previous post, I spent some time figuring out how to get a good photo mosaic. Basically I wanted to create a Mosaic of a family picture, where the "metapixels" (i.e. the small images) would be pictures of the members of the family. The resulting image (about 75cmx100cm) was to be framed and put up at our home, in a corridor with maximum viewing distance of around 5.5 metres. And basically I wanted to make sure that the family picture could be properly appreciated when viewed from a distance, but also that the "metapixels" could be seen when looking at it close-up. So, I had to follow these steps:

1. Select all possible metapixel images (this is trivial but it takes some time: I wanted to make sure that all metapixels were related to the bigger images).

2. I found that many of my images had spaces in their names, which the metapixel software didn't like, so I substituted the spaces with underscores:

rename -v 's/\ /\_/g' *

3. I don't want the metapixels to be streched (metapixel will only work with one metapixels size) so I find for my set of images which sizes they have and how many I have of each size:

angelv@palas:~/Mosaic$ for img in `ls Mosaic-Original/` ; do identify -format "%wx%h" Mosaic-Original/$img ; done > sizes.txt

4. I find how many of them have a 3x4 ratio, and how many a 4x3 ratio. In my case, these numbers are very similar: 1089 (4x3) vs. 1051 (3x4)

5. Despite the number of landscape images being a little bit larger, I decide to build the mosaic out of the portrait ones, since portrait images are usually close-ups, and will be appreciated better when very small. To copy all the 3x4 images I use:

#!bin/bash

find Mosaic-Original/ -exec identify "{}" \; |awk '{
split($3,arr,"x")
split($1,name,"/")
if ( arr[1] < arr[2] ) { cmd = "cp " $1 " Mosaic-Original-3x4/"name[2] system(cmd) } }'


6. So now I can create the thumbnails with the correct ratio:

angelv@palas:~/Mosaic$ metapixel-prepare -r Mosaic-Original-3x4 Mosaic-Thumbs --width=96 --height=128

7. And now I can prepare the final mosaic image, but with the right ratio for the thumbnails:

metapixel --metapixel mosaico_in.jpg mosaico_out_cheat40.png --library Mosaic-Thumbs/ --scale=5 --distance=5 --width=48 --height=64 --cheat=40

The numbers are important...

* As I mentioned, the final picture has to be 75x100. My original image was 1857x2476 pixels. When asking metapixel to scale it by 5, the resulting mosaic has 12384x9280 pixels, so for 100cm (or 39.37 inches), this image can be printed at 314 dpi (300 dpi is considered a very good quality for printing).

* At the same time, each row of the mosaic will have 258 metapixels (12384/48), so each metapixel will be 3.87mm wide, which is small, but definitely viewable when you get close enough.

* A 40% cheating is quite large, but my set of images was not very large, and the distribution of colours was not very good, so when no cheating was used, the resulting image was very poor in colours, so I modified the original image to make its colours brighter, and I used a 40% cheat percentage, so the resulting image can be easily viewed from a distance, and it has plenty of colours. The artifact can be appreciated when getting close to the picture, but I think this is better than having a resulting mosaic with very poor colours.

The resulting image looks very nice, and I sent it yesterday to develop it (which is cheaper than I thought, just about 30 Euros).

Thursday, 10 December 2009

Photo Mosaic Software

I needed to create a Photo Mosaic today, and I just found the Metapixel software. I'm not sure how this rates quality-wise against other tools, but in a matter of minutes I had created a test Mosaic with whatever pictures I had on my hard disk following this post. Really nice! Now we have to spend tweaking the different options to get the desired result...