How to use crocdoc in php - documentviewer

I am using crocdoc in php
https://github.com/crocodoc/crocodoc-php
i downloaded the files in my local i had my API TOKEN so i pasted it there but it doesnt seems to work and throws error shown below for all 15 examples
can any one help me here
This is the error here which i am getting on using above github code with my Token
Example #1 - Upload Form W4 from the IRS by URL.
Uploading... failed :(
Error Code: curl_exception
Error Message: Crocodoc: [curl_exception] Crocodoc::_request
{"curl_errno":60,"curl_error":"SSL certificate problem, verify that the CA cert is OK. Details:\nerror:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed"}
Example #15 - Delete the second file we uploaded.
Deleting... failed :(
Error Code: curl_exception
Error Message: Crocodoc: [curl_exception] Crocodoc::_request
{"curl_errno":60,"curl_error":"SSL certificate problem, verify that the CA cert is OK. Details:\nerror:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed"}
To check i am using the crocodoc API properly i wrote my own code
this is the error i am getting in my own code
::::OUTPUT::::
{"uuid": "300dc39d-e82b-4d92-a701-b1f376600b96"}
checking status of : {"uuid": "300dc39d-e82b-4d92-a701-b1f376600b96"}
Curl error: SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
Curl error: SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
Curl error no: 60
out put for docurlGet is :
bool(false) status is :
Viewing the Document : {"uuid": "300dc39d-e82b-4d92-a701-b1f376600b96"}
this is my code (i am sorry if i am not suppose to paste the whole code but could not understand the whole issue so i am just giving whole code )
<?php
$myToken='gSqV0PpEZhvJfLxQTcuMmoty';
$frameUrl='https://crocodoc.com/api/v2/document/upload';
$api_url = 'https://crocodoc.com/api/v2/';
//curl "https://crocodoc.com/api/v2/document/upload" --data "token=${API_TOKEN}&url=http://web.crocodoc.com/files/test-simple.pdf"
$param='token='.$myToken.'&url=http://web.crocodoc.com/files/test-simple.pdf';
//curl command
$ch = curl_init();
#curl_setopt($ch, CURLOPT_HEADER, 0);
#curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json', 'X-HTTP-Method-Override: POST'));
#curl_setopt($ch, CURLOPT_POST, 1);
#curl_setopt($ch, CURLOPT_URL, $frameUrl);
#curl_setopt($ch, CURLOPT_POSTFIELDS,$param);
#curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
#curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
$uuids = curl_exec($ch);
echo $uuids;
echo "<br>";
echo " checking status of : ", $uuids."<br>";
$status =getStatus($uuids,$api_url,$myToken);
//curl 'https://crocodoc.com/api/v2/document/status?token=F6JOdArWGKmDRlfPQcZna71x&uuids=d5ea0542-baaf-46a1-835c-685a86e70e14'
echo " status is : ", $status."<br>";
echo " Viewing the Document : ", $uuids."<br>";
function getStatus($uuids,$api_url,$myToken){
$isSingleUuid = is_string($uuids);
$obj = json_decode($uuids);
$my_uuid= $obj->uuid;
$url = $api_url.'document/status';
$token = $myToken;
$dataStr = '?token='.$token.'&uuids='.$my_uuid;
$output = my_doCurlGet($url, $dataStr);
var_dump($output);
return $output;
}
function my_doCurlGet($url, $dataStr) {
//var_dump($url.$dataStr);
// var_dump($dataStr);exit;
//
$ch1 = curl_init();
#curl_setopt($ch1, CURLOPT_HEADER, 0);
#curl_setopt($ch1, CURLOPT_HTTPHEADER, array('Accept: application/json', 'X-HTTP-Method-Override: POST'));
#curl_setopt($ch1, CURLOPT_POST, 1);
#curl_setopt($ch1, CURLOPT_URL, $url.$dataStr);
#curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch1);
if(curl_exec($ch1) === false)
{
echo "<br>".'Curl error: ' . curl_error($ch1);
}
else
{
echo "<br>".'Operation completed without any errors'."<br>";
}
//var err_no=curl_errno()
if(curl_errno($ch1))
{
echo "<br>".'Curl error: ' . curl_error($ch1);
echo "<br>".'Curl error no: ' . curl_errno($ch1);
}
echo "<br>". "out put for docurlGet is : $output"."<br>";
return $output;
}
if (curl_errno($ch)) {
print 'An curl error has occurred.';
exit;
}
//var_dump($uuids);
curl_close($ch);
return $uuids;
?>
Thanks for all your help

Curl probably isn't properly configured with a CA bundle, or the configured CA bundle does not include Crocodoc's CA cert.
Check out this answer for more info.

Found the answer
First of all i did enable curl and SSL for beginning but it was not working
i even changed my Localhost name to myHost but it still did not work
so I made few changes in crocodoc.php file which i downloaded from crocodoc api library
CROCODOC PHP LIBRARY
I added this lines and IT WORKED :):):) Thank you all, hope this helps someone else as well.
if(($_SERVER['SERVER_NAME'] == 'myHost') && ($_SERVER['SERVER_ADDR'] == '127.0.0.1') && ($_SERVER['HTTP_HOST'] == 'myHost')) {
$options[CURLOPT_SSL_VERIFYPEER]=false;
}

