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

Revision 22857, 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     * @return void
114     */
115    function destroy()
116    {
117        parent::destroy();
118    }
119
120    /**
121     * パラメーター初期化.
122     *
123     * @param object $objFormParam
124     * @param array  $arrParams  $_POST値
125     * @return void
126     */
127    function initParam(&$objFormParam, &$arrParams)
128    {
129        $objFormParam->addParam('ディレクトリ名', 'admin_dir', ID_MAX_LEN, 'a', array('EXIST_CHECK', 'SPTAB_CHECK', 'ALNUM_CHECK'));
130        $objFormParam->addParam('SSL制限', 'admin_force_ssl', 1, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
131        $objFormParam->addParam('IP制限', 'admin_allow_hosts', LTEXT_LEN, 'a', array('IP_CHECK', 'MAX_LENGTH_CHECK'));
132        $objFormParam->setParam($arrParams);
133        $objFormParam->convParam();
134    }
135
136    /**
137     * 管理機能ディレクトリのチェック.
138     *
139     * @param array  $arrForm  $this->arrForm値
140     * @param array  $arrErr   エラーがあった項目用配列
141     * @return void
142     */
143    function lfCheckAdminArea(&$arrForm, &$arrErr)
144    {
145        $admin_dir = trim($arrForm['admin_dir']) . '/';
146
147        $installData = file(CONFIG_REALFILE, FILE_IGNORE_NEW_LINES);
148        foreach ($installData as $key=>$line) {
149            if (strpos($line,'ADMIN_DIR') !== false and ADMIN_DIR != $admin_dir) {
150                //既存ディレクトリのチェック
151                if (file_exists(HTML_REALDIR . $admin_dir) and $admin_dir != 'admin/') {
152                    $arrErr['admin_dir'] .= ROOT_URLPATH . $admin_dir . 'は既に存在しています。別のディレクトリ名を指定してください。';
153                }
154                //権限チェック
155                if (!is_writable(HTML_REALDIR . ADMIN_DIR)) {
156                    $arrErr['admin_dir'] .= ROOT_URLPATH . ADMIN_DIR . 'のディレクトリ名を変更する権限がありません。';
157                }
158            }
159        }
160    }
161
162    //管理機能ディレクトリのリネームと CONFIG_REALFILE の変更
163    function lfUpdateAdminData(&$arrForm)
164    {
165        $admin_dir = trim($arrForm['admin_dir']) . '/';
166        $admin_force_ssl = 'false';
167        if ($arrForm['admin_force_ssl'] == 1) {
168            $admin_force_ssl = 'true';
169        }
170        $admin_allow_hosts = explode("\n", $arrForm['admin_allow_hosts']);
171        foreach ($admin_allow_hosts as $key=>$host) {
172            $host = trim($host);
173            if (strlen($host) >= 8) {
174                $admin_allow_hosts[$key] = $host;
175            } else {
176                unset($admin_allow_hosts[$key]);
177            }
178        }
179        $admin_allow_hosts = serialize($admin_allow_hosts);
180
181        // CONFIG_REALFILE の書き換え
182        $installData = file(CONFIG_REALFILE, FILE_IGNORE_NEW_LINES);
183        $diff = 0;
184        foreach ($installData as $key=>$line) {
185            if (strpos($line,'ADMIN_DIR') !== false and ADMIN_DIR != $admin_dir) {
186                $installData[$key] = 'define("ADMIN_DIR", "' . $admin_dir . '");';
187                //管理機能ディレクトリのリネーム
188                if (!rename(HTML_REALDIR . ADMIN_DIR,HTML_REALDIR . $admin_dir)) {
189                    $this->arrErr['admin_dir'] .= ROOT_URLPATH . ADMIN_DIR . 'のディレクトリ名を変更できませんでした。';
190                    return false;
191                }
192                $diff ++;
193            }
194
195            if (strpos($line,'ADMIN_FORCE_SSL') !== false) {
196                $installData[$key] = 'define("ADMIN_FORCE_SSL", ' . $admin_force_ssl.');';
197                $diff ++;
198            }
199            if (strpos($line,'ADMIN_ALLOW_HOSTS') !== false and ADMIN_ALLOW_HOSTS != $admin_allow_hosts) {
200                $installData[$key] = "define('ADMIN_ALLOW_HOSTS', '" . $admin_allow_hosts."');";
201                $diff ++;
202            }
203        }
204
205        if ($diff > 0) {
206            $fp = fopen(CONFIG_REALFILE,'wb');
207            $installData = implode("\n",$installData);
208            echo $installData;
209            fwrite($fp, $installData);
210            fclose($fp);
211        }
212
213        return true;
214    }
215}
Note: See TracBrowser for help on using the repository browser.