Design Build Test Repeat

Voluntarily cast upon the waves of outrageous fortune, this lowly geek flops from peak to peak of the technological ocean. Linux, Windows, C, Ruby, Python and embedded systems all attempt to pull our stalwart hero down. Will he survive alone or will the lifeboat of corporate servitude be too tempting.

Meraki – Custom ruby pages

Posted by Diarmuid on May 1, 2007

I have spent over a day now hacking into the Meraki and it’s pretty cool. As mentioned before, it runs a web server, has Ruby, perl, shell and (very importantly) serial access. Generally the serial access will be used to reflash your meraki using new images from Meraki Corp. or from OpenWRT if you are so inclined. I am not. At least not for now. I like what the Meraki does and don’t particularly want to trash it.

Therefore, I am going to try to work with what is there. They don’t make it too easy. Most areas of the meraki seem to be overwritten, including the web pages (Damn you! Damn you all to hell),and /etc/init.d.

I am assuming that you can SSH into your Meraki. Do that. Use Putty from windows. Then type ls -liah –color. The two directories of most interest are /storage and /www. Storage holds some config files for dropbear ( the SSH server), Boot_count( which is a good indication that this is not over written) , etc.

The www directory holds the static web pages (ccs, html, js), cgi (perl and ruby) and a number of directories for admin stuff. You can create files in here fine using vi and they will display if you browse to them, but they will vanish after a reboot and ( I think) after a preset period of time. So if we are to display our own pages, a solution is to be found that makes the pages permanent.

For now let’s experiment.
Go to the www directory by typing cd /www. Then create a file using vi by typing vi simplecgi.rb. Type in the following.
A simple CGI using Ruby
There are some nice vi tutorials out there but it’s dead easy. When presented with a file to edit, type i or a to insert or append text; backspace works but delete does not; use Esc to change commands. Use :wq to write and quit or :quit! to quit without saving.

Now browse to the relevant ip address in your browser and append on simplecgi.rb. You should get the following.
Simple cgi result html

Images map be downloaded (assuming you have a web server) by using wget . Easy, Peasy, Lemon , Squezzy.

But still there is that problem that the files are deleted on reboot. The solution lies is a facility that Meraki have included that allows them to append commands to the startup routine, even though the /etc/init.d area is over written. Because of copywrite issues, I am not going to print any of their code, but basically if a file called /storage/late-init.sh exists, it is run by the meraki startup routine.
My file looks like this
late-init.sh. Used to republish websites
There is another way, and that is to add some lines to the config file of the web server. That is is /etc/lighttpd.conf. But that is for another day.
Another example is one that allows you to append text to a file from a web page.
Code to save text to a file from a web page
And now if you want to read the file into the web page
Code that shows how to read a file and display it in a web page
So I hope that you enjoyed this little tutorial. There are loads of possibilities
In my next tutorial i will show how to write custom c programs for the meraki.
Please leave some comments below.
Cheers
Diarmuid

Advertisements

One Response to “Meraki – Custom ruby pages”

  1. JC said

    Great Tutorial !!! thanks !

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: