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.

get cpanel username

Discussion in 'cPanel Developers' started by tecwithquestion, Jun 4, 2015.

  1. tecwithquestion

    tecwithquestion Active Member

    Joined:
    Oct 20, 2014
    Messages:
    38
    Likes Received:
    0
    Trophy Points:
    6
    cPanel Access Level:
    Root Administrator
    Hello

    I am trying to create new db using php script which I have place in postwwwacct .

    I am able to create db if I manually give username and password in php script. Its works perfect.


    What I wanted to do is, this script will automatically select username for which I am creating cpanel account

    I tried to use :: $cpuser = "'.$opts['user'].'";

    However its not working

    Please assist.
     
    #1 tecwithquestion, Jun 4, 2015
    Last edited: Jun 4, 2015
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,811
    Likes Received:
    671
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello,

    Could you elaborate a bit further on what you are attempting to configure?

    Thank you.
     
  3. tecwithquestion

    tecwithquestion Active Member

    Joined:
    Oct 20, 2014
    Messages:
    38
    Likes Received:
    0
    Trophy Points:
    6
    cPanel Access Level:
    Root Administrator
    Hello

    I used below script in postwwwacct

    <?php
    include("xmlapi.php");
    $db_host = "localhost";
    $cpuser = "'.$opts['user'].'";
    $databasename = 'dbbb';//do not prepend with username
    $databaseuser = 'dbbb';//api will do that for you
    $databasepass = 'P3cJdlvx/vAo5cSRR5djAA==';

    $xmlapi = new xmlapi($db_host);
    $xmlapi->password_auth("root","rootpass");
    $xmlapi->set_debug(1);//this setting will put output into the error log in the directory that you are calling script from
    $xmlapi->set_output('array');//set this for browser output
    //create database
    $createdb = $xmlapi->api1_query($cpuser, "Mysql", "adddb", array($databasename));
    foreach($createdb as $v)
    {
    $result = $v['result'];
    }
    if ($result == 1)
    {
    //create user
    $usr = $xmlapi->api1_query($cpuser, "Mysql", "adduser", array($databaseuser, $databasepass));
    }
    foreach($usr as $v)
    {
    $result2 = $v['result'];
    }
    if ($result2 == 1)
    {
    //add user to database
    $addusr = $xmlapi->api1_query($cpuser, "Mysql", "adduserdb", array($databasename, $databaseuser, 'all'));

    }
    print_r($addusr);
    ?>
     
  4. tecwithquestion

    tecwithquestion Active Member

    Joined:
    Oct 20, 2014
    Messages:
    38
    Likes Received:
    0
    Trophy Points:
    6
    cPanel Access Level:
    Root Administrator
    Bascially I want to install wordpress automatically if custom package is selected in whm. It will work if I am able to get username which is being used for creating cpanel account
     
  5. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,811
    Likes Received:
    671
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello,

    It's likely a good idea to start using standardized hooks:

    Guide to Standardized Hooks

    You can use a post Accounts::Create hook as documented here:

    Accounts::Create

    This event returns the WHM API 1 createacct function's input parameters and values.

    Thank you.
     
Loading...

Share This Page