source: branches/version-2_12-dev/data/class/pages/admin/system/LC_Page_Admin_System_AdminArea.php @ 21689

Revision 21689, 7.8 KB checked in by h_yoshimoto, 12 years ago (diff)

#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_System_AdminArea 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 = 'system/adminarea.tpl';
47        $this->tpl_subno = 'adminarea';
48        $this->tpl_mainno = 'system';
49        $this->tpl_maintitle = 'システム設定';
50        $this->tpl_subtitle = '管理画面設定';
51        $this->tpl_enable_ssl = FALSE;
52    }
53
54    /**
55     * Page のプロセス.
56     *
57     * @return void
58     */
59    function process() {
60        $this->action();
61        $this->sendResponse();
62    }
63
64    /**
65     * Page のアクション.
66     *
67     * @return void
68     */
69    function action() {
70        // フックポイント.
71        $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg);
72        $objPlugin->doAction('lc_page_admin_system_adminarea_action_start', array($this));
73
74        if (strpos(HTTPS_URL,'https://') !== FALSE) {
75            $this->tpl_enable_ssl = TRUE;
76        }
77
78        $objFormParam = new SC_FormParam;
79
80        // パラメーターの初期化
81        $this->initParam($objFormParam, $_POST);
82
83        if (count($_POST) > 0) {
84
85            // エラーチェック
86            $arrErr = $objFormParam->checkError();
87
88            $this->arrForm = $objFormParam->getHashArray();
89
90            //設定ファイルの権限チェック
91            if (!is_writable(CONFIG_REALFILE)) {
92                $arrErr['all'] = CONFIG_REALFILE . ' を変更する権限がありません。';
93            }
94
95            //管理画面ディレクトリのチェック
96            $this->lfCheckAdminArea($this->arrForm, $arrErr);
97
98            if (SC_Utils_Ex::isBlank($arrErr) && $this->lfUpdateAdminData($this->arrForm)) {
99
100                $this->tpl_onload = "window.alert('管理機能の設定を変更しました。URLを変更した場合は、新しいURLにアクセスしてください。');";
101            } else {
102                $this->tpl_onload = "window.alert('設定内容に誤りがあります。設定内容を確認してください。');";
103                $this->arrErr = array_merge($arrErr, $this->arrErr);
104            }
105
106        } else {
107
108            $admin_dir = str_replace('/','',ADMIN_DIR);
109            $this->arrForm = array('admin_dir'=>$admin_dir,'admin_force_ssl'=>ADMIN_FORCE_SSL,'admin_allow_hosts'=>'');
110            if (defined('ADMIN_ALLOW_HOSTS')) {
111                $allow_hosts = unserialize(ADMIN_ALLOW_HOSTS);
112                $this->arrForm['admin_allow_hosts'] = implode("\n",$allow_hosts);
113
114            }
115        }
116        // フックポイント.
117        $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg);
118        $objPlugin->doAction('lc_page_admin_system_adminarea_action_end', array($this));
119    }
120
121    /**
122     * デストラクタ.
123     *
124     * @return void
125     */
126    function destroy() {
127        parent::destroy();
128    }
129
130    /**
131     * パラメーター初期化.
132     *
133     * @param object $objFormParam
134     * @param array  $arrParams  $_POST値
135     * @return void
136     */
137    function initParam(&$objFormParam, &$arrParams) {
138
139        $objFormParam->addParam('ディレクトリ名', 'admin_dir', ID_MAX_LEN, 'a', array('EXIST_CHECK', 'SPTAB_CHECK', 'ALNUM_CHECK'));
140        $objFormParam->addParam('SSL制限', 'admin_force_ssl', 1, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
141        $objFormParam->addParam('IP制限', 'admin_allow_hosts', LTEXT_LEN, 'a', array('IP_CHECK', 'MAX_LENGTH_CHECK'));
142        $objFormParam->setParam($arrParams);
143        $objFormParam->convParam();
144
145    }
146
147    /**
148     * 管理機能ディレクトリのチェック.
149     *
150     * @param array  $arrForm  $this->arrForm値
151     * @param array  $arrErr   エラーがあった項目用配列
152     * @return void
153     */
154    function lfCheckAdminArea(&$arrForm, &$arrErr) {
155        $admin_dir = trim($arrForm['admin_dir']).'/';
156
157        $installData = file(CONFIG_REALFILE, FILE_IGNORE_NEW_LINES);
158        foreach ($installData as $key=>$line) {
159            if (strpos($line,'ADMIN_DIR') !== false and ADMIN_DIR != $admin_dir) {
160                //既存ディレクトリのチェック
161                if (file_exists(HTML_REALDIR.$admin_dir) and $admin_dir != 'admin/') {
162                    $arrErr['admin_dir'] .= ROOT_URLPATH.$admin_dir.'は既に存在しています。別のディレクトリ名を指定してください。';
163                }
164                //権限チェック
165                if (!is_writable(HTML_REALDIR . ADMIN_DIR)) {
166                    $arrErr['admin_dir'] .= ROOT_URLPATH.ADMIN_DIR.'のディレクトリ名を変更する権限がありません。';
167                }
168            }
169        }
170    }
171
172    //管理機能ディレクトリのリネームと CONFIG_REALFILE の変更
173    function lfUpdateAdminData(&$arrForm) {
174        $admin_dir = trim($arrForm['admin_dir']).'/';
175        $admin_force_ssl = 'FALSE';
176        if ($arrForm['admin_force_ssl'] == 1) {
177            $admin_force_ssl = 'TRUE';
178        }
179        $admin_allow_hosts = explode("\n",$arrForm['admin_allow_hosts']);
180        foreach ($admin_allow_hosts as $key=>$host) {
181            $host = trim($host);
182            if (strlen($host) >= 8) {
183                $admin_allow_hosts[$key] = $host;
184            } else {
185                unset($admin_allow_hosts[$key]);
186            }
187        }
188        $admin_allow_hosts = serialize($admin_allow_hosts);
189
190        // CONFIG_REALFILE の書き換え
191        $installData = file(CONFIG_REALFILE, FILE_IGNORE_NEW_LINES);
192        $diff = 0;
193        foreach ($installData as $key=>$line) {
194            if (strpos($line,'ADMIN_DIR') !== false and ADMIN_DIR != $admin_dir) {
195                $installData[$key] = 'define("ADMIN_DIR","'.$admin_dir.'");';
196                //管理機能ディレクトリのリネーム
197                if (!rename(HTML_REALDIR.ADMIN_DIR,HTML_REALDIR.$admin_dir)) {
198                    $this->arrErr['admin_dir'] .= ROOT_URLPATH.ADMIN_DIR.'のディレクトリ名を変更できませんでした。';
199                    return false;
200                }
201                $diff ++;
202            }
203
204            if (strpos($line,'ADMIN_FORCE_SSL') !== false) {
205                $installData[$key] = 'define("ADMIN_FORCE_SSL",'.$admin_force_ssl.');';
206                $diff ++;
207            }
208            if (strpos($line,'ADMIN_ALLOW_HOSTS') !== false and ADMIN_ALLOW_HOSTS != $admin_allow_hosts) {
209                $installData[$key] = "define('ADMIN_ALLOW_HOSTS','".$admin_allow_hosts."');";
210                $diff ++;
211            }
212        }
213
214        if ($diff > 0) {
215            $fp = fopen(CONFIG_REALFILE,'wb');
216            $installData = implode("\n",$installData);
217            echo $installData;
218            fwrite($fp, $installData);
219            fclose($fp);
220        }
221        return true;
222    }
223}
Note: See TracBrowser for help on using the repository browser.