Saturday, June 23, 2012

Build Your Own Web Server In 2 Minutes..

Early this week i have received a e-mail , asking financial help for a 2 year child who was about to undergo a bone marrow surgery.

I have created a spreadsheet using google docs and was updating the donations and calculating the total amount collected minute by minute. :) Very soon i got a feedback that many of our colleagues does not have internet access to view/track the donations :( . I was wondering how can i share the sheet with the users who does not have internet access but we are in connected in network.

Obviously its difficult to share the updated spreadsheet every minute to the requesting person since it involves manual time in gather email id and copying the sheet and mailing them every time i update the sheet.

Suddenly i recollected a light weight web server created few years back in python. I made it again in just minutes and shared the URL. My work got minimized the only thing i need is to update the html page and everyone see it from their browser.

URL is  http://My-System-IP:8000, The below is the screenshot, I have blurred my system ip for security reasons

Building WEB SERVER in 2 Minutes

Step 1)  I am assuming you already have python installed. If you dont have it please download and install it from http://www.python.org/getit/

Step 2)  Python Code, Save the below code as webserver.py
                                        import SimpleHTTPServer
                                        import SocketServer

                                        PORT=8000
                                        Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
                                        httpd = SocketServer.TCPServer(("",PORT), Handler)
                                        print "Serving at port ", PORT
                                        httpd.serve_forever()
Step 3)  Create a index.html or home.html page with the below code and save at the same location where you have saved webserver.py
                       <html>
                       <head><title>Hello </title></head>
                       <body>Hello World </body>
                       </html>

Step 4)  Double click on the webserver.py program,  a command prompt pops out saying
             "Serving at Port 8000" as shown in the below screenshot

Step 5) open your browser and type http://your-system-ip:8000, Should look like below screenshot

Log on the Command prompt which opened at step 4)

Note : If you have note created home/index.html file , python will list the contents of the drive as shown below.This way you can share your documents with colleagues or peers.
     

        

Python Rocks !!!! Creating this a web servers needs heavy application like Tomcat Apache, Of course if you want a light weight application the python is the superb solution

Please share your views/comments at Rakeshkumar.techie@gmail.com

Friday, June 22, 2012

Mount Linux Drive on Windows using samba in just 3 steps

Step 1:
Install samba from source or repository in your linux machine

Step 2:   
    a) Backup the current settings   
       cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
   
    b) vi /etc/samba/smb.conf and add a service as mentioned below
      
        [testsamba]
                comment = TEST
                path = /share-path
                read only = Yes
                guest only = Yes
    c) Run below command as root
         #testparm 

Step 3:
Mouting the Drive
   
Windows:
      c:\net use j: \\Linux-ip\testsamba
Note : Choose any drive letter which does not exists in your machine, like j: in my machine     

The above command should display "Command successfully completed"

Testing the mount from linux machine

Linux :  
    $smbclient //20.252.139.51/testsamba, this will take you to smb prompt.Issue command like ls or l to see the list of files, for more info type help

I will be sharing samba security options in next article

Thursday, June 14, 2012

NFS Mount Steps and Troubleshooting Most Common Errors

How to NFS mount between two computers ?

Source Machine:  Physical location of folder

Target Machine:    Mounted location pointing to the source physical location

SOURCE and TARGET MACHINE

1 )   Installed nfsd from respective package manager like yast,apt ..etc on both the systems

2 )   Check mtab to mount the nfsd in /proc/fs/nfsd

SOURCE MACHINE

3 )   Edit the /etc/export at the source server from which needs to be shared

Syntax
                 Folder Path     IP-Address (rw,sync,no_subtree_check)

# Folder Path which you want to share
# IP-Address of Target machinge

4 )   check if /etc/export changes refreshed "exportfs or exportfs -a" at source computerd

TARGET MACHINE

5 )  Backup the current /etc/fstab like cp /etc/fstab /etc/fstab.bak

6)   Edit the fstab file as shown below  

        IP-Address:Source-Path Destination-Path nfs rw,sync 0 0da

IP-Address : Source Machine  IP

Source Path: Physical location of file

Destination : Mount location

6 )   mount /Destination-Path

TROUBLESHOOTING

a) If the message while mounting is "nfs version not supported"

  /etc/init.d/nfsserver status  -- if this says unused or not started, Please start it using the below command

    /etc/init.d/nfsserver start 

The above command should say nfs services started

b) If the message is "permission denied"

Make sure that /etc/exports entries are correct , and dont forget to type exportfs to reflect the changes on Source machine which will export source folder to target machine

c) If Already mounted and facing issues in re-mouting then try to unmount the existing folder though its not mounted as shown below

umount Destination-folder

mount Destination-Folder

Some time it works like charm 

d) nfsstat should display some nfs server information, else there some prob in installation/starting nfsserver goto step a

Monday, June 11, 2012

How to Multiply two numbers without using +,- or * Operator



Multiplication is nothing but repeated addition, so as long as you could figure out a way to add two numbers, then repeating them will also provide you product of two numbers.

Since, Python is the best language, I am giving the solution in Python only.

import sys
def recurse(a,b):
  x = a^b
  y = a&b
  if y:
     return recurse(x,y<<1)
  else:
     return x

if __name__ == '__main__':
   a = int(raw_input("Enter value of 'a' --> "))
   b = int(raw_input("Enter value of 'b' --> "))

   product=0
   for i in range(0,b):
       product=recurse(product,a)
   print repr(a) + " x " + repr(b) + " = " + repr(product)

Internally this uses bitwise operations.

----
For more info please contact me at rakeshkumar.techie@gmail.com



Happy Programming -- Happy Hacking

Monday, June 4, 2012

Code for Cause - New Delhi ( www.gdg-hack.com )

Coding For Cause , Isn't it sounds exiting? yes, you heard it right. If you are looking to code for cause then here is a right platform. Google Developer Group (GDG) - New Delhi is launching hack fest on 16 and 17 of June 2012.

Choose a theme from http://www.gdg-hack.com/home.php and register yourself(team) at Rs 350* only. (*Registration fee may be increased to 500 Rs later)

Can I code on my own theme ?
yes, enter your own theme under "others" and proceed.

What languages can be used ?
you are free to use any open source languages or technologies.

For more info and updates visit www.gdg-hack.com









               

Friday, June 1, 2012

Hacktivists want Internet curbs to go


Hackers named anonymous are launching a DOS and DDOS attack on various websites which are supporting the internet censorship.

*DOS   : Denial of Service
*DDOS: Distributed Denial of Service

Read more from the below URL

http://www.thehindu.com/todays-paper/tp-national/article3474885.ece