1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of EC-CUBE |
4
|
|
|
* |
5
|
|
|
* Copyright(c) 2000-2015 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
|
|
|
|
25
|
|
|
namespace Eccube\Controller\Admin\Setting\System; |
26
|
|
|
|
27
|
|
|
use Eccube\Application; |
28
|
|
|
use Eccube\Common\Constant; |
29
|
|
|
use Eccube\Controller\AbstractController; |
30
|
|
|
use Eccube\Util\Str; |
31
|
|
|
use Symfony\Component\HttpFoundation\Request; |
32
|
|
|
use Symfony\Component\Yaml\Yaml; |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
class SecurityController extends AbstractController |
|
|
|
|
36
|
|
|
{ |
37
|
|
|
public function index(Application $app, Request $request) |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
|
40
|
|
|
$builder = $app['form.factory']->createBuilder('admin_security'); |
41
|
|
|
$form = $builder->getForm(); |
42
|
|
|
|
43
|
|
|
if ('POST' === $request->getMethod()) { |
|
|
|
|
44
|
|
|
|
45
|
|
|
$form->handleRequest($request); |
46
|
|
|
|
47
|
|
|
if ($form->isValid()) { |
48
|
|
|
$data = $form->getData(); |
49
|
|
|
|
50
|
|
|
// 現在のセキュリティ情報を更新 |
51
|
|
|
$adminRoot = $app['config']['admin_route']; |
52
|
|
|
|
53
|
|
|
$configFile = $app['config']['root_dir'].'/app/config/eccube/config'; |
54
|
|
View Code Duplication |
if (file_exists($configFile.'.php')) { |
|
|
|
|
55
|
|
|
$config = require $configFile.'.php'; |
56
|
|
|
} elseif (file_exists($configFile.'.yml')) { |
57
|
|
|
$config = Yaml::parse(file_get_contents($configFile.'.yml')); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
// trim処理 |
61
|
|
|
$allowHost = Str::convertLineFeed($data['admin_allow_host']); |
62
|
|
|
if (empty($allowHost)) { |
63
|
|
|
$config['admin_allow_host'] = null; |
|
|
|
|
64
|
|
|
} else { |
65
|
|
|
$config['admin_allow_host'] = explode("\n", $allowHost); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
if ($data['force_ssl']) { |
69
|
|
|
// SSL制限にチェックをいれた場合、https経由で接続されたか確認 |
70
|
|
|
if ($request->isSecure()) { |
71
|
|
|
// httpsでアクセスされたらSSL制限をチェック |
72
|
|
|
$config['force_ssl'] = Constant::ENABLED; |
73
|
|
|
} else { |
74
|
|
|
// httpから変更されたらfalseのまま |
75
|
|
|
$config['force_ssl'] = Constant::DISABLED; |
76
|
|
|
$data['force_ssl'] = (bool) Constant::DISABLED; |
77
|
|
|
} |
78
|
|
|
} else { |
79
|
|
|
$config['force_ssl'] = Constant::DISABLED; |
80
|
|
|
} |
81
|
|
|
$form = $builder->getForm(); |
82
|
|
|
$form->setData($data); |
83
|
|
|
|
84
|
|
View Code Duplication |
if (file_exists($configFile.'.php')) { |
|
|
|
|
85
|
|
|
file_put_contents($configFile.'.php', sprintf('<?php return %s', var_export($config, true)).';'); |
86
|
|
|
} |
87
|
|
|
if (file_exists($configFile.'.yml')) { |
88
|
|
|
file_put_contents($configFile.'.yml', Yaml::dump($config)); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
if ($adminRoot != $data['admin_route_dir']) { |
92
|
|
|
// admin_routeが変更されればpath.(yml|php)を更新 |
93
|
|
|
$pathFile = $app['config']['root_dir'].'/app/config/eccube/path'; |
94
|
|
|
|
95
|
|
View Code Duplication |
if (file_exists($pathFile.'.php')) { |
|
|
|
|
96
|
|
|
$config = require $pathFile.'.php'; |
97
|
|
|
} elseif (file_exists($pathFile.'.yml')) { |
98
|
|
|
$config = Yaml::parse(file_get_contents($pathFile.'.yml')); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
$config['admin_route'] = $data['admin_route_dir']; |
102
|
|
|
|
103
|
|
View Code Duplication |
if (file_exists($pathFile.'.php')) { |
|
|
|
|
104
|
|
|
file_put_contents($pathFile.'.php', sprintf('<?php return %s', var_export($config, true)).';'); |
105
|
|
|
} |
106
|
|
|
if (file_exists($pathFile.'.yml')) { |
107
|
|
|
file_put_contents($pathFile.'.yml', Yaml::dump($config)); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
$app->addSuccess('admin.system.security.route.dir.complete', 'admin'); |
111
|
|
|
|
112
|
|
|
// ログアウト |
113
|
|
|
$this->getSecurity($app)->setToken(null); |
114
|
|
|
|
115
|
|
|
// 管理者画面へ再ログイン |
116
|
|
|
return $app->redirect($request->getBaseUrl().'/'.$config['admin_route']); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
$app->addSuccess('admin.system.security.save.complete', 'admin'); |
120
|
|
|
|
|
|
|
|
121
|
|
|
} |
122
|
|
|
} else { |
123
|
|
|
// セキュリティ情報の取得 |
124
|
|
|
$form->get('admin_route_dir')->setData($app['config']['admin_route']); |
125
|
|
|
$allowHost = $app['config']['admin_allow_host']; |
126
|
|
|
if (count($allowHost) > 0) { |
127
|
|
|
$form->get('admin_allow_host')->setData(Str::convertLineFeed(implode("\n", $allowHost))); |
128
|
|
|
} |
129
|
|
|
$form->get('force_ssl')->setData((bool)$app['config']['force_ssl']); |
|
|
|
|
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
return $app->render('Setting/System/security.twig', array( |
133
|
|
|
'form' => $form->createView(), |
134
|
|
|
)); |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|