bobrobclob has asked for the wisdom of the Perl Monks concerning the following question:

Hi Perl Monks,
First of all i would like to say that i am fairly new to linux and extremly new to perl! Any replies should be in idiot form if possible. Thanks.
This problem has had me baffled for a long time now, and i havn't come accross any answers that i think i can use.
I have a script that takes the input from a web page and needs to run the adduser command and edit a few files on my server. Now, i know that all of the input needs to be checked before being run - and i have this bit covered.
For OS reasons, i cannot use Sudo and if i am going to ssh into the server, this will need to be done with key files (as this is the only way my server will accept an ssh connection).
Can someone please help me! examples would bve greatly appreciated.
The above is currently being done by writing files and using cron, but i need an instant way.
Thanks People.

Replies are listed 'Best First'.
Re: Running Commands From Web
by andye (Curate) on Aug 23, 2002 at 17:18 UTC
    Hi bobrobclob,

    Your problem isn't terribly clear - which part are you having trouble with:

    - running a system command from a CGI script (a CGI script is a Perl program which can be run from a web page)?

    - using SSH (maybe from Perl)?

    - something else?

    And is the server that you're trying to run 'adduser' on, the same server that the CGI script and the webserver are running on? (It is, right?)

    If you can expand on your problem a bit, I'm sure someone'll be able to help.

    All the best, andye.

    Update: I read the question again... it's a permissions problem? The user that the webserver runs as doesn't have the privileges to run the sytem command? If so, you might want to look at suidperl and perlman:perlsec.

Re: Running Commands From Web
by neilwatson (Priest) on Aug 23, 2002 at 15:50 UTC
    Your description seems a little vague to me. Howerver, if you are tying to addusers via a web interface perhaps Webmin is what you need.

    Neil Watson
    watson-wilson.ca

      i need to be able to run the command 'adduser .....' from a perl script with only webd permissions.
      I know of Webmin, and would like to know how that goes about adding users to a unix box from the web
        The source code is available for Webmin. If you want to know how it works I suggest you look there.

        Neil Watson
        watson-wilson.ca

      You should use the webmin user / groups editor module. It is easy to use and safer as you are dealing with root permissions.
Re: Running Commands From Web
by rbc (Curate) on Aug 23, 2002 at 16:43 UTC
    You can always execute programs from your Perl script
    with ...
    `myscript -x 123`;
    ... or ...
    system ( 'myscript', '-x 123' );
    Just do ...
    $ perldoc -f system
    ... from your command line and read all about it.
    You might want to also look at CPAN
    for other ways of dealing with ssh.

    I hope that helps.
Re: Running Commands From Web
by Silicon Cactus (Scribe) on Aug 23, 2002 at 19:49 UTC
    Uh, not to beat a dead horse, because this comes up quite frequently here.

    You might want to be careful about running things like this from a web interface. Especially utilities that require root level permissions to run. You could be starting a security nightmare for yourself.

    Just my $.019
Re: Running Commands From Web
by waswas-fng (Curate) on Aug 23, 2002 at 20:34 UTC
    First of all i would like to say that i am fairly new to linux and extremely new to perl!
    You just described a person who should not be doing what you are asking help to do. Try Webadmin, It is written by someone who does have experience with Linux and perl. No need to reinvent the wheel, especially when you don't necessarily comprehend what the wheel does yet. =)

    -Waswas
A reply falls below the community's threshold of quality. You may see it by logging in.