BobCares :: Outsourced Web Hosting Support BobCares :: Outsourced Web Hosting Support   Call us Toll Free US: 1-602-288-9145
Toll Free: 1800-383-5193
Search site:

Contact us | Get custom quote
 
spacer.gif
spacer.gif  
68394 Reads
Add to Google AddThis Social Bookmark Button

Ajaxterm - a Web based terminal

Posted on Tuesday, October 09, 2007 - 08:26 PM
  spacer.gif
 
Ajaxterm is a web based terminal. It is a simple solution for those who wish to run a terminal on web. Ajaxterm is fully written in python and Ajax.

Ajaxterm installation

         Software requirements
         Installation procedures

. Web server configuration

          Lighttpd web server configuration
         Apache web server configuration

Ajaxterm hacking

         Login shell creation
         Editing the startup script
         Increasing the terminal window size

Start Ajaxterm

Conclusion

A. References


Ajaxterm install

Ajaxterm is very simple to install on Linux, MacOS X, FreeBSD, Solaris, cygwin and any Unix that runs python2.3 or later. Ajaxterm will listen on port 8022 (by default ) for HTTP requests. You can change the port to another one.

Software requirements

Ajaxterm will work in most of the POSIX operating systems, including Linux, MacOS X, FreeBSD, Solaris, etc,. Let us take Centos or RHEL or fedora as a test environment.

Installation procedures

I prefer to read the "README.txt"file within the source code before the install. Here are the steps I followed.

# cd /usr/src
# wget  http://antony.lesuisse.org/qweb/files/Ajaxterm-0.10.tar.gz
# tar -xvzf Ajaxterm-0.10.tar.gz
# cd  Ajaxterm-0.10/
Now build Ajaxterm as follows.
# ./configure --prefix=/usr/local
# make
# make install 
Now the installation is completed. Next step is to configure the web server.

Web server configuration

The general idea behind configuring the Ajaxterm with a web server is to setup a proxy. You can see the configuration of Apache web server from the README file. It is very easy. Here is the procedure for configuring with lighttpd.

Lighttpd web server configuration

The lighttpd is a simple, good and lightweight web server You can use the following documentation for installing lighttpd.
http://bobcares.com/article59.html

So after installing the lighttpd web server please proceed with the following instructions. Make sure the module "mod_proxy" is enabled in the lighttpd configuration file ( /etc/lighttpd/lighttpd.conf)

server.modules = ( "mod_proxy" )
Now configure the proxy module as follows,
proxy.server = ( "/ajaxterm/" =>
       	         (
       	         	 ( "host" => "127.0.0.1",
       		            "port" => 8022
        	          )
        	 )

               )
Now in /etc/lighttpd/conf-available/my-proxy.conf add the following,
proxy.server    = ( "/cgi/ajaxterm/" =>
                   (
                    ( "host" => "127.0.0.1",
                      "port" => 8022
                     )
                    )
                   )
It is your own proxy server configuration. After that please copy the following files to your website document root folder.
# cp -vrf /usr/local/share/ajaxterm/   /home/mydomain.com/

Apache web server configuration

If you wish to configure apache web server with proxy, please add the following in the virtual host entry of your domain.

<proxy *="">
               Order deny,allow
               Allow from all
</proxy>
ProxyPass /ajaxterm/ http://mydomain.com:8022/
ProxyPassReverse /ajaxterm/ http://mydomain.com:8022/
Also I recommend to configure Ajaxterm with SSL or TSL for secure connections. Also you can set htpasswd for giving access rights . If so the apache configuration will be as follows,
    Listen 443
    NameVirtualHost *:443

    <virtualhost *:443="">
       ServerName localhost
       SSLEngine On
       SSLCertificateKeyFile ssl/apache.pem
       SSLCertificateFile ssl/apache.pem

       ProxyRequests Off
       <proxy *="">
               AuthType Basic
               AuthName "remote Shell Access"
               AuthUserFile /etc/apache2/htpasswd
               Require user tom
               Order deny,allow
               Allow from all
       </proxy>
       ProxyPass /ajaxterm/ http://mydomain.com:8022/
       ProxyPassReverse /ajaxterm/ http://mydomain.com:8022/
    </virtualhost>
