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 IpTestJSONController 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 array |
||
27 | */ |
||
28 | 2 | public function indexActionGet() : array |
|
29 | { |
||
30 | 2 | $request = $this->di->get("request"); |
|
31 | //request to get GET-info |
||
32 | 2 | $userip = $request->getGet("ip", "Ingen ip angiven"); |
|
33 | |||
34 | 2 | if ($userip) { |
|
35 | 2 | $validation = $this->di->get("iptest"); |
|
36 | 2 | $validation->setInput($userip); |
|
37 | 2 | $ip4 = $validation->ip4test(); |
|
38 | 2 | $ip6 = $validation->ip6test(); |
|
39 | } |
||
40 | |||
41 | 2 | if ($ip6 || $ip4) { |
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
![]() Comprehensibility
Best Practice
introduced
by
|
|||
42 | 1 | $hostname = gethostbyaddr($userip); |
|
43 | 1 | $geoInfo = $this->getGeo($userip); |
|
44 | } else { |
||
45 | 1 | $hostname = "Ej korrekt ip"; |
|
46 | 1 | $geoInfo = "Inget att visa"; |
|
47 | } |
||
48 | |||
49 | $data = [ |
||
50 | 2 | "ip" => $userip, |
|
51 | 2 | "ip4" => $ip4, |
|
52 | 2 | "ip6" => $ip6, |
|
53 | 2 | "host" => $hostname, |
|
54 | 2 | "geoInfo" => $geoInfo, |
|
55 | ]; |
||
56 | |||
57 | 2 | return [$data]; |
|
58 | } |
||
59 | |||
60 | public function getGeo($userip) |
||
61 | { |
||
62 | $geo = $this->di->get("ipgeo"); |
||
63 | $geo->setInput($userip); |
||
64 | $geoInfo = $geo->fetchGeo(); |
||
65 | |||
66 | return $geoInfo; |
||
67 | } |
||
68 | } |
||
69 |