Jump to content

Automate DB & Script Installation


huggys

Recommended Posts

Hello,

 

I didn't know where else to put this, so please forgive me if I am posting in the wrong area.

 

I sell hosting and I use WHMCS (which I absolutely love!!! I am thinking of purchasing a license for a landscaping business too, lol)

 

With my hosting, I install a script for each of my customers. I have most of the script files in the cpanel3-skel folder so that they are automatically uploaded to a client's site upon creation. After that, I password protect 2 folders (one with no password and the other with the user and pass they choose while signing up through whmcs), manually create a database, upload a sql file to the database, modify 3 files (with website and db info), and change the permissions on one of those files through cPanel (it is a config file, so I can't change the permissions through FTP).

 

Is there anyway I can automate this process so that it is all done when a client signs up? Either in or out of WHMCS?

 

Thank you for any help on this!

Link to comment
Share on other sites

I actually did this for osCommerce - using osCommerce as the cart and setting up osCommerce for the customer. I even had a domain checker and registrar module. It definately was involved, but it worked. I like WHMCS better, but haven't got back to automating script installs.

 

I found file permissions set in the cpanel3-skel folder get set on the copy in the customer's folder. This helps.

 

What I used was a form/post class that grabbed variables from the checkout process and posted commands to cPanel to create a database, db user/pass, grant db permissions, run the SQL (file copied from skel), create user/pass, apply to folder to protect, write config files, CHMOD some files, etc. One step at a time and there were some timing issues as you don't have feedback if each step is completed. I had to sleep the script between steps.

 

As this was for a new domain/hosting account, the domain did not resolve yet. The commands had to be posted to my server's IP with the new user/pass.

 

When cPanel was upgraded from 10 to 11, most of the commands changed. If a customer changes their theme, the commands won't work either. I had to mimic the URLs as if you were logged into cPanel performing various tasks.

 

I can share the class file and some sample script if you want.

Link to comment
Share on other sites

Thank you all for replying.

 

Brianoz, I can't figure out how to PM. I've checked the forum help file and it says to click on the email button below a post, but that isn't showing up for me. I don't even see a place in my user cp where I would check messages. I was able to add you to my contacts in the user cp, but I'm not sure what that does.

 

I've just updated my signature to include my hosting link, so please feel free to contact me through that. I would love the help.

 

TonsOfStores, the script I use is osCommerce too, so what you wrote sounds perfect! Any help you could provide would be great!

Edited by huggys
add signature
Link to comment
Share on other sites

Yes, I am installing osCommerce for my customers. I have made a lot of revisions to it to make it more user friendly.

 

I would love it if you could share the specific osC stuff. I'm afraid I have no idea what I am doing. Thanks!

Link to comment
Share on other sites

Sure...But first:

 

*** Attempt on a non-live production machine first. ***

 

I removed out the custom fields I use to populate my table to keep some parts private, but I think you'll get the idea:

 

