public static function get_as_data_maxmind($keep_temporary_file = false)
 {
     // path and filename of source files at maxmind
     define('MAXMIND_PATH', 'http://download.maxmind.com/download/geoip/database/asnum/GeoIPASNum2.zip');
     define('MAXMIND_CSV_FILENAME', 'GeoIPASNum2.csv');
     // check whether there is (maybe) enough memory
     echo 'memory_limit = ' . ini_get('memory_limit') . "<br />\n";
     #if () {
     #}
     // download temporary copy of maxmind zip file
     $temporary_file_path = '';
     $zip_download = ZipDownloader::temporary_zip_download(MAXMIND_PATH, 'GeoIPASNum2', '');
     echo $zip_download['success_message'] . '<br />';
     // read content of csv file in temporary zip file (if download successful)
     if ($zip_download['successful']) {
         echo 'Total time for download: ' . $zip_download['total_time'] . '<br />';
         echo 'Size of downloaded file: ' . $zip_download['size_download'] . '<br />';
         $zip_handle = new ZipArchive();
         if ($zip_handle->open($temporary_file_path . $zip_download['temp_file_name'])) {
             $csv_file_handle = $zip_handle->getStream(MAXMIND_CSV_FILENAME);
             if (!$csv_file_handle) {
                 exit('Error: could not read CSV file within ZIP file.<br />');
             }
             // put data into an array
             $as_data = array();
             while (($data = fgetcsv($csv_file_handle, 0, ',', '"')) !== false) {
                 if (count($data) !== 3) {
                     exit('Error: CSV file structure faulty.');
                 }
                 $new_entry = array();
                 $new_entry['ip_from'] = $data[0];
                 $new_entry['ip_to'] = $data[1];
                 $as_number_and_name = $data[2];
                 $pattern_asn = '/AS\\d+/';
                 preg_match($pattern_asn, $as_number_and_name, $parsed_asn);
                 $new_entry['number'] = substr($parsed_asn[0], 2);
                 $pattern_name = '/\\s.+/';
                 preg_match($pattern_name, $as_number_and_name, $parsed_name);
                 $new_entry['name'] = substr($parsed_name[0], 1);
                 $as_data[] = $new_entry;
             }
             fclose($csv_file_handle);
             echo 'Data successfully extracted: ' . count($as_data) . ' lines.<br />';
         } else {
             echo 'Error: Could not open downloaded temporary copy of ZIP file.<br />';
         }
         // delete temporary zip file if specified by parameter
         if (!$keep_temporary_file) {
             unlink($temporary_file_path . $temporary_file_name);
         }
     }
     #for ($i = count($as_data) - 1; $i > 230677; $i--) {
     #    echo $as_data[$i]['ip_from'] . ' // ' . $as_data[$i]['ip_to'] . ' // ' . $as_data[$i]['number'] . ' // ' . $as_data[$i]['name'] . '<br />';
     #}
     /*
     for ($i = 0; $i < count($as_data); $i++) {
         if ($as_data[$i]['number'] == NULL) {
     echo 'Fehler: ' . $i . '<br />';
     echo $as_data[$i - 1]['number'] . '<br />';
     echo $as_data[$i]['name'] . '<br />';
     echo $as_data[$i + 1]['number'] . '<br />';
         }
     }
     */
     return $as_data;
 }
 /**
  * 動画のzipダウンロード
  *
  * @return CakeResponse
  * @throws NotFoundException 表示できない記事へのアクセス
  * @throws ForbiddenException アクセス権なし
  * @see DownloadComponent::doDownload()
  */
 public function download()
 {
     // ダウンロードリンク使わないなら、400
     if (!$this->useDownloadLink) {
         return $this->setAction('throwBadRequest');
     }
     // ブロック編集許可(編集長以上)持っていないなら403
     if (!Current::permission('block_editable')) {
         throw new ForbiddenException();
     }
     // ここから元コンテンツを取得する処理
     //$this->_prepare();
     $key = $this->params['key'];
     $conditions = $this->Video->getConditions();
     $conditions['Video.key'] = $key;
     $query = array('conditions' => $conditions);
     $video = $this->Video->find('first', $query);
     // ここまで元コンテンツを取得する処理
     // ダウンロード実行
     if (!$video) {
         // 表示できない記事へのアクセスなら404
         throw new NotFoundException(__d('videos', 'Invalid video entry'));
     }
     // 圧縮用パスワードキーを求める
     if (!empty($this->request->data['AuthorizationKey']['authorization_key'])) {
         $zipPassword = $this->request->data['AuthorizationKey']['authorization_key'];
     } else {
         $this->_setFlashMessageAndRedirect($key, __d('authorization_keys', 'please input compression password'));
         return;
     }
     // ダウンロードファイル名はタイトルにする
     $fileName = $video['Video']['title'];
     $zipFileName = $fileName . '.zip';
     $videoFileName = $fileName . '.mp4';
     $realFilePath = APP . WEBROOT_DIR . DS . $video['UploadFile'][Video::VIDEO_FILE_FIELD]['path'] . $video['UploadFile'][Video::VIDEO_FILE_FIELD]['id'] . DS . $video['UploadFile'][Video::VIDEO_FILE_FIELD]['real_file_name'];
     $zip = new ZipDownloader();
     $zip->addFile($realFilePath, $videoFileName);
     $zip->setPassword($zipPassword);
     $zip->close();
     return $zip->download($zipFileName);
 }
Exemple #3
0
 /**
  * createWysiwygZip
  *
  * @param string $data wysiswyg editor content
  * @param string $fileName wysiwygのテキストをまとめるファイル名
  * @return string 作成したZIPファイルへのパス
  * @throws InternalErrorException
  */
 public function createWysiwygZip($data, $fileName = 'document.txt')
 {
     $zip = new ZipDownloader();
     // UPLOADされているファイル情報を取り出す
     $tmpStr = $data;
     $tmpStr = str_replace('<img', "\n<img", $tmpStr);
     $tmpStr = str_replace('<a', "\n<a", $tmpStr);
     $matchCount = preg_match_all(self::WYSIWYG_FILE_KEY_PATTERN, $tmpStr, $matches);
     if ($matchCount > 0) {
         // ファイルのUPLOAD_IDを取り出す
         foreach ($matches[3] as $uploadId) {
             // ファイル情報を取得してくる
             $uploadFile = $this->UploadFile->findById($uploadId);
             if ($uploadFile) {
                 $uploadFile = $uploadFile['UploadFile'];
                 // ルームチェック
                 if ($uploadFile['room_id']) {
                     $roomId = Current::read('Room.id');
                     if ($uploadFile['room_id'] != $roomId) {
                         CakeLog::error('Can not find wysiwyg file ' . $uploadId);
                         throw new InternalErrorException();
                     }
                 }
                 if ($uploadFile['block_key']) {
                     // block_keyによるガード
                     $Block = ClassRegistry::init('Blocks.Block');
                     $uploadFileBlock = $Block->findByKeyAndLanguageId($uploadFile['block_key'], Current::read('Language.id'));
                     if ($Block->isVisible($uploadFileBlock) === false) {
                         CakeLog::error('Can not find wysiwyg file ' . $uploadId);
                         throw new InternalErrorException();
                     }
                 }
                 // そのファイルをZIPに含める
                 $path = WWW_ROOT . trim($uploadFile['path'], '/') . '/' . $uploadId . '/' . $uploadFile['real_file_name'];
                 $zip->addFile($path, $uploadId . '.' . $uploadFile['extension']);
             }
         }
     }
     $zip->addFromString($fileName, $data);
     $zip->close();
     return $zip->path;
 }
 public static function get_geolocation_data_maxmind($keep_temporary_file = false)
 {
     // path and filename of source files at ip2location
     define('MAXMIND_PATH', 'http://geolite.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip');
     define('MAXMIND_CSV_FILENAME', 'GeoIPCountryWhois.csv');
     // download temporary copy of maxmind GeoLite zip file
     $temporary_file_path = '';
     $zip_download = ZipDownloader::temporary_zip_download(MAXMIND_PATH, 'Maxmind-GeoLite-GeoIPCountry', '');
     echo $zip_download['success_message'] . '<br />';
     // read content of csv file in temporary zip file (if download successful)
     if ($zip_download['successful']) {
         echo 'Total time for download: ' . $zip_download['total_time'] . '<br />';
         echo 'Size of downloaded file: ' . $zip_download['size_download'] . '<br />';
         $zip_handle = new ZipArchive();
         if ($zip_handle->open($temporary_file_path . $zip_download['temp_file_name'])) {
             $csv_file_handle = $zip_handle->getStream(MAXMIND_CSV_FILENAME);
             if (!$csv_file_handle) {
                 exit('Error: could not read CSV file within ZIP file.<br />');
             }
             // put data into an array
             $geolocation_data = array();
             while (($data = fgetcsv($csv_file_handle, 0, ',', '"')) !== false) {
                 if (count($data) !== 6) {
                     exit('Error: CSV file structure faulty.');
                 }
                 $new_entry = array();
                 $new_entry['ip_from'] = floatval($data[2]);
                 $new_entry['ip_to'] = floatval($data[3]);
                 if ($data[4] == 'A1' || $data[4] == 'A2' || $data[4] == 'AP') {
                     // A1 stands for "Anonymous Proxy"
                     // A2 stands for "satellite provider"
                     // AP stands for "Asia/Pacific Region"
                     $new_entry['country'] = NULL;
                 } else {
                     $new_entry['country'] = $data[4];
                 }
                 $new_entry['assigning_rir'] = NULL;
                 $new_entry['assigning_date'] = NULL;
                 $geolocation_data[] = $new_entry;
             }
             fclose($csv_file_handle);
             echo 'Data successfully extracted: ' . count($geolocation_data) . ' lines.<br />';
         } else {
             echo 'Error: Could not open downloaded temporary copy of ZIP file.<br />';
         }
         // delete temporary zip file if specified by parameter
         if (!$keep_temporary_file) {
             unlink($temporary_file_path . $zip_download['temp_file_name']);
         }
     }
     return $geolocation_data;
 }
Exemple #5
0
 /**
  * zip download
  *
  * @param string $zipFilename Zipファイル名
  * @param string $csvFilename ZipされるCsvファイル名
  * @param string|null $password Zipにつけるパスワード
  * @return CakeResponse
  */
 public function zipDownload($zipFilename, $csvFilename, $password = null)
 {
     // csvファイルを$csvFilenameへリネーム
     $this->_rename($csvFilename);
     // zipFile作成
     $zip = new ZipDownloader();
     $zip->addFile($this->path);
     // zipのダウンロードを実行
     if (strlen($password)) {
         $zip->setPassword($password);
     }
     $zip->close();
     return $zip->download($zipFilename);
 }