Bugzilla report bug using PHP - php

I was trying to post a bug to my bugzilla account using this code
set_time_limit(0);
$URI = 'http://site.com/bugzilla/xmlrpc.cgi';
$xml_data = array(
'login' => 'email',
'password' => 'password',
'remember' => 0
);
$bug_ids = array(50, 100); // bugs list
//$file_cookie = tempnam('', 'bugzilla-cookie');
$ch = curl_init();
$options = array(
//CURLOPT_VERBOSE => true,
CURLOPT_URL => $URI,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array( 'Content-Type: text/xml', 'charset=utf-8' )
);
curl_setopt($ch, CURLOPT_TIMEOUT,60);
curl_setopt_array($ch, $options);
$request = xmlrpc_encode_request("User.login", $xml_data);
var_dump($request);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
//curl_setopt($ch, CURLOPT_COOKIEJAR, $file_cookie);
$server_output = curl_exec($ch); // Array( [id] => 1 ) for example
print_r ($server_output);
$response = xmlrpc_decode($server_output);
But it keep requesting and i get no response
Also I read the Documentation of the BugZilla and I got nothing from it
Also I found a code for Zend framework
$oClient = new Zend_XmlRpc_Client('http://my.zilla.url/xmlrpc.cgi');
$oHttpClient = new Zend_Http_Client();
$oHttpClient->setCookieJar();
$oClient->setHttpClient($oHttpClient);
$aResponse = $oClient->call('User.login', array(array(
'login' => 'peterh#mydomain.com',
'password' => 'mypassword',
'remember' => 1
)));
$aResponse = $oClient->call('Bug.create', array(array(
'product' => "My Product",
'component' => "My Component",
'summary' => "This is the summary of the bug I'm creating",
'version' => "unspecified",
'description' => "This is a description of the bug",
'op_sys' => "All",
'platform' => "---",
'priority' => "P5",
'severity' => "Trivial"
)));
$iBugId = $aResponse['id'];
$aResponse = $oClient->call('User.logout');
But I am not using Zend framework
And there is also some perl files as I read but I don't know how to deal with them
After three days of searching and reading I came here
Please Help me to accomplish it

i create bug in bugzilla using this code ...i hope this is helpful to someone
set_time_limit(0);
$URI = 'your bugzilla url/xmlrpc.cgi';
$xml_data = array(
'login' => 'username',
'password' => 'password',
'remember' => 0
);
$ch = curl_init();
$file_cookie = tempnam('', 'bugzilla-cookie');
$options = array(
//CURLOPT_VERBOSE => true,
CURLOPT_URL => $URI,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array( 'Content-Type: text/xml', 'charset=utf-8' )
);
curl_setopt($ch, CURLOPT_TIMEOUT,60);
curl_setopt_array($ch, $options);
$request = xmlrpc_encode_request("User.login", $xml_data);
// var_dump($request);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_COOKIEJAR, $file_cookie);
$server_output = curl_exec($ch); // Array( [id] => 1 ) for example
print_r ($server_output);
echo "<br />";
$response = xmlrpc_decode($server_output);
print_r ($response);
$xml_data1 = array(
'product' => "Magento",
'component' => "Menu",
'summary' => "this is third testing bug",
'assigned_to' => "assigneename",
'version' => "1.6.2.0",
'description' => "This is a description of the bug",
'op_sys' => "All",
'platform' => "All",
'priority' => "Normal",
'severity' => "Trivial"
);
$request = xmlrpc_encode_request("Bug.create", $xml_data1); // create a request for filing bugs
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
$response = xmlrpc_decode(curl_exec($ch));
print_r ($response);

This following documentation focus on how to create a XML-RPC Server, but at the end shows a sample for consuming the generated XML-RPC service.
the Bakery - How to create an XML-RPC server with CakePHP
The class may be helpful, since you need someway to connect to a XML-RPC server (bugzilla)

Related

Trying to send a POST request using php, No matter what i do i get "HTTP ERROR 500"