Related

How create WMS layer in GeoServer by REST API?

In PostgreSQL I have a scheme called geo. Inside that scheme, I have a table with a column which has a geometry data type.
I am new in GeoServer and want to know how to create WMS layer by REST API with data of that remote PostgreSQL database? According to the documentation I need to create workspace and datastore first, right? I'm a little confused. What sequence of actions should be? I will be grateful for any example!
Result of curl request:
The REST API works in exactly the same manner as the GUI, so the process is that you can optionally create a new workspace or use an existing one, you then create a store inside a workspace and then create layers from the store. Any layer will automatically become available as a WMS layer.
Create a new PostGIS store, generate a file with the connection details:
<dataStore>
<name>nyc</name>
<connectionParameters>
<host>localhost</host>
<port>5432</port>
<database>nyc</database>
<user>bob</user>
<passwd>postgres</passwd>
<dbtype>postgis</dbtype>
</connectionParameters>
</dataStore>
and POST it to the REST endpoint
curl -v -u admin:geoserver -XPOST -T <file.xml> -H "Content-type: text/xml"
http://localhost:8080/geoserver/rest/workspaces/<WORKSPACENAME>/datastores
Then publish the table as a layer
curl -v -u admin:geoserver -XPOST -H "Content-type: text/xml" -d "<featureType><name>buildings</name></featureType>" http://localhost:8080/geoserver/rest/workspaces/acme/datastores/nyc/featuretypes
optional.
Publishing a table from an existing PostGIS store.
on php curl.
function curl_post($url,$params) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERPWD,"user:password");//--> on geoserver.
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Receive server response ...
$response = curl_exec($ch);
curl_close ($ch);
return $response;
}
//- table_name : xxx
//- work_space_name : your_workspace
//- store_name : dbtest
$layer_name = "xxx";
$params ="
<featureType>
<name>".$layer_name."</name>
<nativeName>".$layer_name."</nativeName>
<title>".$layer_name."</title>
<keywords>
<string>".$layer_name."</string>
<string>features</string>
</keywords>
<srs>EPSG:3857</srs>
<nativeBoundingBox>
<minx>1.0836244E7</minx>
<maxx>1.1759454E7</maxx>
<miny>625842.375</miny>
<maxy>2328151.75</maxy>
</nativeBoundingBox>
<latLonBoundingBox>
<minx>97.34363607648459</minx>
<maxx>105.63697261100442</maxx>
<miny>5.613037739416236</miny>
<maxy>20.464604971116074</maxy>
</latLonBoundingBox>
<projectionPolicy>FORCE_DECLARED</projectionPolicy>
<enabled>true</enabled>
<metadata>
<entry key=\"cachingEnabled\">false</entry>
</metadata>
<maxFeatures>0</maxFeatures>
<numDecimals>0</numDecimals>
</featureType>
";
$str_url = "http://xxx.co.uk/geoserver/rest/workspaces/**your_workspace**/datastores/**your_data_store**/featuretypes";
$rs = curl_post($str_url, $params);

