1
|
|
|
<?php |
2
|
|
|
namespace Aoe\Varnish\Controller; |
3
|
|
|
|
4
|
|
|
/*************************************************************** |
5
|
|
|
* Copyright notice |
6
|
|
|
* |
7
|
|
|
* (c) 2018 AOE GmbH <[email protected]> |
8
|
|
|
* |
9
|
|
|
* All rights reserved |
10
|
|
|
* |
11
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
12
|
|
|
* free software; you can redistribute it and/or modify |
13
|
|
|
* it under the terms of the GNU General Public License as published by |
14
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
15
|
|
|
* (at your option) any later version. |
16
|
|
|
* |
17
|
|
|
* The GNU General Public License can be found at |
18
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
19
|
|
|
* |
20
|
|
|
* This script is distributed in the hope that it will be useful, |
21
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
22
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23
|
|
|
* GNU General Public License for more details. |
24
|
|
|
* |
25
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
26
|
|
|
***************************************************************/ |
27
|
|
|
|
28
|
|
|
use Aoe\Varnish\Domain\Model\Tag\PageTag; |
29
|
|
|
use Aoe\Varnish\Domain\Model\Tag\Tag; |
30
|
|
|
use Aoe\Varnish\System\Varnish; |
31
|
|
|
use TYPO3\CMS\Core\Messaging\AbstractMessage; |
32
|
|
|
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; |
33
|
|
|
|
34
|
|
|
class BanController extends ActionController |
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* @var Varnish |
38
|
|
|
*/ |
39
|
|
|
private $varnish; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param Varnish $varnish |
43
|
|
|
*/ |
44
|
|
|
public function __construct(Varnish $varnish) |
45
|
|
|
{ |
46
|
|
|
$this->varnish = $varnish; |
47
|
|
|
parent::__construct(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function indexAction() |
51
|
|
|
{ |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function confirmBanTypo3PagesAction() |
55
|
|
|
{ |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function banTypo3PagesAction() |
59
|
|
|
{ |
60
|
|
|
$results = $this->varnish |
61
|
|
|
->banByTag(new PageTag()) |
62
|
|
|
->shutdown(); |
63
|
|
|
|
64
|
|
|
foreach ($results as $result) { |
65
|
|
|
if ($result['success']) { |
66
|
|
|
$this->addFlashMessage($result['reason']); |
67
|
|
|
} else { |
68
|
|
|
$this->addFlashMessage($result['reason'], '', AbstractMessage::ERROR); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
$this->redirect('index'); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param string $tagName |
77
|
|
|
*/ |
78
|
|
|
public function confirmBanTagByNameAction($tagName) |
79
|
|
|
{ |
80
|
|
|
if ($this->isValidTagName($tagName)) { |
81
|
|
|
$this->view->assign('tagName', $tagName); |
82
|
|
|
} else { |
83
|
|
|
$this->redirect('index'); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param string $tagName |
89
|
|
|
*/ |
90
|
|
|
public function banTagByNameAction($tagName) |
91
|
|
|
{ |
92
|
|
|
$results = $this->varnish |
93
|
|
|
->banByTag(new Tag($tagName)) |
94
|
|
|
->shutdown(); |
95
|
|
|
|
96
|
|
|
foreach ($results as $result) { |
97
|
|
|
if ($result['success']) { |
98
|
|
|
$this->addFlashMessage($result['reason']); |
99
|
|
|
} else { |
100
|
|
|
$this->addFlashMessage($result['reason'], '', AbstractMessage::ERROR); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
$this->redirect('index'); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @param string $regex |
108
|
|
|
*/ |
109
|
|
|
public function confirmBanByRegexAction($regex) |
110
|
|
|
{ |
111
|
|
|
if (false === $this->isCriticalRegex($regex)) { |
112
|
|
|
$this->view->assign('regex', $regex); |
113
|
|
|
} else { |
114
|
|
|
$this->redirect('index'); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @param string $regex |
120
|
|
|
*/ |
121
|
|
|
public function banByRegexAction($regex) |
122
|
|
|
{ |
123
|
|
|
$results = $this->varnish |
124
|
|
|
->banByRegex($regex) |
125
|
|
|
->shutdown(); |
126
|
|
|
|
127
|
|
|
foreach ($results as $result) { |
128
|
|
|
if ($result['success']) { |
129
|
|
|
$this->addFlashMessage($result['reason']); |
130
|
|
|
} else { |
131
|
|
|
$this->addFlashMessage($result['reason'], '', AbstractMessage::ERROR); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
$this->redirect('index'); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @param string $regex |
139
|
|
|
* @return bool |
140
|
|
|
*/ |
141
|
|
|
private function isCriticalRegex($regex) |
142
|
|
|
{ |
143
|
|
|
if (strlen($regex) < 6) { |
144
|
|
|
$this->addFlashMessage('Bitte geben Sie einen spezifischeren RegEx ein!', '', AbstractMessage::ERROR); |
145
|
|
|
return true; |
146
|
|
|
} |
147
|
|
|
return false; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @param string $tagName |
152
|
|
|
* @return bool |
153
|
|
|
*/ |
154
|
|
|
private function isValidTagName($tagName) |
155
|
|
|
{ |
156
|
|
|
if (strlen($tagName) < 2) { |
157
|
|
|
$this->addFlashMessage('Bitte geben Sie einen gültigen Tag-Namen ein! ', '', AbstractMessage::ERROR); |
158
|
|
|
return false; |
159
|
|
|
} |
160
|
|
|
return true; |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|