Harsh J

Memoirs of a QWERTY Keyboard

Fixing connection breakages in older Belkin routers

leave a comment

A recent power cable burn out near the local transformer in my living area caused a power problem that ended up frying most of my power adapters at home – so it made me take down that spares box I’d forgotten for a good 4 years about.

Within that I found an old router+modem hardware I’d purchased years ago and forgotten all about – a Belkin F7D1401 v1, with its power adapter. Ecstatic about having an alternative route to get back on the internet than having to travel a bit to get a fixed adapter for the existing one, I promptly tried to setup the router to connect to my ISP.

Upon initial startup and connect, I received an IP of the form 169.254.x.x which basically would indicate the router not having actually assigned me an IP, such that my own machine had to do it. After a bit of fiddling I got over this by holding the router’s reset button for about 15 seconds instead of the immediate click-and-release reset. After the hard-reset the router was able to assign my devices its expected range of 192.168.2.x addresses.

The rest was a breeze and the router was promptly serving me worthless social media pages in no time. All smooth except, occasionally but not quite randomly, the internet link would go down and reconnect, making browsing a frustrating activity.

In looking at the System Log on the router, I noticed messages appear in the form of “ADSL Media Down !“, having about 14 seconds of pauses in services before it attempts a PPPoE reconnect (which can take a few additional seconds too). In looking over the web for others having this problem, I couldn’t come to a solution – some only had this problem during the evenings and attributed it to their ISP doing strange stuff then, others had delved down the path of noise increasing in lines during nights, etc. – fun reading for sciences but no real solution. I did not suspect my ISP as I’d know if the line really had a gap in service long enough to cause a reconnect – and monitoring for that revealed no such fact.

I did do a firmware upgrade to the v2 version available on the Belkin website for the router after I had begun using it, and felt that was to blame but there had to be a workaround, some function that is incorrectly reinitialising the router and on a schedule at that.

I found the culprit in my case – the router had a “Reinitialise Automatically” function enabled in it, set to do so to maintain the router’s efficiency by clearing up the memory periodically and the period was set to a proper 3 AMs every Tuesday. Not taking its word for it, and finding about only the second such schedule based function configuration in the UI, I disabled it and BAM! problem solved. Haven’t had connection resets since. My city’s periodic power outages will take care of the router reboots instead, thank you.

Written by Harsh

September 7th, 2014 at 8:47 am

Erlang: Using the timer:tc function in escripts

leave a comment

Both escripts and timer:tc features of Erlang are very useful for writing simple test code to profile functions.

There is one tiny issue with using timer:tc/1 or timer:tc/2 from within escripts though: they will not work in the interpreted execution mode.

For example, you may have an escript such as below:

#!/usr/bin/env escript
-module(test).

-export([generate_list/1]).

generate_list(N) ->
  lists:seq(1, N).

main(_) ->
  io:format("time: ~p~n", [timer:tc(generate_list, [1000])]).

Running this with “escript test.erl” would yield an error:

escript: exception error: undefined function test:generate_list/1
  in function  timer:tc/2 (timer.erl, line 179)

The issue is that the default escript mode is “interpreted” and not “compiled”. This leads to it not finding the function at all.

To fix the execution, one has to add the “-mode(compile).” line to the script, and also use the timer:tc/3 form of execution instead of the timer:tc/1 or timer:tc/2.

A fixed script of the above example would thus be:

#!/usr/bin/env escript
-mode(compile).

-module(test).

-export([generate_list/1]).

generate_list(N) ->
  lists:seq(1, N).

main(_) ->
  io:format("time: ~p~n", [timer:tc(?MODULE, generate_list, [1000])]).

I think the same should hold for apply calls too, or any function that uses the Module-Function-Arguments style of dynamic calls.

Written by Harsh

June 2nd, 2013 at 10:55 am

And they said…

leave a comment

Looking at the awesome activity lately on my blog:

Sorry.

Sorry.

Written by Harsh

May 22nd, 2012 at 6:21 pm

Posted in Personal

Gotta post something

2 comments

So here it is.

Wishing whoever reads this a better time ahead, as you replace those old calendars. And continue doing what you do best.

Written by Harsh

January 1st, 2012 at 2:38 pm

Posted in Personal

Tagged with

Running a local CGIProxy web proxy server on OSX

3 comments

What is CGIProxy?

It is slightly ancient today, but CGIProxy still appears to be one of the good web proxies (non-transparent, CGI-based proxy script) out there.

Also, being essentially a PERL script, its easy to set it up with an existing Apache2 install. Thankfully enough, Mac comes with its own Apache2 server well integrated and the work required to edit and configure it to run PERL scripts is trivial.

Some reasons why you might want to run CGIProxy locally would be to test a local website for how it handles session data, or to even use it generally to filter content over your network, etc.. I had the former need while working with Hadoop‘s web applications as part of what I do on a daily basis at Cloudera.

 

Here’s how to setup CGIProxy locally on your Mac OSX (or earlier/later):

Setup Apache2 to allow Perl and CGI execution

Over Applications – System Preferences – Sharing, disable ‘Web Sharing’ if it is running. This stops the Apache2 web server that may already be running.

System Preferences - Sharing

System Preferences - Sharing

Sharing - Disable Web Sharing before we configure Apache2

Sharing - Disable Web Sharing before we configure Apache2

With that out of the door, we should be able to edit out our Apache2 configs without any issue. With your favorite text editor, I use vim below, edit the file /etc/apache2/httpd.conf and append the following lines to it somewhere along the end:


AddHandler cgi-script .cgi

This would let Apache be able to interpret files ending with .pl as CGI-scripts.

Configure /etc/apache2/httpd.conf with Vim

Configure /etc/apache2/httpd.conf with Vim

The next steps is to configure and allow execution of such files via your user account, which we can do by editing yet another file named /etc/apache2/users/<Your username>.conf. For instance, on my setup, the file is called /etc/apache2/users/harsh.conf. Modify the ‘Options’ configuration to allow CGI Execution:


Options Indexes MultiViews ExecCGI

Configure /etc/apache2/users/"Username".conf with Vim

Configure /etc/apache2/users/"Username".conf with Vim

With that done as well, we’re now ready to setup CGIProxy.

Setting up CGIProxy

Fetch the CGIProxy tarball, which is about 170 KB strong. Extracting this would provide you a script called nph-proxy.cgi. Place it in the ~/Sites directory of your Home.

Place the CGIProxy script into the ~/Sites directory

Place the CGIProxy script into the ~/Sites directory

We’re done with installing CGIProxy.

Running CGIProxy

Now that we’re all set, we’ll just launch the Apache2 web server again and get to using the CGIProxy.

Head back to Applications – System Preferences – Sharing and enable ‘Web Sharing’ to run the server. Once up, you’ll get the public links to your homepage.

Enable Web Sharing under System Preferences - Sharing

Enable Web Sharing under System Preferences - Sharing

Head to <Your URL>/nph-proxy.cgi (For example, http://localhost/~harsh/nph-proxy.cgi) and you should see a properly functional, local CGIProxy ready for consumption. Hit it with a URL of choice and set some options you want it to use, and you’re off. Also look into the script with a text editor to see further configuration options.

CGIProxy in Chrome

CGIProxy in Chrome

Written by Harsh

October 1st, 2011 at 11:49 am

Posted in Personal