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

Revision 22498, 5.6 KB checked in by kim, 11 years ago (diff)

#2084 ID振り直し LC_Page_Admin_Products_UploadCSV_012からLC_Page_Admin_System_Parameterまで

  • 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-2012 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 = t('c_System_01');
49        $this->tpl_subtitle = t('c_EC-CUBE log display_01');
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        $objFormParam = new SC_FormParam_Ex;
71
72        // パラメーター情報初期化
73        $this->lfInitParam($objFormParam);
74
75        // POST値をセット
76        $objFormParam->setParam($_REQUEST);
77        $this->arrErr = $objFormParam->checkError();
78        $this->arrForm = $objFormParam->getFormParamList();
79
80        $this->loadLogList();
81
82        if (empty($this->arrErr)) {
83            $this->line_max = $objFormParam->getValue('line_max');
84
85            $log_path = $this->getLogPath($objFormParam->getValue('log'));
86            $this->tpl_ec_log = $this->getEccubeLog($log_path);
87        }
88
89    }
90
91    /**
92     * デストラクタ.
93     *
94     * @return void
95     */
96    function destroy() {
97        parent::destroy();
98    }
99
100    /**
101     * パラメーターの初期化.
102     *
103     * @return void
104     */
105    function lfInitParam(&$objFormParam) {
106        $objFormParam->addParam(t('c_File_01'), 'log', null, '', array());
107        $objFormParam->addParam(t('c_Number of lines_01'), 'line_max', INT_LEN, '', array('NUM_CHECK', 'MAX_LENGTH_CHECK'), 50);
108    }
109
110    /**
111     * EC-CUBE ログを取得する.
112     *
113     * @return array $arrLogs 取得したログ
114     */
115    function getEccubeLog($log_path_base) {
116
117        $index = 0;
118        $arrLogs = array();
119        for ($gen = 0 ; $gen <= MAX_LOG_QUANTITY; $gen++) {
120            $path = $log_path_base;
121            if ($gen != 0) {
122                $path .= ".$gen";
123            }
124
125            // ファイルが存在しない場合、前世代のログへ
126            if (!file_exists($path)) continue;
127
128            $arrLogTmp = array_reverse(file($path));
129
130            $arrBodyReverse = array();
131            foreach ($arrLogTmp as $line) {
132                // 上限に達した場合、処理を抜ける
133                if (count($arrLogs) >= $this->line_max) break 2;
134
135                $line = chop($line);
136                if (preg_match('/^(\d+\/\d+\/\d+ \d+:\d+:\d+) \[([^\]]+)\] (.*)$/', $line, $arrMatch)) {
137                    $arrLogLine = array();
138                    // 日時
139                    $arrLogLine['date'] = $arrMatch[1];
140                    // パス
141                    $arrLogLine['path'] = $arrMatch[2];
142                    // 内容
143                    $arrBodyReverse[] = $arrMatch[3];
144                    $arrLogLine['body'] = implode("\n", array_reverse($arrBodyReverse));
145                    $arrBodyReverse = array();
146
147                    $arrLogs[] = $arrLogLine;
148                } else {
149                    // 内容
150                    $arrBodyReverse[] = $line;
151                }
152            }
153        }
154        return $arrLogs;
155    }
156
157    /**
158     * ログファイルのパスを取得する
159     *
160     * セキュリティ面をカバーする役割もある。
161     */
162    function getLogPath($log_name) {
163        if (strlen($log_name) === 0) {
164            return LOG_REALFILE;
165        }
166        if (defined($const_name = $log_name . '_LOG_REALFILE')) {
167            return constant($const_name);
168        }
169        trigger_error(t('c_An illegal log was designated._01'), E_USER_ERROR);
170    }
171
172    /**
173     * ログファイルの一覧を読み込む
174     *
175     * TODO mtb_constants から動的生成したい。
176     * @return void
177     */
178    function loadLogList() {
179        $this->arrLogList[''] = t('c_Standard log file_01');
180        $this->arrLogList['CUSTOMER'] = t('c_Member login log file_01');
181        $this->arrLogList['ADMIN'] = t('c_Management area log file_01');
182
183        if (defined('DEBUG_LOG_REALFILE') && strlen(DEBUG_LOG_REALFILE) >= 1) {
184            $this->arrLogList['DEBUG'] = t('c_Debug log file_01');
185        }
186
187        if (defined('ERROR_LOG_REALFILE') && strlen(ERROR_LOG_REALFILE) >= 1) {
188            $this->arrLogList['ERROR'] = t('c_Error log file_01');
189        }
190
191        if (defined('DB_LOG_REALFILE') && strlen(DB_LOG_REALFILE) >= 1) {
192            $this->arrLogList['DB'] = t('c_DB log file_01');
193        }
194    }
195}
Note: See TracBrowser for help on using the repository browser.