The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

WHM Post Account Creation Script

Discussion in 'cPanel Developers' started by adalpe, Aug 28, 2010.

  1. adalpe

    adalpe Registered

    Joined:
    Aug 28, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Hiya!

    I have a script that I am currently configuring:

    PHP:
    <?php
    $resource1 
    mysql_connect('connection string 1');
    $db mysql_select_db(admin_plus$resource1)
                   or die (
    "Couldn't select database.");
    $resource2 mysql_connect('connection string 2');
    $db mysql_select_db(admin_image$resource2)
                   or die (
    "Couldn't select database.");
    $sql "SELECT email FROM users";
    $query mysql_query($sql$resource1);
    for (
    $i=0;$i<($result mysql_fetch_assoc($query));$i++) {
        
    mysql_query("INSERT INTO details ('email') VALUES('email') ($resource2)");
    }

    mysql_close($resource1);
    mysql_close($resource2);   
    ?> 
    That I want to run straight after an account creation, to pull the email address from a clientexec account and put it into my own database table. I then plan to get the user to configure their own details etc.

    My problem is, this is only for one type of hosting that I am providing. It is a hosting account that comes accompanied with various software to accomplish some specific tasks, and I don't want anybody else to be able to access it.

    If there any way I can get this script to run *only* after a specific package has been created?

    Regards,

    Adam
     
  2. adalpe

    adalpe Registered

    Joined:
    Aug 28, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    I would also like to extend this question to ask how you can obtain the newly created account details (email address) etc. from cPanel

    Regards,

    Adam.
     
  3. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Hi Adam,

    Will this be running based on a particular reseller account or will root or multiple resellers possibly be using this for accounts they create?

    The simplest method to have a script fire off after account creation is by using a postwwwacct Script Hook. This is the documentation and here's a blog post about using it (coupled with the XMLAPI) create databases. However, Script Hooks are installed and executed by root, so if you only have reseller access I'm afraid that method is not feasible.

    Assuming that you do have root, and you do choose to use a Script Hook, your Script Hook will be passed variables containing all the information that was use to create the account within WHM (or any other method of account creation, ie CLI or XMLAPI). You can use this information to determine which package as chosen and only perform the additional action as necessary.

    Let me know if you have any specific questions,
    -DavidN
     
  4. MrLeN

    MrLeN Active Member

    Joined:
    Dec 12, 2010
    Messages:
    38
    Likes Received:
    0
    Trophy Points:
    6
    Can I use this to modify a package, after an account has been created?
     
  5. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    This thread is more about doing things regardless of how an account was created, whether it was created in WHM, by some billing automation tool like WHMCS or by a PHP script that just creates accounts.

    If you are just looking to modify a package assigned to an account after you have created an account in a PHP script, it would be much simpler to just do that in the same PHP script after the account was created.
     
Loading...

Share This Page