mirror of https://github.com/MISP/MISP
new: [Cache] search allows bulk lookups
- it is now possible to search for a list of values such as: { "value": ["1.1.1.1", "8.8.8.8", "8.8.4.4"] } - this will now return a dictionary with the key being the lookup value and the value being a list of hits and their metadata - passing a single value will revert to the old behaviour, returning a simple list with the hits and their metadatapull/7358/head
parent
2119c17313
commit
6c6f6170b0
|
@ -1622,7 +1622,6 @@ class Feed extends AppModel
|
|||
|
||||
public function searchCaches($value)
|
||||
{
|
||||
$value = strtolower(trim($value));
|
||||
$hits = array();
|
||||
$this->Server = ClassRegistry::init('Server');
|
||||
$result['Server'] = $this->Server->find('all', array(
|
||||
|
@ -1633,82 +1632,105 @@ class Feed extends AppModel
|
|||
'fields' => array('Server.id', 'Server.name', 'Server.url')
|
||||
));
|
||||
$redis = $this->setupRedis();
|
||||
if (empty($value) || $redis->sismember('misp:feed_cache:combined', md5($value))) {
|
||||
$feeds = $this->find('all', array(
|
||||
'conditions' => array(
|
||||
'caching_enabled' => 1
|
||||
),
|
||||
'recursive' => -1,
|
||||
'fields' => array('Feed.id', 'Feed.name', 'Feed.url', 'Feed.source_format')
|
||||
));
|
||||
foreach ($feeds as $feed) {
|
||||
if (empty($value) || $redis->sismember('misp:feed_cache:' . $feed['Feed']['id'], md5($value))) {
|
||||
if ($feed['Feed']['source_format'] === 'misp') {
|
||||
$uuid = $redis->smembers('misp:feed_cache:event_uuid_lookup:' . md5($value));
|
||||
foreach ($uuid as $k => $url) {
|
||||
$uuid[$k] = explode('/', $url)[1];
|
||||
}
|
||||
$feed['Feed']['uuid'] = $uuid;
|
||||
if (!empty($feed['Feed']['uuid'])) {
|
||||
foreach ($feed['Feed']['uuid'] as $uuid) {
|
||||
$is_array = true;
|
||||
if (!is_array($value)) {
|
||||
$is_array = false;
|
||||
if (empty($value)) {
|
||||
// old behaviour allowd for empty values to return all data
|
||||
$value = [false];
|
||||
} else {
|
||||
$value = [$value];
|
||||
}
|
||||
}
|
||||
foreach ($value as $v) {
|
||||
if ($v !== false) {
|
||||
$v = strtolower(trim($v));
|
||||
}
|
||||
if ($v === false || $redis->sismember('misp:feed_cache:combined', md5($v))) {
|
||||
$feeds = $this->find('all', array(
|
||||
'conditions' => array(
|
||||
'caching_enabled' => 1
|
||||
),
|
||||
'recursive' => -1,
|
||||
'fields' => array('Feed.id', 'Feed.name', 'Feed.url', 'Feed.source_format')
|
||||
));
|
||||
foreach ($feeds as $feed) {
|
||||
if (($v === false) || $redis->sismember('misp:feed_cache:' . $feed['Feed']['id'], md5($v))) {
|
||||
if ($feed['Feed']['source_format'] === 'misp') {
|
||||
$uuid = $redis->smembers('misp:feed_cache:event_uuid_lookup:' . md5($v));
|
||||
foreach ($uuid as $k => $url) {
|
||||
$uuid[$k] = explode('/', $url)[1];
|
||||
}
|
||||
$feed['Feed']['uuid'] = $uuid;
|
||||
if (!empty($feed['Feed']['uuid'])) {
|
||||
foreach ($feed['Feed']['uuid'] as $uuid) {
|
||||
$feed['Feed']['direct_urls'][] = array(
|
||||
'url' => sprintf(
|
||||
'%s/feeds/previewEvent/%s/%s',
|
||||
Configure::read('MISP.baseurl'),
|
||||
h($feed['Feed']['id']),
|
||||
h($uuid)
|
||||
),
|
||||
'name' => __('Event %s', $uuid)
|
||||
);
|
||||
}
|
||||
}
|
||||
$feed['Feed']['type'] = 'MISP Feed';
|
||||
} else {
|
||||
$feed['Feed']['type'] = 'Feed';
|
||||
if (!empty($v)) {
|
||||
$feed['Feed']['direct_urls'][] = array(
|
||||
'url' => sprintf(
|
||||
'%s/feeds/previewEvent/%s/%s',
|
||||
'%s/feeds/previewIndex/%s',
|
||||
Configure::read('MISP.baseurl'),
|
||||
h($feed['Feed']['id']),
|
||||
h($uuid)
|
||||
h($feed['Feed']['id'])
|
||||
),
|
||||
'name' => __('Event %s', $uuid)
|
||||
'name' => __('Feed %s', $feed['Feed']['id'])
|
||||
);
|
||||
}
|
||||
}
|
||||
$feed['Feed']['type'] = 'MISP Feed';
|
||||
} else {
|
||||
$feed['Feed']['type'] = 'Feed';
|
||||
if (!empty($value)) {
|
||||
$feed['Feed']['direct_urls'][] = array(
|
||||
'url' => sprintf(
|
||||
'%s/feeds/previewIndex/%s',
|
||||
Configure::read('MISP.baseurl'),
|
||||
h($feed['Feed']['id'])
|
||||
),
|
||||
'name' => __('Feed %s', $feed['Feed']['id'])
|
||||
);
|
||||
if ($is_array) {
|
||||
$hits[$v][] = $feed;
|
||||
} else {
|
||||
$hits[] = $feed;
|
||||
}
|
||||
}
|
||||
$hits[] = $feed;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (empty($value) || $redis->sismember('misp:server_cache:combined', md5($value))) {
|
||||
$this->Server = ClassRegistry::init('Server');
|
||||
$servers = $this->Server->find('all', array(
|
||||
'conditions' => array(
|
||||
'caching_enabled' => 1
|
||||
),
|
||||
'recursive' => -1,
|
||||
'fields' => array('Server.id', 'Server.name', 'Server.url')
|
||||
));
|
||||
foreach ($servers as $server) {
|
||||
if (empty($value) || $redis->sismember('misp:server_cache:' . $server['Server']['id'], md5($value))) {
|
||||
$uuid = $redis->smembers('misp:server_cache:event_uuid_lookup:' . md5($value));
|
||||
if (!empty($uuid)) {
|
||||
foreach ($uuid as $k => $url) {
|
||||
$uuid[$k] = explode('/', $url)[1];
|
||||
$server['Server']['direct_urls'][] = array(
|
||||
'url' => sprintf(
|
||||
'%s/servers/previewEvent/%s/%s',
|
||||
Configure::read('MISP.baseurl'),
|
||||
h($server['Server']['id']),
|
||||
h($uuid[$k])
|
||||
),
|
||||
'name' => __('Event %s', h($uuid[$k]))
|
||||
);
|
||||
if ($v === false || $redis->sismember('misp:server_cache:combined', md5($v))) {
|
||||
$this->Server = ClassRegistry::init('Server');
|
||||
$servers = $this->Server->find('all', array(
|
||||
'conditions' => array(
|
||||
'caching_enabled' => 1
|
||||
),
|
||||
'recursive' => -1,
|
||||
'fields' => array('Server.id', 'Server.name', 'Server.url')
|
||||
));
|
||||
foreach ($servers as $server) {
|
||||
if ($v === false || $redis->sismember('misp:server_cache:' . $server['Server']['id'], md5($v))) {
|
||||
$uuid = $redis->smembers('misp:server_cache:event_uuid_lookup:' . md5($v));
|
||||
if (!empty($uuid)) {
|
||||
foreach ($uuid as $k => $url) {
|
||||
$uuid[$k] = explode('/', $url)[1];
|
||||
$server['Server']['direct_urls'][] = array(
|
||||
'url' => sprintf(
|
||||
'%s/servers/previewEvent/%s/%s',
|
||||
Configure::read('MISP.baseurl'),
|
||||
h($server['Server']['id']),
|
||||
h($uuid[$k])
|
||||
),
|
||||
'name' => __('Event %s', h($uuid[$k]))
|
||||
);
|
||||
}
|
||||
}
|
||||
$server['Server']['uuid'] = $uuid;
|
||||
$server['Server']['type'] = 'MISP Server';
|
||||
if ($is_array) {
|
||||
$hits[$v][] = array('Feed' => $server['Server']);
|
||||
} else {
|
||||
$hits[] = array('Feed' => $server['Server']);
|
||||
}
|
||||
}
|
||||
$server['Server']['uuid'] = $uuid;
|
||||
$server['Server']['type'] = 'MISP Server';
|
||||
$hits[] = array('Feed' => $server['Server']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue