Parse/Validate CSR code - php

I'm using trustico.com reseller api in order to process ssl certificates. But interestingly I couldn't find any tool for parse CSR code for getting approver email list. There is only one tool in tructico api that requires domain name for getting list.
My question is there any tool for parsing CSR code in PHP in order to get associated domain name? or does trustico api give me a chance to get it?
Thanks in advance
edit: (I coulnt write this as an aswer, so I edit my question)
I make another search and I find this online csr validation tool :
https://secure.comodo.net/utilities/decodeCSR.html
it also gives you an api which you can make queries locally. documentation is here :
https://secure.comodo.net/api/pdf/DecodeCSR%20v1.06.pdf
I wrote it for myself in order to get domain. if csr code is given is correct code returns full domain, if it's not code returns "1". I hope it helps someone needs :
function ssl_getCN($csr) {
$api_url = "http://secure.comodo.net/products/!DecodeCSR";
$fields = array('csr' =>$csr,
'showCN'=>'Y',
'showErrorCodes'=>'N',
'showErrorMessages'=>'N',
'showFieldNames'=>'N',
'showEmptyFields'=>'N',
'showEmptyFields'=>'N',
'showAddress'=>'N',
'showPublicKey'=>'N',
'showKeySize'=>'N',
'showSANDNSNames'=>'N',
'showCS'=>'N'
);
// URL Encode Values
$query_string = http_build_query($fields);
// Initiate CURL POST call
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $api_url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_TIMEOUT, 120);
curl_setopt ($ch, CURLOPT_POST,count($fields));
curl_setopt ($ch, CURLOPT_POSTFIELDS,$query_string);
$result = curl_exec ($ch);
curl_close($ch);
return $result;
}

Related

Google Geocoding API returns ZERO_RESULTS with php CURL

I am trying to get the latitude and longitude from this address. The problem is that when calling the URL with curl it gives the response ZERO_RESULTS, but when calling it from the browser it gives a correct response. The certificate geocode_api exists and it is in the correct path so thats not the problem.What am i missing here? This code works just fine with other addresses
<?php
$url = "https://maps.google.com/maps/api/geocode/json?address=VIA+RISORGIMENTO,+FUMONE,+03010,+FR,+Italia";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO, "modules/Map/cert/geocode_api.crt");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
curl_close($ch);
if(empty($response)){
return;
}
$response_a = json_decode($response);
echo $response;
I tried following requests:
Places autocomplete
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=VIA%20RISORGIMENTO%2C%20FUMONE%2C%2003010%2C%20FR%2C%20Italia&key=YOUR_API_KEY
Geocoding request with components filters by street name, locality and country https://maps.googleapis.com/maps/api/geocode/json?components=route%3AVIA%20RISORGIMENTO%7Clocality%3AFUMONE%7Ccountry%3AIT&key=YOUR_API_KEY
Both return ZERO_RESULTS. That means the via Risorgimento doesn't exist in Google database.
Let's have a look at place/establishment 'Comune di Fumone, Via Risorgimento, 2, 03010 Fumone FR, Italy'
https://google-developers.appspot.com/maps/documentation/utils/geocoder/#place_id%3DChIJaUCe_RdZJRMRZMdLqZRVXnk
On the base map I can see via Covone close to this place, but any sign of via Risorgimento.
I believe you should report a missing road on maps.google.com
https://support.google.com/maps/answer/3094088
Hope it helps!

PHP cURL No Error but not working

