* the cPanel system).  In both cases, the raw response from the cPanel
  * system should be well structured and parsed cleanly (i.e., can be
  * determined by analysing the data in the 'response' container).
  * 
  * Future implementation of error handling and the Cpanel_Query_Object
  * may see some programmatic improvement for this, like throwing a special
  * Exception, however, for now it is up to the programmer to either 1) check
  * the response container for such failures, or 2) extend the parser library
  * with such logic.
  * 
  * Other convenience methods are described below
  */
 $configOpts = array('username' => 'root', 'password' => 'rootsecret');
 $services = array('whm' => array('host' => '10.1.4.102', 'user' => 'root', 'password' => 'rootsecret'));
 $masterConfig = array('config' => $configOpts, 'service' => $services);
 $cp = Cpanel_PublicAPI::getInstance($masterConfig);
 $response = $cp->whm_api('listaccts');
 /**
  * A quick check to see that the server response parsed cleanly.
  */
 if (!$response->validResponse()) {
     $errors = $response->getResponseErrors();
     foreach ($errors as $err) {
         // do something like log or throw Exception
     }
     return;
 }
 /**
  * If authentication failed, there's likely to be a data->reason parsed
  * response
  */
Пример #2
0
 /**
  * Verify exception is throw when no method is passed for indirect 
  * invocation
  * 
  * @depends           testFactoryCanReturnWHMFromSimpleConfig
  * @expectedException Exception
  * @outputBuffering   disabled
  */
 public function testCallerThrowExceptionWhenNoArgsOnDispatchedApiRequest()
 {
     $arr = array('service' => array('whm' => array('config' => array('host' => '1.1.1.1'))));
     Cpanel_PublicAPI::resetInstance();
     $cp = Cpanel_PublicAPI::getInstance($arr);
     $response = $cp->whm_api();
 }
Пример #3
0
/**
 * Please look at the Introduction_to_PublicAPI.php for more details.
 */
try {
    require_once realpath(dirname(__FILE__) . '/../Util/Autoload.php');
    /**
     * PublicAPI style
     */
    $cpCfg = array('cpanel' => array('service' => array('whm' => array('host' => '10.1.4.191', 'user' => 'root', 'password' => 'rootsecret'))));
    $cp = Cpanel_PublicAPI::getInstance($cpCfg);
    $response = $cp->whm_api('version');
    echo "WHM Version: {$response->version}\n";
    /**
     * One alternative style
     */
    $cp = Cpanel_PublicAPI::getInstance();
    $whm = $cp->factory('WHM');
    $whm->setUser('root')->setPassword('rootsecret')->setHost('10.1.4.191');
    $response = $whm->xmlapi_query('version');
    echo "WHM Version: {$response->version}\n";
    /**
     * Another alternative is to pass the config to factory() method
     */
    $config = array('host' => '10.1.4.191', 'user' => 'root', 'password' => 'rootsecret');
    $whm = $cp->factory('WHM');
    $response = $whm->xmlapi_query('version');
    echo "WHM Version: {$response->version}\n";
    /**
     * Using direct library
     */
    $config = array('host' => '10.1.4.191', 'user' => 'root', 'password' => 'rootsecret');
     * class.  However, the PublicAPI client is designed to honor to the
     * conventions of it's sibling Perl client Cpanel::PublicAPI which offers
     * a specific, new set of query methods.
     * 
     * This methods are:
     *  * whm_api($function $func_args)
     *    - For WHM (native XML-API) functions against the WHM Service
     *    
     *  * cpanel_api1_query($service, $mod_func_user_args, $func_args)
     *    - For API1 queries against cPanel or WHM Service
     * 
     *  * cpanel_api2_query($service, $mod_func_user_args, $func_args)
     *    - For API2 queries against cPanel or WHM Service
     *    
     *  api_request($service, $url, $HTTP_REQUEST_TYPE, $formdata, $customHeaders );
     *    - For making a direct URL query against a cPane or WHM Service UI
     *    
     * All of these methods are supported directly in the PublicAPI client.
     * 
     * An example (in it's entirety, and shortest notation) of the previous
     * "version" request is as follows:
     */
    require_once realpath(dirname(__FILE__) . '/../Util/Autoload.php');
    $cpCfg = array('cpanel' => array('service' => array('whm' => array('host' => '10.1.4.191', 'user' => 'root', 'password' => 'rootsecret'))));
    $cp = Cpanel_PublicAPI::getInstance($cpCfg);
    $response = $cp->whm_api('version');
    echo "WHM Version: {$response->version}\n";
} catch (Exception $e) {
    echo $e->getMessage() . "\n" . $e->getTraceAsString() . "\n";
}
echo "EOF: You've successfully ended the " . basename(__FILE__) . " script.\n";