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\Annotation\Component; |
28
|
|
|
use Eccube\Annotation\Inject; |
29
|
|
|
use Eccube\Application; |
30
|
|
|
use Eccube\Common\Constant; |
31
|
|
|
use Eccube\Controller\AbstractController; |
32
|
|
|
use Eccube\Form\Type\Admin\SecurityType; |
33
|
|
|
use Eccube\Util\Str; |
34
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
35
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
36
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
37
|
|
|
use Symfony\Component\Finder\Finder; |
38
|
|
|
use Symfony\Component\Form\FormFactory; |
39
|
|
|
use Symfony\Component\HttpFoundation\Request; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @Component |
43
|
|
|
* @Route(service=SecurityController::class) |
44
|
|
|
*/ |
45
|
|
|
class SecurityController extends AbstractController |
46
|
|
|
{ |
47
|
|
|
/** |
48
|
|
|
* @Inject("config") |
49
|
|
|
* @var array |
50
|
|
|
*/ |
51
|
|
|
protected $appConfig; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @Inject("form.factory") |
55
|
|
|
* @var FormFactory |
56
|
|
|
*/ |
57
|
|
|
protected $formFactory; |
58
|
|
|
|
59
|
|
|
/** |
|
|
|
|
60
|
|
|
* @Route("/{_admin}/setting/system/security", name="admin_setting_system_security") |
61
|
|
|
* @Template("Setting/System/security.twig") |
62
|
|
|
*/ |
|
|
|
|
63
|
|
|
public function index(Application $app, Request $request) |
64
|
|
|
{ |
65
|
|
|
|
66
|
|
|
$builder = $this->formFactory->createBuilder(SecurityType::class); |
67
|
|
|
$form = $builder->getForm(); |
68
|
|
|
|
69
|
|
|
if ('POST' === $request->getMethod()) { |
|
|
|
|
70
|
|
|
|
71
|
|
|
$form->handleRequest($request); |
72
|
|
|
|
73
|
|
|
if ($form->isValid()) { |
74
|
|
|
$data = $form->getData(); |
75
|
|
|
|
76
|
|
|
// 現在のセキュリティ情報を更新 |
77
|
|
|
$adminRoot = $this->appConfig['admin_route']; |
78
|
|
|
|
79
|
|
|
$configFile = $this->appConfig['root_dir'].'/app/config/eccube/config.php'; |
80
|
|
|
$config = require $configFile; |
81
|
|
|
|
82
|
|
|
// trim処理 |
83
|
|
|
$allowHost = Str::convertLineFeed($data['admin_allow_host']); |
84
|
|
|
if (empty($allowHost)) { |
85
|
|
|
$config['admin_allow_host'] = null; |
86
|
|
|
} else { |
87
|
|
|
$config['admin_allow_host'] = explode("\n", $allowHost); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
if ($data['force_ssl']) { |
91
|
|
|
// SSL制限にチェックをいれた場合、https経由で接続されたか確認 |
92
|
|
|
if ($request->isSecure()) { |
93
|
|
|
// httpsでアクセスされたらSSL制限をチェック |
94
|
|
|
$config['force_ssl'] = Constant::ENABLED; |
95
|
|
|
} else { |
96
|
|
|
// httpから変更されたらfalseのまま |
97
|
|
|
$config['force_ssl'] = Constant::DISABLED; |
98
|
|
|
$data['force_ssl'] = (bool)Constant::DISABLED; |
|
|
|
|
99
|
|
|
} |
100
|
|
|
} else { |
101
|
|
|
$config['force_ssl'] = Constant::DISABLED; |
102
|
|
|
} |
103
|
|
|
$form = $builder->getForm(); |
104
|
|
|
$form->setData($data); |
105
|
|
|
|
106
|
|
|
file_put_contents($configFile, sprintf('<?php return %s', var_export($config, true)).';'); |
107
|
|
|
|
108
|
|
|
// ルーティングのキャッシュを削除 |
109
|
|
|
$cacheDir = $this->appConfig['root_dir'].'/app/cache/routing'; |
110
|
|
|
if (file_exists($cacheDir)) { |
111
|
|
|
$finder = Finder::create()->in($cacheDir); |
112
|
|
|
$filesystem = new Filesystem(); |
113
|
|
|
$filesystem->remove($finder); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
if ($adminRoot != $data['admin_route_dir']) { |
117
|
|
|
// admin_routeが変更されればpath.phpを更新 |
118
|
|
|
$pathFile = $this->appConfig['root_dir'].'/app/config/eccube/path.php'; |
119
|
|
|
$config = require $pathFile; |
120
|
|
|
$config['admin_route'] = $data['admin_route_dir']; |
121
|
|
|
|
122
|
|
|
file_put_contents($pathFile, sprintf('<?php return %s', var_export($config, true)).';'); |
123
|
|
|
|
124
|
|
|
$app->addSuccess('admin.system.security.route.dir.complete', 'admin'); |
125
|
|
|
|
126
|
|
|
// ログアウト |
127
|
|
|
$this->getSecurity($app)->setToken(null); |
128
|
|
|
|
129
|
|
|
// 管理者画面へ再ログイン |
130
|
|
|
return $app->redirect($request->getBaseUrl().'/'.$config['admin_route']); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
$app->addSuccess('admin.system.security.save.complete', 'admin'); |
134
|
|
|
|
|
|
|
|
135
|
|
|
} |
136
|
|
|
} else { |
137
|
|
|
// セキュリティ情報の取得 |
138
|
|
|
$form->get('admin_route_dir')->setData($this->appConfig['admin_route']); |
139
|
|
|
$allowHost = $this->appConfig['admin_allow_host']; |
140
|
|
|
if (count($allowHost) > 0) { |
141
|
|
|
$form->get('admin_allow_host')->setData(Str::convertLineFeed(implode("\n", $allowHost))); |
142
|
|
|
} |
143
|
|
|
$form->get('force_ssl')->setData((bool)$this->appConfig['force_ssl']); |
|
|
|
|
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
return [ |
147
|
|
|
'form' => $form->createView(), |
148
|
|
|
]; |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|