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