Пример #1
0
 public static function getInstance()
 {
     if (self::$instance) {
         $instance = self::$instance;
     } else {
         $instance = self::$instance = new Memcache();
         $instance->connect(MEMCACHE_HOST, MEMCACHE_PORT);
     }
     return $instance;
 }
Пример #2
0
 public static function blacklistLink($id, $reporter = null, $ip = null)
 {
     $res = Utils_PDOTon::getInstance()->prepare("INSERT IGNORE INTO blacklist (id, reporter, ip) VALUES (?,?,?)");
     $res->execute([$id, $reporter, $ip]);
     Utils_MemcacheTon::getInstance()->set(BLACKLIST_MEMCACHE_PREFIX . $id, 1, MEMCACHE_COMPRESSED, self::CACHE_BLACKLISTED_TTL);
 }
Пример #3
0
 private function _actionDl($post_data)
 {
     try {
         $dec_link = $this->_decryptLink($post_data->link);
     } catch (Exception_MegaCrypterLinkException $exception) {
         if ($exception->getCode() == Utils_MegaCrypter::EXPIRED_LINK) {
             $dec_link = Utils_MegaCrypter::decryptLink($post_data->link, true);
             if ($post_data->noexpire != base64_encode(hash('sha256', base64_decode($dec_link['secret']), true))) {
                 throw $exception;
             }
         } else {
             throw $exception;
         }
     }
     $ma = new Utils_MegaApi(MEGA_API_KEY);
     try {
         $data = ['url' => $ma->getFileDownloadUrl($dec_link['file_id'], is_bool($post_data->ssl) ? $post_data->ssl : false)];
         if ($dec_link['pass']) {
             list($iterations, $pass, $pass_salt) = explode('#', $dec_link['pass']);
             $iv = openssl_random_pseudo_bytes(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC));
             $data['url'] = $this->_encryptApiField($data['url'], base64_decode($pass), $iv);
             $data['pass'] = base64_encode($iv);
         } else {
             $data['pass'] = false;
         }
     } catch (Exception $exception) {
         Utils_MemcacheTon::getInstance()->delete($dec_link['file_id'] . $dec_link['file_key']);
         throw $exception;
     }
     return $data;
 }
Пример #4
0
 public function getFileInfo($fid, $fkey)
 {
     if (strpos($fid, '*') !== false) {
         list($file_id, $folder_id) = explode('*', $fid);
         if (empty($file_id)) {
             throw new Exception_MegaLinkException(self::ENOENT);
         }
     }
     if ($this->_cache) {
         $cached_file_info = Utils_MemcacheTon::getInstance()->get((isset($file_id) ? $file_id : $fid) . $fkey);
         if (is_int($cached_file_info)) {
             throw new Exception_MegaLinkException($cached_file_info);
         }
     }
     try {
         if (!$this->_cache || $cached_file_info === false) {
             if (isset($file_id) && !empty($folder_id)) {
                 $child_node = $this->getFolderChildFileNode($folder_id, $fkey, $file_id);
                 $file_info = ['name' => $child_node['name'], 'path' => $child_node['path'], 'size' => $child_node['size'], 'key' => $child_node['key']];
             } else {
                 $response = isset($file_id) ? $this->rawAPIRequest(['a' => 'g', 'n' => $file_id]) : $this->rawAPIRequest(['a' => 'g', 'p' => $fid]);
                 $at = $this->_decryptAt($response->at, $fkey);
                 $file_info = ['name' => $at->n, 'size' => $response->s];
             }
             if (empty($file_info['name'])) {
                 $file_info['name'] = md5((isset($file_id) ? $file_id . $file_info['key'] : $fid . $fkey) . base64_decode(GENERIC_PASSWORD));
             }
         } else {
             $file_info = $cached_file_info;
         }
         if ($this->_cache && $file_info['size'] > 0) {
             Utils_MemcacheTon::getInstance()->set((isset($file_id) ? $file_id : $fid) . $fkey, $file_info, MEMCACHE_COMPRESSED, self::CACHE_FILEINFO_TTL);
         }
     } catch (Exception_MegaLinkException $exception) {
         if ($this->_cache && Utils_MiscTools::isCacheableError($exception->getCode())) {
             Utils_MemcacheTon::getInstance()->set((isset($file_id) ? $file_id : $fid) . $fkey, $exception->getCode(), MEMCACHE_COMPRESSED, self::CACHE_FILEINFO_TTL);
         }
         throw $exception->getCode() == self::EINTERNAL ? new Exception_MegaLinkException(self::ETEMPUNAVAIL) : $exception;
     }
     return $file_info;
 }