| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | * This file is part of EC-CUBE |
|---|
| 4 | * |
|---|
| 5 | * Copyright(c) 2000-2007 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 | var $login_id; // ログインユーザ名 |
|---|
| 27 | var $authority; // ユーザ権限 |
|---|
| 28 | var $cert; // 認証文字列(認証成功の判定に使用) |
|---|
| 29 | var $sid; // セッションID |
|---|
| 30 | var $member_id; // ログインユーザの主キー |
|---|
| 31 | var $uniqid; // ページ遷移の正当性チェックに使用 |
|---|
| 32 | |
|---|
| 33 | /* コンストラクタ */ |
|---|
| 34 | function SC_Session() { |
|---|
| 35 | // セッション開始 |
|---|
| 36 | SC_Utils_Ex::sfDomainSessionStart(); |
|---|
| 37 | |
|---|
| 38 | // セッション情報の保存 |
|---|
| 39 | if(isset($_SESSION['cert'])) { |
|---|
| 40 | $this->sid = session_id(); |
|---|
| 41 | $this->cert = $_SESSION['cert']; |
|---|
| 42 | $this->login_id = $_SESSION['login_id']; |
|---|
| 43 | $this->authority = $_SESSION['authority']; // 管理者:0, 一般:1, 閲覧:2 |
|---|
| 44 | $this->member_id = $_SESSION['member_id']; |
|---|
| 45 | if (isset($_SESSION['uniq_id'])) { |
|---|
| 46 | $this->uniqid = $_SESSION['uniq_id']; |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | // ログに記録する |
|---|
| 50 | GC_Utils_Ex::gfPrintLog("access : user=".$this->login_id." auth=".$this->authority." sid=".$this->sid); |
|---|
| 51 | } else { |
|---|
| 52 | // ログに記録する |
|---|
| 53 | GC_Utils_Ex::gfPrintLog("access error."); |
|---|
| 54 | } |
|---|
| 55 | } |
|---|
| 56 | /* 認証成功の判定 */ |
|---|
| 57 | function IsSuccess() { |
|---|
| 58 | global $arrPERMISSION; |
|---|
| 59 | if($this->cert == CERT_STRING) { |
|---|
| 60 | if(isset($arrPERMISSION[$_SERVER['PHP_SELF']])) { |
|---|
| 61 | // 数値が自分の権限以上のものでないとアクセスできない。 |
|---|
| 62 | if($arrPERMISSION[$_SERVER['PHP_SELF']] < $this->authority) { |
|---|
| 63 | return AUTH_ERROR; |
|---|
| 64 | } |
|---|
| 65 | } |
|---|
| 66 | return SUCCESS; |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | return ACCESS_ERROR; |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | /* セッションの書き込み */ |
|---|
| 73 | function SetSession($key, $val) { |
|---|
| 74 | $_SESSION[$key] = $val; |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | /* セッションの読み込み */ |
|---|
| 78 | function GetSession($key) { |
|---|
| 79 | return $_SESSION[$key]; |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | /* セッションIDの取得 */ |
|---|
| 83 | function GetSID() { |
|---|
| 84 | return $this->sid; |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | /** ユニークIDの取得 **/ |
|---|
| 88 | function getUniqId() { |
|---|
| 89 | // ユニークIDがセットされていない場合はセットする。 |
|---|
| 90 | if( empty($_SESSION['uniqid']) ) { |
|---|
| 91 | $this->setUniqId(); |
|---|
| 92 | } |
|---|
| 93 | return $this->GetSession('uniqid'); |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | /** ユニークIDのセット **/ |
|---|
| 97 | function setUniqId() { |
|---|
| 98 | // 予測されないようにランダム文字列を付与する。 |
|---|
| 99 | $this->SetSession('uniqid', SC_Utils_Ex::sfGetUniqRandomId()); |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | /* セッションの破棄 */ |
|---|
| 103 | function EndSession() { |
|---|
| 104 | // デフォルトは、「PHPSESSID」 |
|---|
| 105 | $sname = session_name(); |
|---|
| 106 | // セッション変数を全て解除する |
|---|
| 107 | $_SESSION = array(); |
|---|
| 108 | // セッションを切断するにはセッションクッキーも削除する。 |
|---|
| 109 | // Note: セッション情報だけでなくセッションを破壊する。 |
|---|
| 110 | if (isset($_COOKIE[$sname])) { |
|---|
| 111 | setcookie($sname, '', time()-42000, '/'); |
|---|
| 112 | } |
|---|
| 113 | // 最終的に、セッションを破壊する |
|---|
| 114 | session_destroy(); |
|---|
| 115 | // ログに記録する |
|---|
| 116 | GC_Utils_Ex::gfPrintLog("logout : user=".$this->login_id." auth=".$this->authority." sid=".$this->sid); |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | // 関連セッションのみ破棄する。 |
|---|
| 120 | function logout() { |
|---|
| 121 | unset($_SESSION['cert']); |
|---|
| 122 | unset($_SESSION['login_id']); |
|---|
| 123 | unset($_SESSION['authority']); |
|---|
| 124 | unset($_SESSION['member_id']); |
|---|
| 125 | unset($_SESSION['uniqid']); |
|---|
| 126 | // ログに記録する |
|---|
| 127 | GC_Utils_Ex::gfPrintLog("logout : user=".$this->login_id." auth=".$this->authority." sid=".$this->sid); |
|---|
| 128 | } |
|---|
| 129 | } |
|---|
| 130 | ?> |
|---|