|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Blixter\IpValidate; |
|
4
|
|
|
|
|
5
|
|
|
use Anax\Commons\ContainerInjectableInterface; |
|
6
|
|
|
use Anax\Commons\ContainerInjectableTrait; |
|
7
|
|
|
|
|
8
|
|
|
// use Anax\Route\Exception\ForbiddenException; |
|
9
|
|
|
// use Anax\Route\Exception\NotFoundException; |
|
10
|
|
|
// use Anax\Route\Exception\InternalErrorException; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* A sample controller to show how a controller class can be implemented. |
|
14
|
|
|
* The controller will be injected with $di if implementing the interface |
|
15
|
|
|
* ContainerInjectableInterface, like this sample class does. |
|
16
|
|
|
* The controller is mounted on a particular route and can then handle all |
|
17
|
|
|
* requests for that mount point. |
|
18
|
|
|
* |
|
19
|
|
|
* @SuppressWarnings(PHPMD.TooManyPublicMethods) |
|
20
|
|
|
*/ |
|
21
|
|
|
class IpController implements ContainerInjectableInterface |
|
22
|
|
|
{ |
|
23
|
|
|
use ContainerInjectableTrait; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* This is the index method action, it handles: |
|
27
|
|
|
* GET METHOD mountpoint |
|
28
|
|
|
* GET METHOD mountpoint/ |
|
29
|
|
|
* GET METHOD mountpoint/index |
|
30
|
|
|
* |
|
31
|
|
|
* @return object |
|
32
|
|
|
*/ |
|
33
|
1 |
|
public function indexActionGet(): object |
|
34
|
|
|
{ |
|
35
|
|
|
// Add content as a view and then render the page |
|
36
|
1 |
|
$page = $this->di->get("page"); |
|
37
|
1 |
|
$title = "Validera en Ip-adress"; |
|
38
|
|
|
|
|
39
|
|
|
$data = [ |
|
40
|
1 |
|
"title" => $title, |
|
41
|
|
|
]; |
|
42
|
|
|
|
|
43
|
1 |
|
$page->add("blixter/ipvalidate/header", $data); |
|
44
|
1 |
|
$page->add("blixter/ipvalidate/search-ip", $data); |
|
45
|
|
|
|
|
46
|
|
|
// Deal with the action and return a response. |
|
47
|
1 |
|
return $page->render([ |
|
48
|
1 |
|
"title" => $title, |
|
49
|
|
|
]); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* This is the index method action, it handles: |
|
54
|
|
|
* POST METHOD mountpoint |
|
55
|
|
|
* POST METHOD mountpoint/ |
|
56
|
|
|
* POST METHOD mountpoint/index |
|
57
|
|
|
* |
|
58
|
|
|
* @return object |
|
59
|
|
|
*/ |
|
60
|
2 |
|
public function indexActionPost(): object |
|
61
|
|
|
{ |
|
62
|
|
|
// Add content as a view and then render the page |
|
63
|
2 |
|
$page = $this->di->get("page"); |
|
64
|
2 |
|
$request = $this->di->get("request"); |
|
65
|
2 |
|
$title = "Valideringsresultat"; |
|
66
|
2 |
|
$ipaddress = $request->getPost("ipaddress"); |
|
67
|
|
|
// Using ipValidation class from $di. |
|
68
|
2 |
|
$ipValidation = $this->di->get("ipvalidation"); |
|
69
|
|
|
|
|
70
|
2 |
|
$isIpValid = $ipValidation->isIpValid($ipaddress); |
|
71
|
|
|
|
|
72
|
2 |
|
if ($isIpValid) { |
|
73
|
1 |
|
$protocol = $ipValidation->getProtocol($ipaddress); |
|
74
|
1 |
|
$domain = $ipValidation->getdomain($ipaddress); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
$data = [ |
|
78
|
2 |
|
"title" => $title, |
|
79
|
2 |
|
"ipaddress" => $ipaddress, |
|
80
|
2 |
|
"isIpValid" => $isIpValid, |
|
81
|
2 |
|
"protocol" => $protocol ?? null, |
|
82
|
2 |
|
"domain" => $domain ?? null, |
|
83
|
|
|
]; |
|
84
|
|
|
|
|
85
|
2 |
|
$page->add("blixter/ipvalidate/header", $data); |
|
86
|
2 |
|
$page->add("blixter/ipvalidate/ip-result", $data); |
|
87
|
|
|
|
|
88
|
|
|
// Deal with the action and return a response. |
|
89
|
2 |
|
return $page->render([ |
|
90
|
2 |
|
"title" => $title, |
|
91
|
|
|
]); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|