1
|
|
|
<?php |
2
|
|
|
namespace Anax\Controller; |
3
|
|
|
|
4
|
|
|
use Anax\Commons\ContainerInjectableInterface; |
5
|
|
|
|
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 JSON 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
|
|
|
class ApiExternalController implements ContainerInjectableInterface |
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
use ContainerInjectableTrait; |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string $db a sample member variable that gets initialised |
28
|
|
|
*/ |
29
|
|
|
// private $db = "not active"; |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* This is the index method action, it handles: |
35
|
|
|
* ANY METHOD mountpoint |
36
|
|
|
* ANY METHOD mountpoint/ |
37
|
|
|
* ANY METHOD mountpoint/index |
38
|
|
|
* |
39
|
|
|
* @return string |
40
|
|
|
*/ |
41
|
1 |
|
public function indexAction() : object |
42
|
|
|
{ |
43
|
1 |
|
$title = " | Ip Json API"; |
44
|
1 |
|
$page = $this->di->get("page"); |
45
|
1 |
|
$page->add( |
46
|
1 |
|
"anax/v2/ip-validator/apiExternal", |
47
|
|
|
[ |
48
|
1 |
|
"header" => "hello", |
49
|
|
|
"text" => "text", |
50
|
|
|
] |
51
|
|
|
); |
52
|
|
|
|
53
|
|
|
|
54
|
1 |
|
return $page->render([ |
55
|
1 |
|
"title" => "$title" |
56
|
|
|
]); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
|
60
|
1 |
|
public function externalInfoAction() : object |
61
|
|
|
{ |
62
|
|
|
|
63
|
1 |
|
$title = " | Ip info"; |
64
|
1 |
|
$page = $this->di->get("page"); |
65
|
1 |
|
$page->add("anax/v2/ip-validator/externalInfo", [ |
66
|
1 |
|
"ip" => $this->di->get("request")->getGet("ip"), |
67
|
1 |
|
"type" => $this->di->get("request")->getGet("type"), |
68
|
1 |
|
"country" => $this->di->get("request")->getGet("country"), |
69
|
1 |
|
"latitude" => $this->di->get("request")->getGet("latitude"), |
70
|
1 |
|
"longitude" => $this->di->get("request")->getGet("longitude") |
71
|
|
|
]); |
72
|
|
|
|
73
|
|
|
|
74
|
1 |
|
return $page->render([ |
75
|
1 |
|
"title" => "$title" |
76
|
|
|
]); |
77
|
|
|
} |
78
|
|
|
|
79
|
1 |
|
public function validateipActionGet($ipAdress = null) : void |
80
|
|
|
{ |
81
|
1 |
|
$keykey = $this->di->get("apikey"); |
82
|
1 |
|
$ipInfo = array(); |
83
|
|
|
// if ($this->di->get("request")->getGet("ip")) { |
84
|
|
|
// $ipInfo["IP"] = $this->di->get("request")->getGet("ip") ?? $ipAdress; |
85
|
|
|
// // $ipAdress = $this->di->request->getGet("ip"); |
86
|
|
|
// } else { |
87
|
|
|
// $ipInfo["IP"] = $ipAdress; |
88
|
|
|
// } |
89
|
1 |
|
$ipInfo["IP"] = $this->di->get("request")->getGet("ip") ?? $ipAdress; |
90
|
1 |
|
$apiEx = $this->di->get("ExternalApi"); |
91
|
1 |
|
$res = $apiEx->validateipActionGet($ipInfo["IP"], $keykey); |
92
|
|
|
|
93
|
1 |
|
$obj = json_decode($res); |
94
|
|
|
|
95
|
|
|
|
96
|
|
|
|
97
|
1 |
|
$this->di->get("response")->redirect("apiExternal/externalInfo/?ip=" . $obj->ip |
98
|
1 |
|
. "&type=" . $obj->type . "&country=" . $obj->country_name |
99
|
1 |
|
. "&longitude=" . $obj->longitude . "&latitude=" . $obj->latitude); |
100
|
1 |
|
} |
101
|
|
|
} |
102
|
|
|
|