I've been banging my head on this for a while now and I'm sorta fed up. I'm not a PHP programmer so I might be missing something that is not immediately obvious to my Python infused brain.
So here's the context. I need to write a script to login automatically into a web interface and run a search, and well, absolutely everything I've tried to do seems to fail miserably.
Here's my code:
<?php
echo 'start';
// INIT CURL
$ch = curl_init();
// SET URL FOR THE POST FORM LOGIN
curl_setopt($ch, CURLOPT_URL, 'https://W0110DcIpsOcsRpt02/si_ocs_gui/login.php');
// ENABLE HTTP POST
curl_setopt ($ch, CURLOPT_POST, 1);
// SET POST PARAMETERS : FORM VALUES FOR EACH FIELD
curl_setopt ($ch, CURLOPT_POSTFIELDS, 'username=*****&password=*****&btnSubmit=Login');
// IMITATE CLASSIC BROWSER'S BEHAVIOUR : HANDLE COOKIES
curl_setopt ($ch, CURLOPT_COOKIEJAR, '/var/tmp/cookie.txt');
# Setting CURLOPT_RETURNTRANSFER variable to 1 will force cURL
# not to print out the results of its query.
# Instead, it will return the results as a string return value
# from curl_exec() instead of the usual true/false.
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($ch, CURLOPT_FRESH_CONNECT, 1);
// EXECUTE 1st REQUEST (FORM LOGIN)
$store = curl_exec ($ch);
if($store == False){
echo " store false ";
echo curl_error($ch);
} else {
echo " store true ";
echo $store;
}
// SET FILE TO DOWNLOAD
echo ' second_request ';
curl_setopt($ch, CURLOPT_URL, 'https://W0110DcIpsOcsRpt02/si_ocs_gui/FWOCS1_BL_SUBSCRIBERS_list.php');
curl_setopt ($ch, CURLOPT_POST, 1);
#curl_setopt ($ch, CURLOPT_POSTFIELDS, 'value_ACCESS_NO_4=15142351150');
curl_setopt ($ch, CURLOPT_POSTFIELDS, 'q=\(SUBSCRIBER_ID~equals~1545303\)');
// EXECUTE 2nd REQUEST (FILE DOWNLOAD)
if(!$store == False){
$content = curl_exec ($ch);
echo $content;
}
// CLOSE CURL
curl_close($ch);
echo ' done';
?>
The behaviour of this is as follows. I run the script, and it fails at the first cURL request (the login) and returns no errors. I have modified this line here:
curl_setopt ($ch, CURLOPT_POSTFIELDS, 'username=*****&password=*****&btnSubmit=Login');
by removing the btnSubmit=Login part and I get the login page displayed with the filled in username and password fields. I can press the login button and it will work. However, it seems that my lack of web development is biting me here and I have no idea how that button works. So, here's the code inspected with firebug:
<a class="rnr-button main" href="#" onclick="document.forms[0].submit();return false;">Submit</a>
I also went directly in the PHP code on the web server and found the button corresponding to it:
if ((#$_POST["btnSubmit"] == "Login" || $adSubmit) && $logacc)
Hence why I was trying the btnSubmit=Login.
So my question is pretty simple: what am I doing wrong and how can I get the results I need?
I have got the same problem and find the solution for it.
Code
CURLOPT_RETURNTRANSFER => false
Use this to solve your problem.

Posting to website using curl

This may be another dumb question but anyway. I am trying to post into a search box of the University online public access catalogue and here is what I came up with:
<?php
date_default_timezone_set('Asia/Manila');
$today = date('m-d-Y');
echo $today;
$keyWord=database;
$urltopost = "http://opac.usls.edu.ph/TLCScripts/interpac.dll?SearchForm? Directions=1&Config=pac&Branch=0";
$datatopost = array ('SearchData' => "c++");
$ch = curl_init ($urltopost);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $datatopost);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$returndata = curl_exec ($ch);
echo $returndata;
?>
I get this:
09-19-2013
Configuration has been deleted.
I really need help. What did I do wrong?
Thanks in advance good people of this world.
If you look at how a search is done in that site, you can see that your post url should be
http://opac.usls.edu.ph/TLCScripts/interpac.dll?Search
and data should be something like
FormId=0&Config=pac&LimitsId=0&StartIndex=0&SearchField=7&SearchType=1&ItemsPerPage=10&SearchData=yoursearchtermhere
Since in your example you're not posting the "config" parameter in post data, you get the error message you specified.

get URL Answer with curl or json

I need to get the answer of a page.
The url looks like this:
sp2.looki.de/index.php?page=newsysview&cid=48713&ppx=71&ppy=32&cid=48713&tcv=1355771664807&_=_585_204
The Answer I get looks like this:
{"module":"system","error":[],"syslist":{"15":{"con1":"0","con2":"0","kgm":"257506","kgk":"317370","kgt":"10300255","ppx":"71","ppy":"32","ppz":"15","pname":"Ckaleme","playerid":"5428","flag":"1","noob":"85315748","sperrflag":"-1","nick":"S7alker","tag":"-R-","pid":"707","allianzid":"707","inaktiv":1,"platz0":"82","punkte0":"187044480","platz1":"196","punkte1":"21326785","platz2":"87","punkte2":"105724483","platz3":"69","punkte3":"59993212","oldlogin":null,"nickdays":"0","isnoob":false}},"tflist":[],"ppx":71,"ppy":32,"allianzid":3225,"allianzpid":3225,"debug":{"parsetime":[{"name":"Start","parsetime_complete":"0.000","parsetime_last":"0.000"},{"name":"Ende","parsetime_complete":"0.014","parsetime_last":"0.014"}],"parsetime_total":"0.014","querytime":0.0026}}
I've tried with CURL, file_get_contents and so on ... but the answer was just an
www:redirect
Code edited....no result
$data = "http://some.site.de/index.php?page=newsysview&cid=48713&ppx=50&ppy=50&cid=48713&tcv=1355426935816&_=_552_140";
$ch = curl_init($data);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
curl_close($ch);
The Page --> http://sp2.looki.de/index.php?page=newsysview&cid=48713&ppx=50&ppy=50&cid=48713&tcv=1355511915397&_=_482_292
I get a json as answer
So ... after some days of tryin' I have no ideas anymore.
No idea, how to login there, to jump to a specified page and read the json from there.
maybe someone has an great idea to help me out.
LogIn Page is here --> http://sp2.looki.de/
:'(
Edit 2
I stuck ....
I've the following code now ...
$data1 = "http://sp2.looki.de/index.php?page=newsysview&cid=48713&ppx=50&ppy=50&cid=48713&tcv=1355511915397&_=_482_292";
$ch = curl_init ($data1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$data = curl_exec ($ch);
in my var_dump($data) it's just an {"www-redirect": "/"}
WHY?
oh .... hint:
the original address is: http://sp2.looki.de/index.php?page=gui&cid=666#nothing
the address in $data1 seems to be an ajax request.
Ensure you have Follow Location active in your curl request:
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
Otherwise you are forcing it to not follow the "Location:" headers
http://php.net/manual/es/function.curl-setopt.php
Additionally, maybe the website doesn't allow direct query of that URL, try to trick it using the "Referer" value of curl
curl_setopt($ch, CURLOPT_REFERER, 'http://some.site.de/');

Generate URL with Variable

Hopefully, someone can spot the error, what I need to do is to first fetch the webpage for a token, then curl the new url with the token attached;
here is my code
$text = $siteName;
if (preg_match('/;t=([a-zA-Z0-9_-]{43})%3D/',$text,$matches)) {
// Match... vjVQa1PpcFMYuRsz10_H-1z41mWWe8d6ENEnBLE7gug
echo 'TOKEN: '.$matches[1];
$curltube = curl_init ();
curl_setopt ($curltube, CURLOPT_URL, "http://www.veoh.com/watch?v=opQ9GzRe5qs".$matches[1]);
curl_setopt ($curltube, CURLOPT_RETURNTRANSFER, 0 );
curl_setopt ($curltube, CURLOPT_COOKIEFILE, "cookie8.txt");
$curltubeplay = curl_exec ($curltube);
curl_close ($curltube);
echo $curltubeplay;
} else {
// No match
}
and the previous code before that fetches the web-page
curl_setopt ($ch, CURLOPT_URL, "http://www.veoh.com/watch?v=opQ9GzRe5qs");
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 0 );
curl_setopt ($ch, CURLOPT_COOKIEJAR, "cookie8.txt");
so hopefully, someone can shed some light
My guess (please expand the question to be clear) is that you expect to build a URL like this:
http://www.veoh.com/watch?v=opQ9GzRe5qs;t=abc
But you are building one like this:
http://www.veoh.com/watch?v=opQ9GzRe5qsabc
There are two simple fixes. This one takes the whole matched string, not just the token:
curl_setopt ($curltube, CURLOPT_URL, "http://www.veoh.com/watch?v=opQ9GzRe5qs".$matches[0])
And this one adds back in the missing parts to the URL:
curl_setopt ($curltube, CURLOPT_URL, "http://www.veoh.com/watch?v=opQ9GzRe5qs;t=".$matches[1])

Categories