source: branches/version-2_12-dev/data/class/pages/admin/system/LC_Page_Admin_System_Log.php @ 21693

Revision 21693, 6.1 KB checked in by h_yoshimoto, 12 years ago (diff)

#1692 フックポイント名を変更

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