Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Using exec() for executing shell scripts in CGI

by leocharre (Priest)
on Dec 14, 2006 at 06:10 UTC ( [id://589753]=note: print w/replies, xml ) Need Help??


in reply to Using exec() for executing shell scripts in CGI

I would be asking myself a few things.. For example; is there any chance that someone will run your bash/whatever script from the command line? What if you fed your executable script some bogus info, will it blow up, ruin something? I don't know that you have to make an executable any less secure then a regular cgi script. It *is* easier to debug though then stinkin' cgi.. ack.. ugh. *cough*.. excuse me.

I'm not sure how far along you are in this venture- but i'll risk sounding obvious just in case and mention that: you have to remember that the script will not be run by *you*- it will be run by apache, or whatever user the web server is running as. Unless of course, you are running su exec- it lets scripts run with *your* permissions- super useful- but.. it means your scripts have the power to destroy any data that *you* can.

Also, if you need your script to do some freaky business like add or take out real users fromthe machine, i would look into sudo, which let's regular users (maybe a safer *you* or apache) do things to the machine that only root regularly can.

Personally, I have faced this kind of thing with making modules that have interface independent code/methods/subs- so.. it's really convenient for testing. And then your interface - be it cgi or cli- is almost (almost!) an afterthought.

Your module code would check all the parameters to make sure they are not crud- and then after something happens, it can check that it really did happen- etc. If your cli or your cgi calls the stuff- the meat is the same.

It's amazing how much the web can complicate a trivial task. sigh. Hope any of that helps.

  • Comment on Re: Using exec() for executing shell scripts in CGI

Replies are listed 'Best First'.
Re^2: Using exec() for executing shell scripts in CGI
by stumbler (Acolyte) on Dec 14, 2006 at 11:32 UTC

    Thanks for the responses

    As mentioned in original post, I preset the executables I need to run using the following approach:-

    I have a hash which has the list of commands that can only be used. Something like..

    my %commands = ( opt1 => exe1, opt2 => exe2, opt3 => exe3, );

    In the CGI script, I have a variable , $runmode, which can take a value of 'opt1' or 'opt2' or 'opt3'. I retrieve the executable by $commands{ 'opt1' } and pass it on to the shell script.

    I don't do any admin activities such as adding new user, deleting or modifying existing user accounts, etc.. using CGI scripts.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://589753]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (1)
As of 2024-04-25 02:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found