You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.4 KiB
PHTML
51 lines
1.4 KiB
PHTML
|
6 years ago
|
<?php
|
||
|
|
|
||
|
|
namespace App\Middleware;
|
||
|
|
|
||
|
|
use App\Services\Config;
|
||
|
|
use App\Models\Node;
|
||
|
|
use App\Services\MalioConfig;
|
||
|
|
|
||
|
|
class Mod_Mu
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* @param \Slim\Http\Request $request
|
||
|
|
* @param \Slim\Http\Response $response
|
||
|
|
* @param callable $next
|
||
|
|
*
|
||
|
|
* @return \Slim\Http\Response
|
||
|
|
*/
|
||
|
|
public function __invoke($request, $response, $next)
|
||
|
|
{
|
||
|
|
$key = $request->getQueryParam('key');
|
||
|
|
if ($key === null) {
|
||
|
|
return $response->withjson([
|
||
|
|
'ret' => 0,
|
||
|
|
'data' => 'Your key is null.'
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
|
||
|
|
$keys = Config::getMuKey();
|
||
|
|
$auth = in_array($key, $keys);
|
||
|
|
|
||
|
|
if ($auth == false) {
|
||
|
|
$res['ret'] = 0;
|
||
|
|
$res['data'] = 'token is invalid';
|
||
|
|
$response->getBody()->write(json_encode($res));
|
||
|
|
return $response;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (Config::get('checkNodeIp') === true){
|
||
|
|
$node = Node::where('node_ip', 'LIKE', $_SERVER['REMOTE_ADDR'] . '%')->first();
|
||
|
|
if ($auth === false || ($node === null && $_SERVER['REMOTE_ADDR'] != '127.0.0.1')) {
|
||
|
|
return $response->withJson([
|
||
|
|
'ret' => 0,
|
||
|
|
'data' => 'Token or IP is invalid. Now, your IP address is ' . $_SERVER['REMOTE_ADDR']
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return $next($request, $response);
|
||
|
|
}
|
||
|
|
}
|