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\Form\Type\Admin; |
26
|
|
|
|
27
|
|
|
use Symfony\Component\Form\AbstractType; |
28
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
29
|
|
|
use Symfony\Component\Form\FormError; |
30
|
|
|
use Symfony\Component\Form\FormEvents; |
31
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
32
|
|
|
|
33
|
|
|
class SecurityType extends AbstractType |
34
|
|
|
{ |
35
|
|
|
private $app; |
36
|
|
|
private $config; |
37
|
|
|
|
38
|
663 |
|
public function __construct($app) |
|
|
|
|
39
|
|
|
{ |
40
|
663 |
|
$this->app = $app; |
41
|
663 |
|
$this->config = $app['config']; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* {@inheritdoc} |
46
|
|
|
*/ |
47
|
7 |
|
public function buildForm(FormBuilderInterface $builder, array $options) |
48
|
|
|
{ |
49
|
7 |
|
$app = $this->app; |
50
|
|
|
$builder |
51
|
7 |
|
->add('admin_route_dir', 'text', array( |
52
|
7 |
|
'label' => 'ディレクトリ名', |
53
|
|
|
'constraints' => array( |
54
|
7 |
|
new Assert\NotBlank(), |
55
|
7 |
|
new Assert\Length(array('max' => $this->config['stext_len'])), |
56
|
7 |
|
new Assert\Regex(array( |
57
|
7 |
|
'pattern' => "/^[0-9a-zA-Z]+$/", |
58
|
|
|
)), |
59
|
|
|
), |
60
|
|
|
)) |
61
|
7 |
|
->add('admin_allow_host', 'textarea', array( |
62
|
7 |
|
'required' => false, |
63
|
7 |
|
'label' => 'IP制限', |
64
|
|
|
'constraints' => array( |
65
|
7 |
|
new Assert\Length(array('max' => $this->config['stext_len'])), |
66
|
|
|
), |
67
|
|
|
)) |
68
|
7 |
|
->add('force_ssl', 'checkbox', array( |
69
|
7 |
|
'label' => 'SSLを強制', |
70
|
|
|
'required' => false, |
71
|
|
|
)) |
72
|
7 |
View Code Duplication |
->addEventListener(FormEvents::POST_SUBMIT, function ($event) use($app) { |
|
|
|
|
73
|
6 |
|
$form = $event->getForm(); |
74
|
6 |
|
$data = $form->getData(); |
75
|
|
|
|
76
|
6 |
|
$ips = preg_split("/\R/", $data['admin_allow_host'], null, PREG_SPLIT_NO_EMPTY); |
77
|
|
|
|
78
|
6 |
|
foreach($ips as $ip) { |
79
|
4 |
|
$errors = $app['validator']->validateValue($ip, array( |
80
|
4 |
|
new Assert\Ip(), |
81
|
|
|
) |
82
|
|
|
); |
83
|
4 |
|
if ($errors->count() != 0) { |
84
|
6 |
|
$form['admin_allow_host']->addError(new FormError($ip . 'はIPv4アドレスではありません。')); |
|
|
|
|
85
|
|
|
} |
86
|
|
|
} |
87
|
7 |
|
}) |
88
|
|
|
; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* {@inheritdoc} |
93
|
|
|
*/ |
94
|
663 |
|
public function getName() |
95
|
|
|
{ |
96
|
663 |
|
return 'admin_security'; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|