[BlueOnyx:11536] Re: Need CGI script to execute command as root - SOLVED

David Thacker David at ThackerNet.com
Mon Oct 15 08:00:56 -05 2012


>>
>> Okay, I guess I will pursue the cron job approach as suggested by 
>> others.
>>
>
> You could have a php script send an email.
> Then have a perl script run from a cron job that parses the contents of 
> that
> mbox and acts on it.
>
> I do something similar for customers that want to bock IP addresses but
> don't want to ssh.
> Ken


Thanks for the additional idea Ken.

For those of you keeping score at home, I did get my file download system 
working on the new server using a combination of a PHP input form and a 
couple shell scripts run via cron. This system is to create or delete 
symlinks in a virtual website that point to product zip files that are 
located in a folder outside of the /home/sites folder tree. When a 
customer purchases a software product, I generate the unique 
customer-specific download symlink and email that to them. After a 
specified number of days the symlink is removed.

1. I have my Download Manager PHP form in a virtual site, accessible to 
siteadmin only via .htaccess. This PHP script validates the input, and 
instead of actually creating and removing the download symlinks as the old 
Perl CGI script did on the RAQ, this one just writes out a job file into 
the same web folder as the script. There are "add link" jobs and "drop 
link" jobs. This does not need root access, so no need to run in the 
AdmServ realm as the old system did.

2. I created two shell scripts, one for adding links and another for 
dropping links. These shell scripts look for the add or drop job files in 
the vsite folder, and process them line by line adding or dropping links 
as the case may be. These shell scripts are owned by root. Actions are 
also logged to a file for review.

3. I added two jobs to the /etc/crontab schedule to invoke the addlink and 
droplink shell scripts every 5 minutes, like this:

*/5 *  *  *  * root /path/to/cron/addlink.sh


So, everything works great now, and I learned a thing or two regarding PHP 
in the process. Just enough to be dangerous...

dAvid tHacker                                  Email: David at ThackerNet.com
Thacker Network Technologies Inc.                Http://www.ThackerNet.com




More information about the Blueonyx mailing list