Random Wisdom

Software

SSH automatic reconnect on timeout

by on Mar.15, 2006, under How To ..., Linux, Software

There may already be some builtin option that allows a client to reconnect when a timeout occurs but I was too lazy to look through the man pages. So I came up with line of bash commands that will do just that:


$ while [ 1 ]; do ssh user@host.domain; sleep 120; done

This will keep reconnecting to the host 120 seconds after a connection drops out for whatever reason. This is specially handy to make sure that a remote tunnel stays open. Right now I use it to reach a single host (A,http) on a remote private network from home (B) via another machine in the private network (C) and an intermediate SSH server (D):

  1. [user@C ~]$ while [ 1 ]; do ssh -R someport:A:80 user@D; sleep 120; done
  2. [user@B ~]$ ssh -L 80:localhost:someport user@D
  3. [root@B ~]# echo "127.0.0.1    A" >> /etc/hosts

Now it is possible to type “http://A” and visit the site from B as easily as from within the remote private network.

4 Comments :, more...

Prosper & PDF Output

by on Feb.24, 2006, under How To ..., LaTeX, Software

Prosper cannot be used with PDFTeX and hence PDF files must be obtained via the DVI -> PS -> PDF route. The default ps2pdf conversion, however, generates a PDF with pages that are a bit too narrow. This is easily remedied by specifying the size of the output desired to the ps2pdf program:


$ ps2pdf -dDEVICEWIDTHPOINTS=x -dDEVICEHEIGHTPOINTS=y somefile.ps

Where ‘x’ is the width in and ‘y’ is the height in 1/72″ units. So, for an approximately A4 size output, ‘x’=595 & ‘y’=842.

Leave a Comment :, , , more...


Tesselated Cells

by on Feb.03, 2006, under How To ..., Software

Finally .. a script (link broken since 2007) that will generate a square field of tesselated cells in MATLAB. The script take as input the desired cell radius and the dimension of the square field.

Generating a cell is simple enough. The corners are simply R*exp(j*(-pi:pi/3:pi)+pi/6)/cos(pi/6). The additional pi/6 is needed to rotate the resulting hexagon. The real challenge is in the tesselation. In order to achieve that, two base vectors that govern the tesselation must be defined:

vi = 2*R;
vj = 2*R*(cos(pi/3) + j*sin(pi/3))

Using these base vectors, the centers of every cell in the tesselation can be defined:

for a = 1:x
    for b = 1:x
        centr(a,b) = a*vi+b*vj;
    end
end

One we have the centers, use the MATLAB repmat function to replicate the corners around each of the centers to get the tesselated cells:

cells = repmat(corners.', 1,...
               numel(centr))+repmat(reshape(centr.',1,...
               numel(centr)),length(corners), 1);

A plot of the cells can be achieved using:

plot(real(cells),imag(cells));

This will however, generate a tesselation that is skewed. The linked *.m file takes care of that issue to generate a square tesselated field.

2 Comments :, , more...

HTTP Access Control

by on Jan.25, 2006, under How To ..., Software

Finally figured out how to password protect individual directories on the server:

Authentication, Authorization and Access Control

It’s a simple 2-step process:

1. Create a passwords file for the users using “htpasswd“:

jsmith@server:~/public_html/db$ htpasswd -c ~/htpasswds jdoe
New password:
Re-type new password:
Adding password for user jdoe
jsmith@server:~/public_html/db$

2. Create a file “.htaccess” in the directory to be protected:

jsmith@server:~/public_html/db$ cat .htaccess
AuthType Basic
AuthName "db"
AuthUserFile /home/jsmith/htpasswds
Require user jdoe
2 Comments :, , , , more...

Proxy tools

by on Jan.25, 2006, under Software

There’s a very nice list of servers here:

Proxyz.net

This Firefox extension is handy for changing Proxies quickly: SwitchProxy

Leave a Comment :, , , more...

coLinux

by on Jan.19, 2006, under How To ..., Linux, Software

Recently, I needed to use Umbrello but didn’t have access to a workstation that had it installed. And since I’m stuck with a Windows PC, I thought I’d take a look at the KDE-Cygwin project. It seems that they’ve stopped working on the project since there is a better alternative: Cooperative Linux. It’s basically a modified Linux 2.6.10 kernel that runs on Windows — kind of a like a virtual machine but it’s different — it’s definitely a lot faster. Here’s a snippet from the coLinux homepage:

