[18179] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | * This file is part of EC-CUBE |
---|
| 4 | * |
---|
[22206] | 5 | * Copyright(c) 2000-2013 LOCKON CO.,LTD. All Rights Reserved. |
---|
[18179] | 6 | * |
---|
| 7 | * http://www.lockon.co.jp/ |
---|
| 8 | * |
---|
| 9 | * This program is free software; you can redistribute it and/or |
---|
| 10 | * modify it under the terms of the GNU General Public License |
---|
| 11 | * as published by the Free Software Foundation; either version 2 |
---|
| 12 | * of the License, or (at your option) any later version. |
---|
| 13 | * |
---|
| 14 | * This program is distributed in the hope that it will be useful, |
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | * GNU General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with this program; if not, write to the Free Software |
---|
| 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
| 22 | */ |
---|
| 23 | |
---|
[20534] | 24 | require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php'; |
---|
[18179] | 25 | |
---|
| 26 | /** |
---|
| 27 | * ログ のページクラス. |
---|
| 28 | * |
---|
| 29 | * @package Page |
---|
| 30 | * @author Seasoft 塚田将久 |
---|
[20116] | 31 | * @version $Id$ |
---|
[18179] | 32 | */ |
---|
[22856] | 33 | class LC_Page_Admin_System_Log extends LC_Page_Admin_Ex |
---|
[22567] | 34 | { |
---|
[21647] | 35 | var $arrLogList = array(); |
---|
[18179] | 36 | |
---|
| 37 | /** |
---|
| 38 | * Page を初期化する. |
---|
| 39 | * |
---|
| 40 | * @return void |
---|
| 41 | */ |
---|
[22567] | 42 | function init() |
---|
| 43 | { |
---|
[18179] | 44 | parent::init(); |
---|
| 45 | $this->tpl_mainpage = 'system/log.tpl'; |
---|
| 46 | $this->tpl_subno = 'log'; |
---|
| 47 | $this->tpl_mainno = 'system'; |
---|
[20911] | 48 | $this->tpl_maintitle = 'システム設定'; |
---|
[19715] | 49 | $this->tpl_subtitle = 'EC-CUBE ログ表示'; |
---|
[18179] | 50 | $this->line_max = 50; |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | /** |
---|
| 54 | * Page のプロセス. |
---|
| 55 | * |
---|
| 56 | * @return void |
---|
| 57 | */ |
---|
[22567] | 58 | function process() |
---|
| 59 | { |
---|
[19661] | 60 | $this->action(); |
---|
| 61 | $this->sendResponse(); |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | /** |
---|
| 65 | * Page のアクション. |
---|
| 66 | * |
---|
| 67 | * @return void |
---|
| 68 | */ |
---|
[22567] | 69 | function action() |
---|
| 70 | { |
---|
[21986] | 71 | $objFormParam = new SC_FormParam_Ex; |
---|
[20267] | 72 | |
---|
[20970] | 73 | // パラメーター情報初期化 |
---|
[20271] | 74 | $this->lfInitParam($objFormParam); |
---|
| 75 | |
---|
| 76 | // POST値をセット |
---|
[21647] | 77 | $objFormParam->setParam($_REQUEST); |
---|
| 78 | $this->arrErr = $objFormParam->checkError(); |
---|
| 79 | $this->arrForm = $objFormParam->getFormParamList(); |
---|
[20271] | 80 | |
---|
[21647] | 81 | $this->loadLogList(); |
---|
| 82 | |
---|
| 83 | if (empty($this->arrErr)) { |
---|
| 84 | $this->line_max = $objFormParam->getValue('line_max'); |
---|
| 85 | |
---|
| 86 | $log_path = $this->getLogPath($objFormParam->getValue('log')); |
---|
| 87 | $this->tpl_ec_log = $this->getEccubeLog($log_path); |
---|
[18179] | 88 | } |
---|
[20267] | 89 | |
---|
[18179] | 90 | } |
---|
| 91 | |
---|
| 92 | /** |
---|
[20970] | 93 | * パラメーターの初期化. |
---|
[18179] | 94 | * |
---|
[20271] | 95 | * @return void |
---|
[18179] | 96 | */ |
---|
[22567] | 97 | function lfInitParam(&$objFormParam) |
---|
| 98 | { |
---|
[21647] | 99 | $objFormParam->addParam('ファイル', 'log', null, '', array()); |
---|
| 100 | $objFormParam->addParam('行数', 'line_max', INT_LEN, '', array('NUM_CHECK', 'MAX_LENGTH_CHECK'), 50); |
---|
[18179] | 101 | } |
---|
| 102 | |
---|
| 103 | /** |
---|
[20267] | 104 | * EC-CUBE ログを取得する. |
---|
[18179] | 105 | * |
---|
[20267] | 106 | * @return array $arrLogs 取得したログ |
---|
[18179] | 107 | */ |
---|
[22567] | 108 | function getEccubeLog($log_path_base) |
---|
| 109 | { |
---|
[18179] | 110 | $index = 0; |
---|
| 111 | $arrLogs = array(); |
---|
| 112 | for ($gen = 0 ; $gen <= MAX_LOG_QUANTITY; $gen++) { |
---|
[21647] | 113 | $path = $log_path_base; |
---|
[18179] | 114 | if ($gen != 0) { |
---|
| 115 | $path .= ".$gen"; |
---|
| 116 | } |
---|
[20267] | 117 | |
---|
[18179] | 118 | // ファイルが存在しない場合、前世代のログへ |
---|
| 119 | if (!file_exists($path)) continue; |
---|
[20267] | 120 | |
---|
[18179] | 121 | $arrLogTmp = array_reverse(file($path)); |
---|
[20267] | 122 | |
---|
[18281] | 123 | $arrBodyReverse = array(); |
---|
[18179] | 124 | foreach ($arrLogTmp as $line) { |
---|
[21647] | 125 | // 上限に達した場合、処理を抜ける |
---|
| 126 | if (count($arrLogs) >= $this->line_max) break 2; |
---|
| 127 | |
---|
[18281] | 128 | $line = chop($line); |
---|
[18179] | 129 | if (preg_match('/^(\d+\/\d+\/\d+ \d+:\d+:\d+) \[([^\]]+)\] (.*)$/', $line, $arrMatch)) { |
---|
| 130 | $arrLogLine = array(); |
---|
| 131 | // 日時 |
---|
| 132 | $arrLogLine['date'] = $arrMatch[1]; |
---|
| 133 | // パス |
---|
| 134 | $arrLogLine['path'] = $arrMatch[2]; |
---|
| 135 | // 内容 |
---|
[18281] | 136 | $arrBodyReverse[] = $arrMatch[3]; |
---|
| 137 | $arrLogLine['body'] = implode("\n", array_reverse($arrBodyReverse)); |
---|
| 138 | $arrBodyReverse = array(); |
---|
[20267] | 139 | |
---|
[18179] | 140 | $arrLogs[] = $arrLogLine; |
---|
| 141 | } else { |
---|
| 142 | // 内容 |
---|
[18281] | 143 | $arrBodyReverse[] = $line; |
---|
[18179] | 144 | } |
---|
| 145 | } |
---|
| 146 | } |
---|
[22856] | 147 | |
---|
[18179] | 148 | return $arrLogs; |
---|
| 149 | } |
---|
[21647] | 150 | |
---|
| 151 | /** |
---|
| 152 | * ログファイルのパスを取得する |
---|
| 153 | * |
---|
| 154 | * セキュリティ面をカバーする役割もある。 |
---|
| 155 | */ |
---|
[22567] | 156 | function getLogPath($log_name) |
---|
| 157 | { |
---|
[21647] | 158 | if (strlen($log_name) === 0) { |
---|
| 159 | return LOG_REALFILE; |
---|
| 160 | } |
---|
| 161 | if (defined($const_name = $log_name . '_LOG_REALFILE')) { |
---|
| 162 | return constant($const_name); |
---|
| 163 | } |
---|
| 164 | trigger_error('不正なログが指定されました。', E_USER_ERROR); |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | /** |
---|
| 168 | * ログファイルの一覧を読み込む |
---|
| 169 | * |
---|
| 170 | * TODO mtb_constants から動的生成したい。 |
---|
| 171 | * @return void |
---|
| 172 | */ |
---|
[22567] | 173 | function loadLogList() |
---|
| 174 | { |
---|
[21647] | 175 | $this->arrLogList[''] = '標準ログファイル'; |
---|
| 176 | $this->arrLogList['CUSTOMER'] = '会員ログイン ログファイル'; |
---|
| 177 | $this->arrLogList['ADMIN'] = '管理機能ログファイル'; |
---|
| 178 | |
---|
| 179 | if (defined('DEBUG_LOG_REALFILE') && strlen(DEBUG_LOG_REALFILE) >= 1) { |
---|
| 180 | $this->arrLogList['DEBUG'] = 'デバッグログファイル'; |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | if (defined('ERROR_LOG_REALFILE') && strlen(ERROR_LOG_REALFILE) >= 1) { |
---|
| 184 | $this->arrLogList['ERROR'] = 'エラーログファイル'; |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | if (defined('DB_LOG_REALFILE') && strlen(DB_LOG_REALFILE) >= 1) { |
---|
| 188 | $this->arrLogList['DB'] = 'DBログファイル'; |
---|
| 189 | } |
---|
[22978] | 190 | if (defined('PLUGIN_LOG_REALFILE') && strlen(PLUGIN_LOG_REALFILE) >= 1) { |
---|
| 191 | $this->arrLogList['PLUGIN'] = 'プラグインログファイル'; |
---|
| 192 | } |
---|
[21647] | 193 | } |
---|
[18179] | 194 | } |
---|