Created
March 17, 2012 16:57
-
-
Save mitaken/2062442 to your computer and use it in GitHub Desktop.
Clone for movie.ezweb.ne.jp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| session_start(); | |
| final class Download | |
| { | |
| /** | |
| * Data Directory (end with /) | |
| * @varr string | |
| */ | |
| const DATA_DIR = '/path/to/data/dir/'; | |
| /** | |
| * Debug IP | |
| * @var string | |
| */ | |
| const DEBUG_IP = '127.0.0.1'; | |
| /** | |
| * Debug EZNO | |
| * @var string | |
| */ | |
| const DEBUG_EZNO = '00000000000000_aa.ezweb.ne.jp'; | |
| /** | |
| * Download Log | |
| * @var string | |
| */ | |
| const DL_LOG = '/path/to/log/file.csv'; | |
| /** | |
| * File Name | |
| * @var string | |
| */ | |
| public $name; | |
| /** | |
| * Authentication Information | |
| * @var array | |
| */ | |
| private $_auth = array(); | |
| /** | |
| * File Information | |
| * @var array | |
| */ | |
| private $_info = array(); | |
| /** | |
| * MIME Types | |
| * @var array | |
| */ | |
| private $_mime = array( | |
| //'ext' => array('mime/type', 'disposition', force EZget flag) | |
| 'bmp' => array('image/bmp', ''), | |
| 'txt' => array('text/plain', 'devte4z'), | |
| 'cld' => array('text/plain', 'devhldy'), | |
| '3gp' => array('audio/3gpp', 'devmgzz'), | |
| 'png' => array('image/png', 'dev8aww', 1), | |
| 'gif' => array('image/gif', 'devgi0z', 1), | |
| 'jpg' => array('image/jpeg', 'devjaww'), | |
| '3g2' => array('audio/3gpp2', 'devmpzz'), | |
| 'qcp' => array('audio/vnd.qcelp', 'dev13anq', 1), | |
| 'sps' => array('application/x-sps', 'SNSP01a'), | |
| 'tar' => array('application/x-tar', 'devsmzw'), | |
| 'kjx' => array('application/x-kjx', 'devkdjx', 1), | |
| 'hjx' => array('application/x-hjx', 'devhihjx', 1), | |
| 'mmf' => array('application/x-smaf', 'devm53z', 1), | |
| 'm3f' => array('application/x-smaf', 'devqmpm', 1), | |
| 'mqf' => array('application/x-smaf', 'devtmpm', 1), | |
| 'amc' => array('application/x-mpeg', 'devdl1q'), | |
| 'pbx' => array('application/x-pobox', 'SNPB01a'), | |
| 'jav' => array('application/x-midp2.0', 'ptjvmzz'), | |
| 'aad' => array('application/x-atokdic', '', 1), | |
| 'cpf' => array('application/x-kddi-kcf', 'devkcf1'), | |
| 'kcf' => array('application/x-kddi-kcf', 'devkcf1'), | |
| 'mcx' => array('application/x-kddi-mcx', 'devdmcx'), | |
| 'auc' => array('application/x-kddi-auc', 'devauc1', 1), | |
| 'di1' => array('application/x-tsb-rupo', 'tsrupo', 1), | |
| 'ys1' => array('application/x-tsb-rupoys', 'tsrupoy', 1), | |
| 'ys2' => array('application/x-tsb-rupoys', 'tsrupoy2'), | |
| 'mtf' => array('application/x-tsb-tsfont', 'tsfont1'), | |
| 'kvf' => array('application/x-kddi-video', 'devlivi'), | |
| 'kmf' => array('application/x-kddi-ezmusic', 'devcufz'), | |
| 'khm' => array('application/x-kddi-htmlmail', 'dev1htm'), | |
| 'kar' => array('application/x-kddi-karrange', 'devkdka'), | |
| 'kpl' => array('application/x-kddi-playlist', 'devdlpl'), | |
| 'swf' => array('application/x-shockwave-flash', 'devfl7z'), | |
| 'sdj' => array('application/x-sharp-dictionary', 'sharpd1'), | |
| 'dsh' => array('application/x-sharp-dictionary2', 'sharpd2'), | |
| 'hvs' => array('application/vnd.yamaha.hv-script', 'devm58z') | |
| ); | |
| /** | |
| * Comment String | |
| * @var array | |
| */ | |
| private $_string = array( | |
| 'auth' => '認証失敗', | |
| 'back' => '戻る', | |
| 'ezno' => 'EZ番号が通知されていません', | |
| 'fail' => 'ダウンロードに失敗しました', | |
| 'file' => 'ファイルが壊れています', | |
| 'true' => 'ダウンロードが完了しました', | |
| 'mime' => '対応機種ではありません', | |
| 'error' => 'エラーが発生しました', | |
| 'found' => 'ファイルが見つかりません', | |
| 'attach' => '添付データの再生をONにして下さい', | |
| 'forbid' => 'このURLにはアクセスできません', | |
| 'reload' => '2画面前に戻ってやり直して下さい' | |
| ); | |
| /** | |
| * Constructor | |
| * | |
| * @param string $name | |
| * @return void | |
| */ | |
| function __construct($name = null) | |
| { | |
| $this->name = self::DATA_DIR . $name; | |
| } | |
| /** | |
| * Set Authentication Request | |
| * | |
| * @param string $user | |
| * @param string $pass | |
| * @return boolean | |
| */ | |
| function setAuth($user, $pass) | |
| { | |
| if (strlen($user) && strlen($pass)) { | |
| $this->_auth['user'] = $user; | |
| $this->_auth['pass'] = $pass; | |
| } else { | |
| return false; | |
| } | |
| return true; | |
| } | |
| /** | |
| * do Download | |
| * | |
| * @return boolean | |
| */ | |
| function doDown() | |
| { | |
| if (strstr($_SERVER['REQUEST_URI'], '&od=3')) { | |
| $this->_successDownload(); | |
| } | |
| if ($this->_checkAccess()) { | |
| if ($this->_info['type']) { | |
| $this->_ezGet(); | |
| } else { | |
| $this->_ezGet2001(); | |
| } | |
| $this->_getDetail(); | |
| if (!isset($_GET['od'])) { | |
| $_SESSION['id'] = md5($_SERVER['HTTP_USER_AGENT'] . $_SERVER['HTTP_X_UP_MULTIMEDIA'] . $_SERVER['HTTP_X_UP_SUBNO']); | |
| } | |
| $title = htmlspecialchars($this->_info['title']); | |
| list($path) = explode('?', htmlspecialchars($this->_info['path'])); | |
| if ($this->_info['type']) { | |
| $param = array( | |
| 'url' => $path, | |
| 'name' => md5_file($this->name) . '.' . $this->_info['ext'], | |
| 'size' => $this->_info['size'] + 2, | |
| 'disposition' => $this->_info['disp'], | |
| 'title' => mb_convert_encoding($title, 'SJIS-win', 'UTF-8'), | |
| 'checkout' => 1 | |
| ); | |
| $addr = 'device:data/dnld?' . http_build_query($param, '', '&'); | |
| $com = '<wml:anchor><wml:spawn href="' . $addr . '" />' . $title . '<catch /></wml:anchor>'; | |
| } else { | |
| $param = array( | |
| 'ac' => md5_file($this->name), | |
| 'size' => $this->_info['size'], | |
| 'title' => $title, | |
| 'disposition' => $this->_info['disp'], | |
| 'checkout' => 1, | |
| 'pcsharing' => 1 | |
| ); | |
| $com = '<object data="' . $path . '" type="' . $this->_info['mime'] . '" copyright="no" standby="' . $title . '">'; | |
| foreach ($param as $key => $value) { | |
| $com .= '<param name="' . $key . '" value="' . $value . '" valuetype="data" />'; | |
| } | |
| $com .= '</object>'; | |
| } | |
| $this->_dispOut($com, 'Download'); | |
| } else if ($this->_checkAuth()) { | |
| $title = mb_convert_encoding($this->_info['title'], 'SJIS-win', 'UTF-8'); | |
| header('Content-Type: ' . $this->_info['mime'] . '; charset=Shift_JIS'); | |
| header('Content-Length: ' . $this->_info['size']); | |
| header('Content-Disposition: attachment; filename="' . $title . '.' . $this->_info['ext'] . '"'); | |
| die(readfile($this->name)); | |
| } else { | |
| header('HTTP/1.1 403 Forbidden'); | |
| header('Content-Type: text/plain; charset=UTF-8'); | |
| die($this->_string['forbid']); | |
| } | |
| return true; | |
| } | |
| /** | |
| * Download Successful | |
| * | |
| * @return string | |
| */ | |
| function _successDownload() | |
| { | |
| if (self::DEBUG_EZNO !== $_SERVER['HTTP_X_UP_SUBNO']) { | |
| $fp = self::DL_LOG ? $fp = @fopen(self::DL_LOG, 'a') : false; | |
| if ($fp && flock($fp, LOCK_EX)) { | |
| $log = array( | |
| time(), | |
| str_replace(self::DATA_DIR, '', $this->name), | |
| $_SERVER['HTTP_USER_AGENT'], | |
| substr($_SERVER['HTTP_X_UP_SUBNO'], 0, 17) | |
| ); | |
| fwrite($fp, implode(',', $log) . "\n"); | |
| fclose($fp); | |
| } | |
| } | |
| $_SESSION = array(); | |
| $this->_dispOut($this->_string['true'], 'Succeed'); | |
| } | |
| /** | |
| * EZGet Download | |
| * | |
| * @return string | |
| */ | |
| private function _ezGet() | |
| { | |
| if (isset($_GET['count'], $_GET['offset'])) { | |
| $start = (int)$_GET['offset']; | |
| $length = (int)$_GET['count']; | |
| if (!strstr($_SERVER['HTTP_ACCEPT'], $this->_info['mime']) && strstr($_SERVER['HTTP_ACCEPT'], 'application/x-up-download') && $this->_isValid('?name=')) { | |
| $fp = fopen($this->name, 'rb'); | |
| $size = $this->_info['size'] + 2; | |
| if ($start >= 0 && $length > 0 && $start + $length <= $size) { | |
| if ($start + $length !== $size && $length !== 8192) { | |
| $this->_dispOut($this->_string['forbid']); | |
| } | |
| fseek($fp, $start); | |
| $data = fread($fp, $length); | |
| fclose($fp); | |
| if ($start + $length - $size === 0) { | |
| $crcTable = array( | |
| 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7, | |
| 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF, | |
| 0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6, | |
| 0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE, | |
| 0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485, | |
| 0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D, | |
| 0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4, | |
| 0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC, | |
| 0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823, | |
| 0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B, | |
| 0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12, | |
| 0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A, | |
| 0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41, | |
| 0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49, | |
| 0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70, | |
| 0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78, | |
| 0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F, | |
| 0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067, | |
| 0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E, | |
| 0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256, | |
| 0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D, | |
| 0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, | |
| 0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C, | |
| 0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634, | |
| 0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB, | |
| 0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3, | |
| 0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A, | |
| 0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92, | |
| 0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9, | |
| 0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1, | |
| 0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8, | |
| 0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0 | |
| ); | |
| $file = file_get_contents($this->name); | |
| $crc = 0xFFFF; | |
| for ($i = 0;$i < $this->_info['size'];++$i) { | |
| $crc = $crcTable[(($crc & 0xFF00) >> 8) ^ ord($file[$i])] ^ (($crc << 8) & 0xFFFF); | |
| } | |
| unset($file); | |
| if ($crc &= 0xFFFF) { | |
| $data .= chr(($crc & 0xFF00) >> 8) . chr($crc & 0x00FF); | |
| $_SESSION['end'] = true; | |
| } else { | |
| $this->_dispOut($this->_string['file']); | |
| } | |
| } | |
| header('Content-Type: application/x-up-download'); | |
| header('Content-Length: ' . $length); | |
| die($data); | |
| } else { | |
| $this->_dispOut($this->_string['forbid']); | |
| } | |
| } else if (isset($_SESSION['end']) && $start === -1 && $length === -1) { | |
| $this->_successDownload(); | |
| } else { | |
| $this->_dispOut($this->_string['error']); | |
| } | |
| } | |
| } | |
| /** | |
| * EZGet 2001 | |
| * | |
| * @return string | |
| */ | |
| private function _ezGet2001() | |
| { | |
| if (isset($_SERVER['HTTP_RANGE']) && $this->_isValid('&od=2')) { | |
| list($start, $end) = explode('-', substr($_SERVER['HTTP_RANGE'], 6)); | |
| if (ctype_digit($start) && ctype_digit($end) && $start < $end) { | |
| $start = (int)$start; | |
| $end = (int)$end; | |
| } else { | |
| $this->_dispOut($this->_string['forbid']); | |
| } | |
| $count = ($end > $this->_info['size'] - 1) ? $this->_info['size'] - 1 : $end; | |
| if ($count !== $end && $end - $start !== 129535) { | |
| $this->_dispOut($this->_string['forbid']); | |
| } | |
| $length = $count - $start + 1; | |
| header('HTTP/1.1 206 Partial Content'); | |
| header('Content-Type: ' . $this->_info['mime']); | |
| header('Content-Length: ' . $length); | |
| header('Content-Range: bytes ' . $start . '-' . $count . '/' . $this->_info['size']); | |
| $fp = fopen($this->name, 'rb'); | |
| fseek($fp, $start); | |
| $data = fread($fp, $length); | |
| fclose($fp); | |
| die($data); | |
| } | |
| } | |
| /** | |
| * Check Validate File | |
| * | |
| * @param string $key | |
| * @return boolean | |
| */ | |
| private function _isValid($key) | |
| { | |
| if (strstr($_SERVER['REQUEST_URI'], $key) && preg_match('/(ac|name)=([a-z0-9]{32})/', $_SERVER['REQUEST_URI'], $this->_info['match'])) { | |
| if (isset($_SESSION['id']) && strlen($this->_info['match'][2]) === 32) { | |
| if (md5($_SERVER['HTTP_USER_AGENT'] . $_SERVER['HTTP_X_UP_MULTIMEDIA'] . $_SERVER['HTTP_X_UP_SUBNO']) === $_SESSION['id']) { | |
| if (md5_file($this->name) === $this->_info['match'][2]) { | |
| return true; | |
| } else { | |
| $this->_dispOut($this->_string['file']); | |
| } | |
| } else { | |
| $this->_dispOut($this->_string['forbid']); | |
| } | |
| } else { | |
| $this->_dispOut($this->_string['reload']); | |
| } | |
| } | |
| return false; | |
| } | |
| /** | |
| * Check Access | |
| * | |
| * @return boolean | |
| */ | |
| private function _checkAccess() | |
| { | |
| if ($_SERVER['REMOTE_ADDR'] === self::DEBUG_IP) { | |
| $this->_getInformation(); | |
| return true; | |
| } | |
| //$host = '/^w[ab](cc)?\d{1,2}(s|proxy)\d{1,2}\.ezweb\.ne\.jp$/'; | |
| $host = '/^w[ab]\d{2,3}proxy\d{2}.ezweb\.ne\.jp$/'; | |
| if (preg_match($host, @gethostbyaddr($_SERVER['REMOTE_ADDR'])) && strpos($_SERVER['HTTP_USER_AGENT'], 'KDDI-') === 0) { | |
| if (!preg_match('/^0[578]0[0-7][0-9]{10}_[a-z]{2}\.ezweb\.ne\.jp$/', $_SERVER['HTTP_X_UP_SUBNO'])) { | |
| $this->_dispOut($this->_string['ezno']); | |
| } | |
| if (isset($_SERVER['HTTP_X_UP_DEVCAP_NONATTACHMENT'])) { | |
| $this->_dispOut($this->_string['attach']); | |
| } | |
| $this->_getInformation(); | |
| if (!($this->_info['type'] && isset($_GET['name'], $_GET['count'], $_GET['offset'])) && | |
| !(strpos($_SERVER['HTTP_USER_AGENT'], 'KDDI-SA32') === 0 && $this->_info['ext'] === 'kmf') && | |
| !(strpos($_SERVER['HTTP_USER_AGENT'], 'KDDI-TS') === 0 && strstr($this->_info['mime'], '/x-tsb-'))) { | |
| if (!strstr($_SERVER['HTTP_ACCEPT'], $this->_info['mime'])) { | |
| $this->_dispOut($this->_string['mime']); | |
| } | |
| } | |
| return true; | |
| } | |
| return false; | |
| } | |
| /** | |
| * Check Authorization | |
| * | |
| * @return boolean | |
| */ | |
| private function _checkAuth() | |
| { | |
| if (isset($this->_auth['user']) && isset($this->_auth['pass']) && | |
| $_SERVER['PHP_AUTH_USER'] === $this->_auth['user'] && $_SERVER['PHP_AUTH_PW'] === $this->_auth['pass']) { | |
| $this->_getInformation(); | |
| $this->_getDetail(); | |
| return true; | |
| } else if (isset($this->_auth['user']) && isset($this->_auth['pass'])) { | |
| header('WWW-Authenticate: Basic realm="Authorization Area"'); | |
| header('HTTP/1.1 401 Unauthorized'); | |
| die($this->_string['auth']); | |
| } | |
| return false; | |
| } | |
| /** | |
| * Get File Information | |
| * | |
| * @return boolean true | |
| */ | |
| private function _getInformation() | |
| { | |
| if (!is_file($this->name)) { | |
| $this->_dispOut($this->_string['found']); | |
| } | |
| $ext = strtolower(substr(strrchr($this->name, '.'), 1)); | |
| if (isset($this->_mime[$ext])) { | |
| $this->_info['ext'] = $ext; | |
| $this->_info['mime'] = $this->_mime[$this->_info['ext']][0]; | |
| $this->_info['disp'] = $this->_mime[$this->_info['ext']][1]; | |
| $this->_info['type'] = $this->_mime[$this->_info['ext']][2]; | |
| $this->_info['path'] = $_SERVER['REQUEST_URI']; | |
| $this->_info['size'] = filesize($this->name); | |
| } else { | |
| $this->_dispOut($this->_string['error']); | |
| } | |
| return true; | |
| } | |
| /** | |
| * Get File Detail | |
| * | |
| * @return boolean True | |
| */ | |
| private function _getDetail() | |
| { | |
| $file = file_get_contents($this->name); | |
| $agent = substr($_SERVER['HTTP_USER_AGENT'], 5, 4); | |
| switch ($this->_info['ext']) { | |
| case 'bmp': | |
| case 'jpg': | |
| case 'gif'; | |
| case 'png': | |
| if ($_SERVER['HTTP_X_UP_DEVCAP_MULTIMEDIA'][5] >= 5 || $agent === 'TS39' || $agent === 'TS3A') { | |
| list($width, $height) = getimagesize($this->name); | |
| if (false&&$width === 240 && $height === 320) { | |
| $this->_info['disp'] = 'devavat'; | |
| } | |
| } | |
| if (preg_match("/kddi_copyright=(on|off),([^\\xFF]+)/", $file, $this->_info['match'])) { | |
| $this->_info['title'] = $this->_info['match'][2]; | |
| } | |
| break; | |
| case 'mmf': | |
| if (($pos = strpos($file, "ST\x00")) !== false) { | |
| $len = hexdec(bin2hex(substr($file, $pos - 4, 4))); | |
| $this->_info['title'] = substr($file, $pos + 4, $len - 4); | |
| } | |
| break; | |
| case '3gp': | |
| case '3g2': | |
| case 'amc': | |
| if ($agent === 'SA32') { | |
| $this->_info['path'] = 'http://movie.ezweb.ne.jp@' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; | |
| } | |
| if (strstr($file, 'vide')) { | |
| $this->_info['mime'] = str_replace('audio', 'video', $this->_info['mime']); | |
| } | |
| if (preg_match("/titl\\x00\\x00\\x00\\x00\\x2A\\x0E([^\\x00]+)/", $file, $this->_info['match'])) { | |
| $this->_info['title'] = $this->_info['match'][1]; | |
| } else if (preg_match("/titl([^\\x00]+)/", $file, $this->_info['match'])) { | |
| $this->_info['title'] = $this->_info['match'][1]; | |
| } | |
| break; | |
| case 'kmf': | |
| if (!preg_match('/^(HI33|HI34|HI35|CA31|CA32|SA32|SA34|KC33)$/', $agent) || strstr($_SERVER['HTTP_USER_AGENT'], '.a.')) { | |
| $this->_dispOut($this->_string['mime']); | |
| } | |
| switch ($agent) { | |
| case 'SA32': | |
| $this->_info['mime'] = 'application/x-tar'; | |
| $this->_info['disp'] = 'devsmzw'; | |
| break; | |
| case 'SA34': | |
| $this->_info['path'] = 'http://movie.ezweb.ne.jp@' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; | |
| break; | |
| default: | |
| $this->_info['mime'] = 'audio/3gpp2'; | |
| $this->_info['disp'] = 'devmpzz'; | |
| } | |
| if (strstr($file, 'KDDIMV')) { | |
| $this->_info['disp'] = 'devlimv'; | |
| } | |
| if (preg_match("/title,([^\r\n]+)/", $file, $this->_info['match'])) { | |
| $this->_info['title'] = $this->_info['match'][1]; | |
| } | |
| break; | |
| case 'tar': | |
| if ($this->_info['size'] > 1536000) { | |
| $this->_info['disp'] = 'devdpzw'; | |
| } | |
| if (strstr($file, 'KDDIAVAT')) { | |
| $this->_info['disp'] = 'devavat'; | |
| } | |
| if (strstr($file, 'KDDIMAP')) { | |
| $this->_info['disp'] = 'devmpdx'; | |
| } | |
| if (strstr($file, 'KDDIDMAIL')) { | |
| $this->_info['disp'] = 'devdmpk'; | |
| } | |
| if (preg_match('/"title" content="([^"]+)"/', $file, $this->_info['match'])) { | |
| $this->_info['title'] = $this->_info['match'][1]; | |
| } | |
| break; | |
| case 'cpf': | |
| case 'kcf': | |
| if (preg_match('/<title>([^<]+)</', $file, $this->_info['match'])) { | |
| $this->_info['title'] = $this->_info['match'][1]; | |
| } | |
| break; | |
| case 'hjx': | |
| case 'kjx': | |
| case 'jav': | |
| if (preg_match("/MIDlet-Name:\\s+([^\n]+)/", $file, $this->_info['match'])) { | |
| $this->_info['title'] = $this->_info['match'][1]; | |
| } | |
| if ($this->_info['ext'] === 'kjx') { | |
| if (($pos = strpos($file, 'KDDIP-')) !== false) { | |
| switch (substr($file, $pos + 6, 3)) { | |
| case '1.0': | |
| $this->_info['disp'] = 'devkdjx'; | |
| break; | |
| case '2.0': | |
| case '2.5': | |
| $this->_info['disp'] = 'devkdj2'; | |
| break; | |
| case '3.0': | |
| $this->_info['disp'] = 'devkdj3'; | |
| break; | |
| } | |
| } | |
| } | |
| if ($this->_info['ext'] === 'jav') { | |
| if (!strstr($file, 'Pantech Wireless Japan Inc.')) { | |
| $this->_dispOut($this->_string['mime']); | |
| } | |
| } | |
| break; | |
| case 'aad': | |
| if ($_SERVER['HTTP_X_UP_DEVCAP_MULTIMEDIA'][5] >= 5) { | |
| $this->_info['disp'] = 'devdica'; | |
| } else { | |
| switch (substr($_SERVER['HTTP_USER_AGENT'], 5, 2)) { | |
| case 'CA': | |
| $this->_info['disp'] = 'caaada0'; | |
| break; | |
| case 'HI': | |
| $this->_info['disp'] = 'hiaada0'; | |
| break; | |
| case 'MA': | |
| $this->_info['disp'] = 'maaada0'; | |
| break; | |
| } | |
| } | |
| if (preg_match("/^.{12}([^\\x00]*)/", $file, $this->_info['match'])) { | |
| if (!strstr($this->_info['match'][1], "\0")) { | |
| $this->_info['title'] = $this->_info['match'][1]; | |
| } | |
| } | |
| break; | |
| case 'pbx': | |
| if (preg_match("/DicTitle:([^\r\n]+)/", $file, $this->_info['match'])) { | |
| $this->_info['title'] = $this->_info['match'][1]; | |
| } | |
| break; | |
| case 'sdj': | |
| case 'dsh': | |
| if (preg_match("/Title: ([^\r\n]+)/", $file, $this->_info['match'])) { | |
| $this->_info['title'] = $this->_info['match'][1]; | |
| } | |
| break; | |
| case 'kpl': | |
| if (preg_match("/PLTT([^\r\n]+)/", $file, $this->_info['match'])) { | |
| $this->_info['title'] = $this->_info['match'][1]; | |
| } | |
| break; | |
| case 'mtf': | |
| if (preg_match("/([^\\x00]+)/", substr($file, 20), $this->_info['match'])) { | |
| $this->_info['title'] = $this->_info['match'][1]; | |
| } | |
| break; | |
| } | |
| if (!isset($this->_info['title']) || strlen($this->_info['title']) === 0) { | |
| $this->_info['title'] = basename(basename($this->name), strrchr(basename($this->name), '.')); | |
| } | |
| $pat = array('\\', '/', ':', '*', '?', '"', '<', '>', '|'); | |
| $rep = array('¥', '/', ':', '*', '?', '”', '<', '>', '|'); | |
| $this->_info['title'] = str_replace($pat, $rep, mb_convert_encoding(trim($this->_info['title']), 'UTF-8', 'UTF-8, SJIS-win')); | |
| return true; | |
| } | |
| /** | |
| * Show Html Page | |
| * | |
| * @param string $body | |
| * @param string $title | |
| */ | |
| private function _dispOut($body, $title = 'ERROR') | |
| { | |
| header('Content-Type: text/html; charset=UTF-8'); | |
| header('Content-Style-Type: text/css'); | |
| header('Cache-Control: no-cache'); | |
| die('<?xml version="1.0" encoding="UTF-8"?>' | |
| . '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">' | |
| . '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja">' | |
| . '<head>' | |
| . '<meta name="vnd.up.markable" content="false" />' | |
| . '<title>' . $title . '</title>' | |
| . '<style type="text/css">' | |
| . 'body{background-color:#ff6633;}' | |
| . 'p{text-align:center;}' | |
| . '</style>' | |
| . '</head>' | |
| . '<body>' | |
| . '<p>' | |
| . $body | |
| . '<br /><br />' | |
| . '<wml:do type="button" label="' . $this->_string['back'] . '"><prev /></wml:do>' | |
| . '</p>' | |
| . '</body>' | |
| . '</html>'); | |
| } | |
| } | |
| if (isset($_SERVER['PATH_INFO']) && strlen($_SERVER['PATH_INFO']) > 5) { | |
| list(, $path) = explode('/', $_SERVER['PATH_INFO'], 2); | |
| $path = str_replace(array('../', './'), '', $path); | |
| $dl = new Download($path); | |
| /** | |
| * Authorization if you want | |
| */ | |
| //$dl->setAuth('username', 'password'); | |
| $dl->doDown(); | |
| } else { | |
| header('HTTP/1.1 403 Forbidden'); | |
| header('Content-Type: text/plain'); | |
| die('Access Forbidden'); | |
| } | |
| // Access to http://example.com/stdchrg.php/download_file.3g2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment