Example #1
0
 protected function ReadInternal($Buffer, $Length, $SherlockFunction)
 {
     if ($Buffer->Remaining() === 0) {
         throw new InvalidPacketException('Failed to read any data from socket', InvalidPacketException::BUFFER_EMPTY);
     }
     $Header = $Buffer->GetLong();
     if ($Header === -1) {
         // We don't have to do anything
     } else {
         if ($Header === -2) {
             $Packets = [];
             $IsCompressed = false;
             $ReadMore = false;
             do {
                 $RequestID = $Buffer->GetLong();
                 switch ($this->Engine) {
                     case SourceQuery::GOLDSOURCE:
                         $PacketCountAndNumber = $Buffer->GetByte();
                         $PacketCount = $PacketCountAndNumber & 0xf;
                         $PacketNumber = $PacketCountAndNumber >> 4;
                         break;
                     case SourceQuery::SOURCE:
                         $IsCompressed = ($RequestID & 0x80000000) !== 0;
                         $PacketCount = $Buffer->GetByte();
                         $PacketNumber = $Buffer->GetByte() + 1;
                         if ($IsCompressed) {
                             $Buffer->GetLong();
                             // Split size
                             $PacketChecksum = $Buffer->GetUnsignedLong();
                         } else {
                             $Buffer->GetShort();
                             // Split size
                         }
                         break;
                 }
                 $Packets[$PacketNumber] = $Buffer->Get();
                 $ReadMore = $PacketCount > sizeof($Packets);
             } while ($ReadMore && $SherlockFunction($Buffer, $Length));
             $Data = Implode($Packets);
             // TODO: Test this
             if ($IsCompressed) {
                 // Let's make sure this function exists, it's not included in PHP by default
                 if (!Function_Exists('bzdecompress')) {
                     throw new \RuntimeException('Received compressed packet, PHP doesn\'t have Bzip2 library installed, can\'t decompress.');
                 }
                 $Data = bzdecompress($Data);
                 if (CRC32($Data) !== $PacketChecksum) {
                     throw new InvalidPacketException('CRC32 checksum mismatch of uncompressed packet data.', InvalidPacketException::CHECKSUM_MISMATCH);
                 }
             }
             $Buffer->Set(SubStr($Data, 4));
         } else {
             throw new InvalidPacketException('Socket read: Raw packet header mismatch. (0x' . DecHex($Header) . ')', InvalidPacketException::PACKET_HEADER_MISMATCH);
         }
     }
     return $Buffer;
 }
 /**
  * Decrypt string
  *
  * @param $decrypt
  *
  * @return bool|mixed|string
  */
 public function decrypt($decrypt)
 {
     $decrypt = explode('|', $decrypt . '|');
     $decoded = base64_decode($decrypt[0]);
     $iv = base64_decode($decrypt[1]);
     if (strlen($iv) !== mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC)) {
         return false;
     }
     $key = pack('H*', sprintf('%u', CRC32($this->key)));
     $decrypted = trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $decoded, MCRYPT_MODE_CBC, $iv));
     $mac = substr($decrypted, -64);
     $decrypted = substr($decrypted, 0, -64);
     $calcmac = hash_hmac('sha256', $decrypted, substr(bin2hex($key), -32));
     if ($calcmac !== $mac) {
         return false;
     }
     $decrypted = unserialize($decrypted);
     return $decrypted;
 }