function actionhook_ClientSignup($vars) {

 

# This function runs when a new client is added

# $vars["ClientID"]

# $vars["FirstName"]

# $vars["LastName"]

# $vars["CompanyName"]

# $vars["Email"]

# $vars["Address1"]

# $vars["Address2"]

# $vars["City"]

# $vars["State"]

# $vars["Postcode"]

# $vars["Country"]

# $vars["PhoneNumber"]

# $vars["Password"]

$vars["custom1"];

$vars["custom2"];

$vars["custom4"];

if ($_POST["custom4"] == "2"){

// do nothing

} else{

 

### Setting up to send custom email and insert ###

// The Group ID to insert the user as belonging to. Leave as zero for no group.

$ttgid = 0;

// The Database name

$ttdb_db = "put your db name here";

// The MySQL username with access to this database

$ttdb_user = "user name here";

// The MySQL user's password

$ttdb_pass = "password";

// The host the database is on - most of the time - its localhost; other wise add IP:Port

$ttdb_host = "localhost";

 

#####################

 

$ttdb = mysql_connect($ttdb_host, $ttdb_user, $ttdb_pass);

mysql_select_db($ttdb_db, $ttdb);

$query = mysql_query(("insert into MY CUSTOM TABLE set firstname = '".$_POST["firstname"]."', lastname = '".$_POST["lastname"]."', custom1 = '".$_POST["custom1"]."', custom2 = '".intval($_POST["custom2"])."', custom4 = '".intval($_POST["custom4"])."', zipcode = '".$_POST["postcode"]."', email = '".$_POST["email"].'"), $ttdb);

 

// prep to send email

$to = $_POST["email"];

$subject = "Registration Complete";

 

$message = '';

$message .= '<br>';

$message .= '<br>';

$message .= '<p>Hello '.$_POST["firstname"].' '.$_POST["lastname"].'.';

$message .= '<br>';

$message .= '<br>';

$message .= '<p>First name: '.$_POST["firstname"];

$message .= '<p>Last name: '.$_POST["lastname"];

$message .= '<p>Email: '.$_POST["email"];

$message .= '<br>';

$message .= '<br>';

$message .= '<br><p>Regards,<br>';

$message .= 'Support Team';

$message .= '<br>';

$message .= '<br>';

$headers = "MIME-Version: 1.0\r\n";

$headers .= "Content-type: text/html; charset=windows-1251\r\n";

$headers .= "From: Registration Team <registration@yourdomain.com>\n";

$headers .= "Bcc: you@yourdomain.com\n";

mail($to, $subject, $message, $headers);

 

mysql_query($query, $ttdb);

mysql_close($ttdb);

 

}

 

}

 

RB

Link to comment
Share on other sites

Hi, thank you so much for posting. I contacted my host (I resell hosting) and they say that I can't do anything through cPanel's /scripts/postwwwacct script because of the way that their servers are setup. So, going through WHMCS is the way I need to do this.

 

Unfortunatley, I was not able to get this to work. I use dreamweaver and the line:

$ttdb = mysql_connect($ttdb_host, $ttdb_user, $ttdb_pass);
mysql_select_db($ttdb_db, $ttdb);
$query = mysql_query(("insert into MY CUSTOM TABLE set firstname = '".$_POST["firstname"]."', lastname = '".$_POST["lastname"]."', custom1 = '".$_POST["custom1"]."', custom2 = '".intval($_POST["custom2"])."', custom4 = '".intval($_POST["custom4"])."', zipcode = '".$_POST["postcode"]."', email = '".$_POST["email"].'"), $ttdb);

 

Seems to be missing a ' (of course, I'm not sure where, dreamweaver just pointed out the error).

 

All of this is greek to me. I really just copied/pasted this into WHMCS where the function actionhook_ClientSignup($vars) left off.

 

I'm assuming that the

### Setting up to send custom email and insert ###
// The Group ID to insert the user as belonging to. Leave as zero for no group.
$ttgid = 0;
// The Database name
$ttdb_db = "put your db name here";
// The MySQL username with access to this database
$ttdb_user = "user name here";
// The MySQL user's password
$ttdb_pass = "password";
// The host the database is on - most of the time - its localhost; other wise add IP:Port
$ttdb_host = "localhost";

is where I enter the database information for where I uploaded my sql file that I want on everyone's account. Am I correct?

 

I'm not worried about the automated email since WHMCS already sends an automated email with my custom message when an account is created.

 

Also, I'm not sure what all the [custom] stuff is.

 

Thank you everyone for all of your help so far! I really appreciate this.

Link to comment
Share on other sites

Thanks, that does look better. However, it is still not working. I am now thinking that it is missing a " because of the beginning:

(("insert into

shouldn't that have another " at the end somewhere?

 

Also, for the:

insert into MY CUSTOM TABLE set firstname

should I leave that as it is or should I be replacing the MY CUSTOM TABLE for something?

 

Thanks again for helping me with this! I'm sorry I'm such a newbie.

Link to comment
Share on other sites

  • 6 months later...

I'm still subscribed to the forum though and I really appreciate the help. I haven't tried this since I last posted 7 months ago and I can't wait to try it again.

 

I don't know if I'll be able to try it today though because I am trying to decide if I want to stick with the reseller hosting I am doing or if I should go with a dedicated server. I know if I went with a dedicated server, I would be able to automate this another way.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated