source: branches/version-2_13_3/data/class/SC_Session.php @ 23670

Revision 23670, 4.7 KB checked in by shinichi_takahashi, 9 years ago (diff)

#2645 管理者権限のアクセス制限が効いていない の修正

  • 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-2014 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/* セッション管理クラス */
25class 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            $admin_path = preg_replace('/' . preg_quote(ROOT_URLPATH, '/') . '/', '/', $admin_path);
74            $admin_path = preg_replace('/' . preg_quote(ADMIN_DIR, '/') . '/', 'admin/', $admin_path);
75            $arrPERMISSION = array_change_key_case($masterData->getMasterData('mtb_permission'));
76            if (isset($arrPERMISSION[$admin_path])) {
77                // 数値が自分の権限以上のものでないとアクセスできない。
78                if ($arrPERMISSION[$admin_path] < $this->authority) {
79                    return AUTH_ERROR;
80                }
81            }
82
83            return SUCCESS;
84        }
85
86        return ACCESS_ERROR;
87    }
88
89    /* セッションの書き込み */
90
91    /**
92     * @param string $key
93     */
94    public function SetSession($key, $val)
95    {
96        $_SESSION[$key] = $val;
97    }
98
99    /* セッションの読み込み */
100
101    /**
102     * @param string $key
103     */
104    public function GetSession($key)
105    {
106        return $_SESSION[$key];
107    }
108
109    /* セッションIDの取得 */
110    public function GetSID()
111    {
112        return $this->sid;
113    }
114
115    /** ユニークIDの取得 **/
116    public function getUniqId()
117    {
118        // ユニークIDがセットされていない場合はセットする。
119        if (empty($_SESSION['uniqid'])) {
120            $this->setUniqId();
121        }
122
123        return $this->GetSession('uniqid');
124    }
125
126    /** ユニークIDのセット **/
127    public function setUniqId()
128    {
129        // 予測されないようにランダム文字列を付与する。
130        $this->SetSession('uniqid', SC_Utils_Ex::sfGetUniqRandomId());
131    }
132
133    // 関連セッションのみ破棄する。
134    public function logout()
135    {
136        unset($_SESSION['cert']);
137        unset($_SESSION['login_id']);
138        unset($_SESSION['authority']);
139        unset($_SESSION['member_id']);
140        unset($_SESSION['uniqid']);
141        // トランザクショントークンを破棄
142        SC_Helper_Session_Ex::destroyToken();
143        // ログに記録する
144        GC_Utils_Ex::gfPrintLog('logout : user='.$this->login_id.' auth='.$this->authority.' sid='.$this->sid);
145    }
146
147    /**
148     * セッションIDを新しいIDに書き換える
149     *
150     * @return bool
151     */
152    public function regenerateSID()
153    {
154        return session_regenerate_id(true);
155    }
156}
Note: See TracBrowser for help on using the repository browser.