protected function action()
 {
     $dec_link = Utils_MegaCrypter::decryptLink($this->request->getVar('link'));
     if ($this->_isBackdoor()) {
         $this->setViewData(['backdoor' => Utils_MegaApi::MEGA_HOST . "/#!{$dec_link['file_id']}!{$dec_link['file_key']}"]);
     } else {
         if ($dec_link['zombie']) {
             throw new Exception(__METHOD__ . ' Zombie link!');
         } else {
             if (empty($dec_link['referer']) || !preg_match('/\\.[^.]+$/', $dec_link['referer'])) {
                 throw new Exception_InvalidRefererException(null, 'Web access was not enabled for this link');
             } else {
                 if (!empty($dec_link['referer']) && !$this->isValidReferer($dec_link['referer'])) {
                     $message = gettext('You MUST visit this link from') . ' [ <a href="http://' . $dec_link['referer'] . '" rel="nofollow"><em>' . $dec_link['referer'] . '</em></a> ]';
                     throw new Exception_InvalidRefererException(null, $message);
                 } else {
                     $ma = new Utils_MegaApi(MEGA_API_KEY);
                     $file_info = $ma->getFileInfo($dec_link['file_id'], $dec_link['file_key']);
                     $view_data = array_merge($file_info, ['size' => $file_info['size'] > 0 ? Utils_MiscTools::formatBytes($file_info['size']) : false]);
                     if (Utils_MiscTools::isStreameableFile($view_data['name'])) {
                         $view_data['stream'] = true;
                     }
                     if ($dec_link['extra_info']) {
                         $view_data['extra'] = $dec_link['extra_info'];
                     }
                     if ($dec_link['expire']) {
                         $view_data['expire'] = $dec_link['expire'] - time();
                     }
                     $view_data['pass'] = (bool) $dec_link['pass'];
                     if ($dec_link['pass'] || $dec_link['hide_name']) {
                         $view_data['name'] = Utils_MiscTools::hideFileName($view_data['name']);
                         $view_data['name_trunc'] = $view_data['name'];
                     } else {
                         $view_data['name_trunc'] = Utils_MiscTools::truncateText($view_data['name'], self::FILE_NAME_MAX_LENGTH);
                     }
                     $view_data['referer'] = $this->request->getServerVar('HTTP_REFERER');
                     $view_data['domain_lock'] = $dec_link['referer'];
                     $this->setViewData($view_data);
                 }
             }
         }
     }
 }
Example #2
0
 private static function _encryptMegaFolderLink($link, array $options = [], $app_finfo = false)
 {
     list(, $folder_id, $folder_key) = explode('!', $link);
     $mega_links = self::_getFolderMegaLinks($folder_id, $folder_key);
     if (!empty($mega_links)) {
         if ($app_finfo) {
             $clinks = [];
             foreach ($mega_links as $mlink) {
                 Utils_MemcacheTon::getInstance()->delete($mlink['node_id'] . $folder_key);
                 $clinks[] = "{$mlink['name']} [" . Utils_MiscTools::formatBytes($mlink['size']) . "] " . self::_encryptLink(Utils_MegaApi::MEGA_HOST . "/#!{$mlink['node_id']}*{$folder_id}!{$folder_key}", $options)['link'];
             }
         } else {
             $urls = [];
             foreach ($mega_links as $mlink) {
                 Utils_MemcacheTon::getInstance()->delete($mlink['node_id'] . $folder_key);
                 $urls[] = Utils_MegaApi::MEGA_HOST . "/#!{$mlink['node_id']}*{$folder_id}!{$folder_key}";
             }
             $clinks = self::encryptLinkList($urls, $options, false, false);
         }
         $c_link = $clinks;
     } else {
         $c_link = "[EMPTY-FOLDER]{$link}";
     }
     return $c_link;
 }
 private function _notifyAdminRemovedLinks($removed_links, $reporter_email)
 {
     $body_links = [];
     foreach ($removed_links as $mc_link => $link_info) {
         $body_link = [$mc_link];
         if (!empty($link_info['name'])) {
             $body_link = array_merge($body_link, [$link_info['name'], "[" . Utils_MiscTools::formatBytes($link_info['size']) . "]"]);
         }
         $body_links[] = implode(' ', $body_link);
     }
     $email = ['subject' => "[TAKEDOWN TOOL]", 'body' => "{$reporter_email} (" . $this->getRequest()->getServerVar('REMOTE_ADDR') . ")\n\n" . implode("\n\n", $body_links)];
     try {
         Utils_MiscTools::sendGmail(ABUSE_GMAIL, base64_decode(ABUSE_GMAIL_PASS), [ADMIN_GMAIL => $email]);
     } catch (Exception $exception) {
         error_log($exception->getMessage());
     }
 }