source: branches/version-2_13_0/data/class/pages/admin/system/LC_Page_Admin_System_AdminArea.php @ 23126

Revision 23126, 7.3 KB checked in by m_uehara, 11 years ago (diff)

#2348 r23116 - r23125 をマージ

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