DNS 325 - Funplug 0.7 : Administrate your NAS with Ajaxterm

Contents[Hide]

dropcap-dns325-ajaxterm

You may have to administrate your DNS-325 in console mode when you are away from home, without any SSH client available.

An easy and efficient solution is to use Ajaxterm SSH Web terminal.

It allows you to connect to your NAS with a simple Browser. You will be in front of a real SSH console, but within your browser.

This article will explain how to install Ajaxterm on your DNS-325. It should also be compatible with a DNS-320, but I've not tested it.

A pre-requisite is to have fully prepared your DNS-325 following DNS 325 - Fun_plug 0.7 : Extend your NAS possibilities (Optware is not needed anymore).

1. Install Python

As Ajaxterm is based on Python scripts, we need to install Python. Python is now provided by different repositories.

But as Ajaxterm is only compatible with Python 2.x, we need to install latest 2.7 version available from mijzelf repository.

# slacker -a mijzelf:python

2. Install Ajaxterm

Next thing to do is to :

  1. get the latest Ajaxterm package from qweb git
  2. install ajaxterm and qweb scripts under /ffp/opt/ajaxterm
  3. patch it with latest sarissa 0.9.8 javascripts (version 0.9.9 is not compatible)
    sarissa patch is needed to make it compatible with latest firefox releases.
    Otherwise, terminal background won't show and its width won't be handled properly.
  4. patch main script to run under /ffp instead of /usr
  5. modify main script to allow it to listen on all the network interfaces

# git clone git://github.com/antonylesuisse/qweb.git
# mv ./qweb/ajaxterm /ffp/opt/ajaxterm
# mv ./qweb/qweb_python/qweb/qweb.py /ffp/opt/ajaxterm
# rm -R qweb

# wget http://downloads.sourceforge.net/project/sarissa/sarissa/Sarissa%200.9.8.1/sarissa-0.9.8.1.zip
# unzip sarissa-0.9.8.1.zip
# mv ./sarissa-0.9.8.1/sarissa/*.js /ffp/opt/ajaxterm/
# rm -R sarissa*

# sed -i "s/\/usr/\/ffp/" /ffp/opt/ajaxterm/ajaxterm.py
# sed -i "s/ip='localhost'/ip='0.0.0.0'/" /ffp/opt/ajaxterm/ajaxterm.py

Ajaxterm is ready for configuration.

3. Configure terminal size

By default ajaxterm is providing a terminal of 80 columns and 25 lines.

You can change it by editing line 12 of /ffp/opt/ajaxterm/ajaxterm.html and replacing the values in the line :

/ffp/opt/ajaxterm/ajaxterm.html

...
t=ajaxterm.Terminal("term",132,32);
...

4. Setup background image

When using ajaxterm on multiple devices, you may need to setup a specific background image to make sure you always know on which device you are connected to.

This can be done quite easily with ajaxterm.

First thing is to inform the embedded web server that it should serve .jpg images (we suppose the background will be a JPG image).

You just need to modify line 478 of /ffp/opt/ajaxterm/ajaxterm.py to add the 'jpg' file type :

/ffp/opt/ajaxterm/ajaxterm.html

...
for i in ['css','html','js','jpg']:
...

Then, you need to modify the default /ffp/opt/ajaxterm/ajaxterm.css to :

  • set the background image
  • change font color to white (if background is dark)
  • set the transparency for all cells

/ffp/opt/ajaxterm/ajaxterm.css

...
pre.term {
...
background-color: black;
background-image:url('background.jpg');
...
}
...
pre.term span.f7 { color: white; }
...
pre.term span.b0 { background-color: transparent; }
pre.term span.b1 { background-color: transparent; }
pre.term span.b2 { background-color: transparent; }
pre.term span.b3 { background-color: transparent; }
pre.term span.b4 { background-color: transparent; }
pre.term span.b5 { background-color: transparent; }
pre.term span.b6 { background-color: transparent; }
pre.term span.b7 { background-color: transparent; }

Last thing is to place a background.jpg image under /ffp/opt/ajaxterm/.

It should have a proper size (934×490 px for a terminal of 132 x 32).

5. Create startup script

For Ajaxterm to be launched at every boot, we have to create a startup script /ffp/start/ajaxterm.sh that will be handled by funplug.

This script has to be executable.

# mc -e /ffp/start/ajaxterm.sh
# chmod +x /ffp/start/ajaxterm.sh

/ffp/start/ajaxterm.sh

#!/ffp/bin/sh
#
# ajaxterm startup script
#
# History :
# 23/04/2013, V1.0 - New version without optware

# PROVIDE: ajaxterm
# REQUIRE: LOGIN

. /ffp/etc/ffp.subr

name="ajaxterm"
start_cmd="ajaxterm_start"
stop_cmd="ajaxterm_stop"
restart_cmd="ajaxterm_restart"

# get ajaxterm PID
AJAXTERM_PID='ps aux|gawk '$12 == "/ffp/opt/ajaxterm/ajaxterm.py" {print $2}''

ajaxterm_start()
{
  # start ajaxterm
  /ffp/opt/ajaxterm/ajaxterm.py -c "ssh localhost" &
}

ajaxterm_stop()
{
  # kill running instance from PID
  kill $AJAXTERM_PID
}

ajaxterm_restart()
{
  # kill running instance from PID
 kill $AJAXTERM_PID

  # start ajaxterm
  /ffp/opt/ajaxterm/ajaxterm.py -c "ssh localhost" &
}

# run the command given as parameter
run_rc_command "$1"

6. Start the service

You can now start the service :

# /ffp/start/ajaxterm.sh start

Only thing left is to connect to your NAS with your browser http://your.nap.ip:8022/

You should see something like that !

dns325-ajaxterm-screenshot

7. Access thru a Reverse Proxy

If your DNS 325 is not directly accessible from internet, you can configure your Apache 2 web server to act as a reverse proxy to forward the request to your DNS 325 Ajaxterm console.

You just need to declare the following lines in your Apache 2 virtual host :

apache virtual host configuration file

<VirtualHost *:443>
 ServerName your.site.url

 ProxyRequests Off
 Order deny,allow
 Allow from all 

 # DNS-325 - Ajaxterm reverse proxy
 ProxyPass /ajaxterm/dns325/ http://192.168.x.x:8022/
 ProxyPassReverse /ajaxterm/dns325/ http://192.168.x.x:8022/
</VirtualHost>

where 192.168.x.x is the LAN address of your DNS-325.

After an Apache 2 restart, you will be able to access your DSN-325 ajaxterm from :

  • http://your.site.url/ajaxterm/dns325/ if your host is a standard HTTP host
  • https://your.site.url/ajaxterm/dns325/ if your host is a SSL one

It is obviously advised to use a SSL reverse proxy for your SSH connexions !

Hope it helps ...

Signature Technoblog

This article is published "as is", without any warranty that it will work for your specific need.
If you think this article needs some complement, or simply if you think it saved you lots of time & trouble,
just let me know at This email address is being protected from spambots. You need JavaScript enabled to view it.. Cheers !

icon linux icon debian icon apache icon mysql icon php icon piwik icon googleplus