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

Revision 22857, 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     * @param array $objFormParam フォームパラメータークラス
108     * @return void
109     */
110    function lfInitParam(&$objFormParam)
111    {
112        $objFormParam->addParam('ID', 'login_id', ID_MAX_LEN, '', array('EXIST_CHECK', 'ALNUM_CHECK' ,'MAX_LENGTH_CHECK'));
113        $objFormParam->addParam('PASSWORD', 'password', ID_MAX_LEN, '', array('EXIST_CHECK', 'ALNUM_CHECK', 'MAX_LENGTH_CHECK'));
114    }
115
116    /**
117     * パラメーターのエラーチェック
118     *
119     * TODO: ブルートフォースアタック対策チェックの実装
120     *
121     * @param array $objFormParam フォームパラメータークラス
122     * @return array $arrErr エラー配列
123     */
124    function lfCheckError(&$objFormParam)
125    {
126        // 書式チェック
127        $arrErr = $objFormParam->checkError();
128        if (SC_Utils_Ex::isBlank($arrErr)) {
129            $arrForm = $objFormParam->getHashArray();
130            // ログインチェック
131            if (!$this->lfIsLoginMember($arrForm['login_id'], $arrForm['password'])) {
132                $arrErr['password'] = 'ログイン出来ません。';
133                $this->lfSetIncorrectData($arrForm['login_id']);
134            }
135        }
136
137        return $arrErr;
138    }
139
140    /**
141     * 有効な管理者ID/PASSかどうかチェックする
142     *
143     * @param string $login_id ログインID文字列
144     * @param string $pass ログインパスワード文字列
145     * @return boolean ログイン情報が有効な場合 true
146     */
147    function lfIsLoginMember($login_id, $pass)
148    {
149        $objQuery =& SC_Query_Ex::getSingletonInstance();
150        //パスワード、saltの取得
151        $cols = 'password, salt';
152        $table = 'dtb_member';
153        $where = 'login_id = ? AND del_flg <> 1 AND work = 1';
154        $arrData = $objQuery->getRow($cols, $table, $where, array($login_id));
155        if (SC_Utils_Ex::isBlank($arrData)) {
156            return false;
157        }
158        // ユーザー入力パスワードの判定
159        if (SC_Utils_Ex::sfIsMatchHashPassword($pass, $arrData['password'], $arrData['salt'])) {
160            return true;
161        }
162
163        return false;
164    }
165
166    /**
167     * 管理者ログイン設定処理
168     *
169     * @param string $login_id ログインID文字列
170     * @return void
171     */
172    function lfDoLogin($login_id)
173    {
174        $objQuery =& SC_Query_Ex::getSingletonInstance();
175        //メンバー情報取得
176        $cols = 'member_id, authority, login_date, name';
177        $table = 'dtb_member';
178        $where = 'login_id = ?';
179        $arrData = $objQuery->getRow($cols, $table, $where, array($login_id));
180        // セッション登録
181        $sid = $this->lfSetLoginSession($arrData['member_id'], $login_id, $arrData['authority'], $arrData['name'], $arrData['login_date']);
182        // ログイン情報記録
183        $this->lfSetLoginData($sid, $arrData['member_id'], $login_id, $arrData['authority'], $arrData['login_date']);
184    }
185
186    /**
187     * ログイン情報セッション登録
188     *
189     * @param integer $member_id メンバーID
190     * @param string $login_id ログインID文字列
191     * @param integer $authority 権限ID
192     * @param string $login_name ログイン表示名
193     * @param string $last_login 最終ログイン日時(YYYY/MM/DD HH:ii:ss形式) またはNULL
194     * @return string $sid 設定したセッションのセッションID
195     */
196    function lfSetLoginSession($member_id, $login_id, $authority, $login_name, $last_login)
197    {
198        $objSess = new SC_Session_Ex();
199        // 認証済みの設定
200        $objSess->SetSession('cert', CERT_STRING);
201        $objSess->SetSession('member_id', $member_id);
202        $objSess->SetSession('login_id', $login_id);
203        $objSess->SetSession('authority', $authority);
204        $objSess->SetSession('login_name', $login_name);
205        $objSess->SetSession('uniqid', $objSess->getUniqId());
206        if (SC_Utils_Ex::isBlank($last_login)) {
207            $objSess->SetSession('last_login', date('Y-m-d H:i:s'));
208        } else {
209            $objSess->SetSession('last_login', $last_login);
210        }
211
212        return $objSess->GetSID();
213    }
214
215    /**
216     * ログイン情報の記録
217     *
218     * @param mixed $sid セッションID
219     * @param integer $member_id メンバーID
220     * @param string $login_id ログインID文字列
221     * @param integer $authority 権限ID
222     * @param string $last_login 最終ログイン日時(YYYY/MM/DD HH:ii:ss形式) またはNULL
223     * @return void
224     */
225    function lfSetLoginData($sid, $member_id, $login_id, $authority, $last_login)
226    {
227        // ログイン記録ログ出力
228        $str_log = "login: user=$login_id($member_id) auth=$authority "
229                    . "lastlogin=$last_login sid=$sid";
230        GC_Utils_Ex::gfPrintLog($str_log);
231
232        // 最終ログイン日時更新
233        $objQuery =& SC_Query_Ex::getSingletonInstance();
234        $sqlval = array();
235        $sqlval['login_date'] = date('Y-m-d H:i:s');
236        $table = 'dtb_member';
237        $where = 'member_id = ?';
238        $objQuery->update($table, $sqlval, $where, array($member_id));
239    }
240
241    /**
242     * ログイン失敗情報の記録
243     *
244     * TODO: ブルートフォースアタック対策の実装
245     *
246     * @param string $login_id ログイン失敗時に投入されたlogin_id文字列
247     * @return void
248     */
249    function lfSetIncorrectData($error_login_id)
250    {
251        GC_Utils_Ex::gfPrintLog($error_login_id . ' password incorrect.');
252    }
253}
Note: See TracBrowser for help on using the repository browser.