<?php include ("debuglib.php") ?>
<?php
// http://www.framework.zend.com/manual/1.9/en/zend.rest.client.html
// http://www.framework.zend.com/manual/2.0/en/modules/zendservice.twitter.html
// const VERSION = '1.9.7';
// http://www.quadrillian.com/#view-project/161

set_time_limit(600); // increase timeout

define('ATMAIL_MIN_PHP_VERSION', '5.1.6');

// Read in current Atmail version
$atmailVersion = trim(@file_get_contents('../.VERSION'));

// Setup lib paths
define('APP_ROOT', dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR);
$path = dirname(dirname(__FILE__));
//set_include_path('.' . PATH_SEPARATOR . "$path/library/");
set_include_path('.' . PATH_SEPARATOR . "$path/library/" . PATH_SEPARATOR . "$path/sso/phpseclib/");

session_start();

require_once 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance();

//$loader->registerNamespace('App_'); //for model namespacing
$loader->setFallbackAutoloader(true);
$loader->suppressNotFoundWarnings(false);

// Report all errors except E_NOTICE
//error_reporting(E_ALL ^ E_NOTICE);
error_reporting(0);

// $client = new Zend_Rest_Client('http://framework.zend.com/rest');
// echo $client->sayHello('Davey', 'Day')->get(); // "Hello Davey, Good Day"

echo "<hr />";
echo "cookies:<br />";
print_r($_COOKIE);
echo "<hr />";

print_r($_COOKIE[atmailuser]);
echo "<hr />";

print_r($_COOKIE[PHPSESSID]);

echo "<hr />";

//$base_url = 'http://www.example.com';
//$endpoint = '/path/to/endpoint';
//$data = array('param1' => 'value1', 'param2' => 'value2', 'param3' => 'value3');
//$client = new Zend_Rest_Client($base_url);
//$response = $client->restPost($endpoint, $data);
//print_r($response);


$base_url = 'http://maps.googleapis.com';
$endpoint = '/maps/api/geocode/json';
$data = array('address' => '1313+Harbor+Boulevard,+Anaheim,+CA', 'sensor' => 'false');

$base_url = 'http://atmail.local';
$endpoint = '/index.php/mail/auth/processlogin';
$data = array('emailName' => 'atmail', 
              'emailDomain' => 'bigvi.com',
//              'emailDomainDefault' => '',
//              'cssStyle' => 'Original',
              'email' => 'atmail@bigvi.com',
              'password' => 'atmail',
              'requestedServer' => 'localhost',
//              'requestedServer' => '',
              'MailType' => 'IMAP',
//              'Language' => '',
//              'RememberMe' => '1',
              'expectJson' => '1'
              );

$client = new Zend_Rest_Client($base_url);

error_reporting(0);

// $response = $client->restPost($endpoint, $data);
$response = $client->restGet($endpoint, $data);

echo "<hr />";
echo "response:<br />";
print_r($response);

echo "<hr />";
echo "response body:<br />";
print_r($response->getBody());

$x = $response->getBody();

$ac = $x->results;
print_r($ac);

$stuff = json_decode($x);

$_COOKIE['monkey'] = $stuff->{'SessionID'};
$_COOKIE['atmail6'] = $stuff->{'SessionID'};

setcookie('monkey', $stuff->{'SessionID'});
setcookie('atmail6', $stuff->{'SessionID'});
// session($stuff->{'SessionID'});


$data2 = array(
    'emailName' => 'atmail',
    'emailDomain' => 'bigvi.com',
    'emailDomainDefault' => '',
    'cssStyle' => 'Original',
    'email' => 'atmail@bigvi.com',
    'password' => 'atmail',
    'requestedServer' => 'localhost',
    'MailType' => 'IMAP',
    'Language' => '',
    'RememberMe' => '1'
);

redirect_post('http://atmail.local/index.php/mail/auth/processlogin', $data2);

exit;





var_dump($stuff);
print_r($stuff);

echo "<hr />";
echo "formatted address:<br />";
$ac2 = $ac['formatted_address'];
print_r($ac2);

echo $stuff->results[0]->formatted_address;
echo "<hr />";

$xlat = $stuff->{'results'}[0]->{'geometry'}->{'location'}->{'lat'};
echo 'xlang: ' . $xlat;
echo "<hr />";

$xlong= $stuff->{'results'}[0]->{'geometry'}->{'location'}->{'lng'};
echo 'xlong: ' . $xlong;
echo "<hr />";

// Using the frame size 590px by 500px
$output = "<iframe frameborder='0' marginwidth='0' marginheight='0'
           scrolling='no' width='590' height='500' src='";

// Starting with the static Google map URI string portion
// appended by our pre-formatted address
$output .= "https://maps.google.ca/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=".$g_addr_str;

