1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

executing LInux commands from web

Discussion in 'Perl' started by john83reuben, Feb 19, 2008.

  1. john83reuben

    john83reuben New Member

    Joined:
    Feb 19, 2008
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    am trying to develop something just for fun by using perl & cgi scripting with linux.

    What I am trying to do is, creating user from the web.

    This is my html script
    HTML:
    <HTML>
    <BODY>
    <FORM METHOD="POST" ACTION="/cgi-bin/myscript2.cgi">
    <PRE>
    First Name <INPUT TYPE="text" NAME="name" MAXLENGTH=15 SIZE=15>
    <INPUT TYPE="submit" VALUE="Send Mail!">
    <INPUT TYPE="reset" value=" Clear-Form">
    </PRE>
    </FORM>
    </BODY>
    </HTML>
    
    This script suppose to get user input.

    then myscript2.cgi looks like tis
    Code:
    #!/usr/bin/perl
    
    use strict;
    use CGI;
    
    my $q = new CGI;
    my $name = $q->param( "name" );
    
    system("/etc/sbin/useradd $name");
    
    print $q->header( "text/html" ),
    $q->start_html( "Welcome" ),
    $q->p( "Hi $name!" ),
    $q->end_html;
    
    BUt it does not create the users. I wonder y. This system lacks in security. BUt I am doing it only for fun in localhost. Im learning step by step phase.if can create users. I wana figure it out how it can be done securely.
    But my question is how to receive the parameter from the web and use the parameter with useradd comand and create the user.

    HOpe u guys can give me ideas
     
    Last edited by a moderator: Feb 19, 2008
  2. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    Your perl script is executed by the Web Server's user (usually apache or nobody), which have few system privileges. To run these commands you need to run the script as a privileged user. You can use suexec(http://httpd.apache.org/docs/1.3/suexec.html) or use the sudo command.
    To secure your script you must implement some authentication to access the script, additionally you may also use SSL to access the script.
     

Share This Page