| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
namespace Liuch\DmarcSrg; |
| 44 |
|
| 45 |
use Liuch\DmarcSrg\Hosts\Host; |
| 46 |
use Liuch\DmarcSrg\Users\User; |
| 47 |
use Liuch\DmarcSrg\Plugins\PluginManager; |
| 48 |
use Liuch\DmarcSrg\Exception\SoftException; |
| 49 |
use Liuch\DmarcSrg\Exception\RuntimeException; |
| 50 |
|
| 51 |
require realpath(__DIR__ . '/..') . '/init.php'; |
| 52 |
|
| 53 |
if (Core::isJson()) { |
| 54 |
try { |
| 55 |
$core = Core::instance(); |
| 56 |
|
| 57 |
if (Core::requestMethod() == 'GET') { |
| 58 |
$core->auth()->isAllowed(User::LEVEL_USER); |
| 59 |
|
| 60 |
if (isset($_GET['host']) && isset($_GET['fields'])) { |
| 61 |
$host = new Host($_GET['host']); |
| 62 |
$fields = explode(',', trim($_GET['fields'])); |
| 63 |
if (!count($fields) || count(array_diff( |
| 64 |
$fields, |
| 65 |
[ 'main.rdns', 'main.rip', 'stats.reports', 'stats.messages', 'stats.last_report' ] |
| 66 |
))) { |
| 67 |
throw new SoftException('Incorrect field list'); |
| 68 |
} |
| 69 |
|
| 70 |
$res = []; |
| 71 |
if (count($fields)) { |
| 72 |
$data = [ 'ip' => $host, 'fields' => $fields ]; |
| 73 |
PluginManager::dispatchEvent('Host', 'hostInformationStart', $data); |
| 74 |
if (isset($data['fields'])) { |
| 75 |
$data['result'] = $host->information($data['fields']); |
| 76 |
PluginManager::dispatchEvent('Host', 'hostInformationFinish', $data); |
| 77 |
$res['data'] = $data['result'] ?? []; |
| 78 |
if (isset($data['dictionary'])) { |
| 79 |
$res['dictionary'] = $data['dictionary']; |
| 80 |
} |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
Core::sendJson($res); |
| 85 |
return; |
| 86 |
} |
| 87 |
|
| 88 |
Core::sendJson([ 'error_code' => -1, 'message' => 'Bad request' ]); |
| 89 |
} |
| 90 |
} catch (RuntimeException $e) { |
| 91 |
Core::sendJson(ErrorHandler::exceptionResult($e)); |
| 92 |
} |
| 93 |
return; |
| 94 |
} |
| 95 |
|
| 96 |
Core::sendBad(); |