Current time: 04-19-2024, 08:49 AM Hello There, Guest! (LoginRegister)


Post Reply 
Automatic subdomain creation PLUS more...
Author Message
bulforce Offline
Junior Member
*

Posts: 63
Joined: Oct 2007
Reputation: 0
Post: #1
Automatic subdomain creation PLUS more...
Hello Everybody,

I have a little problem trying to figure out few things... Here is what i am trying to achieve.

I want users(random surfers) to be able to create new websites automatically as subdomains(for now, later as domains too).
But note that the site cannot be blank, i want them to have pre-installed CMS that i already have.

Currently i successfully created a web form that asks the user for the desired subdomain name and upon submit the domain is created in the system along with all files and directory structure. (dirty hack as usual)

However i get stuck on the point where the cms files needs to be copied in the newly created directory for the subdomain. I have tried php copy(), it was crying for basedir restrictions, disable it in php.ini but continue to cry "permissions denied". Then i decide to try shell_exec but it was crying because of disabled functions in effect, after removing the restriction there was no more errors, however no file was copied either. So i put everything back to normal in php.ini and start backtracing the normal creation of htdocs/* files... if i am not wrong it looks like its been handled by perl scripts withing the engine/ folder. Unfortunatelly perl is nothing that i know or even been exposed to, so i came here to ask for a little help.

How can i replace the default index page ?

here is my roadmap.
1. Automatic subdomain creation (Done, needs some tweaking)
2. Automatic Dump CMS files in /htdocs (STUCK)
3. Automatic Create mysql database and dump some data in it! (Pending)
4. Automatic Post Process (Pending)

Any help will be greatly appreciated.

Thank you
01-30-2009 05:09 PM
Find all posts by this user Quote this message in a reply
joximu Offline
helper
*****
Moderators

Posts: 7,024
Joined: Jan 2007
Reputation: 92
Post: #2
RE: Automatic subdomain creation PLUS more...
put the cms here:
/var/www/ispcp/gui/domain_default_page


about automatic domain registraton:
take care that no foreign domains can be registered. eg. gmail.com, hotmail.com - otherwise a customer can register this domain on your server, add a catch-all account and then get all mails to gmail.com and hotmail.com from the other customers of your server who send mails using your server.

/J
01-30-2009 05:20 PM
Visit this user's website Find all posts by this user Quote this message in a reply
bulforce Offline
Junior Member
*

Posts: 63
Joined: Oct 2007
Reputation: 0
Post: #3
RE: Automatic subdomain creation PLUS more...
I tried as you said just now, but nothing happened. All file permissions were set properly.
I wish it was that easy Smile


I am aware of the mail kidnapping variant, domain registration will be added in the future and will go trough some manual activation/validation.

Also the users wont get any access to the system at all anyway, just username and password for the cms.

Thanks

ADD:
Actually i just noticed the subdomain that i added while /var/www/ispcp/gui/domain_default_page was containing the CMS file. Is now displayed with status "Unknown Error" and i cannot even delete it trough the client interface.
(This post was last modified: 01-30-2009 06:08 PM by bulforce.)
01-30-2009 05:37 PM
Find all posts by this user Quote this message in a reply
ceco91 Offline
Moderator
*****
Moderators

Posts: 95
Joined: Jan 2009
Reputation: 0
Post: #4
RE: Automatic subdomain creation PLUS more...
Make a tar.bz2 with you CMS file and put it in /var/www/ispcp/gui/domain_default_page.

You should edit some perl' files.
IN /var/www/ispcp/engine/ispcp-dmn-mngr you should add in "dmn_add_httpd_file_data()":

Code:
sys_command("$main::cfg{'CMD_CP'} -p $main::cfg{'GUI_ROOT_DIR'}/domain_default_page/<you archive> $www_dir/$dmn_name/htdocs");
#Now the archive is copied in your domain htdocs directory
sys_command("$main::cfg{'
CMD_TAR'} -jzf $www_dir/$dmn_name/htdocs<your archive>");
#You have your cms extracted
sys_command('$main::cfg{'CMD_CHOWN'} $sys_user:$sys_user $www_dir/$dmn_name/htdocs/* -R');
sys_command('$main::cfg{'CMD_CHMOD'} 0644 $www_dir/$dmn_name/htdocs/* -R');
sys_command('$main::cfg{'CMD_CP'} $www_dir/$dmn_name/htdocs/<your archive> -f');

I don't know how to configure the cms but this will deploy your cms, I think.

Sorry for editing. I use too much copy-paste Smile
(This post was last modified: 01-30-2009 07:41 PM by ceco91.)
01-30-2009 06:22 PM
Find all posts by this user Quote this message in a reply
bulforce Offline
Junior Member
*

Posts: 63
Joined: Oct 2007
Reputation: 0
Post: #5
RE: Automatic subdomain creation PLUS more...
Thank you for your reply!

However i have little bit different approach. I am trying to do all those file manipulations within the ispcp-sub-mngr right after
Code:
opendir(DIR, "$sub_dir/htdocs/images/");
        my @files = readdir(DIR);
        closedir(DIR);

        foreach (@files) {
            # ignore . and .. :
            next if ($_ eq "." || $_ eq "..");
            $rs = setfmode("$sub_dir/htdocs/images/$_", $sys_user, $sys_group, 0644);
            return $rs if ($rs != 0);
        }

Thanks to ceco that help me to understand better how ispcp and perl are working i can now write things like:
Code:
$rs = sys_command("$main::cfg{'CMD_CP'} -rp $main::cfg{'GUI_ROOT_DIR'}/domain_default_page/cms-pakage/* $sub_dir/htdocs/");
return $rs if ($rs != 0);
## Files were copied
Which works perfectly fine, however... the following
Code:
$rs = sys_command("$main::cfg{'CMD_RM'} $sub_dir/htdocs/images $sub_dir/htdocs/index.html -RF");
return $rs if ($rs != 0);
or
Code:
$rs = sys_command("$main::cfg{'CMD_TAR'} -zxv $sub_dir/htdocs/cms-pakage.tgz");
return $rs if ($rs != 0);
Are resulting an errors and putting the subdomain in a "Unknown Error" Status

Quick look at the ispcp mysql database reveals this error messages:
Code:
sys_command() | ERROR: External command '/bin/rm /var/www/virtual/abc.com//123/htdocs/images /var/www/virtual/abc.com//123/htdocs/index.html -R' returned '1' status !
and
sys_command() | ERROR: External command '/bin/tar -zxv /var/www/virtual/abc.com//123/htdocs/cms-pakage.tgz' returned '2' status !


I believe that the problem is with the //, and i am wondering why $sub_dir translates to //123 instead of /123

Any ideas ?

Thank you
01-31-2009 09:06 AM
Find all posts by this user Quote this message in a reply
ceco91 Offline
Moderator
*****
Moderators

Posts: 95
Joined: Jan 2009
Reputation: 0
Post: #6
RE: Automatic subdomain creation PLUS more...
That means that your sub process has failed with error code 2.

You should test every command in bash window.
(This post was last modified: 01-31-2009 07:48 PM by ceco91.)
01-31-2009 07:48 PM
Find all posts by this user Quote this message in a reply
bulforce Offline
Junior Member
*

Posts: 63
Joined: Oct 2007
Reputation: 0
Post: #7
RE: Automatic subdomain creation PLUS more...
Just to let you know that i have some problems so i decide to upgrade ispcp to the latest nightly and now the commands are working good. I have few more questions if somebody can help me will be great.

1st
i have a file .../gui/tools/builder/adder.php that consist just of a modified subdomain add form. The data from the form is passed to modified copy of subdomain_add.php file that i am keeping in the same ..../builder/ dir.

I want to wrap my code in ispcp-sub-mngr with some if statement because now every subdomain i create no mather trough where is getting equiped with my cms files.
Here is the code:

Quote: foreach (@files) {
# ignore . and .. :
next if ($_ eq "." || $_ eq "..");
$rs = setfmode("$sub_dir/htdocs/images/$_", $sys_user, $sys_group, 0644);
return $rs if ($rs != 0);
}
## LINE 1524
## MOD "DEPLOY CMS"
$rs = sys_command("$main::cfg{'CMD_CP'} -rp $main::cfg{'GUI_ROOT_DIR'}/domain_default_page/cms-pakage/* $sub_dir/htdocs/");
return $rs if ($rs != 0);
## Files were copied
$rs = sys_command("$main::cfg{'CMD_RM'} -rf $sub_dir/htdocs/images $sub_dir/htdocs/index.html");
return $rs if ($rs != 0);

## END "DEPLOY CMS"


}

push_el(\@main::el, 'sub_add_httpd_file_data()', 'Ending...');

return 0;


2nd
Any ideas where should i start the automatic mysql db creation and the initial dump of data?

Thank you
(This post was last modified: 02-06-2009 08:51 AM by bulforce.)
02-06-2009 08:50 AM
Find all posts by this user Quote this message in a reply
ephigenie Offline
Project Leader
*******
Administrators

Posts: 1,578
Joined: Oct 2006
Reputation: 15
Post: #8
RE: Automatic subdomain creation PLUS more...
Right after you copied the data.
Just create a new db based on the subdomain name and then fill it with content from a dummy db maybe with importing a sql file into your newly created db like on a shell :

mysql --password=<newpass> -u <subuser> -p -U <newdb> < dummy-cms.sql

after it :
mysql --password=<newpass> -u <subuser> -p -U <newdb> -e "update users set password = crypt('newpassword');"
Or write it directly in perl this depends on your knowledge.
Have a look at the ispcp-setup or the upgrade script to find out how to do it in perl.
02-06-2009 09:02 AM
Visit this user's website Find all posts by this user Quote this message in a reply
bulforce Offline
Junior Member
*

Posts: 63
Joined: Oct 2007
Reputation: 0
Post: #9
RE: Automatic subdomain creation PLUS more...
Thank you.

I will try your advice and will post back.
02-06-2009 09:18 AM
Find all posts by this user Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)