I am looking to automate the creation of a MySQL database via a json api call. To list dbs, I can just use something like:
https://example.com:2083/json-api/cpanel?user=username&cpanel_jsonapi_module=MysqlFE&cpanel_jsonapi_func=listdbs&cpanel_jsonapi_version=2
This is successful via HTTP Sockets and CURL. Is there any equivalent call for adddb?
https://example.com:2083/json-api/cpanel?user=username&cpanel_jsonapi_module=Mysql&cpanel_jsonapi_func=adddb&dbname=aa1&cpanel_jsonapi_version=1
This doesn't work. I get the following error:
“username_†is an invalid database name. It contains invalid characters.
Any ideas?
UPDATE:
I am running this via an HTTP Socket connection in CakePHP with the following code:
$query = 'cpanel_jsonapi_module=MysqlFE&cpanel_jsonapi_func=adddb&dbname=aa1&cpanel_jsonapi_version=2';
$request = array(
'auth' => array(
'user' => $queryData['conditions']['username'],
'pass' => $queryData['conditions']['password'],
'method' => 'Basic',
),
'uri' => array(
'scheme' => 'https',
'host' => $queryData['conditions']['host'],
'port' => '2083',
'user' => $queryData['conditions']['username'],
'path' => 'json-api/cpanel',
'query' => $query,
),
);
$result = json_decode($this->connection->request($request), true);
http://docs.cpanel.net/twiki/bin/view/ApiDocs/Api1/ApiMysql#Mysql::adddb
You've got dbname in the url twice but I don't know if that matters...
I'm not sure how the url API works, you could try ..._jsonapi_func=adddb(thedbname) but I have no clue if that would work.
Found the solution. In order to create / delete a DB through the cPanel API, it must be processed through API 1. The API access is a little bit different.
You must first get the theme your cPanel account is using (StatsBar:stat (theme):
https://example.com:2083/json-api/cpanel?user=USERNAME&cpanel_jsonapi_module=StatsBar&cpanel_jsonapi_func=stat&display=theme&cpanel_jsonapi_version=2
Then you plug that theme into another request:
https://example.com:2083/frontend/THEME/sql/addb.html?db=aa1
Of course, you must have the Authentication in the HTTP Socket (or CURL). Works like a charm!
Related
On my new server, I have to use a proxy to make the different API calls to other services.
I'm using Mailjet, and making the calls with the official PHP Wrapper (with no composer : https://github.com/mailjet/mailjet-apiv3-php-no-composer ).
I try to configure the proxy like that :
$mj = new \Mailjet\Client(
APIKEY,
APIKEY2,
true,
[
'version' => 'v3.1',
'connect_timeout' => 4,
'proxy' => [
'http' => someurl,
'https' => someurl
]
]
);
As you can see I'm also trying to edit the "CONNECT_TIMEOUT" variable. (I tried to set the variables in uppercase too, same result)
Unfortunaly, through all my tests I could have observe that only version and url variables are considered and set as asked. Any other variable, random or supposed to be taken care of, are not setted and stay with their default value.
I guess I'm not configuring as I should, perhaps those options should be elsewhere in the call, but even the Mailjet Support couldn't have inform me...
In the mean time I edited the /Mailjet/src/Mailjet/Client.php file from
private $requestOptions = [
self::TIMEOUT => 15,
self::CONNECT_TIMEOUT => 2,
];
to
private $requestOptions = [
self::TIMEOUT => 15,
self::CONNECT_TIMEOUT => 4,
self::PROXY => someurl
];
It works, but I prefer not having to edit this file and pass the variables as I should.
That class has a public method called setConnectionTimeout which you can use in your Client instance (e.g $mj->setConnectionTimeout(4))
I am trying to call a courier api with specified method. I am able to connect with the api using soapclient but getting following error:
Object reference not set to an instance of an object
I am using following code and data
$proxy = new SoapClient($my_api_url);
$params = array(
"UserName" => '****',
"Password" => '****',
"OrderNumber" => '41111',
"ClientName" => 'My Name',
"ContactNumber1" => '123456789',
"EmailAddress" => 'testapi#rohitdhiman.in',
"ShippingAddress1" => 'site 15'
);
$result = $proxy->BayOneAddOrder($params);
print_r($result);
If it works using SOAP UI then you can try using a PHP tool like https://providr.io as it will give you the exact PHP request using OOP approach.
If you do not want to use the online tool, then you can generate your own PHP package from your WSDL using PackageGenerator so you'll send request easily still using OOP approach.
I have created an ec2 client using the method mentioned in the AWS docs. I am using the aws.phar file for the SDK. The ec2 client is created properly because when I var_dump the client, it returns the Ec2Client object. But when I attempt to access the describeInstanceStatus from the ec2 client it throws a You are not authorized to perform this operation. exception. This is my code.
use Aws\Ec2\Ec2Client;
require 'aws.phar';
$ec2Client = Ec2Client::factory(array(
'key' => '<aws access key>',
'secret' => '<aws secret key>',
'region' => 'us-east-1'
));
try{
$ec2Client->describeInstanceStatus(array(
'DryRun' => false,
'InstanceIds' => array('InstanceId'),
'Filters' => array(
array(
'Name' => 'availability-zone',
'Values' => array('us-east-1'),
),
),
'MaxResults' => 10,
'IncludeAllInstances' => false,
));}
catch(Exception $e){
echo $e->getMessage();
}
Please tell me where am I getting this wrong. I've tried googling it, looked in the AWS forums but to no result. Thank you.
The error is coming from the Access that you have been granted/denied via AWS IAM.
The user, whose access/secret keys you are using in the code, does not have privilege to describe instances. This privilege is configured in the IAM policy which is applied to this user.
There is nothing wrong with your code. You need to look into the IAM policy about what all privileges are granted/denied to this user.
I'm semi-familiar with the ZendFramework/ZendOAuth library found here https://github.com/zendframework/ZendOAuth
I am able to use it no problem with Twitter, but I can't figure out how to get it to work with Google OAuth 2.0. The code I'm trying to use is as follows:
$config = array(
'callbackUrl' => 'https://www.example.com/callback',
'siteUrl' => 'https://accounts.google.com/o/oauth2',
'userAuthorizationUrl' => 'https://accounts.google.com/o/oauth2/auth',
'requestTokenUrl' => 'https://accounts.google.com/o/oauth2/token',
'consumerKey' => 'MY-CONSUMER-KEY-HERE',
'consumerSecret' => 'MY-SECRET-KEY-HERE',
'version' => '2.0',
);
$scopes = array(
'https://www.googleapis.com/oauth2/v2/userinfo'
);
$consumer = new Consumer($config);
$token = $consumer->getRequestToken(array('scope' => implode('', $scopes), 'response_type' => 'code', 'redirect_uri' => 'https://www.example.com/callback'));
$consumer->redirect();
According to the documentation for ZendOAuth, an array in the getRequestToken function gets treated as custom OAuth parameters. However, when I run this code I get redirected to a Google page that says:
Required parameter is missing: response_type
The URL in the browser shows the following:
https://accounts.google.com/o/oauth2/auth?oauth_token=&oauth_callback=https%3A%2F%2Fwww.example.com%2Fcallback
I've tried throwing debug statements around in the ZendOAuth library, but I can't seem to be able to find the problem.
If anyone has a solution to this, it would be much appreciated.
Thanks,
I believe the ZendOAuth package only supports OAuth 1, so for OAuth 2 you'll need to find a different library. I've used https://github.com/php-loep/oauth2-client with ZF2 applications so you could start there.
This is a code snippet I am using to manipulate my EC2 instance.
$ec2 = Aws::factory(array(
'key' => $key,
'secret' => $secret,
'region' => $region)
)->get('ec2', true);
$volId = createVol();// This step creates the volume correctly
$ec2->waitUntil('__VolumeStatus', array(
'VolumeIds' => array($volId),
'waiter.success.value' => VolumeState::AVAILABLE
));
attachVolume();//Error
The problem is attachVolume function is throwing error that volume is not available that means waitUntil function is not working correctly. Is there somethings wrong with the way I called this function?
It seems that the EC2 API is eventually consistent. So waiters are working correctly but sometimes the API is returning the wrong statuses
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/query-api-troubleshooting.html
http://blog.cloudfoundry.com/2013/06/18/dealing-with-eventual-consistency-in-the-aws-ec2-api/