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

Revision 22856, 5.7 KB checked in by Seasoft, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.13.0)

  • 主に空白・空白行の調整。もう少し整えたいが、一旦現状コミット。
  • 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
24require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php';
25
26/**
27 * ログ のページクラス.
28 *
29 * @package Page
30 * @author Seasoft 塚田将久
31 * @version $Id$
32 */
33class LC_Page_Admin_System_Log extends LC_Page_Admin_Ex
34{
35    var $arrLogList = array();
36
37    /**
38     * Page を初期化する.
39     *
40     * @return void
41     */
42    function init()
43    {
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    {
60        $this->action();
61        $this->sendResponse();
62    }
63
64    /**
65     * Page のアクション.
66     *
67     * @return void
68     */
69    function action()
70    {
71        $objFormParam = new SC_FormParam_Ex;
72
73        // パラメーター情報初期化
74        $this->lfInitParam($objFormParam);
75
76        // POST値をセット
77        $objFormParam->setParam($_REQUEST);
78        $this->arrErr = $objFormParam->checkError();
79        $this->arrForm = $objFormParam->getFormParamList();
80
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);
88        }
89
90    }
91
92    /**
93     * デストラクタ.
94     *
95     * @return void
96     */
97    function destroy()
98    {
99        parent::destroy();
100    }
101
102    /**
103     * パラメーターの初期化.
104     *
105     * @return void
106     */
107    function lfInitParam(&$objFormParam)
108    {
109        $objFormParam->addParam('ファイル', 'log', null, '', array());
110        $objFormParam->addParam('行数', 'line_max', INT_LEN, '', array('NUM_CHECK', 'MAX_LENGTH_CHECK'), 50);
111    }
112
113    /**
114     * EC-CUBE ログを取得する.
115     *
116     * @return array $arrLogs 取得したログ
117     */
118    function getEccubeLog($log_path_base)
119    {
120        $index = 0;
121        $arrLogs = array();
122        for ($gen = 0 ; $gen <= MAX_LOG_QUANTITY; $gen++) {
123            $path = $log_path_base;
124            if ($gen != 0) {
125                $path .= ".$gen";
126            }
127
128            // ファイルが存在しない場合、前世代のログへ
129            if (!file_exists($path)) continue;
130
131            $arrLogTmp = array_reverse(file($path));
132
133            $arrBodyReverse = array();
134            foreach ($arrLogTmp as $line) {
135                // 上限に達した場合、処理を抜ける
136                if (count($arrLogs) >= $this->line_max) break 2;
137
138                $line = chop($line);
139                if (preg_match('/^(\d+\/\d+\/\d+ \d+:\d+:\d+) \[([^\]]+)\] (.*)$/', $line, $arrMatch)) {
140                    $arrLogLine = array();
141                    // 日時
142                    $arrLogLine['date'] = $arrMatch[1];
143                    // パス
144                    $arrLogLine['path'] = $arrMatch[2];
145                    // 内容
146                    $arrBodyReverse[] = $arrMatch[3];
147                    $arrLogLine['body'] = implode("\n", array_reverse($arrBodyReverse));
148                    $arrBodyReverse = array();
149
150                    $arrLogs[] = $arrLogLine;
151                } else {
152                    // 内容
153                    $arrBodyReverse[] = $line;
154                }
155            }
156        }
157
158        return $arrLogs;
159    }
160
161    /**
162     * ログファイルのパスを取得する
163     *
164     * セキュリティ面をカバーする役割もある。
165     */
166    function getLogPath($log_name)
167    {
168        if (strlen($log_name) === 0) {
169            return LOG_REALFILE;
170        }
171        if (defined($const_name = $log_name . '_LOG_REALFILE')) {
172            return constant($const_name);
173        }
174        trigger_error('不正なログが指定されました。', E_USER_ERROR);
175    }
176
177    /**
178     * ログファイルの一覧を読み込む
179     *
180     * TODO mtb_constants から動的生成したい。
181     * @return void
182     */
183    function loadLogList()
184    {
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.