source: branches/version-2_13_0/data/class/pages/admin/LC_Page_Admin_Index.php @ 23126

Revision 23126, 8.2 KB checked in by m_uehara, 11 years ago (diff)

#2348 r23116 - r23125 をマージ

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