1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Lioo19\Controller; |
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
|
|
|
* |
14
|
|
|
* @SuppressWarnings(PHPMD.TooManyPublicMethods) |
15
|
|
|
*/ |
16
|
|
|
class IpTestController implements ContainerInjectableInterface |
17
|
|
|
{ |
18
|
|
|
use ContainerInjectableTrait; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* This is the index method action, it handles: |
22
|
|
|
* ANY METHOD mountpoint |
23
|
|
|
* ANY METHOD mountpoint/ |
24
|
|
|
* ANY METHOD mountpoint/index |
25
|
|
|
* |
26
|
|
|
* @return string |
27
|
|
|
*/ |
28
|
1 |
|
public function indexAction() : object |
29
|
|
|
{ |
30
|
1 |
|
$page = $this->di->get("page"); |
31
|
1 |
|
$request = $this->di->get("request"); |
32
|
1 |
|
$ipDefault = $this->di->get("ipdefault"); |
33
|
1 |
|
$usersIp = $ipDefault->getDefaultIp($request); |
34
|
|
|
|
35
|
|
|
$data = [ |
36
|
1 |
|
"defaultIp" => $usersIp, |
37
|
|
|
]; |
38
|
|
|
|
39
|
|
|
//MAPPEN inte url |
40
|
1 |
|
$page->add("ip/iptest", $data); |
41
|
|
|
|
42
|
1 |
|
return $page->render([ |
43
|
1 |
|
"title" => __METHOD__, |
44
|
|
|
]); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* POST for ip, redirects to result-page |
49
|
|
|
* Sends the ip-adress with post and redirects |
50
|
|
|
* |
51
|
|
|
* @return object |
52
|
|
|
*/ |
53
|
1 |
|
public function validationActionPost() : object |
54
|
|
|
{ |
55
|
|
|
|
56
|
1 |
|
$request = $this->di->get("request"); |
57
|
1 |
|
$page = $this->di->get("page"); |
58
|
1 |
|
$validation = $this->di->get("iptest"); |
59
|
1 |
|
$title = "Validera IP"; |
60
|
|
|
//request to get the posted information |
61
|
1 |
|
$userip = $request->getPost("ipinput", null); |
62
|
|
|
|
63
|
|
|
// $validation = new IpTest(); |
64
|
1 |
|
$validation->setInput($userip); |
65
|
1 |
|
$ip4 = $validation->ip4test(); |
66
|
1 |
|
$ip6 = $validation->ip6test(); |
67
|
|
|
|
68
|
1 |
|
if ($ip6 || $ip4) { |
69
|
1 |
|
$hostname = gethostbyaddr($userip); |
70
|
1 |
|
$geoInfo = $this->getGeo($userip); |
71
|
|
|
} else { |
72
|
1 |
|
$hostname = "Ej korrekt ip"; |
73
|
1 |
|
$geoInfo = "Inget att visa"; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
$data = [ |
77
|
1 |
|
"ip" => $userip, |
78
|
1 |
|
"ip4" => $ip4, |
79
|
1 |
|
"ip6" => $ip6, |
80
|
1 |
|
"hostname" => $hostname, |
81
|
1 |
|
"geoInfo" => $geoInfo, |
82
|
|
|
]; |
83
|
|
|
|
84
|
1 |
|
$page->add("ip/validation", $data); |
85
|
|
|
|
86
|
1 |
|
return $page->render([ |
87
|
1 |
|
"title" => $title, |
88
|
|
|
]); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function getGeo($userip) |
92
|
|
|
{ |
93
|
|
|
$geo = $this->di->get("ipgeo"); |
94
|
|
|
$geo->setInput($userip); |
95
|
|
|
$geoInfo = $geo->fetchGeo(); |
96
|
|
|
|
97
|
|
|
return $geoInfo; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|