To make an HTTP request, someone suggested I try using PHP and gave me a piece of code to work on:
$url = 'https://example.com/dashboard/api';
$data = array('to' => PHONE_NUMBER, 'from' => SENDER_ID, 'message' => TEXT, 'email' => EMAIL, 'api_secret' => SECRET, 'unicode' => BOOLEAN, 'id' => IDENTIFIER);
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) { /* Handle error */ }
var_dump($result);
So I took the code, edited the fields that I needed to, pasted it into a .php file, uploaded on my web server (running PHP 5.6) and then while trying to run the .php file, I get HTTP ERROR 500.
I'm a complete newbie to all this and I'm not even sure if I am doing everything correctly.
$url = 'https://domainname.com/dashboard/api';
$params = array('to' => PHONE_NUMBER, 'from' => SENDER_ID, 'message' => TEXT, 'email' => EMAIL, 'api_secret' => SECRET, 'unicode' => BOOLEAN, 'id' => IDENTIFIER);
$query_content = http_build_query($params);
$context = stream_context_create([
'http' => [
'header' => [
'Content-type: application/x-www-form-urlencoded',
'Content-Length: ' . strlen($query_content)
],
'method' => 'POST',
'content' => $query_content
]
]);
$result = file_get_contents($url, false, $context);
$url = 'https://domainname.com/dashboard/api';
$header = [
'Content-type: application/x-www-form-urlencoded',
];
$params = array('to' => PHONE_NUMBER, 'from' => SENDER_ID, 'message' => TEXT, 'email' => EMAIL, 'api_secret' => SECRET, 'unicode' => BOOLEAN, 'id' => IDENTIFIER);
$c = curl_init();
curl_setopt($c, CURLOPT_URL,$url);
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, $params);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($c, CURLOPT_HTTPHEADER, $header);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
$res = curl_exec($c);
var_dump($res);

"Page expired" when trying to log in with curl

I made a little apllication with Laravel and now I want to create a curl script that logs in to automate some testing. I have just this code to log in:
<?php
$postData = array(
'name' => 'postmanole',
'password' => 'password'
);
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => 'http://a.localhost/login',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
));
$output = curl_exec($ch);
echo $output;
?>
But I get "Page expired" view when I run the file.
Im completely new to curl so I don't really know how to take this.
Thanks in advance.
I think you should try this code.
$postData = array(
'name' => 'postmanole',
'password' => 'password'
);
$url = 'http://a.localhost/login';
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, $postData);
curl_setopt($handle,CURLOPT_RETURNTRANSFER,true);
$output = curl_exec($handle);
curl_close($handle);
print_r($output);
Hope this will help you.
try this one:
<?php
$postData = array(
'name' => 'postmanole',
'password' => 'password',
'_token' => csrf_token(),
);
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => 'http://a.localhost/login',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
));
$output = curl_exec($ch);
echo $output;
?>
I hope it would help you.

Integrate Coinbase Commerce in PHP

