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

Revision 22567, 7.5 KB checked in by shutta, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.12.4)
Zend Framework PHP 標準コーディング規約のコーディングスタイルへ準拠。
classおよびfunctionの開始波括弧「{」のスタイルを修正。

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