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

Revision 21743, 8.0 KB checked in by AMUAMU, 12 years ago (diff)

#1754 (exit;を個別の処理でしない) #1692 (プラグイン機能) 各ファイルでフックポイントの呼出を書かないで、自動的にフックポイントを呼び出すように修正。

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