Cooperative Linux is the first working free and open source method for optimally running Linux on Microsoft Windows natively. More generally, Cooperative Linux (short-named coLinux) is a port of the Linux kernel that allows it to run cooperatively alongside another operating system on a single machine. For instance, it allows one to freely run Linux on Windows 2000/XP, without using a commercial PC virtualization software such as VMware, in a way which is much more optimal than using any general purpose PC virtualization software.

The project page had a preconfigured Debian image and so that’s what I’m using at the moment. The native X server does not work though — so the Cygwin based X server is needed to diplay all the GUI stuff.

Getting it installed was a piece of cake. The Wiki site for coLinux has a lot of helpful info.

Once the basic text-mode linux is up and running (must be able to reach the host via the network), we need to run some commands from the cygwin shell. First run


$ cygserver-config

to configure the cygwin server and then start the server with:


$ cygrunserver -S cygserver

Then, we need to set


$ export CYGWIN=server

And then start the X server in rootless mode. The easiest way is to just make a copy of the startxwin.bat file and then edit it to change the options to XWin.

Once the X server is running, we need to run “xhost +” from the xterm that had popped up. Then, we switch over to the coLinux console and run:


$ export DISPLAY=<ip of windows host>:0

And that’s it! Now you have a fully functional linux distro! I would have gone for a Fedora install but couldn’t find a proper image.

Leave a Comment :, , , more...

PSfrag for EPS Graphichs Text Manipulation

by on Jan.17, 2006, under How To ..., LaTeX, Software

There’s a nice package called psfrag that allows you to insert LaTeX constructs into EPS figures. This is specially useful with EPS files saved from MATLAB plots. The way it works is by replacing a given tag in the text of the EPS file with the LaTeX construct.

E.g. label the x-axis of of the plot as XLABEL and save the plot as an EPS file. Then, when you include that file, just put in the \psfrag{}{} tag:


\psfrag{XLABEL}{$\frac{\tau}{\sigma}$}
\includegraphics{file}

The most obvious disadvantage is that it only works with EPS figures — so no PdfLaTeX. So, to compile a document to PDF, you’ll need to go the old latex -> dvi2ps -> ps2pdf way.

More details can be found on CTAN.

Leave a Comment :, , , , , more...

Return of DARKWORLD

by on Jan.15, 2006, under Hardware, Software

Yup! My favorite PC just regained Net connectivity today. I moved into the new apartment this morning and was up and running by the evening. The guy who I share the place with wasn’t around and so I would have had to wait till I got the info about the wireless network. So, instead of waiting, I just decided to see what kind of a WLAN he has … and oh my oh my … there were 5 freakin’ access points around — and 3 of them completely unsecured! As it turned out, one belonged to the dude I share the place with …

Anyway, then I decided to catch up on my TV eps (Stargate SG1/Atlantis, Threshold, Supernatural, Doctor Who) and f*** the speed sux! It’s a bloody T-Online DSL1000 Flat deal. Anyway, the IP I got was “192.168.0.5”, so I deduced that the router should be at “192.168.0.1” or “192.168.0.254”. And sure enough there it was in the first address. Obviously, it asked me for a password that I didn’t know. So, I just tried “admin:1234” .. and nope, no go .. Then I thought I’d just do a little net search. The router was NETGEAR (deduced from the WLAN SSID), so I just googled “netgear default password” and the 4th hit came up with “admin:password”. Turns out the guy didn’t even change that password 😀 So, I got in, fiddled around with the NAT settings and Azureus was NAT free in no time. This has got to be the prime example of an unsecured network …

Anyway, once the guy got back, I explained everything to him and changed the router password and setup a WEP-key. It seems there was a machine leeching off of this net and things improved a little once that dude got kicked out. It turns out DSL6000 costs just as much as he pays right now — but he has no use for so much bandwidth when I’m gone — so we’ll just change to DSL2000 with 384k upload for now. That should be enough for me to download the occasional SG1 / Doctor Who episode 😀

Leave a Comment :, , more...

Proxy Bypass

by on Jan.10, 2006, under How To ..., Linux, Software

I guess it’s usual for every institution to have a central firewall/proxy that all internal traffic must go through to reach the outside world. I am by no means paranoid about security/privacy but it got me thinking.

… And once again, SSH to the rescue! It almost feels like the possibilites of a SSH tunnel with Local port forwarding are limitless 😀

I just picked up a public German proxy from this page:

http://www.publicproxyservers.com/index.html

And then setup a SSH connection to forward local port 8080 to proxy:port. Then for the browser I just set localhost:8080 as the proxy.

Well, the speed is a little short of astounding but it’s very much usable 😀 Now all that the central firewall/proxy should be seeing is a bunch of encrypted traffic.

Leave a Comment :, , , , , , more...