// This took some experimentation but including the map coordinates
// helps to center the map properly
$output .= "&amp;aq=&amp;sll=".(float)($xlat-10.5).",".(float)($xlong-11.5)."&amp;sspn=".(float)($xlat+10.5).",".(float)($xlong+11.5)."&amp;ie=UTF8&amp;hq=&amp;hnear=".$g_addr_str;

// Setting the map atributes to t=m (for map) and z15 (for zoom 15)
$output .= "&amp;t=m&amp;z=15";

$output .= "&amp;ll=".$xlat.",".$xlong."&amp;spn=0.0,0.0&amp;t=m&amp;z=14&amp;output=embed'></iframe>";

echo $output;

echo "<hr />";

// http://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false
// $client = new Zend_Rest_Client('http://framework.zend.com/rest');
// echo $client->sayHello('Davey', 'Day')->get(); // "Hello Davey, Good Day"

/*
// RSA 2048 bits would be preferable.

$rsa = new Crypt_RSA();

$rsa->setPrivateKeyFormat(CRYPT_RSA_PRIVATE_FORMAT_PKCS1);
$rsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_PKCS1);

//define('CRYPT_RSA_EXPONENT', 65537);
//define('CRYPT_RSA_SMALLEST_PRIME', 64); // makes it so multi-prime RSA is used
// extract($rsa->createKey()); // == $rsa->createKey(1024) where 1024 is the key size

extract($rsa->createKey(2048)); // == $rsa->createKey(1024) where 1024 is the key size

echo "<pre>";
echo "<hr />";
echo "privatekey:<br /><br />\n";
echo $privatekey;
echo "<br /><hr /><br />\n";
echo "publickey:<br /><br />\n";
echo $publickey;
echo "<br /><hr /><br />\n";
echo "</pre>";

echo "<hr /><br />rsa:<br />";
print_a($rsa);

echo "<hr /><br />rsa:<br />";
print_r($rsa);

exit;
*/

/*
$rsa = new Crypt_RSA();
// extract($rsa->createKey());
$key = $rsa->createKey();
extract($key);
print_r($key);
*/

$privatekey2048 = <<<EOT
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAic+PHLYH1cArOxizZ7M1xuy1/pPlKiDDBVTSatvEBSP4Llnc
mUQQ17ZgDIkQXLDfUjzbY3yAn9t7zl6o7YC8SSCxGFIQ7YF1dygB7Akf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sDzM+gP2dZCR3+dOWbjiWJGNRuISJHUi+tilQ
VGpPSMdOtcodIZv+3RfIAQKBgQCsH/m9QZjASSpEBDnMBvHp67sNGivpulm/BH6N
Afg2LEbbPZotz8djd+jZYJ+meq/1Ps/2z9EivkTMHKL9Vpku5SUUfls+MKitrl2/
n6mzlFIagxGzV4tddxUzjmXRBdqlszoZH4r2VJm0vw4qYfcgunUlaGoiOQGw3cyB
CvaM0wKBgQCOaQvjAaJMeATsk4+LNx+inPFpHbG/VpFJa8L2ZWzqm6SD4iUDGqzw
zIj1h0dlt4vySoUInfqBRJZLJASek4+LELRiVPQ6JqndfI1/JPR6k00UPim99sx8
tXn1loIoFsYDJGoj2jcuEuS2zT0CnOqjzr8eLzLYAvtoYu7oPqQnpw==
-----END RSA PRIVATE KEY-----
EOT;


$publickey2048 = <<<EOT
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAic+PHLYH1cArOxizZ7M1
xuy1/pPlKiDDBVTSatvEBSP4LlncmUQQ17ZgDIkQXLDfUjzbY3yAn9t7zl6o7YC8
SSCxGFIQ7YF1dygB7Akf57lj0X49mO5cUVqnA3XOGIXhdx6KdC4Z0Wr3LY2Lxkpm
+yVezXySsSJVa/Sj49FpmepQouCIbkwCzoYRybvfIifHOAnjILWUSnip5HHF1W/7
5FRrCaCWFjFjrNnyDizl7pgi7sDRK9M7zWmM/84dAjNdAXJE3FLtF8Tfj/zIZXya
Yeq51HEC51DJAuOP1JolZi2gvK4Jp4CUETSpnyMA8kSOlyVn65zGGTwifFm9uH0s
VwIDAQAB
-----END PUBLIC KEY-----
EOT;

