mirror of https://github.com/MISP/MISP
Enhancements to the reportValidationIssuesAttributes action
- now also shows issues not related to the value field - takes an optional parameter to validate a single event's attributespull/639/head
parent
9f8e5049a6
commit
43c2290097
|
@ -1 +1 @@
|
||||||
{"major":2, "minor":3, "hotfix":122}
|
{"major":2, "minor":3, "hotfix":123}
|
|
@ -1830,11 +1830,11 @@ class AttributesController extends AppController {
|
||||||
$this->set('rpzSettings', $rpzSettings);
|
$this->set('rpzSettings', $rpzSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function reportValidationIssuesAttributes() {
|
public function reportValidationIssuesAttributes($eventId = false) {
|
||||||
// TODO improve performance of this function by eliminating the additional SQL query per attribute
|
// TODO improve performance of this function by eliminating the additional SQL query per attribute
|
||||||
// search for validation problems in the attributes
|
// search for validation problems in the attributes
|
||||||
if (!self::_isSiteAdmin()) throw new NotFoundException();
|
if (!self::_isSiteAdmin()) throw new NotFoundException();
|
||||||
$this->set('result', $this->Attribute->reportValidationIssuesAttributes());
|
$this->set('result', $this->Attribute->reportValidationIssuesAttributes($eventId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generateCorrelation() {
|
public function generateCorrelation() {
|
||||||
|
|
|
@ -1412,12 +1412,14 @@ class Attribute extends AppModel {
|
||||||
return $k;
|
return $k;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function reportValidationIssuesAttributes() {
|
public function reportValidationIssuesAttributes($eventId) {
|
||||||
|
$conditions = array();
|
||||||
|
if ($eventId && is_numeric($eventId)) $conditions = array('event_id' => $eventId);
|
||||||
// for efficiency reasons remove the unique requirement
|
// for efficiency reasons remove the unique requirement
|
||||||
$this->validator()->remove('value', 'unique');
|
$this->validator()->remove('value', 'unique');
|
||||||
|
|
||||||
// get all attributes..
|
// get all attributes..
|
||||||
$attributes = $this->find('all', array('recursive' => -1, 'fields' => array('id')));
|
$attributes = $this->find('all', array('recursive' => -1, 'fields' => array('id'), 'conditions' => $conditions));
|
||||||
|
|
||||||
// for all attributes..
|
// for all attributes..
|
||||||
$result = array();
|
$result = array();
|
||||||
|
@ -1431,7 +1433,10 @@ class Attribute extends AppModel {
|
||||||
$errors = $this->validationErrors;
|
$errors = $this->validationErrors;
|
||||||
$result[$i]['id'] = $attribute['Attribute']['id'];
|
$result[$i]['id'] = $attribute['Attribute']['id'];
|
||||||
// print_r
|
// print_r
|
||||||
$result[$i]['error'] = $errors['value'][0];
|
$result[$i]['error'] = array();
|
||||||
|
foreach ($errors as $field => $error) {
|
||||||
|
$result[$i]['error'][$field] = array('value' => $attribute['Attribute'][$field], 'error' => $error[0]);
|
||||||
|
}
|
||||||
$result[$i]['details'] = 'Event ID: [' . $attribute['Attribute']['event_id'] . "] - Category: [" . $attribute['Attribute']['category'] . "] - Type: [" . $attribute['Attribute']['type'] . "] - Value: [" . $attribute['Attribute']['value'] . ']';
|
$result[$i]['details'] = 'Event ID: [' . $attribute['Attribute']['event_id'] . "] - Category: [" . $attribute['Attribute']['category'] . "] - Type: [" . $attribute['Attribute']['type'] . "] - Value: [" . $attribute['Attribute']['value'] . ']';
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,10 +4,12 @@
|
||||||
foreach ($result as $r) {
|
foreach ($result as $r) {
|
||||||
?>
|
?>
|
||||||
<h3>Validation errors for attribute: <?php echo h($r['id']); ?></h3>
|
<h3>Validation errors for attribute: <?php echo h($r['id']); ?></h3>
|
||||||
<?php print_r($r['error']); ?><br />
|
<?php
|
||||||
Attribute details:<br />
|
foreach ($r['error'] as $field => $error) {
|
||||||
<?php echo h($r['details']); ?>
|
echo '<b>[' . h($field) . ']</b>: Value found: ' . h($error['value']) . ' - Error: ' . h($error['error']) . '<br />';
|
||||||
<br/>
|
}
|
||||||
|
?>
|
||||||
|
<b>[Attribute details]</b>: <?php echo h($r['details']); ?><br/>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Reference in New Issue