Click to See Complete Forum and Search --> : Execute system command via web page


nry
06-19-2002, 03:23 PM
Hi all,

I'm not too new to HTML but new to perl. I've been attempting to allow myself to run a perl script which executes a system command (in this case 'squid -z reconfigure' ). When run via a command line the script works as required ie it reconfigures squid.

I'm likely missing a simple step but I have a web page which has a link to said script. All it does when clicked is display the Internal Error page in my browser. Browser is on a remote PC (LAN)...

I know it is possible to do this type of thing but what am I missing? if it is alot can anyone point me a URL which would be useful? I've searched for ages myself to no avail.

Cheers,

nry

dchidelf
06-19-2002, 09:30 PM
Assuming everything is configured correctly to run CGI from the script's location, through the webserver...

Depending on the webserver's configuration, you may need to add a line to print HTTP headers at the start of the perl script.
print "Content-type: text/html\n\n";

If the script still fails try running it from the command line like this:
env - ./script_name.cgi
- or -
env -i ./script_name.cgi

That will run the script without any environmental variables... If it fails there it is likely you are missing evironmental variables needed to run the command.
You can set the needed variables in the script like:
%ENV{variable_name}='variable_value';

Thirdly...
It is likely to configure squid you need to have some higher permissions on the box. Even if regular users can run the command, you will have to check your webserver configuration to see if the cgi runs as nobody (or some other artificial webserver user) or if the script is run as the owner.
You can look into suexec to determine if it is compiled to work for the directory your cgi is in (its usually set to public_html in user directories)

Those are a few places you can start...

l01yuk
06-20-2002, 03:18 AM
(in this case 'squid -z reconfigure' ).


With system() commands you should to use the complete path to the program you want to run so you are not relying on the PATH variable which can be modified by the user.

system("/<path>/squid -z reconfigure");