Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

xml_api issue on database creation

Discussion in 'cPanel Developers' started by edwin67, Mar 9, 2011.

  1. edwin67

    edwin67 Registered

    Joined:
    Feb 3, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    51
    hi there,

    I tried to make my script to work with no error but it seems it isn't so easy as I thought.

    I followed all that was said at Frequently Asked Scripts: "How do I automate XYZ after creating an account?" - cPanel Integration

    Code:
    <?php
    include('/usr/local/cpanel/base/frontend/x3/cake/xmlapi.php');
    
    ini_set(display_errors,1);
    
            // Return the string
            return $string;
        }
    
    ## $_GET vars
        //$new_username = mysql_real_escape_string( $_POST['new_user'] );
        //$new_dbname = mysql_real_escape_string( $_POST['new_dbname'] );
        //$new_dbpass = mysql_real_escape_string( $_POST['new_dbpass'] );
    
        //$new_username = $cp_name.'_'.rand_str($lenght=7, $chars);
        //$new_dbname = $cp_name.'_'.rand_str($lenght=6, $chars);
        $new_dbpass = rand_str($lenght=5, $chars);
    
    /**
    * extend the basic xmlapi class
    *  add the method for getting args
    */
    Class cpScriptsXmlApi extends XMLAPI
    {
    
      public $cliargs = array();
      ...
     }
    
    //create our xmlapi object and set it's params
    $xmlapi = new cpScriptsXmlApi($argv,'127.0.0.1');
    
        //your root auth hash
        $hash = '15b6b89b89d729739';
        $xmlapi->set_user('root');
        $xmlapi->set_hash($hash);
        $xmlapi->set_port('2087'); //NOTE: you must have compiled OpenSSL or cURL w/SSL to use secure ports in 
        //generic vars for automation//
        $dbname = rand_str($lenght=6, $chars); // "new database"
        $virtusername = rand_str($lenght=7, $chars); // "new user"
        $privs = array('all');
    
    /*
    $xmlapi->createUserDb($xmlapi->cliargs['user'], $dbname);
    $xmlapi->createDbVirtuser($xmlapi->cliargs['user'],$virtusername, $new_dbpass);
    */
    echo $xmlapi->cliargs['user'];
    
    
    this is what I got:
    Code:
    Notice: Undefined variable: argv in /tmp/cpanel_phpengine.1299686646.31775Zw1Yt16JVc on line 151
    
    Warning: array_shift() [function.array-shift]: The argument should be an array in /tmp/cpanel_phpengine.1299686646.31775Zw1Yt16JVc on line 100
    
    Notice: Undefined index: user in /tmp/cpanel_phpengine.1299686646.31775Zw1Yt16JVc on line 167
    

    thx
     
  2. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    3
    Trophy Points:
    68
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Hi edwin67,

    The code that is used in the blog post you reference is for a postwwwacct script hooks, not a PHP application running under cPanel. You can use the base xmlapi.php class in PHP applications, but they'll probably need to get their values for a form (i.e. $_POST) as opposed to $argv.

    "$argv" is a special PHP variable for use with PHP scripts (i.e. CLI based PHP stuff, not applications served by a webserver). It is documented here PHP: $argv - Manual

    Regards,
    -DavidN
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice