Copy files between cPanel accounts with PHP

robocrop

Member
Mar 19, 2008
14
0
51
I have a central website on my VPS. That website creates HTML micro sites for my users. That central site is on a regular cPanel account.

Each time someone requests an HTML site, the PHP script creates a cPanel account for that user and in theory (PHP) copies the HTML to it.

However I can not do this due to permissions problems with PHP. One cPanel account can not copy files to another. This is only one way, i.e. only the central website cPanel account will ever need to copy files from itself to the user's cPanel account (never the other way).

Is there any way of accomplishing this? Could I grant that central user root privileges?



Thanks,
Ed.
 

d_t

Well-Known Member
Sep 20, 2003
245
3
168
Bucharest
if you have open_basedir enabled, you cannot access other users files from PHP. You can try to disable open_basedir for central account, but this solve only first part of the problem. After central account create the files for the other accounts, they will have user "nobody" so the other users cannot change them from FTP (but also allows you to change the files from central account).
 

robocrop

Member
Mar 19, 2008
14
0
51
Thanks for the reply. The users will never have access to ftp or their cpanel account. Only the main account needs to be able to copy from itself to the use account.

Even with open_basedir disabled, wouldn't there be an apache perms issue? If cPanel account (and hence apache user) 'mainaccount' tried to copy from /home/mainaccount/public_html TO /home/someuser/publich_html would it be allowed? And would it be able to overwrite those files with newer ones in the future?

Thanks,
Ed.
 

d_t

Well-Known Member
Sep 20, 2003
245
3
168
Bucharest
If users will never have direct access to files (from FTP or cPanel's File Manager) then you can create all files under nobody user (the user of apache/php). By default, nobody user can only read the files in user's public_html directories. You should also set write permission (you can du this automatically, using postwww script (see http://www.cpanel.net/support/docs/hooks.htm command will be chmod g+w /path/to/public_html )

This can be a security problem if other users have access to FTP, because they can also write files in user's public_html directories. For those, you should activate open_basedir and disable any shell execution from php. More, if sitebuilder generate only html files and no php files, you can disable php for users and keep it enabled only for central account
 

robocrop

Member
Mar 19, 2008
14
0
51
my php file is actually called by a cron job. That php file 'websiteMaker.php' executes a shell command 'wget' which saves the flat HTML files. It's those files that I want to copy across to the relevant /home/userAccount/public_html

Those flat HTML files are not created under nobody user, they are created by 'mainAccount' user.

I will look into postwww. Will this enable me to chmod 0777 the /home/userAccount/public_html ?If so, my main account would be able to copy and overwrite files to it?

Thanks.
 

d_t

Well-Known Member
Sep 20, 2003
245
3
168
Bucharest
I see. You can give 0777 permission to public_html using postwww script but this is not a good ideea for security (anyone can write in user website .. is a bad ideea).

You can do something else: set the cron job for each user, insead of mainAccount. In this way, files will be saved with userAccount owner and no need to change public_html permissions.

Or you can use FTP for transfering files from mail to user account. In this case, you need to store in sitebuilder the user/pass for FTP access to each user account. I saw this in latest Joomla versions.

In both ways, you need to make changes in sitebuilder software.
 

brianoz

Well-Known Member
Mar 13, 2004
1,146
7
168
Melbourne, Australia
cPanel Access Level
Root Administrator
Another alternative that may work better for you is to do a live include of the files from a master directory somewhere on the VPS. This has two advantages:
  • it saves disk space as only one copy of the PHP files is held;
  • it makes updating really easy - just update the central copy files and all the others will automatically get the latest versions

The disadvantage is that an error in the central scripts will take every site down, but then it's easy to fix once in the central scripts instead of having to edit every script.

I'd suspect the right way to do this is with the cpanel3-skel directory that provides a default set of files for a new account, but this may not be necessary.

If you're doing this sort of thing you may be interested in the free scripts we use here to allow postwwwacct to use a directory /etc/postwwwacct.d containing a bunch of small scripts to be run when an account is created. We use it for automated installation of software based on package names, amongst other things. See it here at www.whitedoggreenfrog.com/scripts/
 

robocrop

Member
Mar 19, 2008
14
0
51
thanks for the reply. My files are just flat HTML files. In the end I added a post account create hook to allow me access to the user's public_html file which is good enough for now. Thanks for the link also. :)