Exemple #1
0
function udf_sha1($str, $raw_output = FALSE)
{
    if ($raw_output === TRUE) {
        return pack('H*', udf_sha1($str, FALSE));
    }
    $x = sha1_str2blks_SHA1($str);
    $a = 1732584193;
    $b = -271733879;
    $c = -1732584194;
    $d = 271733878;
    $e = -1009589776;
    $x_count = count($x);
    for ($i = 0; $i < $x_count; $i += 16) {
        $olda = $a;
        $oldb = $b;
        $oldc = $c;
        $oldd = $d;
        $olde = $e;
        for ($j = 0; $j < 80; $j++) {
            $w[$j] = $j < 16 ? $x[$i + $j] : sha1_rol($w[$j - 3] ^ $w[$j - 8] ^ $w[$j - 14] ^ $w[$j - 16], 1);
            $t = sha1_safe_add(sha1_safe_add(sha1_rol($a, 5), sha1_ft($j, $b, $c, $d)), sha1_safe_add(sha1_safe_add($e, $w[$j]), sha1_kt($j)));
            $e = $d;
            $d = $c;
            $c = sha1_rol($b, 30);
            $b = $a;
            $a = $t;
        }
        $a = sha1_safe_add($a, $olda);
        $b = sha1_safe_add($b, $oldb);
        $c = sha1_safe_add($c, $oldc);
        $d = sha1_safe_add($d, $oldd);
        $e = sha1_safe_add($e, $olde);
    }
    return sprintf('%08x%08x%08x%08x%08x', $a, $b, $c, $d, $e);
}
Exemple #2
0
 function atom($data = false)
 {
     $return = false;
     //$host = false, $path = false, $method = 'POST', $authentication = 'SECURE', $protocol = 'SSL', $content = '', $issued = NOW)
     if (isset($data['HOST']) && isset($data['PATH'])) {
         $data['METHOD'] = isset($data['METHOD']) ? $data['METHOD'] : 'POST';
         $data['AUTHENTICATION'] = isset($data['AUTHENTICATION']) ? $data['AUTHENTICATION'] : 'SECURE';
         $data['PROTOCOL'] = isset($data['PROTOCOL']) ? $data['PROTOCOL'] : 'SSL';
         $data['CONTENT'] = isset($data['CONTENT']) ? $data['CONTENT'] : '';
         $data['ISSUED'] = isset($data['ISSUED']) ? $data['ISSUED'] : NOW;
         $data['USERNAME'] = isset($data['USERNAME']) ? $data['USERNAME'] : '';
         $data['PASSWORD'] = isset($data['PASSWORD']) ? $data['PASSWORD'] : '';
         //$data[''] = isset($data['']) ? $data[''] : '';
         if (strncmp($data['AUTHENTICATION'], 'SECURE', 6) == 0) {
             include_once PATH_INCLUDE . '/functions_sha1.php';
             $headers = $data['METHOD'] == 'POST' ? $this->_secureHeaders : $this->_getHeadersSecure;
             if (strstr($data['AUTHENTICATION'], '-RPC') != false) {
                 $headers = str_replace('application/atom+xml', 'text/xml', $headers);
             }
             $created = gmdate("Y-m-d\\TH:i:s\\Z", $data['ISSUED']);
             $nonce = udf_sha1($created . ':' . 'FF_*_TEXT', true);
             $passwordDigest = base64_encode(udf_sha1($nonce . $created . $data['PASSWORD'], true));
             $requestData = str_replace(array('{PATH}', '{USERNAME}', '{PASSWORDDIGEST}', '{NONCE}', '{CREATED}', '{CONTENTLENGTH}', '{USERAGENT}', '{HOST}', '{CONTENT}'), array($data['PATH'], $data['USERNAME'], $passwordDigest, $nonce, $created, strlen($data['CONTENT']), "FotoFlix CApiClient v{$this->_version}", $data['HOST'], $data['CONTENT']), $headers);
         } else {
             if (strncmp($data['AUTHENTICATION'], 'BASIC', 5) == 0) {
                 $headers = $data['METHOD'] == 'POST' ? $this->_basicHeaders : $this->_getHeadersBasic;
                 if (strstr($data['AUTHENTICATION'], '-RPC') != false) {
                     $headers = str_replace('application/atom+xml', 'text/xml', $headers);
                 }
                 $requestData = str_replace(array('{PATH}', '{CREDENTIALS}', '{CONTENTLENGTH}', '{USERAGENT}', '{HOST}', '{CONTENT}'), array($data['PATH'], base64_encode($data['USERNAME'] . ':' . $data['PASSWORD']), strlen($data['CONTENT']), "FotoFlix CApiClient v{$this->_version}", $data['HOST'], $data['CONTENT']), $headers);
             }
         }
         //echo '<!-- jm -->' . $requestData . '<!-- // jm -->';
         //die();
         $fp = $data['PROTOCOL'] == 'SSL' ? fsockopen('ssl://' . $data['HOST'], 443) : fsockopen($data['HOST'], 80);
         //print_r($fp);
         if ($fp) {
             fputs($fp, $requestData);
             //preg_match('/\s(\d+)/', fgets($fp, 1024), $responseCode);
             //$return = $responseCode[1];
             $i = 0;
             $return = '';
             while (!feof($fp)) {
                 $return .= fgets($fp, 1024);
                 if ($i > 100) {
                     break;
                 }
                 $i++;
             }
         }
     }
     return $return;
 }