source: branches/camp/camp-2_13-plugin/data/class/pages/admin/system/LC_Page_Admin_System_Log.php @ 22692

Revision 22692, 5.8 KB checked in by adachi, 11 years ago (diff)

#2181 ログファイルを追加

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
RevLine 
[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
24// {{{ requires
[20534]25require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php';
[18179]26
27/**
28 * ログ のページクラス.
29 *
30 * @package Page
31 * @author Seasoft 塚田将久
[20116]32 * @version $Id$
[18179]33 */
[22567]34class LC_Page_Admin_System_Log extends LC_Page_Admin_Ex
35{
[18179]36
[21647]37    var $arrLogList = array();
[18179]38
39    /**
40     * Page を初期化する.
41     *
42     * @return void
43     */
[22567]44    function init()
45    {
[18179]46        parent::init();
47        $this->tpl_mainpage = 'system/log.tpl';
48        $this->tpl_subno    = 'log';
49        $this->tpl_mainno   = 'system';
[20911]50        $this->tpl_maintitle = 'システム設定';
[19715]51        $this->tpl_subtitle = 'EC-CUBE ログ表示';
[18179]52        $this->line_max     = 50;
53    }
54
55    /**
56     * Page のプロセス.
57     *
58     * @return void
59     */
[22567]60    function process()
61    {
[19661]62        $this->action();
63        $this->sendResponse();
64    }
65
66    /**
67     * Page のアクション.
68     *
69     * @return void
70     */
[22567]71    function action()
72    {
[21591]73
[21986]74        $objFormParam = new SC_FormParam_Ex;
[20267]75
[20970]76        // パラメーター情報初期化
[20271]77        $this->lfInitParam($objFormParam);
78
79        // POST値をセット
[21647]80        $objFormParam->setParam($_REQUEST);
81        $this->arrErr = $objFormParam->checkError();
82        $this->arrForm = $objFormParam->getFormParamList();
[20271]83
[21647]84        $this->loadLogList();
85
86        if (empty($this->arrErr)) {
87            $this->line_max = $objFormParam->getValue('line_max');
88
89            $log_path = $this->getLogPath($objFormParam->getValue('log'));
90            $this->tpl_ec_log = $this->getEccubeLog($log_path);
[18179]91        }
[20267]92
[18179]93    }
94
95    /**
96     * デストラクタ.
97     *
98     * @return void
99     */
[22567]100    function destroy()
101    {
[18179]102        parent::destroy();
103    }
[20267]104
[18179]105    /**
[20970]106     * パラメーターの初期化.
[18179]107     *
[20271]108     * @return void
[18179]109     */
[22567]110    function lfInitParam(&$objFormParam)
111    {
[21647]112        $objFormParam->addParam('ファイル', 'log', null, '', array());
113        $objFormParam->addParam('行数', 'line_max', INT_LEN, '', array('NUM_CHECK', 'MAX_LENGTH_CHECK'), 50);
[18179]114    }
115
116    /**
[20267]117     * EC-CUBE ログを取得する.
[18179]118     *
[20267]119     * @return array $arrLogs 取得したログ
[18179]120     */
[22567]121    function getEccubeLog($log_path_base)
122    {
[20267]123
[18179]124        $index = 0;
125        $arrLogs = array();
126        for ($gen = 0 ; $gen <= MAX_LOG_QUANTITY; $gen++) {
[21647]127            $path = $log_path_base;
[18179]128            if ($gen != 0) {
129                $path .= ".$gen";
130            }
[20267]131
[18179]132            // ファイルが存在しない場合、前世代のログへ
133            if (!file_exists($path)) continue;
[20267]134
[18179]135            $arrLogTmp = array_reverse(file($path));
[20267]136
[18281]137            $arrBodyReverse = array();
[18179]138            foreach ($arrLogTmp as $line) {
[21647]139                // 上限に達した場合、処理を抜ける
140                if (count($arrLogs) >= $this->line_max) break 2;
141
[18281]142                $line = chop($line);
[18179]143                if (preg_match('/^(\d+\/\d+\/\d+ \d+:\d+:\d+) \[([^\]]+)\] (.*)$/', $line, $arrMatch)) {
144                    $arrLogLine = array();
145                    // 日時
146                    $arrLogLine['date'] = $arrMatch[1];
147                    // パス
148                    $arrLogLine['path'] = $arrMatch[2];
149                    // 内容
[18281]150                    $arrBodyReverse[] = $arrMatch[3];
151                    $arrLogLine['body'] = implode("\n", array_reverse($arrBodyReverse));
152                    $arrBodyReverse = array();
[20267]153
[18179]154                    $arrLogs[] = $arrLogLine;
155                } else {
156                    // 内容
[18281]157                    $arrBodyReverse[] = $line;
[18179]158                }
159            }
160        }
161        return $arrLogs;
162    }
[21647]163
164    /**
165     * ログファイルのパスを取得する
166     *
167     * セキュリティ面をカバーする役割もある。
168     */
[22567]169    function getLogPath($log_name)
170    {
[21647]171        if (strlen($log_name) === 0) {
172            return LOG_REALFILE;
173        }
174        if (defined($const_name = $log_name . '_LOG_REALFILE')) {
175            return constant($const_name);
176        }
177        trigger_error('不正なログが指定されました。', E_USER_ERROR);
178    }
179
180    /**
181     * ログファイルの一覧を読み込む
182     *
183     * TODO mtb_constants から動的生成したい。
184     * @return void
185     */
[22567]186    function loadLogList()
187    {
[21647]188        $this->arrLogList[''] = '標準ログファイル';
189        $this->arrLogList['CUSTOMER'] = '会員ログイン ログファイル';
190        $this->arrLogList['ADMIN'] = '管理機能ログファイル';
191
192        if (defined('DEBUG_LOG_REALFILE') && strlen(DEBUG_LOG_REALFILE) >= 1) {
193            $this->arrLogList['DEBUG'] = 'デバッグログファイル';
194        }
195
196        if (defined('ERROR_LOG_REALFILE') && strlen(ERROR_LOG_REALFILE) >= 1) {
197            $this->arrLogList['ERROR'] = 'エラーログファイル';
198        }
199
200        if (defined('DB_LOG_REALFILE') && strlen(DB_LOG_REALFILE) >= 1) {
201            $this->arrLogList['DB'] = 'DBログファイル';
202        }
[22690]203        if (defined('PLUGIN_LOG_REALFILE') && strlen(PLUGIN_LOG_REALFILE) >= 1) {
[22692]204            $this->arrLogList['PLUGIN'] = 'プラグインログファイル';
[22690]205        }
[21647]206    }
[18179]207}
Note: See TracBrowser for help on using the repository browser.