/*
privatekey:
-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEAhhhvNIRGE/M1kuzc0rmLvG6FTPweolEXv7FfbonlR7tjAa3o
BYubmRbbF7ftgE6onjOERg5FwKCGcdhNEm2V010YZvU/BH1Wb8ZQZ6A6Cg7FOtQv
p3Dp+5WNO4jv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UN1O/4
xLGZJSy1aeod+CspUJ8zEwKBgETXXwCqTqNtfRaIX24RW4Av18AKQXtf+xUX+Qgs
FHdWT8xJQet2W0Cq1PqdIfNxWfHnkS6lF1WgGrfCGgzDZdl+V0udO4tuJX8ydqob
iwVfnNAtXtj5zwipIdSzJudcfZ5WPvae4hKIhSvUdcLa32OxozfMu3jA10fvrC3r
JAbXAoGASpgEt1VkMjxpKyFnQN+ubRiynjk+htNSO54qA5zDGscMMUixqILl3md5
ZH+iHH+lm+9rrJmv7vVcPafx3Nrcifeijp8spt4j/utEUR0F/X7yDY4A/AEwRBf4
caSo7ueNhWQoBkU4Ix/oYhbeQQAIaa29J37y71MeymaM/l3c4HA=
-----END RSA PRIVATE KEY-----


publickey:
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAhhhvNIRGE/M1kuzc0rmL
vG6FTPweolEXv7FfbonlR7tjAa3oBYubmRbbF7ftgE6onjOERg5FwKCGcdhNEm2V
010YZvU/BH1Wb8ZQZ6A6Cg7FOtQvp3Dp+5WNO4jvRzFIgVeu3tgzGZb7MShUT6Kh
AlGxkYw28I73qksSlCoa7d/PvcDCZZNO80Kcd2CEEAIx476Q6fqR071hbQwHSvAv
z0Vj7h+NHdNBeMvfz3rRa7YOoI8+50oLM/SSz1VILmgLmxGFzAjPFloQgp72ueZ8
B0vfQ4xX9imWCAdL/tWCSxneQSG6Z1uCHYZzZbjYr92nDubdQQeeLgF8ibqzFYIb
CQIDAQAB
-----END PUBLIC KEY-----
*/


$privatekey = <<<EOT
-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQCZtAsXevilwj+XrZvnr9UTz1bqiFHnYvt0DSXrlaNaaYxfKzXN
prHBn9bLxe40wsFElQ2njNhnzEhgn0r1AhyItHatfEjaSZ+10YqA1EQ3wytCX7Kg
UPGCrBKVjdSayawhrExqfKOJUYlJhDBhCV0fR2hRWR6bSiKIUK8UnMvyzwIDAQA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M2psw02J6CFgWhV5QRxYqjg5O2ffHeWIU
sc51Zvy0r/lu+DgNZm0CQAILv20LC89aPcKUj+fjVFrK8VPCkKMXH3WEGI3Se18I
xrvYrRXM5BiN2TOPEEp3WRE+i2m4lyvpBpNSFcchLMA=
-----END RSA PRIVATE KEY-----
EOT;


echo "<hr />";
echo "privatekey:<br />";
echo $privatekey;
echo "<hr />";
echo "publickey:<br />";
echo $publickey;
echo "<hr />";


echo "privatekey2:<br />";
echo $privatekey2;
echo "<hr />";
echo "publickey2:<br />";
echo $publickey2;
echo "<hr />";


//    $plaintext = 'terrafrost xyz monkey in a tree!';
$plaintext = $x;


$rsa = new Crypt_RSA();
$rsa->loadKey($publickey2);
//$rsa->setPublicKey($publickey2);
$ciphertext = $rsa->encrypt($plaintext);
echo "<br /><hr /><br />";
echo "ciphertext (raw):<br />";
echo $ciphertext;


$ciphertext = base64_encode($ciphertext);

echo "<br /><hr /><br />";
echo "ciphertext (base64):<br />";
echo $ciphertext;

echo "<br /><hr /><br />";

$rsa = new Crypt_RSA();
$rsa->loadKey($privatekey2);

$ciphertext = base64_decode($ciphertext);

echo "decrypt:<br />";
echo $rsa->decrypt($ciphertext);


echo "<hr /><br />xxxdecrypt:<br />";
print_a($rsa);
// print_a($rsa, 'max_y:5;window:0;label:my_array');
// print_a($rsa, 'window:0;label:my_arrayx');

echo "<hr /><br />";
show_vars();

// DbugL::help();

exit;

/**
 * Redirect with POST data.
 *
 * @param string $url URL.
 * @param array $post_data POST data. Example: array('foo' => 'var', 'id' => 123)
 * @param array $headers Optional. Extra headers to send.
 */
function redirect_post($url, array $data, array $headers = null) {
    $params = array(
        'http' => array(
            'method' => 'POST',
            'content' => http_build_query($data)
        )
    );
    if (!is_null($headers)) {
        $params['http']['header'] = '';
        foreach ($headers as $k => $v) {
            $params['http']['header'] .= "$k: $v\n";
        }
    }
    $ctx = stream_context_create($params);
    $fp = @fopen($url, 'rb', false, $ctx);
    if ($fp) {
        echo @stream_get_contents($fp);
        die();
    } else {
        // Error
        throw new Exception("Error loading '$url', $php_errormsg");
    }
}