-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
51 lines (42 loc) · 1.19 KB
/
index.php
1
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
44
45
46
47
48
49
50
51
<?php
use Elasticsearch\ClientBuilder;
require 'vendor/autoload.php';
require 'functions.php';
require 'config.php';
$client = ClientBuilder::create()->setHosts($esHosts)->build();
$prefix = $_GET['prefix'];
$page = isset($_GET['page']) ? (int) $_GET['page'] : 1;
$limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 1;
$searchParams = [
'index' => 'main_index_dns_1466675086',
'type' => 'dns_records',
'body' => [
'size' => $limit,
'from' => $limit * ($page - 1),
'sort' => [
'ip_dec' => [
'order' => 'asc',
],
],
'filter' => [
'range' => [
'ip_dec' => getPrefixRange($prefix),
],
],
]
];
$searchResults = $client->search($searchParams);
$records = [];
foreach ($searchResults['hits']['hits'] as $searchResult) {
$records[$searchResult['_source']['entry']][] = $searchResult['_source']['input'];
}
$data = [
'query_time' => $searchResults['took'] . 'ms',
'total' => $searchResults['hits']['total'],
'limit' => $limit,
'page' => $page,
'records' => $records,
];
header('Content-Type: application/json');
echo json_encode($data);
die();