Google Gmail Contacts API to get email contacts PHP

Here’s some simple PHP code, to get google gmail contacts.
File: getcontacts.php

<?php

if(!isset($_GET["code"]))
header("location: https://accounts.google.com/o/oauth2/auth?client_id=enteryourclientidhere&redirect_uri=http://yoursite.com/getcontacts.php&scope=https://www.google.com/m8/feeds/&response_type=code");

$authcode= $_GET["code"];

$clientid='enteryourclientidhere';

$clientsecret='enteryourclientsecrethere';

$redirecturi='http://yoursite.com/getcontacts.php';

$fields=array(

'code'=> urlencode($authcode),

'client_id'=> urlencode($clientid),

'client_secret'=> urlencode($clientsecret),

'redirect_uri'=> urlencode($redirecturi),

'grant_type'=> urlencode('authorization_code')

);

//url-ify the data for the POST

$fields_string='';

foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }

$fields_string=rtrim($fields_string,'&');

//open connection

$ch = curl_init();

//set the url, number of POST vars, POST data

curl_setopt($ch,CURLOPT_URL,'https://accounts.google.com/o/oauth2/token');

curl_setopt($ch,CURLOPT_POST,5);

curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);

// Set so curl_exec returns the result instead of outputting it.

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

//to trust any ssl certificates

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

//execute post

$result = curl_exec($ch);

//close connection

curl_close($ch);

//extracting access_token from response string

$response= json_decode($result);

$accesstoken= $response->access_token;

//passing accesstoken to obtain contact details

$xmlresponse= file_get_contents('https://www.google.com/m8/feeds/contacts/default/full?max-results=9999&oauth_token='.$accesstoken);
//echo $xmlresponse;

//reading xml using SimpleXML

$xml= new SimpleXMLElement($xmlresponse);

$xml->registerXPathNamespace('gd', 'http://schemas.google.com/g/2005');
$xml->registerXPathNamespace('default', 'http://www.w3.org/2005/Atom');

$result = $xml->xpath('//default:entry|//gd:email');

for($i=0;$i

if(isset($result[$i+1]->attributes()->address))
echo $result[$i]->title .":". $result[$i+1]->attributes()->address . "

";

}

?>

API to get Windows Live/MSN/Hotmail contact emails unhashed using delegation

Here’s a PHP implementation of the API to get the email addresses of all contacts:

  1. Create getcontacts.php

    <?
    /* Get the ConsentToken returned by Windows Live, its a string containing:
    locationID(synonymous to uid)
    DelegatedToken, etc
    */

    $return=urldecode($_POST['ConsentToken']);
    echo $return;

    /* Separate the values in the ConsentToken using parse_str to obtain $lid, $delt etc.
    parse_str($return);
    */

    $headers = array
    (
    "Authorization: DelegatedToken dt=\"$delt\""
    );

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, "https://livecontacts.services.live.com/users/@L@$lid/rest/invitationsbyemail");
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_TIMEOUT, 60);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    $data = curl_exec($curl);
    curl_close($curl);

    //Parse the returned XML
    $data=new SimpleXMLElement($data);
    echo '<pre>';
    print_r($data);
    echo '</pre>';

    ?>

  2. Upload getcontacts.php to yoursite.com, eg: http://yoursite.com/getcontacts.php
  3. Point to this link: https://consent.live.com/Delegation.aspx?ps=Contacts.View&ru=http://yoursite.com/getcontacts.php&pl=http://yoursite.com/privacypolicy.htm
    where:
    ru is the return url http://yoursite.com/getcontacts.php
    pl is the privacy policy url where you can let the user know how you will handle their info, just text for the user’s information.

Magento unable to change base url, SID in url, SSL, redirect, unable to access admin solved

Today I ran into some serious problems with Magento regarding changing the base_url. No matter what I would change it to, it would not show.
This is because I did not realize there is more than one base_url to be set. There are different scopes for settings.

Under System->Configuration, there is a dropdown called “Current Configuration Scope”. There are different settings for different scope. And store scope is given preference over default scope. So I simply change the scope to the store scope. Selected “Web”. Changed the base url, and made sure all the base urls where the same. This solved my problems.

In case you got to a point where you admin is not working, edit the MYSQL tables directly using phpmyadmin or however you prefer. All the settings are stored in a table called “core_config_data”.

To find the values that need to be changed run the following queries:

SELECT * FROM `core_config_data` WHERE path = 'web/unsecure/base_url' OR path = 'web/unsecure/base_link_url'

and for SSL:

SELECT * FROM `core_config_data` WHERE path = 'web/secure/base_url' OR path = 'web/secure/base_link_url'

Set these values to the ones you need and you should be fine.

How to fix: WordPress permalinks page not found error

First, check if the .htaccess file is created at the root directory of your blog, if not, its a permission issue. Set the folder permissions to let wordpress create the file. If your hosting doesn’t let you do this, then upload a .htaccess file manually.

Works with apache webserver:
If the .htaccess file exists and you’re still having problems, you gotta check your apache config.
set AllowOverride to All
reload apache,
it worked for me.

PHP urlencode urldecode POST form data

PHP urlencode() is used to encode the url in a GET request, this is to make sure that the data is sent properly without any unexpected behaviour.

The GET variables are automatically decoded when accessed by the PHP script.

POST data is usually not urlencoded. But it is highly recommended that you do.

For example, I noticed special characters in my POST data breaking my php script. So I simply did a urlencode() on the data before sending it. And the receiver script did a urldecode() and this solved the problem.

The difference between using urlencode for GET and POST is that with GET the data is automatically decoded, and with POST you have to manually decode the data using urldecode().

Where can I find the Endicia Label Server API Documentation?

I took up a freelancer job to implement the Endicia Label Server API for a customer to print prepaid shipping labels. Now as a freelancer I need to know if this is something I can do, what the API is capable of etc before bidding, I can’t be applying at the site and waiting for them to give it to me. Did some search and here it is:

Encidia Label Server API Documentation

Hope I saved you some time with that, really wish they would put it up somewhere on their site its easy to find.

Brute forcing sha1 on the Amazon EC2 cloud using Cryptohaze’s CUDA Multiforcer

I was bidding on a freelance project to create a distributed sha1 password brute forcer, as a test I had to crack a demo hash in the fastest time. So I signed up for the Amazon EC2 cloud service. They provide access to 2 x NVIDIA Tesla “Fermi” M2050 GPUs. The hash was a ten digit number which took 8 minutes to crack on my laptop with an AMD athlon X2 CPU.

Now GPUs are particularly useful when it comes to bruteforcing as the work can be easily distributed among its cores(thread processors). Now the Tesla M2050 has 448 cores, and GPU option on Amazon’s EC2 provides two of them. That’s a whopping 896 cores which peaks at around. terra flop speed.

The program I used to utilize the GPU to crack the hash is Cryptohaze’s Multiforcer 0.7 for linux. Unfortunately it could only utilize only 192 cores of one of the GPUs. I’m guessing its cause it was built with older CUDA libraries that didn’t support this card. Either way it cracked the hash in 10 seconds. In case you’re wondering why I didn’t use the newer version of the Multiforcer is cause I did try it, it did recognize both GPUs but got all buggy on me and wouldn’t run. So if anyone else had any luck with this do let me know.

I used these two posts to help me get this done:

http://blog.theroux.ca/security/cracking-passwords-using-linux-and-cuda-multiforcer-howto/

http://stacksmashing.net/2010/11/15/cracking-in-the-cloud-amazons-new-ec2-gpu-instances/