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

Revision 23605, 5.8 KB checked in by kimoto, 10 years ago (diff)

#2448 typo修正・ソース整形・ソースコメントの改善 for 2.13.3

Scrutinizer Auto-Fixes

This patch was automatically generated as part of the following inspection:
 https://scrutinizer-ci.com/g/nobuhiko/EC-CUBE/inspections/d8722894-69a6-4b1b-898d-43618035c60d

Enabled analysis tools:

  • PHP Analyzer
  • PHP PDepend
  • PHP Similarity Analyzer
  • PHP Change Tracking Analyzer
  • 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-2014 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    public $arrLogList = array();
36
37    /**
38     * Page を初期化する.
39     *
40     * @return void
41     */
42    public 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    public function process()
59    {
60        $this->action();
61        $this->sendResponse();
62    }
63
64    /**
65     * Page のアクション.
66     *
67     * @return void
68     */
69    public 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     * @param SC_FormParam_Ex $objFormParam
96     * @return void
97     */
98    public function lfInitParam(&$objFormParam)
99    {
100        $objFormParam->addParam('ファイル', 'log', null, '', array());
101        $objFormParam->addParam('行数', 'line_max', INT_LEN, '', array('NUM_CHECK', 'MAX_LENGTH_CHECK'), 50);
102    }
103
104    /**
105     * EC-CUBE ログを取得する.
106     *
107     * @return array $arrLogs 取得したログ
108     */
109    public function getEccubeLog($log_path_base)
110    {
111        $index = 0;
112        $arrLogs = array();
113        for ($gen = 0 ; $gen <= MAX_LOG_QUANTITY; $gen++) {
114            $path = $log_path_base;
115            if ($gen != 0) {
116                $path .= ".$gen";
117            }
118
119            // ファイルが存在しない場合、前世代のログへ
120            if (!file_exists($path)) continue;
121
122            $arrLogTmp = array_reverse(file($path));
123
124            $arrBodyReverse = array();
125            foreach ($arrLogTmp as $line) {
126                // 上限に達した場合、処理を抜ける
127                if (count($arrLogs) >= $this->line_max) break 2;
128
129                $line = chop($line);
130                if (preg_match('/^(\d+\/\d+\/\d+ \d+:\d+:\d+) \[([^\]]+)\] (.*)$/', $line, $arrMatch)) {
131                    $arrLogLine = array();
132                    // 日時
133                    $arrLogLine['date'] = $arrMatch[1];
134                    // パス
135                    $arrLogLine['path'] = $arrMatch[2];
136                    // 内容
137                    $arrBodyReverse[] = $arrMatch[3];
138                    $arrLogLine['body'] = implode("\n", array_reverse($arrBodyReverse));
139                    $arrBodyReverse = array();
140
141                    $arrLogs[] = $arrLogLine;
142                } else {
143                    // 内容
144                    $arrBodyReverse[] = $line;
145                }
146            }
147        }
148
149        return $arrLogs;
150    }
151
152    /**
153     * ログファイルのパスを取得する
154     *
155     * セキュリティ面をカバーする役割もある。
156     */
157    public function getLogPath($log_name)
158    {
159        if (strlen($log_name) === 0) {
160            return LOG_REALFILE;
161        }
162        if (defined($const_name = $log_name . '_LOG_REALFILE')) {
163            return constant($const_name);
164        }
165        trigger_error('不正なログが指定されました。', E_USER_ERROR);
166    }
167
168    /**
169     * ログファイルの一覧を読み込む
170     *
171     * TODO mtb_constants から動的生成したい。
172     * @return void
173     */
174    public function loadLogList()
175    {
176        $this->arrLogList[''] = '標準ログファイル';
177        $this->arrLogList['CUSTOMER'] = '会員ログイン ログファイル';
178        $this->arrLogList['ADMIN'] = '管理機能ログファイル';
179
180        if (defined('DEBUG_LOG_REALFILE') && strlen(DEBUG_LOG_REALFILE) >= 1) {
181            $this->arrLogList['DEBUG'] = 'デバッグログファイル';
182        }
183
184        if (defined('ERROR_LOG_REALFILE') && strlen(ERROR_LOG_REALFILE) >= 1) {
185            $this->arrLogList['ERROR'] = 'エラーログファイル';
186        }
187
188        if (defined('DB_LOG_REALFILE') && strlen(DB_LOG_REALFILE) >= 1) {
189            $this->arrLogList['DB'] = 'DBログファイル';
190        }
191        if (defined('PLUGIN_LOG_REALFILE') && strlen(PLUGIN_LOG_REALFILE) >= 1) {
192            $this->arrLogList['PLUGIN'] = 'プラグインログファイル';
193        }
194    }
195}
Note: See TracBrowser for help on using the repository browser.