How to fix: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed

I am currently working on cygwin.
I was trying to send and email through phpmailer using my gmail account and the following script (obtained online, then hacked):
<?php
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer(true);
try {
$mail->ISSMTP();
$mail->Host='smtp.gmail.com';
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => true,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->Port = 587;
$mail->Username = "myemail#gmail.com";
$mail->Password = "MyGooglePassword";
$mail->setFrom('myemail#gmail.com', 'my name1');
$mail->addAddress('anotheremail#email.fr', 'my name2');
$mail->Subject = 'PHPMailer Exceptions test';
$mail->Body = "Hi, This is the HTML BODY "; //HTML Body
$mail->AltBody = 'This is a plain-text message body';
$mail->send();
echo "Message sent!";
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage();
}
I have seen multiple solutions on stack overflow, but I haven't found any telling how to properly self sign my localhost so that I would be able to avoid this error message:
PHP Warning: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /usr/share/pear/phpmailer/class.smtp.php on line 346
2015-11-30 08:47:15 SMTP Error: Could not connect to SMTP host.
2015-11-30 08:47:15 CLIENT -> SERVER: QUIT
2015-11-30 08:47:15 SMTP ERROR: QUIT command failed
I have also tried resolving the issues by setting 'verify_peer' to false at "$mail->SMTPOptions" (as recommended in: PHPMailer - SSL3_GET_SERVER_CERTIFICATE:certificate verify failed), but when I do that, my gmail account refuse to cooperate saying that the signing attempt does not meet modern security standard!!
Please let me know if there is a proper tutorial that would allow me to properly set my ssl and have the email successfuly sent with the proper verifications.
Here is below a link to the gmail message: Gmail - sign in attempt prevented

Error Paypal REST API (sandbox) 404:"The requested URL /cgi-bin/ppapi was not found on this server."

I'm using PHP curl and it is communicating with the server. I'm trying to get a token. I get the following unhelpful response from the paypal sandbox:
Not Found
The requested URL /cgi-bin/ppapi was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Apache Server at api.sandbox.paypal.com Port 443
I'm running the code (below) from localhost on my laptop.
/gettoken.php
<?php
//header('Content-Type:application/javascript');
$url = "https://api.sandbox.paypal.com/token";
$client_id = "xxx";
$secret = "xxx";
// Initiate curl
$ch = curl_init();
// set basic auth
curl_setopt($ch,CURLOPT_HTTPAUTH,CURLAUTH_BASIC);
// set user/password
curl_setopt($ch,CURLOPT_USERPWD,$client_id.":".$secret);
// set header accept
$headers = array('Accept:application/json','Accept-Language:en_US');
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
// set mode to POST
curl_setopt($ch,CURLOPT_POST,1);
// add post fields (1)
$fields_string = "grant_type=client_credentials";
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
// Disable SSL verification
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
// Will return the response, if false it print the response
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
// Set the url
curl_setopt($ch, CURLOPT_URL,$url);
// Execute
$result=curl_exec($ch);
if($result === false)
{
echo 'Curl error: ' . curl_error($ch);
}
// close curl
curl_close($ch);
// decode result
//var json = json_decode($result, true);
echo('<pre>'.$result.'</pre>');
?>
My apologies, the url to the REST service was wrong.. should have been:
https://api.sandbox.paypal.com/v1/oauth2/token
At least we know that if you get this error that it is likely the REST endpoint url is probably wrong.

fql multiquery giving bad request error, failed to open stream

