fix: Fixed a few silly issues with the hids export

- allow POSTed parameters
- simpler response always responds with txt type, won't complain about view not being set for incorrect accept headers
pull/2229/head
iglocska 2017-05-22 15:03:56 +02:00
parent ccde4a8770
commit 66613dd38f
2 changed files with 17 additions and 2 deletions

View File

@ -1964,6 +1964,21 @@ class EventsController extends AppController {
public function hids($type, $key = 'download', $tags = false, $from = false, $to = false, $last = false, $enforceWarninglist = false) {
$simpleFalse = array('tags', 'from', 'to', 'last', 'enforceWarninglist');
if ($this->request->is('post')) {
if (empty($this->request->data)) {
throw new BadRequestException('Either specify the search terms in the url, or POST a json or xml with the filter parameters.');
} else {
$data = $this->request->data;
}
if (!isset($data['request'])) {
$data = array('request' => $data);
}
foreach ($simpleFalse as $sF) {
if (isset($data['request'][$sF])) {
${$sF} = $data['request'][$sF];
}
}
}
foreach ($simpleFalse as $sF) {
if (!is_array(${$sF}) && (${$sF} === 'null' || ${$sF} == '0' || ${$sF} === false || strtolower(${$sF}) === 'false')) {
${$sF} = false;
@ -1993,7 +2008,7 @@ class EventsController extends AppController {
}
$this->loadModel('Attribute');
$rules = $this->Attribute->hids($this->Auth->user(), $type, $tags, $from, $to, $last, false, $enforceWarninglist);
$this->set('rules', $rules);
return new CakeResponse(array('body'=> implode(PHP_EOL, $rules), 'status' => 200, 'type' => 'txt'));
}
// csv function

View File

@ -1543,7 +1543,7 @@ class Attribute extends AppModel {
if ($type == 'md5') $typeArray[] = 'malware-sample';
$rules = array();
$eventIds = $this->Event->fetchEventIds($user, $from, $to, $last);
if ($tags !== '') {
if (!empty($tags)) {
$tag = ClassRegistry::init('Tag');
$args = $this->dissectArgs($tags);
$tagArray = $tag->fetchEventTagIds($args[0], $args[1]);