Now copy the following files to your website document root folder.
# cp -vrf /usr/local/share/ajaxterm/   /home/mydomain.com/

Ajaxterm hacking

By default the Ajaxterm will start the program /bin/login. But I have created a simple login script for Ajaxterm ( using plain authentication ) . I will explain the procedure below,

Login shell creation

You can create a login shell by using bash scripting as follows.

First cerate a passwd file,
# cat >  /etc/we.shadow << EOF
  test:testpasswd
  EOF
Now create a shell as follows,
#cat > /bin/webshell << EOF
#!/bin/bash
export _user=`cat /etc/we.shadow| cut -d: -f1`
export _pwd=`cat /etc/we.shadow| cut -d: -f2`
echo -n "Enter Login Name:"
read login
echo -n "Enter Password:"
read pass
if [ $_user = $login ];then
        if [ $_pwd = $pass ];then
                exec /bin/bash
        else
                echo "Wrong Authentication"
        fi
else
        echo "Wrong Authentication !!!"
fi
EOF
Now give execute permission to this script as follows.
# chmod 755   /bin/webshell
So our login shell creation is completed. You can modify the above script for giving access to more than one users or for giving an encrypted password authentication.

5.2 Editing the startup script

So after creating the login shell . Let us change the default program to this shell. So please continue with the following steps.

Edit the startup script /etc/init.d/ajaxterm and modify the following line as given below.
daemon $ajaxterm --daemon --port=$port --uid=$user  --command=/bin/webshell  $OPTIONS
Here --command=/bin/webshell is the new option added to the startup script, so that the daemon will run this program by default.

Increasing the terminal window size

By default the Ajaxterm window size is 80x25. You can increase the window width as follows ,

Edit the file /usr/local/share/ajaxterm/ajaxterm.html
# nano  /usr/local/share/ajaxterm/ajaxterm.html
window.onload=function() {
               t=ajaxterm.Terminal("term",120,30);
      };
       
Now edit the python script /usr/local/share/ajaxterm/ajaxterm.py
#pico /usr/local/share/ajaxterm/ajaxterm.py
def __init__(self,width=120,height=30):

Start Ajaxterm

Let us start the Ajaxterm and web server

# /etc/init.d/ajaxterm start
# /etc/init.d/lighttpd restart
If you using apache as web server, then start the service as follows,
# /etc/init.d/ajaxterm start
# /etc/init.d/httpd restart
Now the Ajaxterm is up and running. You can access it as follows.
If you configured the proxy, then access the ajaxterm in the browser as ,
  http://mydomaiin.com/ajaxterm 
If you don't using the proxy, then access the ajaxterm as ,
http://mydomain.com:8022
The 8022 is the default port. If you wish to change the port, then change the port in web server configuration file and /etc/init.d/ajaxterm

hen you access the above mentioned url , then the browser will prompt for a login information. So now give the login information as mentioned in /etc/we.shadow

eg: 
	Enter Login Name: test
   	Enter Password: testpasswd
    	bash-3.00$
Now you can " su " to root or any other user . Even you can ssh to another server from this shell.

Conclusion

It is a nice script. It will help you to access your server terminal from any where in the world. The only requirements are an Internet connection and a web browser.

A. References

1. http://antony.lesuisse.org/qweb/trac/wiki/AjaxTerm
2. http://trac.lighttpd.net/trac/wiki/Ajaxterm


Articles by Sherinmon A About the author: Sherinmon works as System Administrator. He audits and maintains VPS servers for Datacenters.

In addition to System Administration, his passion is KungFu. He is a certified KungFu master.

 
spacer.gif
spacer.gif spacer.gif spacer.gif spacer.gif
Online
There are 26 guests and 0 members online.
 
FAQ | AUP | Partners | Contact Us | RSS RSS | Sitemap
© Poornam Info Vision LLC. All rights reserved.
Call us Toll Free: 1800-383-5193