mirror of https://github.com/MISP/MISP
chg: Changed Object to MispObject internally
parent
02464da6f2
commit
3a5b2f0157
|
@ -3,6 +3,8 @@
|
|||
App::uses('AppController', 'Controller');
|
||||
|
||||
class ObjectsController extends AppController {
|
||||
var $uses = 'MispObject';
|
||||
|
||||
public $components = array('Security' ,'RequestHandler', 'Session');
|
||||
|
||||
public $paginate = array(
|
||||
|
@ -35,12 +37,12 @@ class ObjectsController extends AppController {
|
|||
} else {
|
||||
throw new NotFoundException('Invalid event.');
|
||||
}
|
||||
$event = $this->Object->Event->find('first', $eventFindParams);
|
||||
$event = $this->MispObject->Event->find('first', $eventFindParams);
|
||||
if (empty($event) || (!$this->_isSiteAdmin() && $event['Event']['orgc_id'] != $this->Auth->user('org_id'))) {
|
||||
throw new NotFoundException('Invalid event.');
|
||||
}
|
||||
$eventId = $event['Event']['id'];
|
||||
$template = $this->Object->ObjectTemplate->find('first', array(
|
||||
$template = $this->MispObject->ObjectTemplate->find('first', array(
|
||||
'conditions' => array('ObjectTemplate.id' => $templateId),
|
||||
'recursive' => -1,
|
||||
'contain' => array(
|
||||
|
@ -57,25 +59,25 @@ class ObjectsController extends AppController {
|
|||
if (!isset($this->request->data['Attribute'])) {
|
||||
$this->request->data = array('Attribute' => $this->request->data);
|
||||
}
|
||||
$object = $this->Object->attributeCleanup($this->request->data);
|
||||
$object = $this->MispObject->attributeCleanup($this->request->data);
|
||||
// we pre-validate the attributes before we create an object at this point
|
||||
// This allows us to stop the process and return an error (API) or return
|
||||
// to the add form
|
||||
foreach ($object['Attribute'] as $k => $attribute) {
|
||||
$object['Attribute'][$k]['event_id'] = $eventId;
|
||||
$this->Object->Event->Attribute->set($attribute);
|
||||
if (!$this->Object->Event->Attribute->validates()) {
|
||||
$error = 'Could not save object as at least one attribute has failed validation (' . $attribute['object_relation'] . '). ' . json_encode($this->Object->Event->Attribute->validationErrors);
|
||||
$this->MispObject->Event->Attribute->set($attribute);
|
||||
if (!$this->MispObject->Event->Attribute->validates()) {
|
||||
$error = 'Could not save object as at least one attribute has failed validation (' . $attribute['object_relation'] . '). ' . json_encode($this->MispObject->Event->Attribute->validationErrors);
|
||||
}
|
||||
}
|
||||
if (empty($error)) {
|
||||
$error = $this->Object->ObjectTemplate->checkTemplateConformity($template, $object);
|
||||
$error = $this->MispObject->ObjectTemplate->checkTemplateConformity($template, $object);
|
||||
if ($error === true) {
|
||||
$result = $this->Object->saveObject($object, $eventId, $template, $this->Auth->user(), $errorBehaviour = 'halt');
|
||||
$result = $this->MispObject->saveObject($object, $eventId, $template, $this->Auth->user(), $errorBehaviour = 'halt');
|
||||
}
|
||||
if ($this->_isRest()) {
|
||||
if (is_numeric($result)) {
|
||||
$object = $this->Object->find('first', array(
|
||||
$object = $this->MispObject->find('first', array(
|
||||
'recursive' => -1,
|
||||
'conditions' => array('Object.id' => $result),
|
||||
'contain' => array('Attribute')
|
||||
|
@ -102,10 +104,10 @@ class ObjectsController extends AppController {
|
|||
if (!empty($error)) {
|
||||
$this->Session->setFlash($error);
|
||||
}
|
||||
$template = $this->Object->prepareTemplate($template);
|
||||
$template = $this->MispObject->prepareTemplate($template);
|
||||
$enabledRows = array_keys($template['ObjectTemplateElement']);
|
||||
$this->set('enabledRows', $enabledRows);
|
||||
$distributionData = $this->Object->Event->Attribute->fetchDistributionData($this->Auth->user());
|
||||
$distributionData = $this->MispObject->Event->Attribute->fetchDistributionData($this->Auth->user());
|
||||
$this->set('distributionData', $distributionData);
|
||||
$this->set('event', $event);
|
||||
$this->set('ajax', false);
|
||||
|
@ -127,7 +129,7 @@ class ObjectsController extends AppController {
|
|||
$lookupField = 'id';
|
||||
throw new NotFoundException('Invalid event.');
|
||||
}
|
||||
$event = $this->Object->Event->find('first', array(
|
||||
$event = $this->MispObject->Event->find('first', array(
|
||||
'recursive' => -1,
|
||||
'fields' => array('Event.id', 'Event.uuid', 'Event.orgc_id'),
|
||||
'conditions' => array('Event.id' => $eventId)
|
||||
|
@ -139,12 +141,12 @@ class ObjectsController extends AppController {
|
|||
if (!$this->_isSiteAdmin() && ($event['Event']['orgc_id'] != $this->Auth->user('org_id') || !$this->userRole['perm_modify'])) {
|
||||
throw new UnauthorizedException('You do not have permission to do that.');
|
||||
}
|
||||
$this->Object->delete($id);
|
||||
$this->MispObject->delete($id);
|
||||
}
|
||||
|
||||
public function view($id) {
|
||||
if ($this->_isRest()) {
|
||||
$objects = $this->Object->fetchObjects($this->Auth->user(), array('conditions' => array('Object.id' => $id)));
|
||||
$objects = $this->MispObject->fetchObjects($this->Auth->user(), array('conditions' => array('Object.id' => $id)));
|
||||
if (!empty($objects)) {
|
||||
return $this->RestResponse->viewData($objects, $this->response->type());
|
||||
}
|
||||
|
|
|
@ -312,7 +312,7 @@ class Event extends AppModel {
|
|||
'counterQuery' => ''
|
||||
),
|
||||
'Object' => array(
|
||||
'className' => 'Object',
|
||||
'className' => 'MispObject',
|
||||
'foreignKey' => 'event_id',
|
||||
'dependent' => true,
|
||||
'conditions' => '',
|
||||
|
|
|
@ -2,14 +2,16 @@
|
|||
|
||||
App::uses('AppModel', 'Model');
|
||||
|
||||
class Object extends AppModel {
|
||||
class MispObject extends AppModel {
|
||||
|
||||
public $useTable = 'objects';
|
||||
|
||||
public $actsAs = array(
|
||||
'Containable',
|
||||
'SysLogLogable.SysLogLogable' => array(
|
||||
'roleModel' => 'Object',
|
||||
'roleKey' => 'object_id',
|
||||
'change' => 'full'
|
||||
),
|
||||
'SysLogLogable.SysLogLogable' => array( // TODO Audit, logable
|
||||
'userModel' => 'User',
|
||||
'userKey' => 'user_id',
|
||||
'change' => 'full'),
|
||||
);
|
||||
|
||||
public $belongsTo = array(
|
||||
|
@ -25,7 +27,7 @@ class Object extends AppModel {
|
|||
'className' => 'ObjectTemplate',
|
||||
'foreignKey' => false,
|
||||
'dependent' => false,
|
||||
'conditions' => array('Object.template_uuid' => 'ObjectTemplate.uuid')
|
||||
'conditions' => array('MispObject.template_uuid' => 'ObjectTemplate.uuid')
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -45,21 +47,25 @@ class Object extends AppModel {
|
|||
|
||||
public function beforeValidate($options = array()) {
|
||||
parent::beforeValidate();
|
||||
if (isset($this->data['Object'])) {
|
||||
$this->data['MispObject'] = $this->data['Object'];
|
||||
unset($this->data['Object']);
|
||||
}
|
||||
|
||||
if (empty($this->data['Object']['comment'])) {
|
||||
$this->data['Object']['comment'] = "";
|
||||
if (empty($this->data['MispObject']['comment'])) {
|
||||
$this->data['MispObject']['comment'] = "";
|
||||
}
|
||||
// generate UUID if it doesn't exist
|
||||
if (empty($this->data['Object']['uuid'])) {
|
||||
$this->data['Object']['uuid'] = CakeText::uuid();
|
||||
if (empty($this->data['MispObject']['uuid'])) {
|
||||
$this->data['MispObject']['uuid'] = CakeText::uuid();
|
||||
}
|
||||
// generate timestamp if it doesn't exist
|
||||
if (empty($this->data['Object']['timestamp'])) {
|
||||
if (empty($this->data['MispObject']['timestamp'])) {
|
||||
$date = new DateTime();
|
||||
$this->data['Object']['timestamp'] = $date->getTimestamp();
|
||||
$this->data['MispObject']['timestamp'] = $date->getTimestamp();
|
||||
}
|
||||
if (!isset($this->data['Object']['distribution']) || $this->data['Object']['distribution'] != 4) $this->data['Object']['sharing_group_id'] = 0;
|
||||
if (!isset($this->data['Object']['distribution'])) $this->data['Object']['distribution'] = 5;
|
||||
if (!isset($this->data['MispObject']['distribution']) || $this->data['MispObject']['distribution'] != 4) $this->data['MispObject']['sharing_group_id'] = 0;
|
||||
if (!isset($this->data['MispObject']['distribution'])) $this->data['MispObject']['distribution'] = 5;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -73,9 +79,9 @@ class Object extends AppModel {
|
|||
'template_uuid' => 'uuid'
|
||||
);
|
||||
foreach ($templateFields as $k => $v) {
|
||||
$object['Object'][$k] = $template['ObjectTemplate'][$v];
|
||||
$object['MispObject'][$k] = $template['ObjectTemplate'][$v];
|
||||
}
|
||||
$object['Object']['event_id'] = $eventId;
|
||||
$object['MispObject']['event_id'] = $eventId;
|
||||
$result = false;
|
||||
if ($this->save($object)) {
|
||||
$id = $this->id;
|
|
@ -6,10 +6,9 @@ class Object extends AppModel {
|
|||
public $actsAs = array(
|
||||
'Containable',
|
||||
'SysLogLogable.SysLogLogable' => array( // TODO Audit, logable
|
||||
'roleModel' => 'Object',
|
||||
'roleKey' => 'object_id',
|
||||
'change' => 'full'
|
||||
),
|
||||
'userModel' => 'User',
|
||||
'userKey' => 'user_id',
|
||||
'change' => 'full'),
|
||||
);
|
||||
|
||||
public $belongsTo = array(
|
||||
|
|
|
@ -6,10 +6,9 @@ class ObjectTemplate extends AppModel {
|
|||
public $actsAs = array(
|
||||
'Containable',
|
||||
'SysLogLogable.SysLogLogable' => array( // TODO Audit, logable
|
||||
'roleModel' => 'Object',
|
||||
'roleKey' => 'object_id',
|
||||
'change' => 'full'
|
||||
),
|
||||
'userModel' => 'User',
|
||||
'userKey' => 'user_id',
|
||||
'change' => 'full'),
|
||||
);
|
||||
|
||||
public $belongsTo = array(
|
||||
|
|
|
@ -6,10 +6,9 @@ class ObjectTemplateElement extends AppModel {
|
|||
public $actsAs = array(
|
||||
'Containable',
|
||||
'SysLogLogable.SysLogLogable' => array( // TODO Audit, logable
|
||||
'roleModel' => 'Object',
|
||||
'roleKey' => 'object_id',
|
||||
'change' => 'full'
|
||||
),
|
||||
'userModel' => 'User',
|
||||
'userKey' => 'user_id',
|
||||
'change' => 'full'),
|
||||
);
|
||||
|
||||
public $belongsTo = array(
|
||||
|
|
|
@ -364,6 +364,11 @@
|
|||
?>
|
||||
<li id='liindex'><a href="<?php echo $baseurl;?>/objectTemplates/index">List Object Templates</a></li>
|
||||
<?php
|
||||
if ($isSiteAdmin):
|
||||
?>
|
||||
<li><?php echo $this->Form->postLink('Update Objects', '/objectTemplates/update'); ?></li>
|
||||
<?php
|
||||
endif;
|
||||
if ($menuItem === 'view'):
|
||||
?>
|
||||
<li class="active"><a href="#">View Object Template</a></li>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<div class="<?php if (!isset($ajax) || !$ajax) echo 'form';?>">
|
||||
<?php
|
||||
echo $this->Form->create('Object', array('id', 'url' => '/objects/add/' . $event['Event']['id'] . '/' . $template['ObjectTemplate']['id'], 'enctype' => 'multipart/form-data'));
|
||||
echo $this->Form->create('MispObject', array('id', 'url' => '/objects/add/' . $event['Event']['id'] . '/' . $template['ObjectTemplate']['id'], 'enctype' => 'multipart/form-data'));
|
||||
?>
|
||||
<h3><?php echo 'Add ' . Inflector::humanize(h($template['ObjectTemplate']['name'])) . ' Object'; ?></h3>
|
||||
<div class="row-fluid" style="margin-bottom:10px;">
|
||||
|
|
Loading…
Reference in New Issue