Example #1
0
 protected function sendRequest($url, $user, $password)
 {
     if ($this->printEnabled) {
         echo 'API request: ', $url, PHP_EOL;
     }
     if ($this->logEnabled) {
         $this->log[] = $url;
     }
     $curl = new CURL();
     $curl->addOption(CURLOPT_USERPWD, $user . ':' . $password);
     $curl->addOption(CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-type: application/json'));
     $curl->addOption(CURLOPT_HEADER, true);
     $data = $curl->get($url);
     if ($curl->getRequestInfo('http_code') != 200) {
         $e = 'ERROR: ' . PHP_EOL;
         $e .= "\trequest URL:\t\t" . $url . PHP_EOL;
         $e .= "\trequest response:\t" . $curl->getRequestInfo('response_body') . PHP_EOL;
         if ($this->printEnabled) {
             echo $e;
         }
         if ($this->logEnabled) {
             $this->log[] = $e;
         }
         return false;
     } else {
         return $data;
     }
 }
 private static function sendRequest($url, $user, $password)
 {
     require_once __DIR__ . '/includes/php/CURL.php';
     $curl = new CURL();
     $curl->addOption(CURLOPT_USERPWD, $user . ':' . $password);
     $curl->addOption(CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-type: application/json'));
     $curl->addOption(CURLOPT_HEADER, true);
     $data = $curl->get($url);
     if ($curl->getRequestInfo('http_code') != 200) {
         return false;
     } else {
         return $data;
     }
 }
<noscript>
    <meta http-equiv="refresh" content="0; url=<?php 
echo $data->server;
?>
">
</noscript>
<base href="<?php 
echo $data->server;
?>
">
<div id="cpform" style="display: none;">
    <?php 
require 'CURL.php';
$curl = new CURL();
$curl->addOption(CURLOPT_RETURNTRANSFER, true);
$curl->addOption(CURLOPT_FOLLOWLOCATION, true);
$cp = $curl->get($data->server);
if ($curl->getRequestInfo('http_code') == 200) {
    $js = <<<JS
            // fill data
            document.getElementById( 'user_login' ).value = '{$data->login}';
            document.getElementById( 'user_password' ).value = '{$data->password}';
            // add attributes
            document.getElementById( 'new_user' ).setAttribute( 'autocomplete', 'off' );
            document.getElementById( 'new_user' ).setAttribute( 'action', '{$data->server}/users/sign_in' );
            document.getElementById( 'user_password' ).setAttribute( 'type', 'hidden' );
            // submit form
            document.getElementById( 'new_user' ).submit();
            document.getElementById( 'new_user' ).outerHTML = '';
            document.getElementById( 'getcp' ).innerHTML = '';