$fql_multiquery_url = 'https://graph.facebook.com/'
. 'fql?q={"query1":"SELECT+uid,sex,name,pic_square+FROM+user+WHERE+uid+IN+(SELECT+uid2+FROM+friend+WHERE+uid1=me())+AND+sex=\"'.$sex.'\"","query2":"SELECT+url+FROM+profile_pic+WHERE+id+IN+(SELECT+uid+FROM+#query1)"}'
. '&access_token=' . $access_token;
This gives error
failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request\r\n in /var/www/facebook-php-sdk-master/examples/fqlsample.php on line 82
but the below query works fine.
$fql_multiquery_url = 'https://graph.facebook.com/'
. 'fql?q={"query1":"SELECT+uid,sex,name,pic_square+FROM+user+WHERE+uid+IN+(SELECT+uid2+FROM+friend+WHERE+uid1=me())+AND+sex=\"'.$sex.'\"","query2":"SELECT+url+FROM+profile_pic+WHERE+id+IN+(SELECT+uid2+FROM+friend+WHERE+uid1=me())"}'
. '&access_token=' . $access_token;
the problem is in thhis part
(SELECT+uid+FROM+#query1)
why the multi query fails to work.
any idea?

gmail smtp not working in my hosting using codeigniter framework

i wish to use gmail smtp to send user information to the registered email.
The code that i am using is working fine in my localhost, but when i changed into shared hosting it come out with the below error.
A PHP Error was encountered
Severity: Warning
Message: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.googlemail.com:465 (Connection timed out)
Filename: libraries/Email.php
Line Number: 1652
A PHP Error was encountered
Severity: Warning
Message: fwrite(): supplied argument is not a valid stream resource
Filename: libraries/Email.php
Line Number: 1795
.... (more error msg here)
An Error Was Encountered
The following SMTP error was encountered: 110 Connection timed out
Unable to send data: AUTH LOGIN
Failed to send AUTH LOGIN command. Error:
Unable to send data: MAIL FROM:
from:
The following SMTP error was encountered:
Unable to send data: RCPT TO:
to:
The following SMTP error was encountered:
Unable to send data: DATA
.... (more error msg here)
Here's my email config
$pass = $this->generatePassword('6');
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_timeout'=>'30',
'smtp_user' => 'username#gmail.com',
'smtp_pass' => 'mypassword',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('admin#lalala.com','Title');
$this->email->to($this->input->post('email'));
$this->email->subject('Subject here');
$this->email->message('Your login username is '.$this->input->post('username').'<br/>'.'Password is '.$pass);
if (!$this->email->send()){
show_error($this->email->print_debugger());
}else{ echo 'YEAH!!!';}
i try to check my share hosting openssl whether is enabled or not. and i found this
openssl
OpenSSL support enabled
OpenSSL Version OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008
If openssl is enabled. still what will be the mistake in my code?
I start to be frustrated to use my localhost to develop and when its uploaded to share hosting, it came out wit lots of error.
Any help would be appreciate!! thx in advanced
Looks like ur ssl port in shared hosting is close,
use this code to check if it is open.
$fp = fsockopen("www.google.com", 80, &$errno, &$errstr, 10); // work fine
if (!$fp)
echo "www.google.com - $errstr ($errno)<br>\n";
else
echo "www.google.com - ok<br>\n";
$fp = fsockopen("smtp.gmail.com", 465, &$errno, &$errstr, 10); // NOT work
if (!$fp)
echo "smtp.gmail.com 465 - $errstr ($errno)<br>\n";
else
echo "smtp.gmail.com 465 - ok<br>\n";
$fp = fsockopen("smtp.gmail.com", 587, &$errno, &$errstr, 10); // NOT work
if (!$fp)
echo "smtp.gmail.com 587 - $errstr ($errno)<br>\n";
else
echo "smtp.gmail.com 587 - ok<br>\n";
there is update for test script in newer php
version:
<?php
$fp = fsockopen("www.google.com", 80, $errno, $errstr, 10); // work fine
if (!$fp)
echo "www.google.com - $errstr ($errno)<br>\n";
else
echo "www.google.com - ok<br>\n";
$fp = fsockopen("smtp.gmail.com", 465, $errno, $errstr, 10); // NOT work
if (!$fp)
echo "smtp.gmail.com 465 - $errstr ($errno)<br>\n";
else
echo "smtp.gmail.com 465 - ok<br>\n";
$fp = fsockopen("smtp.gmail.com", 587, $errno, $errstr, 10); // NOT work
if (!$fp)
echo "smtp.gmail.com 587 - $errstr ($errno)<br>\n";
else
echo "smtp.gmail.com 587 - ok<br>\n";
?>