Forum Moderators: coopster

Message Too Old, No Replies

Autoprovisioning in WHM/CPANEL

         

Bluesprocket

10:06 pm on Jul 11, 2008 (gmt 0)

10+ Year Member



Hi, I am writing a script to auto set up new sites using WHM's API.

The issue I have is populating the sites after it is provisioned.... I am able to provision, create the databases, populate the databases, ftp a tarball to the new site all using my PHP script but I need to know how to untar the file. I have tried shell_exec, exec, etc... and as PHP runs as "nobody", I get no love. Anybody overcome this issue in a "secure" way? Any help would be appreciated.

[edited by: Bluesprocket at 10:07 pm (utc) on July 11, 2008]

eelixduppy

5:24 am on Jul 12, 2008 (gmt 0)



What are the errors you are getting, if any? Are you running in safe mode?

Bluesprocket

5:09 pm on Jul 12, 2008 (gmt 0)

10+ Year Member



I dont get any errors. It just wont untar the file...which I am sure has to do with the fact that PHP runs as nobody and wont execute a shell command on a different account than the one it was initialized on.

I can of course ftp individual files to the new account but the page I am trying to populate the site with is a complete site in a tar file.....ALOT of coding to create a script that creates directories and moves each file by itself....trying to cut down on that and just get this project finished....anyone know of a solution? And no..it isnt running in safe mode

[edited by: Bluesprocket at 5:14 pm (utc) on July 12, 2008]

Chris_Mohr

8:01 pm on Jul 12, 2008 (gmt 0)

10+ Year Member



When I was doing something similar, I did it like this in ruby.

destination_directory = "/home/#{user_name}/www/"
`sudo cp -rRp #{$source_directory}/. #{destination_directory}`
`sudo chown -R newguy:newgrp #{destination_directory}`

I don't remember exactly why though.

Hope it helps.

I imagine you could untar using sudo as well. Not sure if you can find a secure way of letting php use sudo though, especially if it's running as 'nobody'.

I imagine that you can specify a user for php to run as. Maybe in the conf file?

eelixduppy

4:27 am on Jul 14, 2008 (gmt 0)



Try exec() again, but this time let's do some debugging:

$output = array();
$return = null;
$command = 'Your command...';
exec($command, $output, $return);
# debug info
echo '<pre>'; print_r($output); echo '</pre>';
echo 'Return value: ' . $return;

Tell me what this script outputs.

Bluesprocket

5:01 pm on Jul 14, 2008 (gmt 0)

10+ Year Member



Here is what came back.....

Array
(
)

Return value: 2

eelixduppy

5:09 pm on Jul 14, 2008 (gmt 0)



Are you sure that your command is correct? Can you run the exact same command through the shell? You are getting NOTHING output from the command that you are running and a return value of 2, which to me suggests a specific error is occuring as a return value of 0 usually suggests a success.

Bluesprocket

6:19 pm on Jul 14, 2008 (gmt 0)

10+ Year Member



Here is the command I am running....

tar -xf /path_to_dir/file.tar

simple untar command. Does absolutely nothing to the tar file. tried changing ownership of the tar file to nobody and the the account holder...doesnt work. Pretty much ready to give up and try ftp'ing each file in the tar file individually but I may have issues with creating directories so Im pretty screwed unless grant all permissions to nobody right? Huge security hole there....

eelixduppy

7:47 pm on Jul 14, 2008 (gmt 0)



So you are saying that it doesn't work when you do it manually in the shell, as well? There is something you are doing wrong I'd imagine. You should also note that it doesn't do anything to the tape archive file itself, but rather extracts the data into the directory. So "doing nothing" to the TAR file isn't exactly something wrong, because that's what it normally does. Get this working in a shall first, and then add the PHP to it. If you need further help with the tar command then I'm sure you can find out why it isn't work for you in the Unix Forum here at WebmasterWorld. Good luck!

Bluesprocket

8:32 pm on Jul 14, 2008 (gmt 0)

10+ Year Member



No.... I do it from the shell as root and it works fine. There is nothing wrong with the command I am using. I believe it is a permissions issue but have no work around that will leave my server secure.

I can upload a site specific script that will untar the file in the newly created directory but I cant touch off the script as the script is owned by the site.

As I said, this is so that I can dynamically provision and populate sites using whm's api. Is the only answer to this to upload each page individually? It would be so much easier if I can just send a tar or zip file to the site and open it.

[edited by: Bluesprocket at 8:36 pm (utc) on July 14, 2008]