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

Revision 22856, 7.4 KB checked in by Seasoft, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.13.0)

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