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
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2013 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
37    var $arrLogList = array();
38
39    /**
40     * Page を初期化する.
41     *
42     * @return void
43     */
44    function init()
45    {
46        parent::init();
47        $this->tpl_mainpage = 'system/log.tpl';
48        $this->tpl_subno    = 'log';
49        $this->tpl_mainno   = 'system';
50        $this->tpl_maintitle = 'システム設定';
51        $this->tpl_subtitle = 'EC-CUBE ログ表示';
52        $this->line_max     = 50;
53    }
54
55    /**
56     * Page のプロセス.
57     *
58     * @return void
59     */
60    function process()
61    {
62        $this->action();
63        $this->sendResponse();
64    }
65
66    /**
67     * Page のアクション.
68     *
69     * @return void
70     */
71    function action()
72    {
73
74        $objFormParam = new SC_FormParam_Ex;
75
76        // パラメーター情報初期化
77        $this->lfInitParam($objFormParam);
78
79        // POST値をセット
80        $objFormParam->setParam($_REQUEST);
81        $this->arrErr = $objFormParam->checkError();
82        $this->arrForm = $objFormParam->getFormParamList();
83
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);
91        }
92
93    }
94
95    /**
96     * デストラクタ.
97     *
98     * @return void
99     */
100    function destroy()
101    {
102        parent::destroy();
103    }
104
105    /**
106     * パラメーターの初期化.
107     *
108     * @return void
109     */
110    function lfInitParam(&$objFormParam)
111    {
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
124        $index = 0;
125        $arrLogs = array();
126        for ($gen = 0 ; $gen <= MAX_LOG_QUANTITY; $gen++) {
127            $path = $log_path_base;
128            if ($gen != 0) {
129                $path .= ".$gen";
130            }
131
132            // ファイルが存在しない場合、前世代のログへ
133            if (!file_exists($path)) continue;
134
135            $arrLogTmp = array_reverse(file($path));
136
137            $arrBodyReverse = array();
138            foreach ($arrLogTmp as $line) {
139                // 上限に達した場合、処理を抜ける
140                if (count($arrLogs) >= $this->line_max) break 2;
141
142                $line = chop($line);
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                    // 内容
150                    $arrBodyReverse[] = $arrMatch[3];
151                    $arrLogLine['body'] = implode("\n", array_reverse($arrBodyReverse));
152                    $arrBodyReverse = array();
153
154                    $arrLogs[] = $arrLogLine;
155                } else {
156                    // 内容
157                    $arrBodyReverse[] = $line;
158                }
159            }
160        }
161        return $arrLogs;
162    }
163
164    /**
165     * ログファイルのパスを取得する
166     *
167     * セキュリティ面をカバーする役割もある。
168     */
169    function getLogPath($log_name)
170    {
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     */
186    function loadLogList()
187    {
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        }
203        if (defined('PLUGIN_LOG_REALFILE') && strlen(PLUGIN_LOG_REALFILE) >= 1) {
204            $this->arrLogList['PLUGIN'] = 'プラグインログファイル';
205        }
206    }
207}
Note: See TracBrowser for help on using the repository browser.