I want to integrate Coinbase Commerce API in one of my web application. I have refer this link https://commerce.coinbase.com/docs/ and create a demo in local server. I successfully get the below output
and below screen
Now i want to know After getting the last screen which give me address what to do with that code. does i need to open it in any specific application or I have to use it in my code. If i need to use in code provide me example code.
Also I have try to make curl request of "Create Charge" with following code but I didn't get any response.
$metadata = array(
'customer_id' => '123456',
'customer_name' => 'adarsh bhatt'
);
$request_body = array(
'X-CC-Api-Key' => 'd59xxxxxxxxxxxxxxb8',
'X-CC-Version' => '2018-03-22',
'pricing_type' => 'fixed_price',
'name' => 'Adarsh',
'description' => ' This is test donation',
'local_price' => array(
'amount' => '100.00',
'currency' => 'USD'
),
'metadata' => $metadata
);
$req = curl_init('https://api.commerce.coinbase.com/charges');
curl_setopt($req, CURLOPT_RETURNTRANSFER, false);
curl_setopt($req, CURLOPT_POST, true);
curl_setopt($req, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($req, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen(json_encode($request_body))));
curl_setopt($req, CURLOPT_POSTFIELDS, http_build_query($request_body));
$respCode = curl_getinfo($req, CURLINFO_HTTP_CODE);
$resp = json_decode(curl_exec($req), true);
curl_close($req);
echo '<pre>';
print_r($output);
exit;
The following should be a valid request to create a charge and return the hosted URL:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.commerce.coinbase.com/charges/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$post = array(
"name" => "E currency exchange",
"description" => "Exchange for Whatever",
"local_price" => array(
'amount' => 'AMOUNT',
'currency' => 'USD'
),
"pricing_type" => "fixed_price",
"metadata" => array(
'customer_id' => 'customerID',
'name' => 'ANY NAME'
)
);
$post = json_encode($post);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = "Content-Type: application/json";
$headers[] = "X-Cc-Api-Key: YOUR-API-KEY";
$headers[] = "X-Cc-Version: 2018-03-22";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
curl_close ($ch);
$response = json_decode($result);
return $response->data->hosted_url;
You can try this way. It's work for me
$curl = curl_init();
$postFilds=array(
'pricing_type'=>'no_price',
'metadata'=>array('customer_id'=>10)
);
$postFilds=urldecode(http_build_query($postFilds));
curl_setopt_array($curl,
array(
CURLOPT_URL => "https://api.commerce.coinbase.com/charges",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $postFilds,
CURLOPT_HTTPHEADER => array(
"X-CC-Api-Key: APIKEY",
"X-CC-Version: 2018-03-22",
"content-type: multipart/form-data"
),
)
);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
Hello you can use php sdk for coinbase commerce.
https://github.com/coinbase/coinbase-commerce-php
composer require coinbase/coinbase-commerce
use CoinbaseCommerce\Resources\Charge;
use CoinbaseCommerce\ApiClient;
ApiClient::init('PUT_YOUR_API_KEY');
$chargeData = [
'name' => 'The Sovereign Individual',
'description' => 'Mastering the Transition to the Information Age',
'local_price' => [
'amount' => '100.00',
'currency' => 'USD'
],
'pricing_type' => 'fixed_price'
];
$chargeObj = Charge::create($chargeData);
var_dump($chargeObj);
var_dump($chargeObj->hosted_url);

How to send one signal push notification with large image using PHP

Code sends only a title and message but icon not getting received. I am new to one signal API. Here is my code:
<?php
$fields = array(
'app_id' => 'my app id',
'include_player_ids' => ['player_id'],
'contents' => array("en" =>"test message"),
'headings' => array("en"=>"test heading"),
'largeIcon' => 'https://cdn4.iconfinder.com/data/icons/iconsimple-logotypes/512/github-512.png',
);
$fields = json_encode($fields);
//print("\nJSON sent:\n");
//print($fields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json; charset=utf-8',
'Authorization: Basic M2ZNDYtMjA4ZGM2ZmE5ZGFj'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$response = curl_exec($ch);
curl_close($ch);
print_r($response);
?>
You just simply add:
"chrome_web_image" => "image url";
$fields = array(
'app_id' => 'my app id',
'include_player_ids' => ['player_id'],
'contents' => array("en" =>"test message"),
'headings' => array("en"=>"test heading"),
'chrome_web_image' => 'https://cdn4.iconfinder.com/data/icons/iconsimple-logotypes/512/github-512.png',
);
To further reading please go to: doc appearance of onesignal
Result:
They key for the icon should be large_icon not largeIcon
Check the API for more details
You can use ios_attachments parameter and it must be in array.
This is how I did it:
$iCon = array(
"ios_attachments" => 'https://Your.Image.png'
);
$fields = array(
// OneSignal - Personal ID
'app_id' => "Your_OneSignal_ID",
'included_segments' => array('All'),'data' => array("foo" => "bar"),
// Submitting Title && Message && iCon
'headings' => $headings,
'contents' => $content,
'ios_attachments' => $iCon,
);
$fields = array(
'app_id' => $app_id,
'headings' => array("en"=>$data['title']),
'contents' => ["en" => $data['description']] ,
'big_picture' => $data['file'],
'large_icon' => $data['file'],
'url' => $data['launch_url']
);

Google reCaptcha implementation; response is always NULL

I have the following code for recaptcha veryfication.
$curl = curl_init();
$postfields = array(
'secret' => '------Private Key------',
'response' => $_POST['g-recaptcha-response'],
);
var_dump($_POST['g-recaptcha-response']);
$options = array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://www.google.com/recaptcha/api/siteverify',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $postfields,
);
curl_setopt_array($curl, $options);
$response = json_decode(curl_exec($curl), true);
The problem is that the response I get is always NULL, no matter what. Can somebody help me with this? Thanks

Categories