Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    3

    Default xml_api issue on database creation

    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. #2
    Integration Developer cPanelDavidN's Avatar
    Join Date
    Dec 2009
    Location
    Houston, TX
    Posts
    525

    Default Re: xml_api issue on database creation

    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
    David Neimeyer
    Integration Developer

    sdk.cpanel.net
    APIs: XML-API API1 & API2
    Check Out: Developer Downloads Integration Blog
    Need Support? Support Ticket Developer Forum Feature Request

Similar Threads & Tags
Similar threads

  1. Replies: 10
    Last Post: 01-23-2011, 08:58 AM
  2. Postgres database creation issue ( wrapper )
    By parisdns in forum Database Discussions
    Replies: 2
    Last Post: 05-18-2010, 12:14 PM
  3. MySQL Database Creation
    By thearchitect in forum cPanel and WHM Discussions
    Replies: 3
    Last Post: 10-17-2009, 01:31 AM
  4. Remote database creation
    By cagy in forum cPanel Developers
    Replies: 5
    Last Post: 08-21-2009, 02:07 PM
  5. Database creation bug.
    By beddo in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 02-20-2008, 01:36 PM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube