mirror of https://github.com/MISP/MISP
new: Further progress on the objects
parent
93a99208c6
commit
ee1c1c5de9
|
@ -427,7 +427,8 @@ CREATE TABLE IF NOT EXISTS objects (
|
|||
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci,
|
||||
`meta-category` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci,
|
||||
`description` text CHARACTER SET utf8 COLLATE utf8_unicode_ci,
|
||||
`version` int(11) NOT NULL,
|
||||
`template_uuid` varchar(40) COLLATE utf8_bin DEFAULT NULL,
|
||||
`template_version` int(11) NOT NULL,
|
||||
`event_id` int(11) NOT NULL,
|
||||
`uuid` varchar(40) COLLATE utf8_bin DEFAULT NULL,
|
||||
`timestamp` int(11) NOT NULL DEFAULT 0,
|
||||
|
@ -435,8 +436,10 @@ CREATE TABLE IF NOT EXISTS objects (
|
|||
`sharing_group_id` int(11),
|
||||
`comment` text COLLATE utf8_bin NOT NULL,
|
||||
PRIMARY KEY (id),
|
||||
INDEX `name` (`name`(255)),
|
||||
INDEX `meta-category` (`meta-category`(255)),
|
||||
INDEX `name` (`name`),
|
||||
INDEX `template_uuid` (`template_uuid`),
|
||||
INDEX `template_version` (`template_version`),
|
||||
INDEX `meta-category` (`meta-category`),
|
||||
INDEX `event_id` (`event_id`),
|
||||
INDEX `uuid` (`uuid`),
|
||||
INDEX `timestamp` (`timestamp`),
|
||||
|
@ -629,6 +632,7 @@ CREATE TABLE IF NOT EXISTS `roles` (
|
|||
`perm_sharing_group` tinyint(1) NOT NULL DEFAULT 0,
|
||||
`perm_tag_editor` tinyint(1) NOT NULL DEFAULT 0,
|
||||
`perm_sighting` tinyint(1) NOT NULL DEFAULT 0,
|
||||
`perm_object_template` tinyint(1) NOT NULL DEFAULT 0,
|
||||
`default_role` tinyint(1) NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
|
||||
|
@ -1177,23 +1181,23 @@ INSERT INTO `feeds` (`id`, `provider`, `name`, `url`, `distribution`, `default`,
|
|||
-- 7. Read Only - read
|
||||
--
|
||||
|
||||
INSERT INTO `roles` (`id`, `name`, `created`, `modified`, `perm_add`, `perm_modify`, `perm_modify_org`, `perm_publish`, `perm_sync`, `perm_admin`, `perm_audit`, `perm_full`, `perm_auth`, `perm_regexp_access`, `perm_tagger`, `perm_site_admin`, `perm_template`, `perm_sharing_group`, `perm_tag_editor`, `perm_delegate`, `perm_sighting`, `default_role`)
|
||||
VALUES (1, 'admin', NOW(), NOW(), 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0);
|
||||
INSERT INTO `roles` (`id`, `name`, `created`, `modified`, `perm_add`, `perm_modify`, `perm_modify_org`, `perm_publish`, `perm_sync`, `perm_admin`, `perm_audit`, `perm_full`, `perm_auth`, `perm_regexp_access`, `perm_tagger`, `perm_site_admin`, `perm_template`, `perm_sharing_group`, `perm_tag_editor`, `perm_delegate`, `perm_sighting`, `perm_object_template`, `default_role`)
|
||||
VALUES (1, 'admin', NOW(), NOW(), 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0);
|
||||
|
||||
INSERT INTO `roles` (`id`, `name`, `created`, `modified`, `perm_add`, `perm_modify`, `perm_modify_org`, `perm_publish`, `perm_sync`, `perm_admin`, `perm_audit`, `perm_full`, `perm_auth`, `perm_regexp_access`, `perm_tagger`, `perm_site_admin`, `perm_template`, `perm_sharing_group`, `perm_tag_editor`, `perm_delegate`, `perm_sighting`, `default_role`)
|
||||
VALUES (2, 'Org Admin', NOW(), NOW(), 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0);
|
||||
INSERT INTO `roles` (`id`, `name`, `created`, `modified`, `perm_add`, `perm_modify`, `perm_modify_org`, `perm_publish`, `perm_sync`, `perm_admin`, `perm_audit`, `perm_full`, `perm_auth`, `perm_regexp_access`, `perm_tagger`, `perm_site_admin`, `perm_template`, `perm_sharing_group`, `perm_tag_editor`, `perm_delegate`, `perm_sighting`, `perm_object_template`, `default_role`)
|
||||
VALUES (2, 'Org Admin', NOW(), NOW(), 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0);
|
||||
|
||||
INSERT INTO `roles` (`id`, `name`, `created`, `modified`, `perm_add`, `perm_modify`, `perm_modify_org`, `perm_publish`, `perm_sync`, `perm_admin`, `perm_audit`, `perm_full`, `perm_auth`, `perm_regexp_access`, `perm_tagger`, `perm_site_admin`, `perm_template`, `perm_sharing_group`, `perm_tag_editor`, `perm_delegate`, `perm_sighting`, `default_role`)
|
||||
VALUES (3, 'User', NOW(), NOW(), 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1);
|
||||
INSERT INTO `roles` (`id`, `name`, `created`, `modified`, `perm_add`, `perm_modify`, `perm_modify_org`, `perm_publish`, `perm_sync`, `perm_admin`, `perm_audit`, `perm_full`, `perm_auth`, `perm_regexp_access`, `perm_tagger`, `perm_site_admin`, `perm_template`, `perm_sharing_group`, `perm_tag_editor`, `perm_delegate`, `perm_sighting`, `perm_object_template`, `default_role`)
|
||||
VALUES (3, 'User', NOW(), NOW(), 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1);
|
||||
|
||||
INSERT INTO `roles` (`id`, `name`, `created`, `modified`, `perm_add`, `perm_modify`, `perm_modify_org`, `perm_publish`, `perm_sync`, `perm_admin`, `perm_audit`, `perm_full`, `perm_auth`, `perm_regexp_access`, `perm_tagger`, `perm_site_admin`, `perm_template`, `perm_sharing_group`, `perm_tag_editor`, `perm_delegate`, `perm_sighting`, `default_role`)
|
||||
VALUES (4, 'Publisher', NOW(), NOW(), 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0);
|
||||
INSERT INTO `roles` (`id`, `name`, `created`, `modified`, `perm_add`, `perm_modify`, `perm_modify_org`, `perm_publish`, `perm_sync`, `perm_admin`, `perm_audit`, `perm_full`, `perm_auth`, `perm_regexp_access`, `perm_tagger`, `perm_site_admin`, `perm_template`, `perm_sharing_group`, `perm_tag_editor`, `perm_delegate`, `perm_sighting`, `perm_object_template`, `default_role`)
|
||||
VALUES (4, 'Publisher', NOW(), NOW(), 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0);
|
||||
|
||||
INSERT INTO `roles` (`id`, `name`, `created`, `modified`, `perm_add`, `perm_modify`, `perm_modify_org`, `perm_publish`, `perm_sync`, `perm_admin`, `perm_audit`, `perm_full`, `perm_auth`, `perm_regexp_access`, `perm_tagger`, `perm_site_admin`, `perm_template`, `perm_sharing_group`, `perm_tag_editor`, `perm_delegate`, `perm_sighting`, `default_role`)
|
||||
VALUES (5, 'Sync user', NOW(), NOW(), 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0);
|
||||
INSERT INTO `roles` (`id`, `name`, `created`, `modified`, `perm_add`, `perm_modify`, `perm_modify_org`, `perm_publish`, `perm_sync`, `perm_admin`, `perm_audit`, `perm_full`, `perm_auth`, `perm_regexp_access`, `perm_tagger`, `perm_site_admin`, `perm_template`, `perm_sharing_group`, `perm_tag_editor`, `perm_delegate`, `perm_sighting`, `perm_object_template`, `default_role`)
|
||||
VALUES (5, 'Sync user', NOW(), NOW(), 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0);
|
||||
|
||||
INSERT INTO `roles` (`id`, `name`, `created`, `modified`, `perm_add`, `perm_modify`, `perm_modify_org`, `perm_publish`, `perm_sync`, `perm_admin`, `perm_audit`, `perm_full`, `perm_auth`, `perm_regexp_access`, `perm_tagger`, `perm_site_admin`, `perm_template`, `perm_sharing_group`, `perm_tag_editor`, `perm_delegate`, `perm_sighting`, `default_role`)
|
||||
VALUES (6, 'Read Only', NOW(), NOW(), 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
INSERT INTO `roles` (`id`, `name`, `created`, `modified`, `perm_add`, `perm_modify`, `perm_modify_org`, `perm_publish`, `perm_sync`, `perm_admin`, `perm_audit`, `perm_full`, `perm_auth`, `perm_regexp_access`, `perm_tagger`, `perm_site_admin`, `perm_template`, `perm_sharing_group`, `perm_tag_editor`, `perm_delegate`, `perm_sighting`, `perm_object_template`, `default_role`)
|
||||
VALUES (6, 'Read Only', NOW(), NOW(), 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
App::uses('AppController', 'Controller');
|
||||
|
||||
class ObjectTemplateElementsController extends AppController {
|
||||
public $components = array('Security' ,'RequestHandler', 'Session');
|
||||
|
||||
public $paginate = array(
|
||||
'limit' => 60,
|
||||
'order' => array(
|
||||
'ObjectTemplateElement.id' => 'desc'
|
||||
),
|
||||
'recursive' => -1
|
||||
);
|
||||
|
||||
public function viewElements($id, $context = 'all') {
|
||||
$this->paginate['conditions'] = array('ObjectTemplateElement.object_template_id' => $id);
|
||||
$elements = $this->paginate();
|
||||
$this->set('list', $elements);
|
||||
$this->layout = 'ajax';
|
||||
$this->render('ajax/view_elements');
|
||||
}
|
||||
}
|
|
@ -2,16 +2,21 @@
|
|||
|
||||
App::uses('AppController', 'Controller');
|
||||
|
||||
class ObjectsController extends AppController {
|
||||
class ObjectTemplatesController extends AppController {
|
||||
public $components = array('Security' ,'RequestHandler', 'Session');
|
||||
|
||||
public $paginate = array(
|
||||
'limit' => 20,
|
||||
'limit' => 60,
|
||||
'order' => array(
|
||||
'Object.id' => 'desc'
|
||||
),
|
||||
'contain' => array(
|
||||
'Organisation' => array('fields' => array('Organisation.id', 'Organisation.name', 'Organisation.uuid'))
|
||||
),
|
||||
'recursive' => -1
|
||||
);
|
||||
|
||||
/*
|
||||
public function add($eventId) {
|
||||
|
||||
}
|
||||
|
@ -23,13 +28,71 @@ class ObjectsController extends AppController {
|
|||
public function delete($id) {
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
public function objectChoice() {
|
||||
$templates_raw = $this->ObjectTemplate->find('all', array(
|
||||
'recursive' => -1,
|
||||
'fields' => array('id', 'meta-category', 'name', 'description', 'org_id'),
|
||||
'contain' => array('Organisation.name')
|
||||
));
|
||||
$templates = array();
|
||||
foreach ($templates_raw as $k => $template) {
|
||||
unset($template['ObjectTemplate']['meta-category']);
|
||||
$template['ObjectTemplate']['org_name'] = $template['Organisation']['name'];
|
||||
$templates[$templates_raw[$k]['ObjectTemplate']['meta-category']][] = $template['ObjectTemplate'];
|
||||
}
|
||||
debug($templates);
|
||||
$this->set('templates', $templates);
|
||||
}
|
||||
|
||||
public function view($id) {
|
||||
|
||||
$params = array(
|
||||
'recursive' => -1,
|
||||
'contain' => array(
|
||||
'Organisation' => array('fields' => array('Organisation.id', 'Organisation.name', 'Organisation.uuid'))
|
||||
),
|
||||
'conditions' => array('ObjectTemplate.id' => $id)
|
||||
);
|
||||
if ($this->_isSiteAdmin()) {
|
||||
$params['contain']['User']= array('fields' => array('User.id', 'User.email'));
|
||||
}
|
||||
$objectTemplate = $this->ObjectTemplate->find('first', $params);
|
||||
if (empty($objectTemplate)) {
|
||||
throw new NotFoundException('Invalid object template');
|
||||
}
|
||||
if ($this->_isRest()) {
|
||||
return $this->RestResponse->viewData($objectTemplate, $this->response->type());
|
||||
} else {
|
||||
$this->set('id', $id);
|
||||
$this->set('template', $objectTemplate);
|
||||
}
|
||||
}
|
||||
|
||||
public function viewElements($id, $context = 'all') {
|
||||
$elements = $this->ObjectTemplate->ObjectTemplateElement->find('all', array(
|
||||
'conditions' => array('ObjectTemplateElement.object_template_id' => $id)
|
||||
));
|
||||
$this->set('list', $elements);
|
||||
$this->layout = 'ajax';
|
||||
$this->render('ajax/view_elements');
|
||||
}
|
||||
|
||||
public function index() {
|
||||
if ($this->_isRest()) {
|
||||
$rules = $this->paginate;
|
||||
unset($rules['limit']);
|
||||
unset($rules['order']);
|
||||
$objectTemplates = $this->ObjectTemplate->find('all', $rules);
|
||||
return $this->RestResponse->viewData($objectTemplates, $this->response->type());
|
||||
} else {
|
||||
$objectTemplates = $this->paginate();
|
||||
$this->set('list', $objectTemplates);
|
||||
}
|
||||
}
|
||||
|
||||
public function update() {
|
||||
$result = $this->ObjectTemplate->update();
|
||||
$result = $this->ObjectTemplate->update($this->Auth->user());
|
||||
$this->Log = ClassRegistry::init('Log');
|
||||
$fails = 0;
|
||||
$successes = 0;
|
||||
|
|
|
@ -12,28 +12,44 @@ class ObjectsController extends AppController {
|
|||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Create an object using a template
|
||||
* POSTing will take the input and validate it against the template
|
||||
* GETing will return the template
|
||||
*/
|
||||
public function add($eventId, $templateId = false) {
|
||||
if (!$this->userRole['perm_add']) {
|
||||
if (!$this->userRole['perm_modify']) {
|
||||
throw new MethodNotAllowedException('You don\'t have permissions to create objects.');
|
||||
}
|
||||
if (Validation::uuid($eventId)) {
|
||||
$lookupField = 'uuid';
|
||||
} else if (!is_numeric($eventId)) {
|
||||
$lookupField = 'id';
|
||||
throw new NotFoundException('Invalid event.');
|
||||
}
|
||||
$event = $this->Object->Event->find('first', array(
|
||||
$eventFindParams = array(
|
||||
'recursive' => -1,
|
||||
'fields' => array('Event.id', 'Event.uuid', 'Event.orgc_id'),
|
||||
'conditions' => array('Event.id' => $eventId)
|
||||
));
|
||||
if (empty($event)) {
|
||||
);
|
||||
|
||||
// Find the event that is to be updated
|
||||
if (Validation::uuid($eventId)) {
|
||||
$eventFindParams['conditions']['Event.uuid'] = $eventId;
|
||||
} else if (is_numeric($eventId)) {
|
||||
$eventFindParams['conditions']['Event.id'] = $eventId;
|
||||
} else {
|
||||
throw new NotFoundException('Invalid event.');
|
||||
}
|
||||
$event = $this->Object->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'];
|
||||
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.');
|
||||
}
|
||||
$template = $this->Object->ObjectTemplate->find('first', array(
|
||||
'conditions' => array('ObjectTemplate.id' => $templateId),
|
||||
'recursive' => -1,
|
||||
'contain' => array(
|
||||
'ObjectTemplateElement'
|
||||
)
|
||||
));
|
||||
$eventId = $event['Event']['id'];
|
||||
|
||||
// If we have received a POST request
|
||||
if ($this->request->is('post')) {
|
||||
if (isset($this->request->data['request'])) {
|
||||
$this->request->data = $this->request->data['request'];
|
||||
|
@ -46,8 +62,17 @@ class ObjectsController extends AppController {
|
|||
throw new MethodNotAllowedException('Object does not meet the template requirements');
|
||||
}
|
||||
$this->Object->saveObject($this->request->data, $eventId, $errorBehaviour = 'halt');
|
||||
} else {
|
||||
}
|
||||
|
||||
// In the case of a GET request or if the object could not be validated, show the form / the requirement
|
||||
if ($this->_isRest()) {
|
||||
return $this->RestResponse->viewData($orgs, $this->response->type());
|
||||
} else {
|
||||
$template = $this->Object->prepareTemplate($template);
|
||||
//debug($template);
|
||||
$this->set('event', $event);
|
||||
$this->set('ajax', false);
|
||||
$this->set('template', $template);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,8 @@ class AppModel extends Model {
|
|||
51 => false, 52 => false, 55 => true, 56 => true, 57 => true,
|
||||
58 => false, 59 => false, 60 => false, 61 => false, 62 => false,
|
||||
63 => false, 64 => false, 65 => false, 66 => false, 67 => true,
|
||||
68 => false, 69 => false, 71 => false, 72 => false, 73 => false
|
||||
68 => false, 69 => false, 71 => false, 72 => false, 73 => false,
|
||||
76 => false
|
||||
)
|
||||
)
|
||||
);
|
||||
|
@ -688,7 +689,7 @@ class AppModel extends Model {
|
|||
$sqlArray[] = 'ALTER TABLE `servers` ADD `unpublish_event` tinyint(1) NOT NULL DEFAULT 0;';
|
||||
$sqlArray[] = 'ALTER TABLE `servers` ADD `publish_without_email` tinyint(1) NOT NULL DEFAULT 0;';
|
||||
break;
|
||||
case '2.4.x':
|
||||
case '2.4.76':
|
||||
$sqlArray[] = "CREATE TABLE IF NOT EXISTS objects (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci,
|
||||
|
@ -703,10 +704,10 @@ class AppModel extends Model {
|
|||
`sharing_group_id` int(11),
|
||||
`comment` text COLLATE utf8_bin NOT NULL,
|
||||
PRIMARY KEY (id),
|
||||
INDEX `name` (`name`(255)),
|
||||
INDEX `name` (`name`),
|
||||
INDEX `template_uuid` (`template_uuid`),
|
||||
INDEX `template_version` (`template_version`(255)),
|
||||
INDEX `meta-category` (`meta-category`(255)),
|
||||
INDEX `template_version` (`template_version`),
|
||||
INDEX `meta-category` (`meta-category`),
|
||||
INDEX `event_id` (`event_id`),
|
||||
INDEX `uuid` (`uuid`),
|
||||
INDEX `timestamp` (`timestamp`),
|
||||
|
@ -739,6 +740,7 @@ class AppModel extends Model {
|
|||
`description` text COLLATE utf8_bin,
|
||||
`version` int(11) NOT NULL,
|
||||
`requirements` text COLLATE utf8_bin,
|
||||
`fixed` tinyint(1) NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (id),
|
||||
INDEX `user_id` (`user_id`),
|
||||
INDEX `org_id` (`org_id`),
|
||||
|
@ -749,8 +751,7 @@ class AppModel extends Model {
|
|||
|
||||
$sqlArray[] = "CREATE TABLE IF NOT EXISTS object_template_elements (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`uuid` varchar(40) COLLATE utf8_bin DEFAULT NULL,
|
||||
`version` int(11) NOT NULL,
|
||||
`object_template_id` int(11) NOT NULL,
|
||||
`in-object-name` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci,
|
||||
`type` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci,
|
||||
`frequency` int(11) NOT NULL,
|
||||
|
@ -758,13 +759,19 @@ class AppModel extends Model {
|
|||
`sane_default` text COLLATE utf8_bin,
|
||||
`values_list` text COLLATE utf8_bin,
|
||||
PRIMARY KEY (id),
|
||||
INDEX `uuid` (`uuid`),
|
||||
INDEX `in-object-name` (`in-object-name`),
|
||||
INDEX `type` (`type`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
|
||||
|
||||
$sqlArray[] = 'ALTER TABLE attributes CHANGE object_id object_id int(11) NOT NULL DEFAULT 0;';
|
||||
$sqlArray[] = 'ALTER TABLE attributes CHANGE object_relation object_relation varchar(255) COLLATE utf8_bin;';
|
||||
$sqlArray[] = 'ALTER TABLE `logs` CHANGE `model` `model` VARCHAR(80) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL;';
|
||||
$sqlArray[] = 'ALTER TABLE `logs` CHANGE `action` `action` VARCHAR(80) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL;';
|
||||
|
||||
$sqlArray[] = 'ALTER TABLE attributes ADD object_id int(11) NOT NULL DEFAULT 0;';
|
||||
$sqlArray[] = 'ALTER TABLE attributes ADD object_relation varchar(255) COLLATE utf8_bin;';
|
||||
|
||||
$sqlArray[] = "ALTER TABLE `roles` ADD `perm_object_template` tinyint(1) NOT NULL DEFAULT 0;";
|
||||
$sqlArray[] = 'UPDATE `roles` SET `perm_object_template` = 1 WHERE `perm_site_admin` = 1;';
|
||||
|
||||
$indexArray[] = array('attributes', 'object_id');
|
||||
$indexArray[] = array('attributes', 'object_relation');
|
||||
break;
|
||||
|
|
|
@ -18,8 +18,14 @@ class Object extends AppModel {
|
|||
'foreignKey' => 'event_id'
|
||||
),
|
||||
'SharingGroup' => array(
|
||||
'className' => 'SharingGroup',
|
||||
'foreignKey' => 'sharing_group_id'
|
||||
'className' => 'SharingGroup',
|
||||
'foreignKey' => 'sharing_group_id'
|
||||
),
|
||||
'ObjectTemplate' => array(
|
||||
'className' => 'ObjectTemplate',
|
||||
'foreignKey' => false,
|
||||
'dependent' => false,
|
||||
'conditions' => array('Object.template_uuid' => 'ObjectTemplate.uuid')
|
||||
)
|
||||
);
|
||||
public $hasMany = array(
|
||||
|
@ -54,14 +60,14 @@ class Object extends AppModel {
|
|||
'AND' => array(
|
||||
'Event.distribution >' => 0,
|
||||
'Event.distribution <' => 4,
|
||||
Configure::read('MISP.unpublishedprivate') ? array('Event.published =' => 1) : array(),
|
||||
Configure::read('MISP.unpublishedprivate') ? array('Event.published' => 1) : array(),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'AND' => array(
|
||||
'Event.sharing_group_id' => $sgids,
|
||||
'Event.distribution' => 4,
|
||||
Configure::read('MISP.unpublishedprivate') ? array('Event.published =' => 1) : array(),
|
||||
Configure::read('MISP.unpublishedprivate') ? array('Event.published' => 1) : array(),
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -205,4 +211,22 @@ class Object extends AppModel {
|
|||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function prepareTemplate($template) {
|
||||
$temp = array();
|
||||
usort($template['ObjectTemplateElement'], function($a, $b) {
|
||||
return $a['frequency'] < $b['frequency'];
|
||||
});
|
||||
foreach ($template['ObjectTemplateElement'] as $k => $v) {
|
||||
$template['ObjectTemplateElement'][$k]['default_category'] = $this->Event->Attribute->typeDefinitions[$template['ObjectTemplateElement'][$k]['type']]['default_category'];
|
||||
$template['ObjectTemplateElement'][$k]['to_ids'] = $this->Event->Attribute->typeDefinitions[$template['ObjectTemplateElement'][$k]['type']]['to_ids'];
|
||||
$template['ObjectTemplateElement'][$k]['categories'] = array();
|
||||
foreach ($this->Event->Attribute->categoryDefinitions as $catk => $catv) {
|
||||
if (in_array($template['ObjectTemplateElement'][$k]['type'], $catv['types'])) {
|
||||
$template['ObjectTemplateElement'][$k]['categories'][$catk] = $catk;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $template;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
App::uses('AppModel', 'Model');
|
||||
|
||||
class Object extends AppModel {
|
||||
class ObjectTemplate extends AppModel {
|
||||
public $actsAs = array(
|
||||
'Containable',
|
||||
'SysLogLogable.SysLogLogable' => array( // TODO Audit, logable
|
||||
|
@ -17,8 +17,8 @@ class Object extends AppModel {
|
|||
'className' => 'User',
|
||||
'foreignKey' => 'user_id'
|
||||
),
|
||||
'Org' => array(
|
||||
'className' => 'Org',
|
||||
'Organisation' => array(
|
||||
'className' => 'Organisation',
|
||||
'foreignKey' => 'org_id'
|
||||
)
|
||||
);
|
||||
|
@ -35,7 +35,21 @@ class Object extends AppModel {
|
|||
public $validate = array(
|
||||
);
|
||||
|
||||
public function update() {
|
||||
public function afterFind($results, $primary = false) {
|
||||
foreach ($results as $k => $result) {
|
||||
if (isset($results[$k]['ObjectTemplate']['requirements'])) {
|
||||
$results[$k]['ObjectTemplate']['requirements'] = json_decode($results[$k]['ObjectTemplate']['requirements'], true);
|
||||
}
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function beforeSave($options = array()) {
|
||||
$this->data['ObjectTemplate']['requirements'] = empty($this->data['ObjectTemplate']['requirements']) ? '[]' : json_encode($this->data['ObjectTemplate']['requirements']);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function update($user) {
|
||||
$objectsDir = APP . 'files/misp-objects/objects';
|
||||
$directories = glob($objectsDir . '/*', GLOB_ONLYDIR);
|
||||
foreach ($directories as $k => $dir) {
|
||||
|
@ -53,12 +67,11 @@ class Object extends AppModel {
|
|||
if (!isset($template['version'])) $template['version'] = 1;
|
||||
$current = $this->find('first', array(
|
||||
'conditions' => array('uuid' => $template['uuid']),
|
||||
'recursive' => -1,
|
||||
'fields' => array('version', 'uuid', 'name')
|
||||
'recursive' => -1
|
||||
));
|
||||
if (empty($current) || $template['version'] > $current['ObjectTemplate']['version']) {
|
||||
$result = $this->__updateObjectTemplate($template, $current);
|
||||
if (is_numeric($result)) {
|
||||
$result = $this->__updateObjectTemplate($template, $current, $user);
|
||||
if ($result === true) {
|
||||
$updated['success'][$result] = array('name' => $template['name'], 'new' => $template['version']);
|
||||
if (!empty($current)) $updated['success'][$result]['old'] = $current['ObjectTemplate']['version'];
|
||||
} else {
|
||||
|
@ -69,4 +82,98 @@ class Object extends AppModel {
|
|||
return $updated;
|
||||
}
|
||||
|
||||
private function __updateObjectTemplate($template, $current, $user) {
|
||||
$success = false;
|
||||
$template['requirements'] = array();
|
||||
$requirementFields = array('required', 'requiredOneOf');
|
||||
foreach ($requirementFields as $field) {
|
||||
if (isset($template[$field])) {
|
||||
$template['requirements'][$field] = $template[$field];
|
||||
}
|
||||
}
|
||||
if (empty($current)) {
|
||||
$template['user_id'] = $user['id'];
|
||||
$template['org_id'] = $user['org_id'];
|
||||
$template['fixed'] = 1;
|
||||
$this->create();
|
||||
$result = $this->save($template);
|
||||
} else {
|
||||
$fieldsToUpdate = array('version', 'description', 'meta-category', 'name', 'requirements', 'fixed');
|
||||
foreach ($fieldsToUpdate as $field) {
|
||||
if (isset($template[$field]) && $current['ObjectTemplate'][$field] != $template[$field]) {
|
||||
$current['ObjectTemplate'][$field] = $template[$field];
|
||||
}
|
||||
}
|
||||
$result = $this->save($current);
|
||||
}
|
||||
if (!$result) {
|
||||
return $this->validationErrors;
|
||||
}
|
||||
$id = $this->id;
|
||||
$existingTemplateElementsTemp = $this->ObjectTemplateElement->find('all', array(
|
||||
'recursive' => -1,
|
||||
'conditions' => array('object_template_id' => $id)
|
||||
));
|
||||
$existingTemplateElements = array();
|
||||
if (!empty($existingTemplateElementsTemp)) {
|
||||
foreach ($existingTemplateElementsTemp as $k => $v) {
|
||||
$existingTemplateElements[$v['ObjectTemplateElement']['in-object-name']] = $v['ObjectTemplateElement'];
|
||||
}
|
||||
}
|
||||
unset($existingTemplateElementsTemp);
|
||||
$fieldsToCompare = array('in-object-name', 'type', 'frequency', 'categories', 'sane_default', 'values_list');
|
||||
foreach ($template['attributes'] as $k => $attribute) {
|
||||
$attribute['in-object-name'] = $k;
|
||||
$attribute = $this->__convertJSONToElement($attribute);
|
||||
if (isset($existingTemplateElements[$k])) {
|
||||
$update_required = false;
|
||||
foreach ($fieldsToCompare as $field) {
|
||||
if (isset($attribute[$field])) {
|
||||
if ($existingTemplateElements[$k][$field] != $attribute[$field]) {
|
||||
$update_required = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($update_required) {
|
||||
$attribute = $existingTemplateElements[$k];
|
||||
unset($existingTemplateElements);
|
||||
$attribute['object_template_id'] = $id;
|
||||
$this->ObjectTemplateElement->save(array('ObjectTemplateElement' => $attribute));
|
||||
}
|
||||
unset($existingTemplateElements[$k]);
|
||||
} else {
|
||||
$this->ObjectTemplateElement->create();
|
||||
$attribute['object_template_id'] = $id;
|
||||
$this->ObjectTemplateElement->save(array('ObjectTemplateElement' => $attribute));
|
||||
}
|
||||
}
|
||||
if (!empty($existingTemplateElements)) {
|
||||
foreach ($existingTemplateElements as $k2 => $v2) {
|
||||
$this->ObjectTemplateElement->delete($v2['id']);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private function __convertJSONToElement($attribute) {
|
||||
$result = array();
|
||||
$translation_table = array(
|
||||
'misp-usage-frequency' => 'frequency',
|
||||
'misp-attribute' => 'type',
|
||||
'description' => 'description',
|
||||
'frequency' => 'frequency',
|
||||
'type' => 'type',
|
||||
'disable_correlation' => 'disable_correlation',
|
||||
'in-object-name' => 'in-object-name',
|
||||
'categories' => 'categories',
|
||||
'sane_default' => 'sane_default',
|
||||
'values_list' => 'values_list'
|
||||
);
|
||||
foreach ($translation_table as $from => $to) {
|
||||
if (isset($attribute[$from])) {
|
||||
$result[$to] = $attribute[$from];
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
App::uses('AppModel', 'Model');
|
||||
|
||||
class Object extends AppModel {
|
||||
class ObjectTemplateElement extends AppModel {
|
||||
public $actsAs = array(
|
||||
'Containable',
|
||||
'SysLogLogable.SysLogLogable' => array( // TODO Audit, logable
|
||||
|
@ -18,4 +18,23 @@ class Object extends AppModel {
|
|||
public $validate = array(
|
||||
);
|
||||
|
||||
public function afterFind($results, $primary = false) {
|
||||
foreach ($results as $k => $result) {
|
||||
$results[$k]['ObjectTemplateElement']['categories'] = json_decode($results[$k]['ObjectTemplateElement']['categories'], true);
|
||||
$results[$k]['ObjectTemplateElement']['values_list'] = json_decode($results[$k]['ObjectTemplateElement']['values_list'], true);
|
||||
$results[$k]['ObjectTemplateElement']['sane_default'] = json_decode($results[$k]['ObjectTemplateElement']['sane_default'], true);
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function beforeSave($options = array()) {
|
||||
if (empty($this->data['ObjectTemplateElement']['description'])) {
|
||||
$this->data['ObjectTemplateElement']['description'] = '';
|
||||
}
|
||||
$json_fields = array('categories', 'values_list', 'sane_default');
|
||||
foreach ($json_fields as $field) {
|
||||
$this->data['ObjectTemplateElement'][$field] = empty($this->data['ObjectTemplateElement'][$field]) ? '[]' : json_encode($this->data['ObjectTemplateElement'][$field]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,8 @@ class Role extends AppModel {
|
|||
'perm_template' => array('id' => 'RolePermTemplate', 'text' => 'Template Editor', 'readonlyenabled' => false),
|
||||
'perm_sharing_group' => array('id' => 'RolePermSharingGroup', 'text' => 'Sharing Group Editor', 'readonlyenabled' => false),
|
||||
'perm_delegate' => array('id' => 'RolePermDelegate', 'text' => 'Delegations Access', 'readonlyenabled' => false),
|
||||
'perm_sighting' => array('id' => 'RolePermSighting', 'text' => 'Sighting Creator', 'readonlyenabled' => true)
|
||||
'perm_sighting' => array('id' => 'RolePermSighting', 'text' => 'Sighting Creator', 'readonlyenabled' => true),
|
||||
'perm_object_template' => array('id' => 'RolePermObjectTemplate', 'text' => 'Object Template Editor', 'readonlyenabled' => false),
|
||||
);
|
||||
|
||||
public $premissionLevelName = array('Read Only', 'Manage Own Events', 'Manage Organisation Events', 'Manage and Publish Organisation Events');
|
||||
|
|
|
@ -65,6 +65,9 @@ class SysLogLogableBehavior extends LogableBehavior {
|
|||
foreach ( $Model->data[$Model->alias] as $key => $value ) {
|
||||
if (isset($Model->data[$Model->alias][$Model->primaryKey]) && !empty($this->old) && isset($this->old[$Model->alias][$key])) {
|
||||
$old = $this->old[$Model->alias][$key];
|
||||
if (is_array($old)) {
|
||||
$old = json_encode($old, true);
|
||||
}
|
||||
} else {
|
||||
$old = '';
|
||||
}
|
||||
|
|
|
@ -91,6 +91,8 @@
|
|||
<li><a href="<?php echo $baseurl;?>/organisations/index">Organisations</a></li>
|
||||
<li><a href="<?php echo $baseurl;?>/roles/index">Role Permissions</a></li>
|
||||
<li class="divider"></li>
|
||||
<li><a href="<?php echo $baseurl;?>/objectTemplates/index">List Object Templates</a></li>
|
||||
<li class="divider"></li>
|
||||
<li><a href="<?php echo $baseurl;?>/sharing_groups/index">List Sharing Groups</a></li>
|
||||
<?php if ($isAclSharingGroup): ?>
|
||||
<li><a href="<?php echo $baseurl;?>/sharing_groups/add">Add Sharing Group</a></li>
|
||||
|
|
|
@ -357,6 +357,16 @@
|
|||
<?php
|
||||
endif;
|
||||
break;
|
||||
case 'objectTemplates':
|
||||
?>
|
||||
<li id='liindex'><a href="<?php echo $baseurl;?>/objectTemplates/index">List Object Templates</a></li>
|
||||
<?php
|
||||
if ($menuItem === 'view'):
|
||||
?>
|
||||
<li class="active"><a href="#">View Object Template</a></li>
|
||||
<?php
|
||||
endif;
|
||||
break;
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
<div class="pagination">
|
||||
<ul>
|
||||
<?php
|
||||
$this->Paginator->options(array(
|
||||
'update' => '#clusters_div',
|
||||
'evalScripts' => true,
|
||||
'before' => '$(".progress").show()',
|
||||
'complete' => '$(".progress").hide()',
|
||||
));
|
||||
|
||||
echo $this->Paginator->prev('« ' . __('previous'), array('tag' => 'li', 'escape' => false), null, array('tag' => 'li', 'class' => 'prev disabled', 'escape' => false, 'disabledTag' => 'span'));
|
||||
echo $this->Paginator->numbers(array('modulus' => 20, 'separator' => '', 'tag' => 'li', 'currentClass' => 'active', 'currentTag' => 'span'));
|
||||
echo $this->Paginator->next(__('next') . ' »', array('tag' => 'li', 'escape' => false), null, array('tag' => 'li', 'class' => 'next disabled', 'escape' => false, 'disabledTag' => 'span'));
|
||||
?>
|
||||
</ul>
|
||||
</div>
|
||||
<table class="table table-striped table-hover table-condensed">
|
||||
<tr>
|
||||
<th><?php echo $this->Paginator->sort('in_object_name');?></th>
|
||||
<th><?php echo $this->Paginator->sort('type');?></th>
|
||||
<th><?php echo $this->Paginator->sort('frequency');?></th>
|
||||
<th><?php echo $this->Paginator->sort('description');?></th>
|
||||
<th>Categories</th>
|
||||
<th>Sane defaults</th>
|
||||
<th>List of valid Values</th>
|
||||
<th class="actions"><?php echo __('Actions');?></th>
|
||||
</tr>
|
||||
<?php
|
||||
$listItems = array('category', 'sane_default', 'values_list');
|
||||
foreach ($list as $k => $item):
|
||||
?>
|
||||
<tr>
|
||||
<td class="short bold"><?php echo h($item['ObjectTemplateElement']['in-object-name']); ?> </td>
|
||||
<td class="short"><?php echo h($item['ObjectTemplateElement']['type']); ?> </td>
|
||||
<td class="short"><?php echo h($item['ObjectTemplateElement']['frequency']); ?> </td>
|
||||
<td class="short"><?php echo h($item['ObjectTemplateElement']['description']); ?> </td>
|
||||
<?php
|
||||
foreach ($listItems as $listItem):
|
||||
?>
|
||||
<td class="short">
|
||||
<?php
|
||||
if (!empty($item['ObjectTemplateElement'][$listItem])) {
|
||||
foreach ($item['ObjectTemplateElement'][$listItem] as $value) {
|
||||
echo h($value) . '</br>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
<?php
|
||||
endforeach;
|
||||
?>
|
||||
<td class="short action-links">
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
endforeach;
|
||||
?>
|
||||
</table>
|
||||
<p>
|
||||
<?php
|
||||
echo $this->Paginator->counter(array('format' => __('Page {:page} of {:pages}, showing {:current} records out of {:count} total, starting on record {:start}, ending on {:end}')));
|
||||
?>
|
||||
</p>
|
||||
<div class="pagination">
|
||||
<ul>
|
||||
<?php
|
||||
echo $this->Paginator->prev('« ' . __('previous'), array('tag' => 'li', 'escape' => false), null, array('tag' => 'li', 'class' => 'prev disabled', 'escape' => false, 'disabledTag' => 'span'));
|
||||
echo $this->Paginator->numbers(array('modulus' => 20, 'separator' => '', 'tag' => 'li', 'currentClass' => 'active', 'currentTag' => 'span'));
|
||||
echo $this->Paginator->next(__('next') . ' »', array('tag' => 'li', 'escape' => false), null, array('tag' => 'li', 'class' => 'next disabled', 'escape' => false, 'disabledTag' => 'span'));
|
||||
?>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function(){
|
||||
});
|
||||
</script>
|
||||
<?php echo $this->Js->writeBuffer(); ?>
|
|
@ -0,0 +1,25 @@
|
|||
<div class="popover_choice">
|
||||
<legend>Select Object Category</legend>
|
||||
<div class="popover_choice_main" id ="popover_choice_main">
|
||||
<table style="width:100%;">
|
||||
<tr style="border-bottom:1px solid black;" class="templateChoiceButton">
|
||||
<td role="button" tabindex="0" aria-label="All clusters" title="All Objects" style="padding-left:10px;padding-right:10px; text-align:center;width:100%;" onClick="getPopup('<?php echo h($event_id); ?>/0', 'galaxies', 'selectCluster');">All Objects</td>
|
||||
</tr>
|
||||
<?php foreach ($galaxies as $galaxy): ?>
|
||||
<tr style="border-bottom:1px solid black;" class="templateChoiceButton">
|
||||
<td role="button" tabindex="0" aria-label="<?php echo h($galaxy['Galaxy']['name']); ?>" title="<?php echo h($galaxy['Galaxy']['name']); ?>" style="padding-left:10px;padding-right:10px; text-align:center;width:100%;" onClick="getPopup('<?php echo h($event_id); ?>/<?php echo h($galaxy['Galaxy']['id']);?>', 'galaxies', 'selectCluster');">Galaxy: <?php echo h($galaxy['Galaxy']['name']); ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
</div>
|
||||
<div role="button" tabindex="0" aria-label="Cancel" title="Cancel" class="templateChoiceButton templateChoiceButtonLast" onClick="cancelPopoverForm();">Cancel</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
resizePopoverBody();
|
||||
});
|
||||
|
||||
$(window).resize(function() {
|
||||
resizePopoverBody();
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,94 @@
|
|||
<div class="objectTemplates index">
|
||||
<h2>Object Template index</h2>
|
||||
<div class="pagination">
|
||||
<ul>
|
||||
<?php
|
||||
$this->Paginator->options(array(
|
||||
'update' => '.span12',
|
||||
'evalScripts' => true,
|
||||
'before' => '$(".progress").show()',
|
||||
'complete' => '$(".progress").hide()',
|
||||
));
|
||||
|
||||
echo $this->Paginator->prev('« ' . __('previous'), array('tag' => 'li', 'escape' => false), null, array('tag' => 'li', 'class' => 'prev disabled', 'escape' => false, 'disabledTag' => 'span'));
|
||||
echo $this->Paginator->numbers(array('modulus' => 20, 'separator' => '', 'tag' => 'li', 'currentClass' => 'active', 'currentTag' => 'span'));
|
||||
echo $this->Paginator->next(__('next') . ' »', array('tag' => 'li', 'escape' => false), null, array('tag' => 'li', 'class' => 'next disabled', 'escape' => false, 'disabledTag' => 'span'));
|
||||
?>
|
||||
</ul>
|
||||
</div>
|
||||
<table class="table table-striped table-hover table-condensed">
|
||||
<tr>
|
||||
<th><?php echo $this->Paginator->sort('id');?></th>
|
||||
<th><?php echo $this->Paginator->sort('name');?></th>
|
||||
<th><?php echo $this->Paginator->sort('uuid');?></th>
|
||||
<th><?php echo $this->Paginator->sort('org_id', 'Organisation');?></th>
|
||||
<th><?php echo $this->Paginator->sort('version');?></th>
|
||||
<th><?php echo $this->Paginator->sort('meta-category');?></th>
|
||||
<th><?php echo $this->Paginator->sort('description');?></th>
|
||||
<th>Requirements</th>
|
||||
<th class="actions">Actions</th>
|
||||
</tr>
|
||||
<?php
|
||||
foreach ($list as $template):
|
||||
$td_attributes = 'ondblclick="document.location.href =\'/objectTemplates/view/' . h($template['ObjectTemplate']['id']) . '\'"';
|
||||
?>
|
||||
<tr>
|
||||
<td class="short" <?php echo $td_attributes; ?>><?php echo h($template['ObjectTemplate']['id']); ?></td>
|
||||
<td class="shortish" <?php echo $td_attributes; ?>>
|
||||
<?php
|
||||
if ($template['ObjectTemplate']['fixed']):
|
||||
?>
|
||||
<img src="<?php echo $baseurl;?>/img/orgs/MISP.png" width="24" height="24" style="padding-bottom:3px;" />
|
||||
<?php
|
||||
endif;
|
||||
?>
|
||||
<span class="bold"><?php echo h($template['ObjectTemplate']['name']); ?></span>
|
||||
</td>
|
||||
<td class="short" <?php echo $td_attributes; ?>><?php echo h($template['ObjectTemplate']['uuid']); ?></td>
|
||||
<td class="short" <?php echo $td_attributes; ?>><?php echo h($template['Organisation']['name']); ?></td>
|
||||
<td class="short" <?php echo $td_attributes; ?>><?php echo h($template['ObjectTemplate']['version']); ?></td>
|
||||
<td class="short" <?php echo $td_attributes; ?>><?php echo h($template['ObjectTemplate']['meta-category']); ?></td>
|
||||
<td <?php echo $td_attributes; ?>><?php echo h($template['ObjectTemplate']['description']); ?></td>
|
||||
<td <?php echo $td_attributes; ?>>
|
||||
<?php
|
||||
if (!empty($template['ObjectTemplate']['requirements'])):
|
||||
foreach ($template['ObjectTemplate']['requirements'] as $group => $requirements):
|
||||
?>
|
||||
<span class="bold"><?php echo h($group); ?></span><br />
|
||||
<?php
|
||||
foreach ($requirements as $requirement):
|
||||
?>
|
||||
<span> <?php echo h($requirement); ?></span><br />
|
||||
<?php
|
||||
endforeach;
|
||||
endforeach;
|
||||
endif;
|
||||
?>
|
||||
</td>
|
||||
<td class="short action-links">
|
||||
<a href='/objectTemplates/view/<?php echo $template['ObjectTemplate']['id']; ?>' class = "icon-list-alt" title = "View"></a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
endforeach; ?>
|
||||
</table>
|
||||
<p>
|
||||
<?php
|
||||
echo $this->Paginator->counter(array(
|
||||
'format' => __('Page {:page} of {:pages}, showing {:current} records out of {:count} total, starting on record {:start}, ending on {:end}')
|
||||
));
|
||||
?>
|
||||
</p>
|
||||
<div class="pagination">
|
||||
<ul>
|
||||
<?php
|
||||
echo $this->Paginator->prev('« ' . __('previous'), array('tag' => 'li', 'escape' => false), null, array('tag' => 'li', 'class' => 'prev disabled', 'escape' => false, 'disabledTag' => 'span'));
|
||||
echo $this->Paginator->numbers(array('modulus' => 20, 'separator' => '', 'tag' => 'li', 'currentClass' => 'active', 'currentTag' => 'span'));
|
||||
echo $this->Paginator->next(__('next') . ' »', array('tag' => 'li', 'escape' => false), null, array('tag' => 'li', 'class' => 'next disabled', 'escape' => false, 'disabledTag' => 'span'));
|
||||
?>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<?php
|
||||
echo $this->element('side_menu', array('menuList' => 'objectTemplates', 'menuItem' => 'index'));
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
echo $this->element('side_menu', array('menuList' => 'objectTemplates', 'menuItem' => 'view'));
|
||||
?>
|
||||
<div class="object_template view">
|
||||
<div class="row-fluid">
|
||||
<div class="span8">
|
||||
<h2><?php echo h(ucfirst($template['ObjectTemplate']['name'])); ?> Object Template</h2>
|
||||
<dl>
|
||||
<dt>Object Template ID</dt>
|
||||
<dd><?php echo h($template['ObjectTemplate']['id']); ?></dd>
|
||||
<dt>Name</dt>
|
||||
<dd><?php echo $template['ObjectTemplate']['name'] ? h($template['ObjectTemplate']['name']) : h($template['ObjectTemplate']['type']); ?></dd>
|
||||
<dt>Organisation</dt>
|
||||
<dd><?php echo h($template['Organisation']['name']); ?></dd>
|
||||
<dt>Uuid</dt>
|
||||
<dd><?php echo h($template['ObjectTemplate']['uuid']); ?></dd>
|
||||
<dt>Version</dt>
|
||||
<dd><?php echo h($template['ObjectTemplate']['version']); ?></dd>
|
||||
<dt>Meta-category</dt>
|
||||
<dd><?php echo h($template['ObjectTemplate']['meta-category']); ?></dd>
|
||||
<dt>Description</dt>
|
||||
<dd><?php echo h($template['ObjectTemplate']['description']); ?></dd>
|
||||
<dt>Requirements</dt>
|
||||
<dd>
|
||||
<?php
|
||||
if (!empty($template['ObjectTemplate']['requirements'])):
|
||||
foreach ($template['ObjectTemplate']['requirements'] as $group => $requirements):
|
||||
?>
|
||||
<span class="bold"><?php echo h($group); ?></span><br />
|
||||
<?php
|
||||
foreach ($requirements as $requirement):
|
||||
?>
|
||||
<span> <?php echo h($requirement); ?></span><br />
|
||||
<?php
|
||||
endforeach;
|
||||
endforeach;
|
||||
endif;
|
||||
?>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
<div id="ajaxContent" style="width:100%;"></div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
<?php
|
||||
$startingTab = 'all';
|
||||
?>
|
||||
$(document).ready(function () {
|
||||
objectTemplateViewContent('<?php echo $startingTab; ?>', '<?php echo h($id);?>');
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,198 @@
|
|||
<div class="<?php if (!isset($ajax) || !$ajax) echo 'form';?>">
|
||||
<div>
|
||||
<?php
|
||||
echo $this->Form->create('Object', array('id', 'url' => '/objects/add/' . $event['Event']['id'] . '/' . $template['ObjectTemplate']['id']));
|
||||
echo $this->Form->input('data', array(
|
||||
'style' => 'display:none;',
|
||||
'label' => false
|
||||
));
|
||||
echo $this->Form->end();
|
||||
?>
|
||||
</div>
|
||||
<h3><?php echo 'Add ' . Inflector::humanize(h($template['ObjectTemplate']['name'])) . ' Object'; ?></h3>
|
||||
<div class="row-fluid">
|
||||
<dl class="span8">
|
||||
<dt>Object Template</dt>
|
||||
<dd>
|
||||
<?php echo Inflector::humanize(h($template['ObjectTemplate']['name'])); ?>
|
||||
</dd>
|
||||
<dt>Description</dt>
|
||||
<dd>
|
||||
<?php echo h($template['ObjectTemplate']['description']); ?>
|
||||
</dd>
|
||||
<?php
|
||||
if (!empty($template['ObjectTemplate']['requirements']['required']) || !empty($template['ObjectTemplate']['requirements']['requiredOneOf'])):
|
||||
?>
|
||||
<dt>Requirements</dt>
|
||||
<dd>
|
||||
<?php
|
||||
if (!empty($template['ObjectTemplate']['requirements']['required'])) {
|
||||
echo '<span class="bold">Required</span>: ' . h(implode(', ', $template['ObjectTemplate']['requirements']['required'])) . '<br />';
|
||||
}
|
||||
if (!empty($template['ObjectTemplate']['requirements']['requiredOneOf'])) {
|
||||
echo '<span class="bold">Required one of</span>: ' . h(implode(', ', $template['ObjectTemplate']['requirements']['requiredOneOf']));
|
||||
}
|
||||
?>
|
||||
</dd>
|
||||
<?php
|
||||
endif;
|
||||
?>
|
||||
<dt>Meta category</dt>
|
||||
<dd>
|
||||
<?php echo Inflector::humanize(h($template['ObjectTemplate']['meta-category'])); ?>
|
||||
</dd>
|
||||
</dl>
|
||||
<table class="table table-striped table-condensed">
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Type</th>
|
||||
<th>Category</th>
|
||||
<th>Value</th>
|
||||
<th>Description</th>
|
||||
<th>To IDS</th>
|
||||
<th>Distribution</th>
|
||||
</tr>
|
||||
<?php
|
||||
foreach ($template['ObjectTemplateElement'] as $k => $element):
|
||||
?>
|
||||
<tr>
|
||||
<td class="shortish bold">
|
||||
<?php echo Inflector::humanize(h($element['in-object-name'])); ?>
|
||||
</td>
|
||||
<td class="short">
|
||||
<?php echo h($element['type']); ?>
|
||||
</td>
|
||||
<td class="short">
|
||||
<select>
|
||||
<?php
|
||||
foreach ($element['categories'] as $category):
|
||||
?>
|
||||
<option id="category_select_<?php echo h($k); ?>" value="<?php echo h($category); ?>" <?php echo $category == $element['default_category'] ? 'selected' : ''; ?>>
|
||||
<?php echo h($category);?>
|
||||
</option>
|
||||
<?php
|
||||
endforeach;
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
<td>
|
||||
<?php
|
||||
if (empty($element['values_list'])):
|
||||
?>
|
||||
<textarea id="value_select_<?php echo h($k); ?>" class="input" style="height:20px;width:400px;" <?php echo 'list="value_select_list_' . $k . '"'; ?>></textarea>
|
||||
<?php
|
||||
if (!empty($elements['sane_default'])):
|
||||
?>
|
||||
<datalist id="exampleList">
|
||||
<option value="A">
|
||||
<option value="B">
|
||||
</datalist>
|
||||
<?php
|
||||
endif;
|
||||
else:
|
||||
?>
|
||||
|
||||
<?php
|
||||
endif;
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
endforeach;
|
||||
?>
|
||||
</table>
|
||||
</div>
|
||||
<?php if ($ajax): ?>
|
||||
<div class="overlay_spacing">
|
||||
<table>
|
||||
<tr>
|
||||
<td style="vertical-align:bottom">
|
||||
<span id="submitButton" class="btn btn-primary" title="Submit" role="button" tabindex="0" aria-label="Submit" onClick="submitPopoverForm('<?php echo $event_id;?>', 'add')">Submit</span>
|
||||
</td>
|
||||
<td style="width:540px;margin-bottom:0px;">
|
||||
<p style="color:red;font-weight:bold;display:none;text-align:center;margin-bottom:0px;" id="warning-message">Warning: You are about to share data that is of a classified nature. Make sure that you are authorised to share this.</p>
|
||||
</td>
|
||||
<td style="vertical-align:bottom;">
|
||||
<span class="btn btn-inverse" title="Cancel" role="button" tabindex="0" aria-label="Cancel" id="cancel_attribute_add">Cancel</span>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<?php
|
||||
else:
|
||||
?>
|
||||
<p style="color:red;font-weight:bold;display:none;" id="warning-message">Warning: You are about to share data that is of a classified nature. Make sure that you are authorised to share this.</p>
|
||||
<?php
|
||||
echo $this->Form->button('Submit', array('class' => 'btn btn-primary'));
|
||||
endif;
|
||||
echo $this->Form->end();
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
if (!$ajax) {
|
||||
echo $this->element('side_menu', array('menuList' => 'event', 'menuItem' => 'addObject', 'event' => $event));
|
||||
}
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
var fieldsArray = new Array('AttributeCategory', 'AttributeType', 'AttributeValue', 'AttributeDistribution', 'AttributeComment', 'AttributeToIds', 'AttributeBatchImport', 'AttributeSharingGroupId');
|
||||
<?php
|
||||
$formInfoTypes = array('distribution' => 'Distribution', 'category' => 'Category', 'type' => 'Type');
|
||||
echo 'var formInfoFields = ' . json_encode($formInfoTypes) . PHP_EOL;
|
||||
foreach ($formInfoTypes as $formInfoType => $humanisedName) {
|
||||
echo 'var ' . $formInfoType . 'FormInfoValues = {' . PHP_EOL;
|
||||
foreach ($info[$formInfoType] as $key => $formInfoData) {
|
||||
echo '"' . $key . '": "<span class=\"blue bold\">' . h($formInfoData['key']) . '</span>: ' . h($formInfoData['desc']) . '<br />",' . PHP_EOL;
|
||||
}
|
||||
echo '}' . PHP_EOL;
|
||||
}
|
||||
?>
|
||||
|
||||
//
|
||||
//Generate Category / Type filtering array
|
||||
//
|
||||
var category_type_mapping = new Array();
|
||||
<?php
|
||||
foreach ($categoryDefinitions as $category => $def) {
|
||||
echo "category_type_mapping['" . addslashes($category) . "'] = {";
|
||||
$first = true;
|
||||
foreach ($def['types'] as $type) {
|
||||
if ($first) $first = false;
|
||||
else echo ', ';
|
||||
echo "'" . addslashes($type) . "' : '" . addslashes($type) . "'";
|
||||
}
|
||||
echo "}; \n";
|
||||
}
|
||||
?>
|
||||
|
||||
$(document).ready(function() {
|
||||
initPopoverContent('Attribute');
|
||||
$('#AttributeDistribution').change(function() {
|
||||
if ($('#AttributeDistribution').val() == 4) $('#SGContainer').show();
|
||||
else $('#SGContainer').hide();
|
||||
});
|
||||
|
||||
$("#AttributeCategory").on('change', function(e) {
|
||||
formCategoryChanged('Attribute');
|
||||
if ($(this).val() === 'Attribution' || $(this).val() === 'Targeting data') {
|
||||
$("#warning-message").show();
|
||||
} else {
|
||||
$("#warning-message").hide();
|
||||
}
|
||||
if ($(this).val() === 'Internal reference') {
|
||||
$("#AttributeDistribution").val('0');
|
||||
$('#SGContainer').hide();
|
||||
}
|
||||
});
|
||||
|
||||
$("#AttributeCategory, #AttributeType, #AttributeDistribution").change(function() {
|
||||
initPopoverContent('Attribute');
|
||||
});
|
||||
<?php if ($ajax): ?>
|
||||
$('#cancel_attribute_add').click(function() {
|
||||
cancelPopoverForm();
|
||||
});
|
||||
|
||||
<?php endif; ?>
|
||||
});
|
||||
</script>
|
||||
<?php echo $this->Js->writeBuffer(); // Write cached scripts
|
|
@ -1933,6 +1933,27 @@ function freetextImportResultsSubmit(id, count) {
|
|||
});
|
||||
}
|
||||
|
||||
function objectTemplateViewContent(context, id) {
|
||||
var url = "/objectTemplateElements/viewElements/" + id + "/" + context;
|
||||
$.ajax({
|
||||
url: url,
|
||||
type:'GET',
|
||||
beforeSend: function (XMLHttpRequest) {
|
||||
$(".loading").show();
|
||||
},
|
||||
error: function(){
|
||||
$('#ajaxContent').html('An error has occured, please reload the page.');
|
||||
},
|
||||
success: function(response){
|
||||
$('#ajaxContent').html(response);
|
||||
},
|
||||
complete: function() {
|
||||
$(".loading").hide();
|
||||
},
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function organisationViewContent(context, id) {
|
||||
organisationViewButtonHighlight(context);
|
||||
var action = "/organisations/landingpage/";
|
||||
|
|
Loading…
Reference in New Issue