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

Revision 21866, 8.2 KB checked in by h_yoshimoto, 12 years ago (diff)

#1831 Copyrightを更新を誤っているので戻します

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