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

Revision 22856, 8.2 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 LOCKON CO.,LTD.
31 * @version $Id$
32 */
33class LC_Page_Admin_Index extends LC_Page_Admin_Ex
34{
35    /**
36     * Page を初期化する.
37     *
38     * @return void
39     */
40    function init()
41    {
42        parent::init();
43        $this->tpl_mainpage = 'login.tpl';
44        $this->httpCacheControl('nocache');
45    }
46
47    /**
48     * Page のプロセス.
49     *
50     * @return void
51     */
52    function process()
53    {
54        $this->action();
55        $this->sendResponse();
56    }
57
58    /**
59     * デストラクタ.
60     *
61     * @return void
62     */
63    function destroy()
64    {
65        parent::destroy();
66    }
67
68    /**
69     * Page のアクション.
70     *
71     * @return void
72     */
73    function action()
74    {
75        // パラメーター管理クラス
76        $objFormParam = new SC_FormParam_Ex();
77
78        switch ($this->getMode()) {
79            case 'login':
80                //ログイン処理
81                $this->lfInitParam($objFormParam);
82                $objFormParam->setParam($_POST);
83                $this->arrErr = $this->lfCheckError($objFormParam);
84                if (SC_Utils_Ex::isBlank($this->arrErr)) {
85                    $this->lfDoLogin($objFormParam->getValue('login_id'));
86
87                    SC_Response_Ex::sendRedirect(ADMIN_HOME_URLPATH);
88                } else {
89                    // ブルートフォースアタック対策
90                    // ログイン失敗時に遅延させる
91                    sleep(LOGIN_RETRY_INTERVAL);
92
93                    SC_Utils_Ex::sfDispError(LOGIN_ERROR);
94                }
95                break;
96            default:
97                break;
98        }
99
100        // 管理者ログインテンプレートフレームの設定
101        $this->setTemplate(LOGIN_FRAME);
102
103    }
104
105    /**
106     * パラメーター情報の初期化
107     *
108     * @param array $objFormParam フォームパラメータークラス
109     * @return void
110     */
111    function lfInitParam(&$objFormParam)
112    {
113        $objFormParam->addParam('ID', 'login_id', ID_MAX_LEN, '', array('EXIST_CHECK', 'ALNUM_CHECK' ,'MAX_LENGTH_CHECK'));
114        $objFormParam->addParam('PASSWORD', 'password', ID_MAX_LEN, '', array('EXIST_CHECK', 'ALNUM_CHECK', 'MAX_LENGTH_CHECK'));
115    }
116
117    /**
118     * パラメーターのエラーチェック
119     *
120     * TODO: ブルートフォースアタック対策チェックの実装
121     *
122     * @param array $objFormParam フォームパラメータークラス
123     * @return array $arrErr エラー配列
124     */
125    function lfCheckError(&$objFormParam)
126    {
127        // 書式チェック
128        $arrErr = $objFormParam->checkError();
129        if (SC_Utils_Ex::isBlank($arrErr)) {
130            $arrForm = $objFormParam->getHashArray();
131            // ログインチェック
132            if (!$this->lfIsLoginMember($arrForm['login_id'], $arrForm['password'])) {
133                $arrErr['password'] = 'ログイン出来ません。';
134                $this->lfSetIncorrectData($arrForm['login_id']);
135            }
136        }
137
138        return $arrErr;
139    }
140
141    /**
142     * 有効な管理者ID/PASSかどうかチェックする
143     *
144     * @param string $login_id ログインID文字列
145     * @param string $pass ログインパスワード文字列
146     * @return boolean ログイン情報が有効な場合 true
147     */
148    function lfIsLoginMember($login_id, $pass)
149    {
150        $objQuery =& SC_Query_Ex::getSingletonInstance();
151        //パスワード、saltの取得
152        $cols = 'password, salt';
153        $table = 'dtb_member';
154        $where = 'login_id = ? AND del_flg <> 1 AND work = 1';
155        $arrData = $objQuery->getRow($cols, $table, $where, array($login_id));
156        if (SC_Utils_Ex::isBlank($arrData)) {
157            return false;
158        }
159        // ユーザー入力パスワードの判定
160        if (SC_Utils_Ex::sfIsMatchHashPassword($pass, $arrData['password'], $arrData['salt'])) {
161            return true;
162        }
163
164        return false;
165    }
166
167    /**
168     * 管理者ログイン設定処理
169     *
170     * @param string $login_id ログインID文字列
171     * @return void
172     */
173    function lfDoLogin($login_id)
174    {
175        $objQuery =& SC_Query_Ex::getSingletonInstance();
176        //メンバー情報取得
177        $cols = 'member_id, authority, login_date, name';
178        $table = 'dtb_member';
179        $where = 'login_id = ?';
180        $arrData = $objQuery->getRow($cols, $table, $where, array($login_id));
181        // セッション登録
182        $sid = $this->lfSetLoginSession($arrData['member_id'], $login_id, $arrData['authority'], $arrData['name'], $arrData['login_date']);
183        // ログイン情報記録
184        $this->lfSetLoginData($sid, $arrData['member_id'], $login_id, $arrData['authority'], $arrData['login_date']);
185    }
186
187    /**
188     * ログイン情報セッション登録
189     *
190     * @param integer $member_id メンバーID
191     * @param string $login_id ログインID文字列
192     * @param integer $authority 権限ID
193     * @param string $login_name ログイン表示名
194     * @param string $last_login 最終ログイン日時(YYYY/MM/DD HH:ii:ss形式) またはNULL
195     * @return string $sid 設定したセッションのセッションID
196     */
197    function lfSetLoginSession($member_id, $login_id, $authority, $login_name, $last_login)
198    {
199        $objSess = new SC_Session_Ex();
200        // 認証済みの設定
201        $objSess->SetSession('cert', CERT_STRING);
202        $objSess->SetSession('member_id', $member_id);
203        $objSess->SetSession('login_id', $login_id);
204        $objSess->SetSession('authority', $authority);
205        $objSess->SetSession('login_name', $login_name);
206        $objSess->SetSession('uniqid', $objSess->getUniqId());
207        if (SC_Utils_Ex::isBlank($last_login)) {
208            $objSess->SetSession('last_login', date('Y-m-d H:i:s'));
209        } else {
210            $objSess->SetSession('last_login', $last_login);
211        }
212
213        return $objSess->GetSID();
214    }
215
216    /**
217     * ログイン情報の記録
218     *
219     * @param mixed $sid セッションID
220     * @param integer $member_id メンバーID
221     * @param string $login_id ログインID文字列
222     * @param integer $authority 権限ID
223     * @param string $last_login 最終ログイン日時(YYYY/MM/DD HH:ii:ss形式) またはNULL
224     * @return void
225     */
226    function lfSetLoginData($sid, $member_id, $login_id, $authority, $last_login)
227    {
228        // ログイン記録ログ出力
229        $str_log = "login: user=$login_id($member_id) auth=$authority "
230                    . "lastlogin=$last_login sid=$sid";
231        GC_Utils_Ex::gfPrintLog($str_log);
232
233        // 最終ログイン日時更新
234        $objQuery =& SC_Query_Ex::getSingletonInstance();
235        $sqlval = array();
236        $sqlval['login_date'] = date('Y-m-d H:i:s');
237        $table = 'dtb_member';
238        $where = 'member_id = ?';
239        $objQuery->update($table, $sqlval, $where, array($member_id));
240    }
241
242    /**
243     * ログイン失敗情報の記録
244     *
245     * TODO: ブルートフォースアタック対策の実装
246     *
247     * @param string $login_id ログイン失敗時に投入されたlogin_id文字列
248     * @return void
249     */
250    function lfSetIncorrectData($error_login_id)
251    {
252        GC_Utils_Ex::gfPrintLog($error_login_id . ' password incorrect.');
253    }
254}
Note: See TracBrowser for help on using the repository browser.