| 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 | // {{{ requires |
|---|
| 25 | require_once CLASS_PATH . 'pages/LC_Page.php'; |
|---|
| 26 | require_once 'utils/LC_Utils_Upgrade.php'; |
|---|
| 27 | require_once 'utils/LC_Utils_Upgrade_Log.php'; |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | /** |
|---|
| 31 | * オーナーズストア認証キーを返すページクラス. |
|---|
| 32 | * |
|---|
| 33 | * @package Page |
|---|
| 34 | * @author LOCKON CO.,LTD. |
|---|
| 35 | * @version $Id$ |
|---|
| 36 | */ |
|---|
| 37 | class LC_Page_Upgrade_EchoKey extends LC_Page { |
|---|
| 38 | |
|---|
| 39 | /** Services_Jsonオブジェクト */ |
|---|
| 40 | var $objJson = null; |
|---|
| 41 | /** SC_FromParamオブジェクト */ |
|---|
| 42 | var $objForm = null; |
|---|
| 43 | |
|---|
| 44 | // }}} |
|---|
| 45 | // {{{ functions |
|---|
| 46 | |
|---|
| 47 | /** |
|---|
| 48 | * Page を初期化する. |
|---|
| 49 | * |
|---|
| 50 | * @return void |
|---|
| 51 | */ |
|---|
| 52 | function init() { |
|---|
| 53 | $this->objJson = new Services_JSON(); |
|---|
| 54 | $this->objLog = new LC_Utils_Upgrade_Log('Echo Key'); |
|---|
| 55 | |
|---|
| 56 | $this->objForm = new SC_FormParam(); |
|---|
| 57 | $this->objForm->addParam('seed', 'seed', MLTEXT_LEN, '', array('EXIST_CHECK', 'ALNUM_CHECK', 'MAX_LENGTH_CHECK')); |
|---|
| 58 | $this->objForm->setParam($_POST); |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | /** |
|---|
| 62 | * Page のプロセス. |
|---|
| 63 | * |
|---|
| 64 | * @return void |
|---|
| 65 | */ |
|---|
| 66 | function process() { |
|---|
| 67 | $objLog =& $this->objLog; |
|---|
| 68 | $objLog->start(); |
|---|
| 69 | |
|---|
| 70 | // IPアドレスの検証 |
|---|
| 71 | if (LC_Utils_Upgrade::isValidIP() !== true) { |
|---|
| 72 | $arrErr = array( |
|---|
| 73 | 'status' => OWNERSSTORE_STATUS_ERROR, |
|---|
| 74 | 'errcode' => OWNERSSTORE_ERR_EK_POST_PARAM, |
|---|
| 75 | 'body' => LC_Utils_Upgrade::getErrMessage(OWNERSSTORE_ERR_EK_INVALID_IP) |
|---|
| 76 | ); |
|---|
| 77 | echo $this->objJson->encode($arrErr); |
|---|
| 78 | $objLog->errLog($arrErr['errcode'], $_SERVER['REMOTE_ADDR']); |
|---|
| 79 | exit; |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | // リクエストの検証 |
|---|
| 83 | if ($this->objForm->checkError()) { |
|---|
| 84 | $arrErr = array( |
|---|
| 85 | 'status' => OWNERSSTORE_STATUS_ERROR, |
|---|
| 86 | 'errcode' => OWNERSSTORE_ERR_EK_POST_PARAM, |
|---|
| 87 | 'body' => LC_Utils_Upgrade::getErrMessage(OWNERSSTORE_ERR_EK_POST_PARAM) |
|---|
| 88 | ); |
|---|
| 89 | echo $this->objJson->encode($arrErr); |
|---|
| 90 | $objLog->errLog($arrErr['errcode'], $_POST); |
|---|
| 91 | exit; |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | $public_key = $this->getPublicKey(); |
|---|
| 95 | |
|---|
| 96 | // 認証キーが設定されていない場合 |
|---|
| 97 | if (empty($public_key)) { |
|---|
| 98 | $arrErr = array( |
|---|
| 99 | 'status' => OWNERSSTORE_STATUS_ERROR, |
|---|
| 100 | 'errcode' => OWNERSSTORE_ERR_EK_KEY_MISSING, |
|---|
| 101 | 'body' => LC_Utils_Upgrade::getErrMessage(OWNERSSTORE_ERR_EK_KEY_MISSING) |
|---|
| 102 | ); |
|---|
| 103 | echo $this->objJson->encode($arrErr); |
|---|
| 104 | $objLog->errLog($arrErr['errcode']); |
|---|
| 105 | exit; |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | // 認証キー + 配信サーバから送られるランダムな値をsha1()にかけechoする |
|---|
| 109 | $arrParams = array( |
|---|
| 110 | 'status' => OWNERSSTORE_STATUS_SUCCESS, |
|---|
| 111 | 'body' => sha1($public_key . $this->objForm->getValue('seed')) |
|---|
| 112 | ); |
|---|
| 113 | |
|---|
| 114 | echo $this->objJson->encode($arrParams); |
|---|
| 115 | exit; |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | /** |
|---|
| 119 | * デストラクタ. |
|---|
| 120 | * |
|---|
| 121 | * @return void |
|---|
| 122 | */ |
|---|
| 123 | function destroy() { |
|---|
| 124 | $this->objLog->end(); |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | /** |
|---|
| 128 | * DBから認証キーを取得する |
|---|
| 129 | * 無い場合はnullを返す |
|---|
| 130 | * |
|---|
| 131 | * @param void |
|---|
| 132 | * @return string|null 認証キー |
|---|
| 133 | */ |
|---|
| 134 | function getPublicKey() { |
|---|
| 135 | $table = 'dtb_ownersstore_settings'; |
|---|
| 136 | $col = 'public_key'; |
|---|
| 137 | |
|---|
| 138 | $objQuery = new SC_Query(); |
|---|
| 139 | |
|---|
| 140 | $arrRet = $objQuery->select($col, $table, $where); |
|---|
| 141 | |
|---|
| 142 | if (isset($arrRet[0]['public_key'])) { |
|---|
| 143 | return $arrRet[0]['public_key']; |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | return null; |
|---|
| 147 | } |
|---|
| 148 | } |
|---|
| 149 | ?> |
|---|