Example #3
0
 /**
  * Prepares a paged search, if possible
  * @param string $filter the LDAP filter for the search
  * @param string[] $bases an array containing the LDAP subtree(s) that shall be searched
  * @param string[] $attr optional, when a certain attribute shall be filtered outside
  * @param int $limit
  * @param int $offset
  * @return bool|true
  */
 private function initPagedSearch($filter, $bases, $attr, $limit, $offset)
 {
     $pagedSearchOK = false;
     if ($this->connection->hasPagedResultSupport && !is_null($limit)) {
         $offset = intval($offset);
         //can be null
         \OCP\Util::writeLog('user_ldap', 'initializing paged search for  Filter ' . $filter . ' base ' . print_r($bases, true) . ' attr ' . print_r($attr, true) . ' limit ' . $limit . ' offset ' . $offset, \OCP\Util::DEBUG);
         //get the cookie from the search for the previous search, required by LDAP
         foreach ($bases as $base) {
             $cookie = $this->getPagedResultCookie($base, $filter, $limit, $offset);
             if (empty($cookie) && $offset > 0) {
                 // no cookie known, although the offset is not 0. Maybe cache run out. We need
                 // to start all over *sigh* (btw, Dear Reader, did you know LDAP paged
                 // searching was designed by MSFT?)
                 // 		Lukas: No, but thanks to reading that source I finally know!
                 $reOffset = $offset - $limit < 0 ? 0 : $offset - $limit;
                 //a bit recursive, $offset of 0 is the exit
                 \OCP\Util::writeLog('user_ldap', 'Looking for cookie L/O ' . $limit . '/' . $reOffset, \OCP\Util::INFO);
                 $this->search($filter, array($base), $attr, $limit, $reOffset, true);
                 $cookie = $this->getPagedResultCookie($base, $filter, $limit, $offset);
                 //still no cookie? obviously, the server does not like us. Let's skip paging efforts.
                 //TODO: remember this, probably does not change in the next request...
                 if (empty($cookie)) {
                     $cookie = null;
                 }
             }
             if (!is_null($cookie)) {
                 if ($offset > 0) {
                     \OCP\Util::writeLog('user_ldap', 'Cookie ' . CRC32($cookie), \OCP\Util::INFO);
                 }
                 $pagedSearchOK = $this->ldap->controlPagedResult($this->connection->getConnectionResource(), $limit, false, $cookie);
                 if (!$pagedSearchOK) {
                     return false;
                 }
                 \OCP\Util::writeLog('user_ldap', 'Ready for a paged search', \OCP\Util::INFO);
             } else {
                 \OCP\Util::writeLog('user_ldap', 'No paged search for us, Cpt., Limit ' . $limit . ' Offset ' . $offset, \OCP\Util::INFO);
             }
         }
     }
     return $pagedSearchOK;
 }
 public function iosPushNotification($deviceToken, $message, $data, $badgeCount = 1)
 {
     // For testing purpose
     $badge = $badgeCount;
     //Notification Count
     //////////////////////////////---Configurations---///////////////////////////////////////
     $isProd = false;
     $URL = "ssl://gateway.sandbox.push.apple.com:2195";
     $certificatePath = public_path() . "/api/notification/ios_push_notification_files/EvolveDev.pem";
     if ($isProd) {
         $URL = "ssl://gateway.push.apple.com:2195";
         //Production File
         $certificatePath = public_path() . "/api/notification/ios_push_notification_files/EvolveProd.pem";
     }
     // Put your private key's passphrase here:
     $passPhrase = 'Evolve!23$';
     /////////////////////////////////---Process---/////////////////////////////////////////////
     $ctx = stream_context_create();
     stream_context_set_option($ctx, 'ssl', 'local_cert', $certificatePath);
     //Certificate file path
     stream_context_set_option($ctx, 'ssl', 'passphrase', $passPhrase);
     //Password of certificate
     // APNS Production Address: ssl://gateway.push.apple.com:2195
     // APNS Development Address: ssl://gateway.sandbox.push.apple.com:2195
     // Open a connection to the APNS server
     $fp = stream_socket_client($URL, $err, $errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx);
     if (!$fp) {
         exit("Failed to connect: {$err} {$errstr}" . PHP_EOL);
     }
     //	'Connected to APNS' . PHP_EOL;
     // Create the payload body
     $body['aps'] = array('sound' => 'default', 'badge' => $badge, 'alert' => $message, 'notificationId' => $data['notificationId'], 'senderId' => $data['senderId'], 'receiverId' => $data['receiverId'], 'name' => $data['name'], 'image' => $data['image'], 'id' => $data['id'], 'flag' => $data['flag'], 'type' => $data['type'], 'isRead' => 0, 'isSeen' => 0);
     // Encode the payload as JSON
     $payload = json_encode($body);
     // Build the binary notification
     $msg = chr(0) . pack('n', 32) . pack('H*', str_replace(' ', '', sprintf('%u', CRC32($deviceToken)))) . pack('n', strlen($payload)) . $payload;
     // Send it to the server
     fwrite($fp, $msg, strlen($msg));
     fclose($fp);
 }
Example #5
0
 /**
  * Decrypts the given string
  *
  * @param  string $str
  * @return string
  * @throws Exception\InvalidStringToDecryptException IF str is not crpyted
  */
 public static function decrypt($str)
 {
     if (false == self::isCrypted($str)) {
         throw new Exception\InvalidStringToDecryptException("\n\t\t\t\tThe string given was not encrypted with this key\n\t\t\t");
     }
     $parts = explode(";", $str);
     $str = $parts[0];
     $key = self::convertKey(rtrim(base64_encode(pack('H*', sprintf('%u', CRC32(self::getKey()))))));
     $ivSize = self::getIvSize();
     $secretTxt = base64_decode($str);
     $ivDec = substr($secretTxt, 0, $ivSize);
     $secretTxt = substr($secretTxt, $ivSize);
     return mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $secretTxt, MCRYPT_MODE_CBC, $ivDec);
 }
