mirror of https://github.com/MISP/MISP
chg: [ipUser] API now accepts lists of IPs
{ "ip": ["8.8.8.8", "1.1.1.1"] }pull/8216/head
parent
7174b86999
commit
86832556a4
|
@ -2727,33 +2727,39 @@ misp.direct_call(relative_path, body)
|
|||
}
|
||||
}
|
||||
|
||||
public function ipUser($ip = false)
|
||||
public function ipUser($input = false)
|
||||
{
|
||||
$params = $this->IndexFilter->harvestParameters(['ip']);
|
||||
if (!empty($params['ip'])) {
|
||||
$ip = $params['ip'];
|
||||
$input = $params['ip'];
|
||||
}
|
||||
$redis = $this->Server->setupRedis();
|
||||
if (!filter_var($ip, FILTER_VALIDATE_IP)) {
|
||||
throw new InvalidArgumentException(__('No valid IP provided.'));
|
||||
if (!is_array($input)) {
|
||||
$input = [$input];
|
||||
}
|
||||
$user_id = $redis->get('misp:ip_user:' . $ip);
|
||||
if (empty($user_id)) {
|
||||
throw new NotFoundException(__('No hits for the provided IP.'));
|
||||
$users = [];
|
||||
foreach ($input as $ip) {
|
||||
if (!filter_var($ip, FILTER_VALIDATE_IP)) {
|
||||
continue;
|
||||
}
|
||||
$user_id = $redis->get('misp:ip_user:' . $ip);
|
||||
if (empty($user_id)) {
|
||||
continue;
|
||||
}
|
||||
$this->loadModel('User');
|
||||
$user = $this->User->find('first', [
|
||||
'recursive' => -1,
|
||||
'conditions' => ['User.id' => $user_id],
|
||||
'contain' => ['Organisation.name']
|
||||
]);
|
||||
if (empty($user)) {
|
||||
throw new NotFoundException(__('User not found (perhaps it has been removed?).'));
|
||||
}
|
||||
$users[$ip] = [
|
||||
'id' => $user['User']['id'],
|
||||
'email' => $user['User']['email'],
|
||||
];
|
||||
}
|
||||
$this->loadModel('User');
|
||||
$user = $this->User->find('first', [
|
||||
'recursive' => -1,
|
||||
'conditions' => ['User.id' => $user_id],
|
||||
'contain' => ['Organisation.name']
|
||||
]);
|
||||
if (empty($user)) {
|
||||
throw new NotFoundException(__('User not found (perhaps it has been removed?).'));
|
||||
}
|
||||
$user = [
|
||||
'id' => $user['User']['id'],
|
||||
'email' => $user['User']['email'],
|
||||
];
|
||||
return $this->RestResponse->viewData($user, $this->response->type());
|
||||
return $this->RestResponse->viewData($users, $this->response->type());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue