| 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 | |
---|
| 24 | /* セッション管理クラス */ |
---|
| 25 | class SC_Session |
---|
| 26 | { |
---|
| 27 | /** ログインユーザ名 */ |
---|
| 28 | public $login_id; |
---|
| 29 | |
---|
| 30 | /** ユーザ権限 */ |
---|
| 31 | public $authority; |
---|
| 32 | |
---|
| 33 | /** 認証文字列(認証成功の判定に使用) */ |
---|
| 34 | public $cert; |
---|
| 35 | |
---|
| 36 | /** セッションID */ |
---|
| 37 | public $sid; |
---|
| 38 | |
---|
| 39 | /** ログインユーザの主キー */ |
---|
| 40 | public $member_id; |
---|
| 41 | |
---|
| 42 | /** ページ遷移の正当性チェックに使用 */ |
---|
| 43 | public $uniqid; |
---|
| 44 | |
---|
| 45 | /* コンストラクタ */ |
---|
| 46 | public function __construct() |
---|
| 47 | { |
---|
| 48 | // セッション情報の保存 |
---|
| 49 | if (isset($_SESSION['cert'])) { |
---|
| 50 | $this->sid = session_id(); |
---|
| 51 | $this->cert = $_SESSION['cert']; |
---|
| 52 | $this->login_id = $_SESSION['login_id']; |
---|
| 53 | // 管理者:0, 店舗オーナー:1, 閲覧:2, 販売担当:3 (XXX 現状 0, 1 を暫定実装。2, 3 は未実装。) |
---|
| 54 | $this->authority = $_SESSION['authority']; |
---|
| 55 | $this->member_id = $_SESSION['member_id']; |
---|
| 56 | if (isset($_SESSION['uniq_id'])) { |
---|
| 57 | $this->uniqid = $_SESSION['uniq_id']; |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | // ログに記録する |
---|
| 61 | GC_Utils_Ex::gfPrintLog('access : user='.$this->login_id.' auth='.$this->authority.' sid='.$this->sid); |
---|
| 62 | } else { |
---|
| 63 | // ログに記録する |
---|
| 64 | GC_Utils_Ex::gfPrintLog('access error.'); |
---|
| 65 | } |
---|
| 66 | } |
---|
| 67 | /* 認証成功の判定 */ |
---|
| 68 | public function IsSuccess() |
---|
| 69 | { |
---|
| 70 | if ($this->cert == CERT_STRING) { |
---|
| 71 | $masterData = new SC_DB_MasterData_Ex(); |
---|
| 72 | $admin_path = strtolower(preg_replace('/\/+/', '/', $_SERVER['SCRIPT_NAME'])); |
---|
| 73 | $arrPERMISSION = array_change_key_case($masterData->getMasterData('mtb_permission')); |
---|
| 74 | if (isset($arrPERMISSION[$admin_path])) { |
---|
| 75 | // 数値が自分の権限以上のものでないとアクセスできない。 |
---|
| 76 | if ($arrPERMISSION[$admin_path] < $this->authority) { |
---|
| 77 | return AUTH_ERROR; |
---|
| 78 | } |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | return SUCCESS; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | return ACCESS_ERROR; |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | /* セッションの書き込み */ |
---|
| 88 | public function SetSession($key, $val) |
---|
| 89 | { |
---|
| 90 | $_SESSION[$key] = $val; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | /* セッションの読み込み */ |
---|
| 94 | public function GetSession($key) |
---|
| 95 | { |
---|
| 96 | return $_SESSION[$key]; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | /* セッションIDの取得 */ |
---|
| 100 | public function GetSID() |
---|
| 101 | { |
---|
| 102 | return $this->sid; |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | /** ユニークIDの取得 **/ |
---|
| 106 | public function getUniqId() |
---|
| 107 | { |
---|
| 108 | // ユニークIDがセットされていない場合はセットする。 |
---|
| 109 | if (empty($_SESSION['uniqid'])) { |
---|
| 110 | $this->setUniqId(); |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | return $this->GetSession('uniqid'); |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | /** ユニークIDのセット **/ |
---|
| 117 | public function setUniqId() |
---|
| 118 | { |
---|
| 119 | // 予測されないようにランダム文字列を付与する。 |
---|
| 120 | $this->SetSession('uniqid', SC_Utils_Ex::sfGetUniqRandomId()); |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | // 関連セッションのみ破棄する。 |
---|
| 124 | public function logout() |
---|
| 125 | { |
---|
| 126 | unset($_SESSION['cert']); |
---|
| 127 | unset($_SESSION['login_id']); |
---|
| 128 | unset($_SESSION['authority']); |
---|
| 129 | unset($_SESSION['member_id']); |
---|
| 130 | unset($_SESSION['uniqid']); |
---|
| 131 | // トランザクショントークンを破棄 |
---|
| 132 | SC_Helper_Session_Ex::destroyToken(); |
---|
| 133 | // ログに記録する |
---|
| 134 | GC_Utils_Ex::gfPrintLog('logout : user='.$this->login_id.' auth='.$this->authority.' sid='.$this->sid); |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | /** |
---|
| 138 | * セッションIDを新しいIDに書き換える |
---|
| 139 | * |
---|
| 140 | * @return bool |
---|
| 141 | */ |
---|
| 142 | public function regenerateSID() |
---|
| 143 | { |
---|
| 144 | return session_regenerate_id(true); |
---|
| 145 | } |
---|
| 146 | } |
---|