Example #6
0
 public function Read($Length = 1400)
 {
     $this->Buffer->Set(FRead($this->Socket, $Length));
     if ($this->Buffer->Remaining() > 0 && $this->Buffer->GetLong() == -2) {
         $Packets = array();
         $IsCompressed = false;
         $ReadMore = false;
         do {
             $RequestID = $this->Buffer->GetLong();
             switch ($this->Engine) {
                 case CI_SourceQuery::GOLDSOURCE:
                     $PacketCountAndNumber = $this->Buffer->GetByte();
                     $PacketCount = $PacketCountAndNumber & 0xf;
                     $PacketNumber = $PacketCountAndNumber >> 4;
                     break;
                 case CI_SourceQuery::SOURCE:
                     $IsCompressed = ($RequestID & 0x80000000) != 0;
                     $PacketCount = $this->Buffer->GetByte();
                     $PacketNumber = $this->Buffer->GetByte() + 1;
                     if ($IsCompressed) {
                         $this->Buffer->GetLong();
                         // Split size
                         $PacketChecksum = $this->Buffer->GetUnsignedLong();
                     } else {
                         $this->Buffer->GetShort();
                         // Split size
                     }
                     break;
             }
             $Packets[$PacketNumber] = $this->Buffer->Get();
             $ReadMore = $PacketCount > sizeof($Packets);
         } while ($ReadMore && $this->Sherlock($Length));
         $Buffer = Implode($Packets);
         // TODO: Test this
         if ($IsCompressed) {
             // Let's make sure this function exists, it's not included in PHP by default
             if (!Function_Exists('bzdecompress')) {
                 throw new RuntimeException('Received compressed packet, PHP doesn\'t have Bzip2 library installed, can\'t decompress.');
             }
             $Data = bzdecompress($Data);
             if (CRC32($Data) != $PacketChecksum) {
                 throw new SourceQueryException('CRC32 checksum mismatch of uncompressed packet data.');
             }
         }
         $this->Buffer->Set(SubStr($Buffer, 4));
     }
 }
Example #7
0
 /**
  * @param \Exception $e
  *
  * @return string
  */
 private function logRef(\Exception $e)
 {
     $logRef = (string) CRC32($e);
     file_put_contents($this->appMeta->logDir . "/{$logRef}.log", $e);
     return $logRef;
 }
Example #8
0
mysql_select_db('HContext');
$Find2 = array();
foreach (array('СЕКС', 'КЕКС', 'ПАРТИЯ') as $Cur) {
    $Find2[] = CRC32($Cur);
}
//$res=mysql_query('SELECT SQL_NO_CACHE * FROM morf where `CRC32` in ('.join(',',$Find2).')') or die(mysql_error());
//while($cur=mysql_fetch_assoc($res))
//	print_R($cur);
$Find = array('ФЫSADASDВ', 'ФЫASASDASDDВ', 'ФЫВЫВЫВФЫВ', 'DSDSDЫФЫВSD', 'ЯРОВАЯ', 'ФЫВФЫВ', 'СМЕЛЫЙ', 'ПАМЯТЬ', 'ЛЕСТЬ', 'ФЫВФЫВ', 'ФВФЫВ', 'ВФЫВЫ', 'ЫВФЫВФЫВ', 'СМЫСЛА', 'СТРАХА', 'ФЫВФЫВ', 'ЛЮБОВЬ', 'ФЫВФЫВЫФФЫ');
$st = microtime(true);
for ($i = 0; $i < 10; $i++) {
    $Find2 = array();
    foreach ($Find as $Cur) {
        $Find2[] = CRC32($Cur . rand());
    }
    $res = mysql_query('SELECT SQL_NO_CACHE * FROM morf where `CRC32` in (' . join(',', $Find2) . ')') or die(mysql_error());
}
echo '<pre>';
echo '<br >mysql ' . (microtime(true) - $st);
$st = microtime(true);
for ($i = 0; $i < 10; $i++) {
    $fp = fopen('binMorf.bin', 'r');
    $Find2 = array();
    foreach ($Find as $Cur) {
        $Find2[] = CRC32($Cur . rand());
    }
    foreach ($Find2 as $Cur) {
        findSF($Cur, $fp);
    }
}
echo '<br >files ' . (microtime(true) - $st);