Merge branch 'feature/templates' into develop

Conflicts:
	app/Model/Event.php
pull/274/head
iglocska 2014-07-19 15:51:30 +02:00
commit e1988690c6
86 changed files with 4395 additions and 154 deletions

2
.gitignore vendored
View File

@ -13,6 +13,8 @@
/app/tmp/cache/views/myapp*
/app/files/*
!/app/files/empty
/app/tmp/files/*
!/app/tmp/files/empty
/app/webroot/img/logo.png
/app/Config/bootstrap.php
/app/Config/database.php

View File

@ -150,7 +150,7 @@ CREATE TABLE IF NOT EXISTS `logs` (
`org` varchar(255) COLLATE utf8_bin DEFAULT NULL,
`description` varchar(255) COLLATE utf8_bin DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1 ;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
-- --------------------------------------------------------
@ -206,6 +206,7 @@ CREATE TABLE IF NOT EXISTS `roles` (
`perm_site_admin` tinyint(1) NOT NULL DEFAULT '0',
`perm_regexp_access` tinyint(1) NOT NULL DEFAULT '0',
`perm_tagger` tinyint(1) NOT NULL DEFAULT '0',
`perm_template` tinyint(1) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
@ -283,6 +284,118 @@ CREATE TABLE IF NOT EXISTS `tasks` (
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table `tasks`
--
CREATE TABLE IF NOT EXISTS `tasks` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`type` varchar(100) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`timer` int(11) NOT NULL,
`scheduled_time` varchar(8) NOT NULL DEFAULT '6:00',
`job_id` int(11) NOT NULL,
`description` varchar(255) NOT NULL,
`next_execution_time` int(11) NOT NULL,
`message` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table `templates`
--
CREATE TABLE IF NOT EXISTS `templates` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`description` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`org` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`share` tinyint(1) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table `template_elements`
--
CREATE TABLE IF NOT EXISTS `template_elements` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`template_id` int(11) NOT NULL,
`position` int(11) NOT NULL,
`element_definition` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table `template_element_attributes`
--
CREATE TABLE IF NOT EXISTS `template_element_attributes` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`template_element_id` int(11) NOT NULL,
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`description` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`to_ids` tinyint(1) NOT NULL DEFAULT '1',
`category` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`complex` tinyint(1) NOT NULL,
`type` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`mandatory` tinyint(1) NOT NULL,
`batch` tinyint(1) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table `template_element_files`
--
CREATE TABLE IF NOT EXISTS `template_element_files` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`template_element_id` int(11) NOT NULL,
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`description` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`category` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`malware` tinyint(1) NOT NULL,
`mandatory` tinyint(1) NOT NULL,
`batch` tinyint(1) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table `template_element_texts`
--
CREATE TABLE IF NOT EXISTS `template_element_texts` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`template_element_id` int(11) NOT NULL,
`text` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table `template_tags`
--
CREATE TABLE IF NOT EXISTS `template_tags` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`template_id` int(11) NOT NULL,
`tag_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
@ -314,7 +427,7 @@ CREATE TABLE IF NOT EXISTS `threat_levels` (
`description` varchar(255) DEFAULT NULL,
`form_description` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
@ -352,7 +465,7 @@ CREATE TABLE IF NOT EXISTS `whitelist` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1 ;
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
-- --------------------------------------------------------

View File

@ -0,0 +1,123 @@
-- Copyright (c) 2009 www.cryer.co.uk
-- Script is free to use provided this copyright header is included.
drop procedure if exists AddColumnUnlessExists;
delimiter '//'
create procedure AddColumnUnlessExists(
IN dbName tinytext,
IN tableName tinytext,
IN fieldName tinytext,
IN fieldDef text)
begin
IF NOT EXISTS (
SELECT * FROM information_schema.COLUMNS
WHERE column_name=fieldName
and table_name=tableName
and table_schema=dbName
)
THEN
set @ddl=CONCAT('ALTER TABLE ',dbName,'.',tableName,
' ADD COLUMN ',fieldName,' ',fieldDef);
prepare stmt from @ddl;
execute stmt;
END IF;
end;
//
delimiter ';'
call AddColumnUnlessExists(Database(), 'roles', 'perm_template', 'TINYINT( 1 ) NOT NULL DEFAULT 0');
-- --------------------------------------------------------
--
-- Table structure for table `templates`
--
CREATE TABLE IF NOT EXISTS `templates` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`description` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`org` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`share` tinyint(1) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table `template_elements`
--
CREATE TABLE IF NOT EXISTS `template_elements` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`template_id` int(11) NOT NULL,
`position` int(11) NOT NULL,
`element_definition` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table `template_element_attributes`
--
CREATE TABLE IF NOT EXISTS `template_element_attributes` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`template_element_id` int(11) NOT NULL,
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`description` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`to_ids` tinyint(1) NOT NULL DEFAULT '1',
`category` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`complex` tinyint(1) NOT NULL,
`type` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`mandatory` tinyint(1) NOT NULL,
`batch` tinyint(1) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table `template_element_files`
--
CREATE TABLE IF NOT EXISTS `template_element_files` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`template_element_id` int(11) NOT NULL,
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`description` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`category` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`malware` tinyint(1) NOT NULL,
`mandatory` tinyint(1) NOT NULL,
`batch` tinyint(1) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table `template_element_texts`
--
CREATE TABLE IF NOT EXISTS `template_element_texts` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`template_element_id` int(11) NOT NULL,
`text` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table `template_tags`
--
CREATE TABLE IF NOT EXISTS `template_tags` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`template_id` int(11) NOT NULL,
`tag_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

View File

@ -138,3 +138,41 @@ INSERT IGNORE INTO `tasks` (`id`, `type`, `timer`, `scheduled_time`, `job_id`, `
(2, 'pull_all', 0, '12:00', 0, 'Initiates a full pull for all eligible instances.', 1391601600, 'Not scheduled yet.'),
(3, 'push_all', 0, '12:00', 0, 'Initiates a full push for all eligible instances.', 1391601600, 'Not scheduled yet.');
CREATE TABLE IF NOT EXISTS `templates` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`description` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`org` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`share` tinyint(1) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE IF NOT EXISTS `template_elements` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`template_id` int(11) NOT NULL,
`position` int(11) NOT NULL,
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`description` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`to_ids` tinyint(1) NOT NULL DEFAULT '1',
`category` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`mandatory` tinyint(1) NOT NULL,
`batch` tinyint(1) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE IF NOT EXISTS `template_tags` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`template_id` int(11) NOT NULL,
`tag_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE IF NOT EXISTS `template_element_types` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`template_element_id` int(11) NOT NULL,
`type` varchar(100) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

View File

@ -130,6 +130,7 @@ class AppController extends Controller {
$this->set('isAclAuth', $role['perm_auth']);
$this->set('isAclRegexp', $role['perm_regexp_access']);
$this->set('isAclTagger', $role['perm_tagger']);
$this->set('isAclTemplate', $role['perm_template']);
$this->userRole = $role;
} else {
$this->set('me', false);
@ -145,6 +146,7 @@ class AppController extends Controller {
$this->set('isAclAuth', false);
$this->set('isAclRegexp', false);
$this->set('isAclTagger', false);
$this->set('isAclTemplate', false);
}
if (Configure::read('debug') > 0) {
$this->debugMode = 'debugOn';

View File

@ -439,8 +439,6 @@ class AttributesController extends AppController {
$this->Attribute->save($temp, array('fieldlist' => array('value', 'type', 'category', 'event_id', 'distribution', 'to_ids', 'comment')));
}
// everything is done, now redirect to event view
$this->Session->setFlash(__('The attachment has been uploaded'));
$this->redirect(array('controller' => 'events', 'action' => 'view', $this->request->data['Attribute']['event_id']));
@ -915,22 +913,26 @@ class AttributesController extends AppController {
if (!$this->Attribute->exists()) {
return false;
}
$result = $this->Attribute->find('first', array(
'conditions' => array('Attribute.id' => $id),
'fields' => array('Attribute.id, Attribute.event_id', 'Attribute.uuid'),
'contain' => array('Event' => array(
'fields' => array('Event.id', 'Event.orgc', 'Event.org', 'Event.locked')
)),
));
if ('true' == Configure::read('MISP.sync')) {
// find the uuid
$result = $this->Attribute->findById($id);
$uuid = $result['Attribute']['uuid'];
}
// check for permissions
if (!$this->_isSiteAdmin()) {
$this->Attribute->read();
if ($this->Attribute->data['Event']['locked']) {
if ($this->_checkOrg() != $this->Attribute->data['Event']['org'] || !$this->userRole['perm_sync']) {
if ($result['Event']['locked']) {
if ($this->_checkOrg() != $result['Event']['org'] || !$this->userRole['perm_sync']) {
throw new MethodNotAllowedException();
}
} else {
if ($this->_checkOrg() != $this->Attribute->data['Event']['orgc']) {
if ($this->_checkOrg() != $result['Event']['orgc']) {
throw new MethodNotAllowedException();
}
}
@ -1695,9 +1697,13 @@ class AttributesController extends AppController {
}
public function generateCorrelation() {
$start = microtime(true);
if (!self::_isSiteAdmin()) throw new NotFoundException();
$k = $this->Attribute->generateCorrelation();
$this->Session->setFlash(__('All done. ' . $k . ' attributes processed.'));
$time_elapsed_us = microtime(true) - $start;
debug($time_elapsed_us);
throw new Exception();
$this->redirect(array('controller' => 'pages', 'action' => 'display', 'administration'));
}
@ -1792,4 +1798,118 @@ class AttributesController extends AppController {
$fieldURL = ucfirst($field);
$this->render('ajax/attributeEdit' . $fieldURL . 'Form');
}
public function attributeReplace($id) {
if (!$this->userRole['perm_add']) {
throw new MethodNotAllowedException('Event not found or you don\'t have permissions to create attributes');
}
$event = $this->Attribute->Event->find('first', array(
'conditions' => array('Event.id' => $id),
'fields' => array('id', 'orgc', 'distribution'),
'recursive' => -1
));
if (empty($event) || (!$this->_isSiteAdmin() && ($event['Event']['orgc'] != $this->Auth->user('org') || !$this->userRole['perm_add']))) throw new MethodNotAllowedException('Event not found or you don\'t have permissions to create attributes');
$this->set('event_id', $id);
if ($this->request->is('get')) {
$this->layout = 'ajax';
$this->request->data['Attribute']['event_id'] = $id;
// combobox for types
$types = array_keys($this->Attribute->typeDefinitions);
$types = $this->_arrayToValuesIndexArray($types);
$this->set('types', $types);
// combobos for categories
$categories = $this->Attribute->validate['category']['rule'][1];
array_pop($categories);
$categories = $this->_arrayToValuesIndexArray($categories);
$this->set('categories', compact('categories'));
$this->set('attrDescriptions', $this->Attribute->fieldDescriptions);
$this->set('typeDefinitions', $this->Attribute->typeDefinitions);
$this->set('categoryDefinitions', $this->Attribute->categoryDefinitions);
}
if ($this->request->is('post')) {
if (!$this->request->is('ajax')) throw new MethodNotAllowedException('This action can only be accessed via AJAX.');
$newValues = explode(PHP_EOL, $this->request->data['Attribute']['value']);
$category = $this->request->data['Attribute']['category'];
$type = $this->request->data['Attribute']['type'];
$to_ids = $this->request->data['Attribute']['to_ids'];
if (!$this->_isSiteAdmin() && $this->Auth->user('org') != $event['Event']['orgc'] && !$this->userRole['perm_add']) throw new MethodNotAllowedException('You are not authorised to do that.');
$oldAttributes = $this->Attribute->find('all', array(
'conditions' => array(
'event_id' => $id,
'category' => $category,
'type' => $type,
),
'fields' => array('id', 'event_id', 'category', 'type', 'value'),
'recursive' => -1,
));
$results = array('untouched' => count($oldAttributes), 'created' => 0, 'deleted' => 0, 'createdFail' => 0, 'deletedFail' => 0);
foreach ($newValues as &$value) {
$value = trim($value);
$found = false;
foreach ($oldAttributes as &$old) {
if ($value == $old['Attribute']['value']) {
$found = true;
}
}
if (!$found) {
$attribute = array(
'value' => $value,
'event_id' => $id,
'category' => $category,
'type' => $type,
'distribution' => $event['Event']['distribution'],
'to_ids' => $to_ids,
);
$this->Attribute->create();
if ($this->Attribute->save(array('Attribute' => $attribute))) {
$results['created']++;
} else {
$results['createdFail']++;
}
}
}
foreach ($oldAttributes as &$old) {
if (!in_array($old['Attribute']['value'], $newValues)) {
if ($this->Attribute->delete($old['Attribute']['id'])) {
$results['deleted']++;
$results['untouched']--;
} else {
$results['deletedFail']++;
}
}
}
$message = '';
$success = true;
if (($results['created'] > 0 || $results['deleted'] > 0) && $results['createdFail'] == 0 && $results['deletedFail'] == 0) {
$message .= 'Update completed without any issues.';
} else {
$message .= 'Update completed with some errors.';
$success = false;
}
if ($results['created']) $message .= $results['created'] . ' attribute' . $this->__checkCountForOne($results['created']) . ' created. ';
if ($results['createdFail']) $message .= $results['createdFail'] . ' attribute' . $this->__checkCountForOne($results['createdFail']) . ' could not be created. ';
if ($results['deleted']) $message .= $results['deleted'] . ' attribute' . $this->__checkCountForOne($results['deleted']) . ' deleted.';
if ($results['deletedFail']) $message .= $results['deletedFail'] . ' attribute' . $this->__checkCountForOne($results['deletedFail']) . ' could not be deleted. ';
$message .= $results['untouched'] . ' attributes left untouched. ';
$this->autoRender = false;
$this->layout = 'ajax';
if ($success) return new CakeResponse(array('body'=> json_encode(array('saved' => true, 'success' => $message)),'status'=>200));
else return new CakeResponse(array('body'=> json_encode(array('saved' => true, 'errors' => $message)),'status'=>200));
}
}
private function __checkCountForOne($number) {
if ($number != 1) return 's';
return '';
}
}

View File

@ -2279,4 +2279,89 @@ class EventsController extends AppController {
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'Tag could not be removed.')),'status'=>200));
}
}
public function freeTextImport($id) {
if (!$this->userRole['perm_add']) {
throw new MethodNotAllowedException('Event not found or you don\'t have permissions to create attributes');
}
$event = $this->Event->find('first', array(
'conditions' => array('Event.id' => $id),
'fields' => array('id', 'orgc'),
'recursive' => -1
));
if (!$this->_isSiteAdmin() && !empty($event) && $event['Event']['orgc'] != $this->Auth->user('org')) throw new MethodNotAllowedException('Event not found or you don\'t have permissions to create attributes');
$this->set('event_id', $id);
if ($this->request->is('get')) {
$this->layout = 'ajax';
$this->request->data['Attribute']['event_id'] = $id;
}
if ($this->request->is('post')) {
App::uses('ComplexTypeTool', 'Tools');
$complexTypeTool = new ComplexTypeTool();
$resultArray = $complexTypeTool->checkComplexRouter($this->request->data['Attribute']['value'], 'FreeText');
foreach ($resultArray as &$r) {
$temp = array();
foreach ($r['types'] as $type) {
$temp[$type] = $type;
}
$r['types'] = $temp;
}
$typeCategoryMapping = array();
foreach ($this->Event->Attribute->categoryDefinitions as $k => $cat) {
foreach ($cat['types'] as $type) {
$typeCategoryMapping[$type][$k] = $k;
}
}
$defaultCategories = array(
'md5' => 'Payload delivery',
'sha1' => 'Payload delivery',
'sha256' => 'Payload delivery',
'regkey' => 'Persistence mechanism',
'filename' => 'Payload delivery',
'ip-src' => 'Network activity',
'ip-dst' => 'Network activity',
'hostname' => 'Network activity',
'domain' => 'Network activity',
'url' => 'Network activity',
'link' => 'Network activity',
'email-src' => 'Payload delivery',
'email-dst' => 'Payload delivery',
'text' => 'Other',
);
$this->set('defaultCategories', $defaultCategories);
$this->set('typeCategoryMapping', $typeCategoryMapping);
$this->set('resultArray', $resultArray);
$this->render('free_text_results');
}
}
public function saveFreeText($id) {
if ($this->request->is('post')) {
$event = $this->Event->find('first', array(
'conditions' => array('id' => $id),
'recursive' => -1,
'fields' => array('orgc', 'id', 'distribution'),
));
$saved = 0;
$failed = 0;
foreach ($this->request->data['Attribute'] as $k => $attribute) {
if ($attribute['save'] == '1') {
$this->Event->Attribute->create();
$attribute['distribution'] = $event['Event']['distribution'];
$attribute['comment'] = 'Imported via the freetext import.';
$attribute['event_id'] = $id;
if ($this->Event->Attribute->save($attribute)) {
$saved++;
} else {
$failed++;
}
}
}
$this->Session->setFlash($saved . ' attributes created. ' . $failed . ' attributes could not be saved. This may be due to attributes with similar values already existing.');
$this->redirect(array('controller' => 'events', 'action' => 'view', $id));
} else {
throw new MethodNotAllowedException();
}
}
}

View File

@ -103,4 +103,17 @@ class TagsController extends AppController {
$this->layout = 'ajax';
$this->render('/Events/ajax/ajaxTags');
}
public function viewTag($id) {
$tag = $this->Tag->find('first', array(
'conditions' => array(
'id' => $id
),
'recursive' => -1,
));
$this->layout = null;
$this->set('tag', $tag);
$this->set('id', $id);
$this->render('ajax/view_tag');
}
}

View File

@ -0,0 +1,240 @@
<?php
App::uses('AppController', 'Controller');
/**
* TemplateElements Controller
*
* @property TemplateElement $TemplateElements
*/
class TemplateElementsController extends AppController {
public $components = array('Security' ,'RequestHandler');
public $paginate = array(
'limit' => 50,
'order' => array(
'TemplateElement.position' => 'asc'
)
);
public function index($id) {
//check permissions
$template = $this->TemplateElement->Template->checkAuthorisation($id, $this->Auth->user(), false);
if (!$this->_isSiteAdmin() && !$template) throw new MethodNotAllowedException('No template with the provided ID exists, or you are not authorised to see it.');
$templateElements = $this->TemplateElement->find('all', array(
'conditions' => array(
'template_id' => $id,
),
'contain' => array(
'TemplateElementAttribute',
'TemplateElementText',
'TemplateElementFile'
),
'order' => array('TemplateElement.position ASC')
));
$this->loadModel('Attribute');
$this->set('validTypeGroups', $this->Attribute->validTypeGroups);
$this->set('id', $id);
$this->layout = 'ajaxTemplate';
$this->set('elements', $templateElements);
$mayModify = false;
if ($this->_isSiteAdmin() || $template['Template']['org'] == $this->Auth->user('org')) $mayModify = true;
$this->set('mayModify', $mayModify);
$this->render('ajax/ajaxIndex');
}
public function templateElementAddChoices($id) {
if (!$this->_isSiteAdmin() && !$this->TemplateElement->Template->checkAuthorisation($id, $this->Auth->user(), true)) throw new MethodNotAllowedException('You are not authorised to do that.');
if (!$this->request->is('ajax')) Throw new MethodNotAllowedException('This action is for ajax requests only.');
$this->set('id', $id);
$this->layout = 'ajax';
$this->render('ajax/template_element_add_choices');
}
public function add($type, $id) {
$ModelType = 'TemplateElement' . ucfirst($type);
if (!$this->_isSiteAdmin() && !$this->TemplateElement->Template->checkAuthorisation($id, $this->Auth->user(), true)) return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'You are not authorised to do that.')), 'status' => 200));
if (!$this->request->is('ajax')) Throw new MethodNotAllowedException('This action is for ajax requests only.');
if ($this->request->is('get')) {
$this->set('id', $id);
if ($type == 'attribute') {
$this->loadModel('Attribute');
// combobox for types
$types = array_keys($this->Attribute->typeDefinitions);
$types = $this->_arrayToValuesIndexArray($types);
$this->set('types', $types);
// combobox for categories
$categories = $this->Attribute->validate['category']['rule'][1];
array_pop($categories);
$categories = $this->_arrayToValuesIndexArray($categories);
$this->set('categories', compact('categories'));
$this->set('attrDescriptions', $this->Attribute->fieldDescriptions);
$this->set('typeDefinitions', $this->Attribute->typeDefinitions);
$categoryDefinitions = $this->Attribute->categoryDefinitions;
foreach ($categoryDefinitions as $k => &$catDef) {
foreach ($catDef['types'] as $l => $t) {
if ($t == 'malware-sample' || $t == 'attachment') {
unset($catDef['types'][$l]);
}
}
}
$this->set('categoryDefinitions', $categoryDefinitions);
$this->set('validTypeGroups', $this->Attribute->validTypeGroups);
$this->set('typeGroupCategoryMapping', $this->Attribute->typeGroupCategoryMapping);
} else if ($type == 'file') {
$this->loadModel('Attribute');
$categoryArray = array();
$categories = array();
foreach ($this->Attribute->categoryDefinitions as $k => $catDef) {
$temp = array();
if (in_array('malware-sample', $catDef['types'])) {
$temp[] = 'malware-sample';
}
if (in_array('attachment', $catDef['types'])) {
$temp[] = 'attachment';
}
if (!empty($temp)) {
$categoryArray[$k] = $temp;
$categories[] = $k;
}
}
$categories = $this->_arrayToValuesIndexArray($categories);
$this->set('categoryArray', $categoryArray);
$this->set('categories', $categories);
}
$this->layout = 'ajaxTemplate';
$this->render('ajax/template_element_add_' . $type);
} else if ($this->request->is('post')) {
$pos = $this->TemplateElement->lastPosition($id);
$this->TemplateElement->create();
$templateElement = array(
'TemplateElement' => array(
'template_id' => $id,
'position' => ++$pos,
'element_definition' => $type
),
);
$errorMessage = 'The element could not be added.';
if ($this->TemplateElement->save($templateElement)) {
$this->request->data[$ModelType]['template_element_id'] = $this->TemplateElement->id;
$this->TemplateElement->$ModelType->create();
if ($this->TemplateElement->$ModelType->save($this->request->data)) {
return new CakeResponse(array('body'=> json_encode(array('saved' => true, 'success' => 'Element successfully added to template.')), 'status' => 200));
} else {
$this->TemplateElement->delete($this->TemplateElement->id);
$errorMessage = $this->TemplateElement->$ModelType->validationErrors;
}
} else {
$errorMessage = $this->TemplateElement->validationErrors;
}
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => $errorMessage)), 'status' => 200));
}
}
public function edit($type, $id) {
$ModelType = 'TemplateElement' . ucfirst($type);
$templateElement = $this->TemplateElement->find('first', array(
'conditions' => array('TemplateElement.id' => $id),
'contain' => array('Template', $ModelType)
));
$this->set('template_id', $templateElement['Template']['id']);
if (!$this->_isSiteAdmin() && !$this->TemplateElement->Template->checkAuthorisation($id, $this->Auth->user(), true)) return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'You are not authorised to do that.')), 'status' => 200));
if (!$this->request->is('ajax')) Throw new MethodNotAllowedException('This action is for ajax requests only.');
if ($this->request->is('get')) {
$this->set('id', $id);
$this->request->data[$ModelType] = $templateElement[$ModelType][0];
if ($type == 'attribute') {
$this->loadModel('Attribute');
// combobox for categories
$categories = $this->Attribute->validate['category']['rule'][1];
array_pop($categories);
$categories = $this->_arrayToValuesIndexArray($categories);
$this->set('categories', compact('categories'));
$categoryDefinitions = $this->Attribute->categoryDefinitions;
foreach ($categoryDefinitions as $k => &$catDef) {
foreach ($catDef['types'] as $l => $t) {
if ($t == 'malware-sample' || $t == 'attachment') {
unset($catDef['types'][$l]);
}
}
}
if ($this->request->data['TemplateElementAttribute']['complex']) {
$this->set('initialTypes', $this->_arrayToValuesIndexArray($this->Attribute->typeGroupCategoryMapping[$templateElement['TemplateElementAttribute'][0]['category']]));
} else {
$this->set('initialTypes', $categoryDefinitions[$templateElement['TemplateElementAttribute'][0]['category']]['types']);
}
$this->set('initialValues', $templateElement['TemplateElementAttribute'][0]);
$this->set('categoryDefinitions', $categoryDefinitions);
$this->set('validTypeGroups', $this->Attribute->validTypeGroups);
$this->set('typeGroupCategoryMapping', $this->Attribute->typeGroupCategoryMapping);
} else if ($type == 'file') {
$this->loadModel('Attribute');
$categoryArray = array();
$categories = array();
foreach ($this->Attribute->categoryDefinitions as $k => $catDef) {
$temp = array();
if (in_array('malware-sample', $catDef['types'])) {
$temp[] = 'malware-sample';
}
if (in_array('attachment', $catDef['types'])) {
$temp[] = 'attachment';
}
if (!empty($temp)) {
$categoryArray[$k] = $temp;
$categories[] = $k;
}
}
$categories = $this->_arrayToValuesIndexArray($categories);
$this->set('categoryArray', $categoryArray);
$this->set('categories', $categories);
}
$this->layout = 'ajaxTemplate';
$this->render('ajax/template_element_edit_' . $type);
} else if ($this->request->is('post') || $this->request->is('put')) {
$this->request->data[$ModelType]['id'] = $templateElement[$ModelType][0]['id'];
$this->request->data[$ModelType]['template_element_id'] = $templateElement[$ModelType][0]['template_element_id'];
if ($this->TemplateElement->$ModelType->save($this->request->data)) {
return new CakeResponse(array('body'=> json_encode(array('saved' => true, 'success' => 'Element successfully edited.')), 'status' => 200));
} else {
$this->TemplateElement->delete($this->TemplateElement->id);
$errorMessage = $this->TemplateElement->$ModelType->validationErrors;
}
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'The element could not be edited.')), 'status' => 200));
}
}
public function delete($id) {
if (!$this->request->is('ajax')) Throw new MethodNotAllowedException('This action is for ajax requests only.');
$this->TemplateElement->read(null, $id);
if (!$this->_isSiteAdmin() && !$this->TemplateElement->Template->checkAuthorisation($this->TemplateElement['Template']['id'], $this->Auth->user(), true)) throw new NotAllowedException('You are not authorised to do that.');
if ($this->request->is('post')) {
if ($this->_isSiteAdmin() || $this->Auth->user('org') == $this->TemplateElement->data['TemplateElement']['org']) {
// check permissions
if (empty($this->TemplateElement->data)) throw new NotFoundException();
$type = 'TemplateElement' . ucfirst($this->TemplateElement->data['TemplateElement']['element_definition']);
if ($this->TemplateElement->$type->delete($this->TemplateElement->data[$type][0]['id'])) {
$this->TemplateElement->delete($this->TemplateElement->data['TemplateElement']['id']);
$this->TemplateElement->Template->trimElementPositions($this->TemplateElement->data['TemplateElement']['template_id']);
return new CakeResponse(array('body'=> json_encode(array('saved' => true, 'success' => 'Element deleted.')), 'status' => 200));
} else {
return new CakeResponse(array('body'=> json_encode(array('saved' => true, 'errors' => 'Couldn\'t delete the Element')), 'status' => 200));
}
} else {
return new CakeResponse(array('body'=> json_encode(array('saved' => true, 'errors' => 'You don\'t have permission to do that.')), 'status' => 200));
}
} else {
$this->set('id', $id);
$this->set('template_id', $this->TemplateElement->data['Template']['id']);
$this->render('ajax/templateElementConfirmationForm');
}
}
}

View File

@ -0,0 +1,420 @@
<?php
App::uses('AppController', 'Controller');
App::uses('Folder', 'Utility');
App::uses('File', 'Utility');
/**
* Templates Controller
*
* @property Template $Templates
*/
class TemplatesController extends AppController {
public $components = array('Security' ,'RequestHandler');
public $paginate = array(
'limit' => 50,
'order' => array(
'Template.id' => 'desc'
)
);
public function beforeFilter() { // TODO REMOVE
parent::beforeFilter();
$this->Security->unlockedActions = array('saveElementSorting', 'populateEventFromTemplate', 'uploadFile', 'deleteTemporaryFile');
}
public function fetchFormFromTemplate($id) {
}
public function index() {
$conditions = array();
if (!$this->_isSiteAdmin()) {
$conditions['OR'] = array('org' => $this->Auth->user('org'), 'share' => true);
}
if (!$this->_isSiteAdmin()) {
$this->paginate = Set::merge($this->paginate,array(
'conditions' =>
array("OR" => array(
array('org' => $this->Auth->user('org')),
array('share' => true),
))));
}
$this->set('list', $this->paginate());
}
public function edit($id) {
$template = $this->Template->checkAuthorisation($id, $this->Auth->user(), true);
if (!$this->_isSiteAdmin() && !$template) throw new MethodNotAllowedException('No template with the provided ID exists, or you are not authorised to edit it.');
$this->set('mayModify', true);
if ($this->request->is('post') || $this->request->is('put')) {
$this->request->data['Template']['id'] = $id;
unset($this->request->data['Template']['tagsPusher']);
$tags = $this->request->data['Template']['tags'];
unset($this->request->data['Template']['tags']);
$this->request->data['Template']['org'] = $this->Auth->user('org');
$this->Template->create();
if ($this->Template->save($this->request->data)) {
$id = $this->Template->id;
$tagArray = json_decode($tags);
$this->loadModel('TemplateTag');
$oldTags = $this->TemplateTag->find('all', array(
'conditions' => array('template_id' => $id),
'recursive' => -1,
'contain' => 'Tag'
));
$newTags = $this->TemplateTag->Tag->find('all', array(
'recursive' => -1,
'conditions' => array('name' => $tagArray)
));
foreach($oldTags as $k => $oT) {
if (!in_array($oT['Tag'], $newTags)) $this->TemplateTag->delete($oT['TemplateTag']['id']);
}
foreach($newTags as $k => $nT) {
if (!in_array($nT['Tag'], $oldTags)) {
$this->TemplateTag->create();
$this->TemplateTag->save(array('TemplateTag' => array('template_id' => $id, 'tag_id' => $nT['Tag']['id'])));
}
}
$this->redirect(array('action' => 'view', $this->Template->id));
} else {
throw new Exception('The template could not be edited.');
}
}
$this->request->data = $template;
// get all existing tags for the tag add dropdown menu
$this->loadModel('Tags');
$tags = $this->Tags->find('all');
$tagArray = array();
foreach ($tags as $tag) {
$tagArray[$tag['Tags']['id']] = $tag['Tags']['name'];
}
//get all tags currently assigned to the event
$currentTags = $this->Template->TemplateTag->find('all', array(
'recursive' => -1,
'contain' => 'Tag',
'conditions' => array('template_id' => $id),
));
$this->set('currentTags', $currentTags);
$this->set('id', $id);
$this->set('template', $template);
$this->set('tags', $tagArray);
$this->set('tagInfo', $tags);
}
public function view($id) {
if (!$this->_isSiteAdmin() && !$this->Template->checkAuthorisation($id, $this->Auth->user(), false)) throw new MethodNotAllowedException('No template with the provided ID exists, or you are not authorised to see it.');
if ($this->Template->checkAuthorisation($id, $this->Auth->user(), true)) $this->set('mayModify', true);
else $this->set('mayModify', false);
$template = $this->Template->find('first', array(
'conditions' => array(
'id' => $id,
),
'contain' => array(
'TemplateElement',
'TemplateTag' => array(
'Tag',
),
),
));
if (empty($template)) throw new NotFoundException('No template with the provided ID exists, or you are not authorised to see it.');
$tagArray = array();
foreach($template['TemplateTag'] as $tt) {
$tagArray[] = $tt;
}
$this->set('id', $id);
$this->set('template', $template);
}
public function add() {
if ($this->request->is('post')) {
unset($this->request->data['Template']['tagsPusher']);
$tags = $this->request->data['Template']['tags'];
unset($this->request->data['Template']['tags']);
$this->request->data['Template']['org'] = $this->Auth->user('org');
$this->Template->create();
if ($this->Template->save($this->request->data)) {
$id = $this->Template->id;
$tagArray = json_decode($tags);
$this->loadModel('TemplateTag');
$this->loadModel('Tag');
foreach ($tagArray as $t) {
$tag = $this->Tag->find('first', array(
'conditions' => array('name' => $t),
'fields' => array('id', 'name'),
'recursive' => -1,
));
$this->TemplateTag->create();
$this->TemplateTag->save(array('TemplateTag' => array('template_id' => $id, 'tag_id' => $tag['Tag']['id'])));
}
$this->redirect(array('action' => 'view', $this->Template->id));
} else {
throw new Exception('The template could not be created.');
}
}
$this->loadModel('Tags');
$tags = $this->Tags->find('all');
$tagArray = array();
foreach ($tags as $tag) {
$tagArray[$tag['Tags']['id']] = $tag['Tags']['name'];
}
$this->set('tags', $tagArray);
$this->set('tagInfo', $tags);
}
public function saveElementSorting() {
// check if user can edit the template
$this->autoRender = false;
$this->request->onlyAllow('ajax');
$orderedElements = $this->request->data;
foreach($orderedElements as &$e) {
$e = ltrim($e, 'id_');
}
$extractedIds = array();
foreach ($orderedElements as $element) $extractedIds[] = $element;
$template_id = $this->Template->TemplateElement->find('first', array(
'conditions' => array('id' => $extractedIds),
'recursive' => -1,
'fields' => array('id', 'template_id'),
));
if (!$this->_isSiteAdmin() && !$this->Template->checkAuthorisation($template_id['TemplateElement']['template_id'], $this->Auth->user(), true)) return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'You are not authorised to do that.')), 'status' => 200));
$elements = $this->Template->TemplateElement->find('all', array(
'conditions' => array('template_id' => $template_id['TemplateElement']['template_id']),
'recursive' => -1,
));
if (empty($elements)) return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'Something went wrong, the supplied template elements don\'t exist, or you are not eligible to edit them.')),'status'=>200));
if (count($elements) != count($orderedElements)) return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'Incomplete template element list passed as argument. Expecting ' . count($elements) . ' elements, only received positions for ' . count($orderedElements) . '.')),'status'=>200));
$template_id = $elements[0]['TemplateElement']['template_id'];
foreach ($elements as &$e) {
if ($template_id !== $e['TemplateElement']['template_id']) return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'Cannot sort template elements belonging to separate templates. You should never see this message during legitimate use.')),'status'=>200));
foreach ($orderedElements as $k => $orderedElement) {
if ($orderedElement == $e['TemplateElement']['id']) {
$e['TemplateElement']['position'] = $k+1;
}
}
}
$this->Template->TemplateElement->saveMany($elements);
return new CakeResponse(array('body'=> json_encode(array('saved' => true, 'success' => 'Elements repositioned.')),'status'=>200));
}
public function delete($id) {
$template = $this->Template->checkAuthorisation($id, $this->Auth->user(), true);
if (!$this->request->is('post')) throw new MethodNotAllowedException('This action can only be invoked via a post request.');
if (!$this->_isSiteAdmin() && !$template) throw new MethodNotAllowedException('No template with the provided ID exists, or you are not authorised to edit it.');
if ($this->Template->delete($id, true)) {
$this->Session->setFlash('Template deleted.');
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash('The template could not be deleted.');
$this->redirect(array('action' => 'index'));
}
}
public function templateChoices($id) {
$this->loadModel('Event');
$event = $this->Event->find('first' ,array(
'conditions' => array('id' => $id),
'recursive' => -1,
'fields' => array('orgc', 'id'),
));
if (empty($event) || (!$this->_isSiteAdmin() && $event['Event']['orgc'] != $this->Auth->user('org'))) throw new NotFoundException('Event not found or you are not authorised to edit it.');
$conditions = array();
if (!$this->_isSiteAdmin) {
$conditions['OR'] = array('Template.org' => $this->Auth->user('org'), 'Template.share' => true);
}
$templates = $this->Template->find('all', array(
'recursive' => -1,
'conditions' => $conditions
));
$this->set('templates', $templates);
$this->set('id', $id);
$this->render('ajax/template_choices');
}
public function populateEventFromTemplate($template_id, $event_id) {
$template = $this->Template->find('first', array(
'conditions' => array('Template.id' => $template_id),
'contain' => array(
'TemplateElement' => array(
'TemplateElementAttribute',
'TemplateElementText',
'TemplateElementFile'
),
'TemplateTag' => array(
'Tag'
)
),
));
$this->loadModel('Event');
$event = $this->Event->find('first', array(
'conditions' => array('id' => $event_id),
'recursive' => -1,
'fields' => array('id', 'orgc', 'distribution'),
));
if (empty($event)) throw new MethodNotAllowedException('Event not found or you are not authorised to edit it.');
if (empty($template)) throw new MethodNotAllowedException('Template not found or you are not authorised to edit it.');
if (!$this->_isSiteAdmin()) {
if ($event['Event']['orgc'] != $this->Auth->user('org')) throw new MethodNotAllowedException('Event not found or you are not authorised to edit it.');
if ($template['Template']['org'] != $this->Auth->user('org') && !$template['Template']['share']) throw new MethodNotAllowedException('Template not found or you are not authorised to use it.');
}
$this->set('template_id', $template_id);
$this->set('event_id', $event_id);
if ($this->request->is('post')) {
$errors = array();
$this->set('template', $this->request->data);
$result = $this->Event->Attribute->checkTemplateAttributes($template, $this->request->data, $event_id, $event['Event']['distribution']);
if (isset($this->request->data['Template']['modify']) || !empty($result['errors'])) {
$fileArray = $this->request->data['Template']['fileArray'];
$this->set('fileArray', $fileArray);
$this->set('errors', $result['errors']);
$this->set('templateData', $template);
$this->set('validTypeGroups', $this->Event->Attribute->validTypeGroups);
} else {
$this->set('errors', $result['errors']);
$this->set('attributes', $result['attributes']);
$fileArray = $this->request->data['Template']['fileArray'];
$this->set('fileArray', $fileArray);
$this->set('distributionLevels', $this->Event->distributionLevels);
$this->render('populate_event_from_template_attributes');
}
} else {
$this->set('templateData', $template);
$this->set('validTypeGroups', $this->Event->Attribute->validTypeGroups);
}
}
public function submitEventPopulation($template_id, $event_id) {
if ($this->request->is('post')) {
$this->loadModel('Event');
$event = $this->Event->find('first', array(
'conditions' => array('id' => $event_id),
'recursive' => -1,
'fields' => array('id', 'orgc', 'distribution', 'published'),
'contain' => 'EventTag',
));
if (empty($event)) throw new MethodNotAllowedException('Event not found or you are not authorised to edit it.');
if (!$this->_isSiteAdmin()) {
if ($event['Event']['orgc'] != $this->Auth->user('org')) throw new MethodNotAllowedException('Event not found or you are not authorised to edit it.');
}
$template = $this->Template->find('first', array(
'id' => $template_id,
'recursive' => -1,
'contain' => 'TemplateTag',
'fields' => 'id',
));
foreach ($template['TemplateTag'] as $tag) {
$exists = false;
foreach ($event['EventTag'] as $eventTag) {
if ($eventTag['tag_id'] == $tag['tag_id']) $exists = true;
}
if (!$exists) {
$this->Event->EventTag->create();
$this->Event->EventTag->save(array('event_id' => $event_id, 'tag_id' => $tag['tag_id']));
}
}
if (isset($this->request->data['Template']['attributes'])) {
$attributes = unserialize($this->request->data['Template']['attributes']);
$this->loadModel('Attribute');
$fails = 0;
foreach($attributes as $k => &$attribute) {
if (isset($attribute['data'])) {
$file = new File(APP . 'tmp/files/' . $attribute['data']);
$content = $file->read();
$attribute['data'] = base64_encode($content);
$file->delete();
}
$this->Attribute->create();
if (!$this->Attribute->save(array('Attribute' => $attribute))) $fails++;
}
$count = $k + 1;
if ($fails == 0) $this->Session->setFlash(__('Event populated, ' . $count . ' attributes successfully created.'));
else $this->Session->setFlash(__('Event populated, but ' . $fails . ' attributes could not be saved.'));
$this->redirect(array('controller' => 'events', 'action' => 'view', $event_id));
} else {
throw new MethodNotAllowedException('No attributes submitted for creation.');
}
} else {
throw new MethodNotAllowedException();
}
}
public function uploadFile($elementId, $batch) {
$this->layout = 'iframe';
$this->set('batch', $batch);
$this->set('element_id', $elementId);
if ($this->request->is('get')) {
$this->set('element_id', $elementId);
} else if ($this->request->is('post')) {
$fileArray = array();
$filenames = array();
$tmp_names = array();
$element_ids = array();
$result = array();
$added = 0;
$failed = 0;
// filename checks
foreach ($this->request->data['Template']['file'] as $k => $file) {
if ($file['size'] > 0 && $file['error'] == 0) {
if (preg_match('@^[\w\-. ]+$@', $file['name'])) {
$fn = $this->Template->generateRandomFileName();
move_uploaded_file($file['tmp_name'], APP . 'tmp/files/' . $fn);
$filenames[] =$file['name'];
$fileArray[] = array('filename' => $file['name'], 'tmp_name' => $fn, 'element_id' => $elementId);
$added++;
} else $failed++;
} else $failed ++;
}
$result = $added . ' files uploaded.';
if ($failed) {
$result .= ' ' . $failed . ' files either failed to upload, or were empty.';
$this->set('upload_error', true);
} else {
$this->set('upload_error', false);
}
$this->set('result', $result);
$this->set('filenames', $filenames);
$this->set('fileArray', json_encode($fileArray));
}
}
private function __combineArrays($array, $array2) {
foreach ($array2 as $element) {
if (!in_array($element, $array)) {
$array[] = $element;
}
}
return $array;
}
public function deleteTemporaryFile($filename) {
if (!$this->request->is('post')) throw new MethodNotAllowedException('This action is restricted to accepting POST requests only.');
//if (!$this->request->is('ajax')) throw new MethodNotAllowedException('This action is only accessible through AJAX.');
$this->autoRender = false;
if (preg_match('/^[a-zA-Z0-9]{12}$/', $filename)) {
$file = new File(APP . 'tmp/files/' . $filename);
if ($file->exists()) {
$file->delete();
}
}
}
}

View File

@ -0,0 +1,129 @@
<?php
class ComplexTypeTool {
public function checkComplexRouter($input, $type) {
switch ($type) {
case 'File':
return $this->checkComplexFile($input);
break;
case 'CnC':
return $this->checkComplexCnC($input);
break;
case 'FreeText':
return $this->checkFreetext($input);
break;
default:
return false;
}
}
// checks if the passed input matches a valid file description attribute's pattern (filename, md5, sha1, sha256, filename|md5, filename|sha1, filename|sha256)
public function checkComplexFile($input) {
$original = $input;
$type = '';
$composite = false;
if (strpos($input, '|')) {
$composite = true;
$result = explode('|', $input);
if (count($result) != 2) $type = 'other';
if (!preg_match("#^.+#", $result[0])) $type = 'other';
$type = 'filename|';
$input = $result[1];
}
if (strlen($input) == 32 && preg_match("#[0-9a-f]{32}$#", $input)) $type .= 'md5';
if (strlen($input) == 40 && preg_match("#[0-9a-f]{40}$#", $input)) $type .= 'sha1';
if (strlen($input) == 64 && preg_match("#[0-9a-f]{64}$#", $input)) $type .= 'sha256';
if ($type == '' && !$composite && preg_match("#^.+#", $input)) $type = 'filename';
if ($type == '') $type = 'other';
return array('type' => $type, 'value' => $original);
}
public function checkComplexCnC($input) {
$type = '';
$toReturn = array();
// check if it's an IP address
if (filter_var($input, FILTER_VALIDATE_IP)) return array('type' => 'ip-dst', 'value' => $input);
if (preg_match("#^[A-Z0-9.-]+\.[A-Z]{2,4}$#i", $input)) {
$result = explode('.', $input);
if (count($result) > 2) {
$toReturn['multi'][] = array('type' => 'hostname', 'value' => $input);
$pos = strpos($input, '.');
$toReturn['multi'][] = array('type' => 'domain', 'value' => substr($input, (1 + $pos)));
return $toReturn;
}
return array('type' => 'domain', 'value' => $input);
}
if (!preg_match("#\n#", $input)) return array('type' => 'url', 'value' => $input);
return array('type' => 'other', 'value' => $input);
}
public function checkFreeText($input) {
$iocArray = preg_split("/[\n,]+/", $input);
$resultArray = array();
foreach ($iocArray as $ioc) {
$ioc = trim($ioc);
$typeArray = $this->__resolveType($ioc);
$temp = $typeArray;
$temp['value'] = $ioc;
$resultArray[] = $temp;
}
return $resultArray;
}
private function __resolveType($input) {
$result = array();
$input = strtolower($input);
// check for hashes
if (strlen($input) == 32 && preg_match("#[0-9a-f]{32}$#", $input)) return array('types' => array('md5'), 'to_ids' => true, 'default_type' => 'md5');
if (strlen($input) == 40 && preg_match("#[0-9a-f]{40}$#", $input)) return array('types' => array('sha1'), 'to_ids' => true, 'default_type' => 'sha1');
if (strlen($input) == 64 && preg_match("#[0-9a-f]{64}$#", $input)) return array('types' => array('sha256'), 'to_ids' => true, 'default_type' => 'sha256');
// check for IP
if (filter_var($input, FILTER_VALIDATE_IP)) return array('types' => array('ip-dst', 'ip-src'), 'to_ids' => true, 'default_type' => 'ip-dst');
// check for domain name, hostname, filename
if (strpos($input, '.') !== false) {
$extra = '';
$temp = explode('.', $input);
if (strpos($temp[0], ':')) {
$extra = '([a-z0-9]+):\/\/';
}
// check if it is a URL
if (filter_var($input, FILTER_VALIDATE_URL)) {
return array('types' => array('url'), 'to_ids' => true, 'default_type' => 'url');
}
//if (filter_var($input, FILTER_VALIDATE_URL)) {
if (preg_match('/^([-\pL\pN]+\.)+([a-z][a-z]|biz|cat|com|edu|gov|int|mil|net|org|pro|tel|aero|arpa|asia|coop|info|jobs|mobi|name|museum|travel)$/u', $input)) {
if (count($temp) > 2) {
return array('types' => array('hostname', 'domain'), 'to_ids' => true, 'default_type' => 'hostname');
} else {
return array('types' => array('domain'), 'to_ids' => true, 'default_type' => 'domain');
}
} else {
if (!preg_match('/[?:<>|\\*:\/@]/', $input)) {
return array('types' => array('filename'), 'to_ids' => true, 'default_type' => 'filename');
}
}
}
if (strpos($input, '\\') !== false) {
$temp = explode('\\', $input);
if (strpos($temp[count($temp)-1], '.')) {
if (!preg_match('/[?:<>|\\*:\/]/', $temp[count($temp)-1])) {
return array('types' => array('filename'), 'category' => 'Payload installation', 'to_ids' => false, 'default_type' => 'filename');
}
} else {
return array('types' => array('regkey'), 'to_ids' => false, 'default_type' => 'regkey');
}
}
if (strpos($input, '@') !== false) {
if (filter_var($input, FILTER_VALIDATE_EMAIL)) return array('types' => array('email-src', 'email-dst'), 'to_ids' => true, 'default_type' => 'email-src');
}
return array('types' => array('text'), 'category' => 'Other', 'to_ids' => false, 'default_type' => 'text');
}
}

View File

@ -306,6 +306,27 @@ class Attribute extends AppModel {
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
);
// automatic resolution of complex types
// If the complex type "file" is chosen for example, then the system will try to categorise the values entered into a complex template field based
// on the regular expression rules
public $validTypeGroups = array(
'File' => array(
'description' => '',
'types' => array('filename', 'filename|md5', 'filename|sha1', 'filename|sha256', 'md5', 'sha1', 'sha256'),
),
'CnC' => array(
'description' => '',
'types' => array('url', 'domain', 'hostname', 'ip-dst'),
),
);
public $typeGroupCategoryMapping = array(
'Payload delviery' => array('File', 'CnC'),
'Payload installation' => array('File'),
'Artifacts dropped' => array('File'),
'Network activity' => array('CnC'),
);
public function __construct($id = false, $table = null, $ds = null) {
parent::__construct($id, $table, $ds);
@ -492,7 +513,6 @@ class Attribute extends AppModel {
public function validateAttributeValue($fields) {
$value = $fields['value'];
$returnValue = false;
// check data validation
switch($this->data['Attribute']['type']) {
case 'md5':
@ -950,6 +970,7 @@ class Attribute extends AppModel {
'Attribute.type !=' => 'comment',
)),
'recursive' => 0,
//'contain' => 'Event',
//'fields' => '', // we want to have the Attribute AND Event, so do not filter here
);
// search for the related attributes for that "value(1|2)"
@ -1329,4 +1350,168 @@ class Attribute extends AppModel {
$result[1] = $reject;
return $result;
}
public function checkForValidationIssues($attribute) {
$this->set($attribute);
if ($this->validates()) {
return false;
} else {
return $this->validationErrors;
}
}
public function checkTemplateAttributes($template, &$data, $event_id, $distribution) {
$result = array();
$errors = array();
$attributes = array();
$files = array();
$savedFiles = array();
if (isset($data['Template']['fileArray'])) $fileArray = json_decode($data['Template']['fileArray'], true);
foreach ($template['TemplateElement'] as $element) {
if ($element['element_definition'] == 'attribute') {
$result = $this->__resolveElementAttribute($element['TemplateElementAttribute'][0], $data['Template']['value_' . $element['id']]);
} else if ($element['element_definition'] == 'file') {
$temp = array();
if (isset($fileArray)) {
foreach ($fileArray as $fileArrayElement) {
if ($fileArrayElement['element_id'] == $element['id']) {
$temp[] = $fileArrayElement;
}
}
}
$result = $this->__resolveElementFile($element['TemplateElementFile'][0], $temp);
if ($element['TemplateElementFile'][0]['mandatory'] && empty($temp) && empty($errors[$element['id']])) $errors[$element['id']] = 'This field is mandatory.';
}
if ($element['element_definition'] == 'file' || $element['element_definition'] == 'attribute') {
if ($result['errors']) {
$errors[$element['id']] = $result['errors'];
} else {
foreach ($result['attributes'] as &$a) {
$a['event_id'] = $event_id;
$a['distribution'] = $distribution;
$test = $this->checkForValidationIssues(array('Attribute' => $a));
if ($test) {
foreach ($test['value'] as $e) {
$errors[$element['id']] = $e;
}
} else {
$attributes[] = $a;
}
}
}
}
}
return array('attributes' => $attributes, 'errors' => $errors);
}
private function __resolveElementAttribute($element, $value) {
$attributes = array();
$results = array();
$errors=null;
if (!empty($value)) {
if ($element['batch']) {
$values = explode("\n", $value);
foreach ($values as $v) {
$v = trim($v);
$attributes[] = $this->__createAttribute($element, $v);
}
} else {
$attributes[] = $this->__createAttribute($element, trim($value));
}
foreach ($attributes as $att) {
if (isset($att['multi'])) {
foreach ($att['multi'] as $a) {
$results[] = $a;
}
} else {
$results[] = $att;
}
}
} else {
if ($element['mandatory']) $errors = 'This field is mandatory.';
}
return array('attributes' => $results, 'errors' => $errors);
}
private function __resolveElementFile($element, $files) {
$attributes = array();
$errors = null;
$results = array();
$count = count($files);
$element['complex'] = false;
if ($element['malware']) {
$element['type'] = 'malware-sample';
$element['to_ids'] = true;
} else {
$element['type'] = 'attachment';
$element['to_ids'] = false;
}
foreach ($files as $file) {
if (!preg_match('@^[\w\-. ]+$@', $file['filename'])) {
$errors = 'Filename not allowed.';
continue;
}
if ($element['malware']) {
$malwareName = $file['filename'] . '|' . hash_file('md5', APP . 'tmp/files/' . $file['tmp_name']);
$tmp_file = new File(APP . 'tmp/files/' . $file['tmp_name']);
if (!$tmp_file->exists()) {
$errors = 'File cannot be read.';
} else {
$element['type'] = 'malware-sample';
$attributes[] = $this->__createAttribute($element, $malwareName);
$content = $tmp_file->read();
$attributes[count($attributes) - 1]['data'] = $file['tmp_name'];
$element['type'] = 'filename|sha256';
$sha256 = $file['filename'] . '|' . (hash_file('sha256', APP . 'tmp/files/' . $file['tmp_name']));
$attributes[] = $this->__createAttribute($element, $sha256);
$element['type'] = 'filename|sha1';
$sha1 = $file['filename'] . '|' . (hash_file('sha1', APP . 'tmp/files/' . $file['tmp_name']));
$attributes[] = $this->__createAttribute($element, $sha1);
}
} else {
$attributes[] = $this->__createAttribute($element, $file['filename']);
$tmp_file = new File(APP . 'tmp/files/' . $file['tmp_name']);
if (!$tmp_file->exists()) {
$errors = 'File cannot be read.';
} else {
$content = $tmp_file->read();
$attributes[count($attributes) - 1]['data'] = $file['tmp_name'];
}
}
}
return array('attributes' => $attributes, 'errors' => $errors, 'files' => $files);
}
private function __createAttribute($element, $value) {
$attribute = array(
'comment' => $element['name'],
'to_ids' => $element['to_ids'],
'category' => $element['category'],
'value' => $value,
);
if ($element['complex']) {
App::uses('ComplexTypeTool', 'Tools');
$complexTypeTool = new ComplexTypeTool();
$result = $complexTypeTool->checkComplexRouter($value, ucfirst($element['type']));
if (isset($result['multi'])) {
$temp = $attribute;
$attribute = array();
foreach($result['multi'] as $k => $r) {
$attribute['multi'][] = $temp;
$attribute['multi'][$k]['type'] = $r['type'];
$attribute['multi'][$k]['value'] = $r['value'];
}
} else if ($result != false) {
$attribute['type'] = $result['type'];
$attribute['value'] = $result['value'];
} else {
return false;
}
} else {
$attribute['type'] = $element['type'];
}
return $attribute;
}
}

View File

@ -1176,20 +1176,21 @@ class Event extends AppModel {
}
}
}
//
// Build a list of the recipients that wish to receive encrypted mails.
//
//
// Build a list of the recipients that wish to receive encrypted mails.
//
if ($eventIsPrivate) {
$conditions = array('User.autoalert' => 1, 'User.gpgkey !=' => "", 'User.org =' => $event['Event']['org']);
} else {
$conditions = array('User.autoalert' => 1, 'User.gpgkey !=' => "");
}
$alertUsers = $this->User->find('all', array(
'conditions' => $conditions,
'recursive' => 0,
)
$alertUsers = $this->User->find('all', array(
'conditions' => $conditions,
'recursive' => 0,
)
);
$max = count($alertUsers);
$max = count($alertUsers);
// encrypt the mail for each user and send it separately
foreach ($alertUsers as $k => &$user) {
// send the email

View File

@ -56,7 +56,8 @@ class Tag extends AppModel {
public $hasMany = array(
'EventTag' => array(
'className' => 'EventTag',
)
),
'TemplateTag',
);

79
app/Model/Template.php Normal file
View File

@ -0,0 +1,79 @@
<?php
App::uses('AppModel', 'Model');
/**
* Template Model
*
*/
class Template extends AppModel {
public $actsAs = array('Containable');
public $hasMany = array(
'TemplateTag' => array(
'dependent' => true,
),
'TemplateElement' => array(
'order' => 'TemplateElement.position',
'dependent' => true,
)
);
public function trimElementPositions($id) {
// permissions
$this->id = $id;
if (!$this->exists()) {
throw new NotFoundException(__('Invalid template.'));
}
$template = $this->find('first', array(
'conditions' => array('id' => $id),
'recursive' => -1,
'contain' => array(
'TemplateElement' => array('id', 'template_id', 'position'),
),
'fields' => array('id', 'org'),
));
foreach ($template['TemplateElement'] as $k => &$element) {
$element['position'] = $k+1;
}
$this->saveAll($template);
}
public function checkAuthorisation($id, $user, $write) {
// fetch the bare template
$template = $this->find('first', array(
'conditions' => array('id' => $id),
'recursive' => -1,
));
// if not found return false
if (empty($template)) return false;
//if the user is a site admin, return the template withoug question
if ($user['Role']['perm_site_admin']) return $template;
if ($write) {
// if write access is requested, check if template belongs to user's org and whether the user is authorised to edit templates
if ($user['org'] == $template['Template']['org'] && $user['Role']['perm_template']) return $template;
return false;
} else {
// if read access is requested, check if the template belongs to the user's org or alternatively whether the template is shareable
if ($user['org'] == $template['Template']['org'] || $template['Template']['share']) return $template;
return false;
}
}
public function generateRandomFileName() {
$length = 12;
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charLen = strlen($characters) - 1;
$fn = '';
for ($p = 0; $p < $length; $p++) {
$fn .= $characters[rand(0, $charLen)];
}
return $fn;
}
}

View File

@ -0,0 +1,31 @@
<?php
App::uses('AppModel', 'Model');
/**
* TemplateElement Model
*
*/
class TemplateElement extends AppModel {
public $actsAs = array('Containable');
public $hasMany = array(
'TemplateElementAttribute' => array(
'dependent' => true
),
'TemplateElementText' => array(
'dependent' => true
),
'TemplateElementFile' => array(
'dependent' => true
)
);
public $belongsTo = array('Template');
public function lastPosition($template_id) {
$result = $this->find('first', array(
'fields' => array('MAX(position) AS pos', 'id', 'template_id'),
'conditions' => array('template_id' => $template_id)
));
return $result[0]['pos'];
}
}

View File

@ -0,0 +1,34 @@
<?php
App::uses('AppModel', 'Model');
/**
* TemplateElementAttribute Model
*
*/
class TemplateElementAttribute extends AppModel {
public $actsAs = array('Containable');
public $belongsTo = array('TemplateElement');
public $validate = array(
'name' => array(
'rule' => 'notEmpty',
'message' => 'Please enter a Name',
),
'description' => array(
'rule' => 'notEmpty',
'message' => 'Please enter a Description',
),
'category' => array(
'rule' => array('comparison', '!=', 'Select Category'),
'message' => 'Please choose a category.'
),
'type' => array(
'rule' => array('comparison', '!=', 'Select Type'),
'message' => 'Please choose a type.'
),
);
public function beforeValidate($options = array()) {
parent::beforeValidate();
}
}

View File

@ -0,0 +1,36 @@
<?php
App::uses('AppModel', 'Model');
/**
* TemplateElementAttribute Model
*
*/
class TemplateElementFile extends AppModel {
public $actsAs = array('Containable');
public $belongsTo = array('TemplateElement');
public $validate = array(
'name' => array(
'rule' => 'notEmpty',
'message' => 'Please enter a Name',
),
'description' => array(
'rule' => 'notEmpty',
'message' => 'Please enter a Description',
),
'category' => array(
'notDefault' => array(
'rule' => array('comparison', '!=', 'Select Category'),
'message' => 'Please choose a category.'
),
'notEmpty' => array(
'rule' => 'notEmpty',
'message' => 'Please choose a category.'
)
),
);
public function beforeValidate($options = array()) {
parent::beforeValidate();
}
}

View File

@ -0,0 +1,23 @@
<?php
App::uses('AppModel', 'Model');
/**
* TemplateElementText Model
*
*/
class TemplateElementText extends AppModel {
public $actsAs = array('Containable');
public $belongsTo = array('TemplateElement');
public $validate = array(
'name' => array(
'rule' => 'notEmpty',
'message' => 'Please enter a Name',
),
'text' => array(
'rule' => 'notEmpty',
'message' => 'Please fill out the text field',
),
);
}

12
app/Model/TemplateTag.php Normal file
View File

@ -0,0 +1,12 @@
<?php
App::uses('AppModel', 'Model');
/**
* TemplateTag Model
*
*/
class TemplateTag extends AppModel {
public $actsAs = array('Containable');
public $belongsTo = array('Template', 'Tag');
}

View File

@ -2,8 +2,8 @@
<?php
echo $this->Form->create('Attribute', array('id'));
?>
<legend><?php echo __('Add Attribute'); ?></legend>
<fieldset>
<legend><?php echo __('Add Attribute'); ?></legend>
<div id="formWarning" class="message ajaxMessage"></div>
<div class="add_attribute_fields">
<?php
@ -125,7 +125,7 @@ function formCategoryChanged(id) {
// Generate tooltip information
//
var formInfoValues = new Array();
var fieldsArrayAttribute = new Array('AttributeCategory', 'AttributeType', 'AttributeDistribution', 'AttributeValue', 'AttributeComment', 'AttributeToIds', 'AttributeBatchImport');
var fieldsArray = new Array('AttributeCategory', 'AttributeType', 'AttributeDistribution', 'AttributeValue', 'AttributeComment', 'AttributeToIds', 'AttributeBatchImport');
<?php
foreach ($typeDefinitions as $type => $def) {
$info = isset($def['formdesc']) ? $def['formdesc'] : $def['desc'];
@ -197,8 +197,7 @@ $(document).ready(function() {
<?php if ($ajax): ?>
$('#cancel_attribute_add').click(function() {
$('#gray_out').fadeOut();
$('#attribute_add_form').fadeOut();
cancelPopoverForm();
});
<?php endif; ?>

View File

@ -1,10 +1,9 @@
<? echo $this->Html->script('ajaxification');?>
<div class="attributes">
<?php
echo $this->Form->create('Attribute', array('action' => 'editSelected'));
?>
<legend><?php echo __('Mass Edit Attributes'); ?></legend>
<fieldset>
<legend><?php echo __('Mass Edit Attributes'); ?></legend>
<div id="formWarning" class="message ajaxMessage"></div>
<div class="add_attribute_fields">
<?php
@ -119,7 +118,7 @@ $(document).ready(function() {
});
$('#cancel_attribute_add').click(function() {
$('#gray_out').fadeOut();
$('#attribute_add_form').fadeOut();
$('#popover_form').fadeOut();
});
});

View File

@ -0,0 +1,153 @@
<div class="attribute_replace">
<?php
echo $this->Form->create('Attribute', array('id'));
?>
<fieldset>
<legend><?php echo __('Attribute Replace Tool'); ?></legend>
<div class="add_attribute_fields">
<p>Choose a category and a type, then paste a list of IOCs that match the selection into the field below. This will delete all of the attributes not found in the new inserted list, whilst creating the attributes that are in the new list but don't exist as attributes. Found matches will be left untouched.</p>
<?php
echo $this->Form->hidden('event_id');
echo $this->Form->input('category', array(
'empty' => '(choose one)'
));
echo $this->Form->input('type', array(
'empty' => '(first choose category)'
));
echo $this->Form->input('to_ids', array(
'type' => 'checkbox',
'label' => 'Mark all new attributes as to IDS',
));
echo $this->Form->input('value', array(
'type' => 'textarea',
'error' => array('escape' => false),
'div' => 'input clear',
'class' => 'input-xxlarge',
'label' => 'Values'
));
$this->Js->get('#AttributeCategory')->event('change', 'formCategoryChanged("#AttributeCategory")');
?>
<div class="input clear"></div>
</div>
</fieldset>
<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 (Attribution / targeting data). Make sure that you are authorised to share this.</p>
<div class="overlay_spacing">
<table>
<tr>
<td style="vertical-align:top">
<span id="submitButton" class="btn btn-primary" onClick="submitPopoverForm('<?php echo $event_id;?>', 'replaceAttributes')">Submit</span>
</td>
<td style="width:540px;">
<p style="color:red;font-weight:bold;display:none;text-align:center" id="warning-message">Warning: You are about to share data that is of a classified nature (Attribution / targeting data). Make sure that you are authorised to share this.</p>
</td>
<td style="vertical-align:top;">
<span class="btn btn-inverse" id="cancel_attribute_add">Cancel</span>
</td>
</tr>
</table>
</div>
<?php
echo $this->Form->end();
?>
</div>
<script type="text/javascript">
//
//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";
}
?>
function formCategoryChanged(id) {
// fill in the types
var options = $('#AttributeType').prop('options');
$('option', $('#AttributeType')).remove();
$.each(category_type_mapping[$('#AttributeCategory').val()], function(val, text) {
options[options.length] = new Option(text, val);
});
// enable the form element
$('#AttributeType').prop('disabled', false);
}
//
//Generate tooltip information
//
var formInfoValues = new Array();
var fieldsArray = new Array('AttributeCategory', 'AttributeType');
<?php
foreach ($typeDefinitions as $type => $def) {
$info = isset($def['formdesc']) ? $def['formdesc'] : $def['desc'];
echo "formInfoValues['" . addslashes($type) . "'] = \"" . addslashes($info) . "\";\n"; // as we output JS code we need to add slashes
}
foreach ($categoryDefinitions as $category => $def) {
$info = isset($def['formdesc']) ? $def['formdesc'] : $def['desc'];
echo "formInfoValues['" . addslashes($category) . "'] = \"" . addslashes($info) . "\";\n"; // as we output JS code we need to add slashes
}
?>
$(document).ready(function() {
$("#AttributeType, #AttributeCategory").on('mouseover', function(e) {
var $e = $(e.target);
if ($e.is('option')) {
$('#'+e.currentTarget.id).popover('destroy');
$('#'+e.currentTarget.id).popover({
trigger: 'focus',
placement: 'right',
container: 'body',
content: formInfoValues[$e.val()],
}).popover('show');
}
});
$("input, label").on('mouseleave', function(e) {
$('#'+e.currentTarget.id).popover('destroy');
});
$("input, label").on('mouseover', function(e) {
var $e = $(e.target);
$('#'+e.currentTarget.id).popover('destroy');
$('#'+e.currentTarget.id).popover({
trigger: 'focus',
placement: 'right',
container: 'body',
}).popover('show');
});
// workaround for browsers like IE and Chrome that do now have an onmouseover on the 'options' of a select.
// disadvangate is that user needs to click on the item to see the tooltip.
// no solutions exist, except to generate the select completely using html.
$("#AttributeType, #AttributeCategory").on('change', function(e) {
if (this.id === "AttributeCategory") {
var select = document.getElementById("AttributeCategory");
if (select.value === 'Attribution' || select.value === 'Targeting data') {
$("#warning-message").show();
} else {
$("#warning-message").hide();
}
}
var $e = $(e.target);
$('#'+e.currentTarget.id).popover('destroy');
$('#'+e.currentTarget.id).popover({
trigger: 'focus',
placement: 'right',
container: 'body',
content: formInfoValues[$e.val()],
}).popover('show');
});
$('#cancel_attribute_add').click(function() {
cancelPopoverForm();
});
});
</script>
<?php echo $this->Js->writeBuffer(); // Write cached scripts

View File

@ -0,0 +1,16 @@
<td>
<div id="tag_bubble_<?php echo $tag['Tag']['id']; ?>">
<table>
<tr>
<td style="padding-right:0px;">
<span class="<?php echo ($editable == 'yes' ? 'tagFirstHalf' : 'tagComplete'); ?>" style="background-color:<?php echo $tag['Tag']['colour'];?>;color:<?php echo $this->TextColour->getTextColour($tag['Tag']['colour']);?>"><?php echo h($tag['Tag']['name']); ?></a>
</td>
<?php if ($editable == 'yes'): ?>
<td style="padding-left:0px;padding-right:5px;">
<span class="tagSecondHalf useCursorPointer" onClick="removeTemplateTag('<?php echo $tag['Tag']['id']; ?>', '<?php echo h($tag['Tag']['name']); ?>');">x</span>
</td>
<?php endif; ?>
</tr>
</table>
</div>
</td>

View File

@ -1,8 +1,6 @@
<?php
echo $this->Html->script('ajaxification');
$mayModify = ($isSiteAdmin || ($isAclModify && $event['Event']['user_id'] == $me['id'] && $event['Event']['orgc'] == $me['org']) || ($isAclModifyOrg && $event['Event']['orgc'] == $me['org']));
$mayPublish = ($isAclPublish && $event['Event']['orgc'] == $me['org']);
if (!empty($eventArray)):
$pageCount = intval($objectCount / 50);
if ($objectCount%50 != 0) $pageCount++;
$possibleAction = 'Proposal';
@ -45,15 +43,34 @@
<?php
endif;
?>
<div id="edit_object_div">
<?php
echo $this->Form->create('Attribute', array('id' => 'delete_selected', 'action' => 'deleteSelected'));
echo $this->Form->input('ids', array(
'type' => 'text',
'value' => 'test',
'style' => 'display:none;',
'label' => false,
));
echo $this->Form->end();
?>
</div>
<div id="attributeList" class="attributeListContainer">
<div class="tabMenu noPrint">
<span id="create-button" class="icon-plus useCursorPointer" onClick="clickCreateButton(<?php echo $event['Event']['id']; ?>, '<?php echo $possibleAction; ?>');"></span>
<span id="multi-edit-button" class="icon-edit mass-select useCursorPointer" onClick="editSelectedAttributes(<?php echo $event['Event']['id']; ?>);"></span>
<span id="multi-delete-button" class = "icon-trash mass-select useCursorPointer" onClick="deleteSelectedAttributes(<?php echo $event['Event']['id']; ?>);"></span>
<div class="tabMenu tabMenuEditBlock noPrint">
<span id="create-button" title="Add attribute" class="icon-plus useCursorPointer" onClick="clickCreateButton(<?php echo $event['Event']['id']; ?>, '<?php echo $possibleAction; ?>');"></span>
<span id="multi-edit-button" title="Edit selected" class="icon-edit mass-select useCursorPointer" onClick="editSelectedAttributes(<?php echo $event['Event']['id']; ?>);"></span>
<span id="multi-delete-button" title="Delete selected" class = "icon-trash mass-select useCursorPointer" onClick="deleteSelectedAttributes(<?php echo $event['Event']['id']; ?>);"></span>
</div>
<?php if ($mayModify): ?>
<div class="tabMenu tabMenuToolsBlock noPrint">
<span id="create-button" title="Populate using a template" class="icon-list-alt useCursorPointer" onClick="getPopup(<?php echo $event['Event']['id']; ?>, 'templates', 'templateChoices');"></span>
<span id="freetext-button" title="Populate using the freetext import tool" class="icon-exclamation-sign useCursorPointer" onClick="getPopup(<?php echo $event['Event']['id']; ?>, 'events', 'freeTextImport');"></span>
<span id="attribute-replace-button" title="Replace all attributes of a category/type combination within the event" class="icon-random useCursorPointer" onClick="getPopup(<?php echo $event['Event']['id']; ?>, 'attributes', 'attributeReplace');"></span>
</div>
<?php endif; ?>
<table class="table table-striped table-condensed">
<tr>
<?php if ($mayModify): ?>
<?php if ($mayModify && !empty($eventArray)): ?>
<th><input class="select_all" type="checkbox" onClick="toggleAllAttributeCheckboxes();" /></th>
<?php endif;?>
<th>Date</th>
@ -108,22 +125,7 @@
<?php endif; ?>
</ul>
</div>
<?php
endif;
?>
<div id="edit_object_div">
<?php
echo $this->Form->create('Attribute', array('id' => 'delete_selected', 'action' => 'deleteSelected'));
echo $this->Form->input('ids', array(
'type' => 'text',
'value' => 'test',
'style' => 'display:none;',
'label' => false,
));
echo $this->Form->end();
?>
</div>
<?php
<?php
for ($j = 0; $j < 2; $j++) {
$side = 'a';
if ($j == 1) $side = 'b';
@ -179,16 +181,16 @@
);
}
endif;
?>
<script type="text/javascript">
$(document).ready(function(){
$('input:checkbox').removeAttr('checked');
$('.mass-select').hide();
$('input[type="checkbox"]').click(function(){
attributeListAnyCheckBoxesChecked();
});
});
</script>
<?php
?>
<script type="text/javascript">
$(document).ready(function(){
$('input:checkbox').removeAttr('checked');
$('.mass-select').hide();
$('input[type="checkbox"]').click(function(){
attributeListAnyCheckBoxesChecked();
});
});
</script>
<?php
echo $this->Js->writeBuffer();
?>

View File

@ -128,9 +128,13 @@ if ($object['objectType'] == 1) {
</div>
</td>
<td class="<?php echo $extra; ?> shortish">
<?php
$turnRed = '';
if ($object['objectType'] == 0 && $object['distribution'] == 0) $turnRed = 'style="color:red"';
?>
<div id = "<?php echo $currentType . '_' . $object['id'] . '_distribution_placeholder'; ?>" class = "inline-field-placeholder"></div>
<div id = "<?php echo $currentType . '_' . $object['id'] . '_distribution_solid'; ?>" class="inline-field-solid" onClick="activateField('<?php echo $currentType; ?>', '<?php echo $object['id']; ?>', 'distribution', <?php echo $event['Event']['id'];?>);">
<?php if ($object['objectType'] != 1 && $object['objectType'] != 2) echo h($distributionLevels[$object['distribution']]); ?>&nbsp;
<div id = "<?php echo $currentType . '_' . $object['id'] . '_distribution_solid'; ?>" <?php echo $turnRed; ?> class="inline-field-solid" onClick="activateField('<?php echo $currentType; ?>', '<?php echo $object['id']; ?>', 'distribution', <?php echo $event['Event']['id'];?>);">
<?php if ($object['objectType'] == 0) echo h($distributionLevels[$object['distribution']]); ?>&nbsp;
</div>
</td>
<td class="short action-links <?php echo $extra;?>">

View File

@ -34,6 +34,11 @@
<li><a href="/tags/add">Add Tag</a></li>
<?php endif; ?>
<li class="divider"></li>
<li><a href="/templates/index">List Templates</a></li>
<?php if ($isAclTemplate): ?>
<li><a href="/templates/add">Add Template</a></li>
<?php endif; ?>
<li class="divider"></li>
<li><a href="/events/export">Export</a></li>
<?php if ($isAclAuth): ?>
<li><a href="/events/automation">Automation</a></li>

View File

@ -6,13 +6,14 @@
if ($menuItem === 'addAttribute' ||
$menuItem === 'addAttachment' ||
$menuItem === 'addIOC' ||
$menuItem === 'addThreatConnect'
$menuItem === 'addThreatConnect' ||
$menuItem === 'populateFromtemplate'
) {
// we can safely assume that mayModify is true if comming from these actions, as they require it in the controller and the user has already passed that check
$mayModify = true;
if ($isAclPublish) $mayPublish = true;
}
?>
?>
<li <?php if ($menuItem === 'viewEvent') echo 'class="active"';?>><a href="/events/view/<?php echo $event['Event']['id'];?>">View Event</a></li>
<li <?php if ($menuItem === 'eventLog') echo 'class="active"';?>><a href="/logs/event_index/<?php echo $event['Event']['id'];?>">View Event History</a></li>
<?php if ($isSiteAdmin || (isset($mayModify) && $mayModify)): ?>
@ -23,6 +24,9 @@
<li <?php if ($menuItem === 'addAttachment') echo 'class="active"';;?>><a href="/attributes/add_attachment/<?php echo $event['Event']['id'];?>">Add Attachment</a></li>
<li <?php if ($menuItem === 'addIOC') echo 'class="active"';?>><a href="/events/addIOC/<?php echo $event['Event']['id'];?>">Populate from OpenIOC</a></li>
<li <?php if ($menuItem === 'addThreatConnect') echo 'class="active"';?>><a href="/attributes/add_threatconnect/<?php echo $event['Event']['id']; ?>">Populate from ThreatConnect</a></li>
<?php if ($menuItem === 'populateFromtemplate'): ?>
<li class="active"><a href="/templates/populateEventFromTemplate/<?php echo $template_id . '/' . $event['Event']['id']; ?>">Populate From Template</a></li>
<?php endif; ?>
<?php elseif (!isset($mayModify) || !$mayModify): ?>
<li class="divider"></li>
<li <?php if ($menuItem === 'proposeAttribute') echo 'class="active"';?>><a href="/shadow_attributes/add/<?php echo $event['Event']['id'];?>">Propose Attribute</a></li>
@ -191,10 +195,26 @@
endif;
if ($menuItem === 'edit'):
?>
<li class="active"><?php echo $this->Html->link('Search Logs', array('action' => 'edit'));?></li>
<li class="active"><?php echo $this->Html->link('Edit Tag', array('action' => 'edit'));?></li>
<?php
endif;
break;
case 'templates': ?>
<li <?php if ($menuItem === 'index') echo 'class="active"';?>><a href="/templates/index">List Templates</a></li>
<?php if ($isSiteAdmin || $isAclTemplate): ?>
<li <?php if ($menuItem === 'add') echo 'class="active"';?>><a href="/templates/add">Add Template</a></li>
<?php
endif;
if (($menuItem === 'view' || $menuItem === 'edit')):
?>
<li <?php if ($menuItem === 'view') echo 'class="active"';?>><a href="/templates/view/<?php echo $id; ?>">View Template</a></li>
<?php if ($mayModify): ?>
<li <?php if ($menuItem === 'edit') echo 'class="active"';?>><a href="/templates/edit/<?php echo $id; ?>">Edit Template</a></li>
<?php
endif;
endif;
break;
}
?>
</ul>

View File

@ -0,0 +1,73 @@
<div id="element_<?php echo $k; ?>" class="templateTableRow templateTableRow80">
<div class="templateElementHeader" style="width:100%; position:relative;">
<div class="templateGlass"></div>
<div class ="templateElementHeaderText">
<?php echo h($element['name']); ?>
<?php if ($element['mandatory']): ?>
<span class="template_mandatory">(*)</span>
<?php endif;?>
</div>
</div>
<div class="populate_template_div_body">
<div class="left">Description:</div>
<div class="right"><?php echo h($element['description']); ?></div><br />
<div class="left">Type<?php if ($element['complex']) echo 's'; ?>:</div>
<div class="right">
<?php
$types = '';
if ($element['complex']) {
foreach ($validTypeGroups[$element['type']]['types'] as $k => $type):
if ($k != 0) $types .= ', ';
$types .= $type;
?>
<div class="templateTypeBox"><?php echo h($type); ?></div>
<?php
endforeach;
} else {
?>
<div class="templateTypeBox"><?php echo h($element['type']); ?></div>
<?php
}
?>
</div>
<div>
<?php
if (isset($template['Template']['value_' . $element_id])) $value = $template['Template']['value_' . $element_id];
if (isset($errors[$element_id])) $error = $errors[$element_id];
if ($element['batch']) {
if ($element['complex']) {
$placeholder = 'Describe the ' . h($element['name']) . ' using one or several (separated by a line-break) of the following types: ' . $types;
} else {
$placeholder = 'Describe the ' . h($element['name']) . ' using one or several ' . h($element['type']) . 's (separated by a line-break)';
}
echo $this->Form->input('value_' . $element_id, array(
'type' => 'textarea',
'label' => false,
'div' => false,
'style' => 'width: calc(100% - 16px);',
'placeholder' => $placeholder,
'value' => $value,
));
} else {
if ($element['complex']) {
$placeholder = 'Describe the ' . h($element['name']) . ' using one of the following types: ' . $types;
} else {
$placeholder = 'Describe the ' . h($element['name']) . ' using a ' . h($element['type']);
}
echo $this->Form->input('value_' . $element_id, array(
'type' => 'text',
'label' => false,
'div' => false,
'style' => 'width: calc(100% - 16px);',
'placeholder' => $placeholder,
'value' => $value,
));
}
?>
</div>
<div class="error-message populateTemplateErrorField" <?php if(!isset($errors[$element_id])) echo 'style="display:none;"';?>>
<?php echo 'Error: ' . $errors[$element_id]; ?>
</div>
</div>
</div>

View File

@ -0,0 +1,22 @@
<div id="populate_template_info_header" class="templateElementHeader" style="width:100%; position:relative;">
<div class="templateGlass"></div>
<div class ="templateElementHeaderText">Template Description</div>
</div>
<div id="populate_template_info_body" class="populate_template_div_body">
<div class="left" style="float:left;">Template ID:</div>
<div class="right" style="float:left;"><?php echo $templateData['Template']['id']; ?></div><br />
<div class="left" style="float:left;">Template Name:</div>
<div class="right" style="float:left;"><?php echo h($templateData['Template']['name']); ?></div><br />
<div class="left" style="float:left;">Created by:</div>
<div class="right" style="float:left;"><?php echo h($templateData['Template']['org']); ?></div><br />
<div class="left" style="float:left;">Description:</div>
<div class="right" style="float:left;"><?php echo h($templateData['Template']['description']); ?></div><br />
<div class="left" style="float:left;">Tags automatically assigned:</div>
<div class="right" style="float:left;">
<?php
foreach($templateData['TemplateTag'] as $tag) {
echo $this->element('ajaxTemplateTag', array('editable' => 'no', 'tag' => array('Tag' => $tag['Tag'])));
}
?>
</div>
</div>

View File

@ -0,0 +1,30 @@
<div id="populate_template_info" class="templateTableRow templateTableRow80">
<div class="templateElementHeader" style="width:100%; position:relative;">
<div class="templateGlass"></div>
<div class ="templateElementHeaderText">
<?php echo h($element['name']);
if ($element['mandatory']): ?>
<span class="template_mandatory">(*)</span>
<?php endif;?>
</div>
</div>
<div id="populate_template_info_body" class="populate_template_div_body">
<div class="left">Description:</div>
<div class="right"><?php echo h($element['description']); ?></div><br />
<div class="left" style="height:26px;">File<?php if ($element['batch']) echo 's'?>:</div>
<div class="right" id ="filenames_<?php echo $element_id; ?>" style="height:26px;">
&nbsp;
</div><br />
<div class="input file" id="file_container_<?php echo $element_id;?>">
</div>
<iframe id="iframe_<?php echo $element_id; ?>" src="/templates/uploadFile/<?php echo $element_id; ?>/<?php echo ($element['batch'] ? 'yes' : 'no'); ?>" style="border:0px;height:30px;width:100%;overflow:hidden;" scrolling="no"></iframe>
<div class="error-message populateTemplateErrorField" <?php if(!isset($errors[$element_id])) echo 'style="display:none;"';?>>
<?php echo 'Error: ' . $errors[$element_id]; ?>
</div>
</div>
</div>
<script type="text/javascript">
var i_<?php echo $element_id; ?> = 0;
var element_id_<?php echo $element_id; ?> = <?php echo $element_id; ?>;
var batch_<?php echo $element_id; ?> = "<?php echo ($element['batch'] ? 'yes' : 'no'); ?>";
</script>

View File

@ -0,0 +1,9 @@
<div id="populate_template_info" class="templateTableRow templateTableRow80">
<div class="templateElementHeader" style="width:100%; position:relative;">
<div class="templateGlass"></div>
<div class ="templateElementHeaderText"><?php echo h($element['name']); ?></div>
</div>
<div id="populate_template_info_body" class="populate_template_div_body">
<div class="solo" style="float:left;"><?php echo $element['text']; ?></div><br />
</div>
</div>

View File

@ -0,0 +1,117 @@
<li id="id_<?php echo $element_id; ?>" class="templateTableRow">
<div class="templateElementHeader" style="width:100%; position:relative;">
<div class="templateGlass"></div>
<div class ="templateElementHeaderText">Attribute</div>
</div>
<table style="width:100%">
<tr>
<td>
<div style="display:inline">
<div class="templateTableTDName templateTableArea">
<div class="templateTableColumnName">
Name
</div>
<div class="">
<?php echo h($element['TemplateElementAttribute'][0]['name']); ?>&nbsp;
</div>
</div>
<div class="templateTableTDDescription templateTableArea">
<div class="templateTableColumnName">
Description
</div>
<div class="">
<?php echo h($element['TemplateElementAttribute'][0]['description']); ?>&nbsp;
</div>
</div>
<div class="templateTableTDCategory templateTableArea">
<div class="templateTableColumnName">
Category
</div>
<div class="">
<?php echo h($element['TemplateElementAttribute'][0]['category']); ?>&nbsp;
</div>
</div>
<div class="templateTableTDTypes templateTableArea">
<div class="templateTableColumnName">
Types
</div>
<div class="">
<?php
if ($element['TemplateElementAttribute'][0]['complex']) {
echo '<span style="color:red">' . h($element['TemplateElementAttribute'][0]['type']) . '</span> (';
foreach ($validTypeGroups[$element['TemplateElementAttribute'][0]['type']]['types'] as $k => $t) {
if ($k != 0) echo ', ';
echo h($t);
}
echo ')';
} else {
echo h($element['TemplateElementAttribute'][0]['type']);
}
?>&nbsp;
</div>
</div>
<div class="templateTableTDShort templateTableArea">
<div class="templateTableColumnName">
Mandatory
</div>
<div class="">
<?php
if ($element['TemplateElementAttribute'][0]['mandatory']) echo 'Yes';
else echo 'No';
?>&nbsp;
</div>
</div>
<div class="templateTableTDShort templateTableArea">
<div class="templateTableColumnName">
Batch
</div>
<div class="">
<?php
if ($element['TemplateElementAttribute'][0]['batch']) echo 'Yes';
else echo 'No';
?>&nbsp;
</div>
</div>
<div class="templateTableTDShort templateTableArea">
<div class="templateTableColumnName">
IDS
</div>
<div class="">
<?php
if ($element['TemplateElementAttribute'][0]['to_ids']) echo 'Yes';
else echo 'No';
?>&nbsp;
</div>
</div>
<div class="templateTableTDActions templateTableArea">
<div class="templateTableColumnName">
Actions
</div>
<div class="">
<?php
if ($mayModify) {
echo $this->Form->create('TemplateElement', array('class' => 'inline-delete', 'style' => 'display:inline-block;', 'id' => 'TemplateElement_' . $element_id . '_delete', 'action' => 'delete'));
?>
<span class="icon-trash useCursorPointer" onClick="deleteObject('template_elements', 'delete' ,'<?php echo $element_id; ?>', '<?php echo $element['TemplateElement']['template_id']; ?>');"></span>
<?php
echo $this->Form->end();
?>
<span class="icon-edit useCursorPointer" onClick="editTemplateElement('attribute' ,'<?php echo $element_id; ?>');"></span>
<?php
} else {
echo '&nbsp;';
}
?>
</div>
</div>
</div>
</td>
</tr>
</table>
</li>

View File

@ -0,0 +1,94 @@
<li id="id_<?php echo $element_id;?>" class="templateTableRow">
<div class="templateElementHeader" style="width:100%; position:relative;">
<div class="templateGlass"></div>
<div class ="templateElementHeaderText">File</div>
</div>
<table class="templateTable">
<tr>
<td>
<div style="display:inline">
<div class="templateTableTDName templateTableArea">
<div class="templateTableColumnName">
Name
</div>
<div class="">
<?php echo h($element['TemplateElementFile'][0]['name']); ?>&nbsp;
</div>
</div>
<div class="templateTableTDDescriptionFile templateTableArea">
<div class="templateTableColumnName">
Description
</div>
<div class="">
<?php echo h($element['TemplateElementFile'][0]['description']); ?>&nbsp;
</div>
</div>
<div class="templateTableTDCategory templateTableArea">
<div class="templateTableColumnName">
Category
</div>
<div class="">
<?php echo h($element['TemplateElementFile'][0]['category']); ?>&nbsp;
</div>
</div>
<div class="templateTableTDShort templateTableArea">
<div class="templateTableColumnName">
Malware
</div>
<div class="">
<?php
if ($element['TemplateElementFile'][0]['malware']) echo 'Yes';
else echo 'No';
?>&nbsp;
</div>
</div>
<div class="templateTableTDShort templateTableArea">
<div class="templateTableColumnName">
Req.
</div>
<div class="">
<?php
if ($element['TemplateElementFile'][0]['mandatory']) echo 'Yes';
else echo 'No';
?>&nbsp;
</div>
</div>
<div class="templateTableTDShort templateTableArea">
<div class="templateTableColumnName">
Batch
</div>
<div class="">
<?php
if ($element['TemplateElementFile'][0]['batch']) echo 'Yes';
else echo 'No';
?>&nbsp;
</div>
</div>
<div class="templateTableTDActions templateTableArea">
<div class="templateTableColumnName">
Actions
</div>
<div class="">
<?php
if ($mayModify) {
echo $this->Form->create('TemplateElement', array('class' => 'inline-delete', 'style' => 'display:inline-block;', 'id' => 'TemplateElement_' . $element_id . '_delete', 'action' => 'delete'));
?>
<span class="icon-trash useCursorPointer" onClick="deleteObject('template_elements', 'delete' ,'<?php echo $element_id; ?>', '<?php echo $element['TemplateElement']['template_id']; ?>');"></span>
<?php
echo $this->Form->end();
?>
<span class="icon-edit useCursorPointer" onClick="editTemplateElement('file' ,'<?php echo $element_id; ?>');"></span>
<?php
} else {
echo '&nbsp;';
}
?>
</div>
</div>
</div>
</td>
</tr>
</table>
</li>

View File

@ -0,0 +1,51 @@
<li id="id_<?php echo $element_id;?>" class="templateTableRow">
<div class="templateElementHeader" style="width:100%; position:relative;">
<div class="templateGlass"></div>
<div class ="templateElementHeaderText">Text</div>
</div>
<table class="templateTable">
<tr>
<td>
<div style="display:inline">
<div class="templateTableTDName templateTableArea">
<div class="templateTableColumnName">
Name
</div>
<div class="">
<?php echo $element['TemplateElementText'][0]['name']; ?>&nbsp;
</div>
</div>
<div class="templateTableTDText templateTableArea">
<div class="templateTableColumnName">
Text
</div>
<div class="">
<?php echo $element['TemplateElementText'][0]['text']; ?>&nbsp;
</div>
</div>
<div class="templateTableTDActions templateTableArea">
<div class="templateTableColumnName">
Actions
</div>
<div class="">
<?php
if ($mayModify) {
echo $this->Form->create('TemplateElement', array('class' => 'inline-delete', 'style' => 'display:inline-block;', 'id' => 'TemplateElement_' . $element_id . '_delete', 'action' => 'delete'));
?>
<span class="icon-trash useCursorPointer" onClick="deleteObject('template_elements', 'delete' ,'<?php echo $element_id; ?>', '<?php echo $element['TemplateElement']['template_id']; ?>');"></span>
<?php
echo $this->Form->end();
?>
<span class="icon-edit useCursorPointer" onClick="editTemplateElement('text' ,'<?php echo $element_id; ?>');"></span>
<?php
} else {
echo '&nbsp;';
}
?>
</div>
</div>
</div>
</td>
</tr>
</table>
</li>

View File

@ -0,0 +1,50 @@
<div class="freetext">
<?php
echo $this->Form->create('Attribute', array('id'));
?>
<fieldset>
<legend><?php echo __('Freetext Import Tool'); ?></legend>
<div class="add_attribute_fields">
<p>Paste a list of IOCs into the field below for automatic detection.</p>
<?php
echo $this->Form->hidden('event_id');
echo $this->Form->input('value', array(
'type' => 'textarea',
'error' => array('escape' => false),
'div' => 'input clear',
'class' => 'input-xxlarge',
'label' => false
));
?>
<div class="input clear"></div>
</div>
</fieldset>
<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 (Attribution / targeting data). Make sure that you are authorised to share this.</p>
<div class="overlay_spacing">
<table>
<tr>
<td style="vertical-align:top">
<button id="submitButton" class="btn btn-primary">Submit</button>
</td>
<td style="width:540px;">
<p style="color:red;font-weight:bold;display:none;text-align:center" id="warning-message"></p>
</td>
<td style="vertical-align:top;">
<span class="btn btn-inverse" id="cancel_attribute_add">Cancel</span>
</td>
</tr>
</table>
</div>
<?php
echo $this->Form->end();
?>
</div>
<script type="text/javascript">
$(document).ready(function() {
$('#cancel_attribute_add').click(function() {
cancelPopoverForm();
});
});
</script>
<?php echo $this->Js->writeBuffer(); // Write cached scripts

View File

@ -0,0 +1,88 @@
<div class="index">
<h2>Freetext Import Results</h2>
<p>Below you can see the attributes that are to be created based on the results of the free-text import. Make sure that the categories and the types are correct, often several options will be offered based on an inconclusive automatic resolution. </p>
<table class="table table-striped table-hover table-condensed">
<tr>
<th>Value</th>
<th>Category</th>
<th>Type</th>
<th>IDS</th>
<th>Actions</th>
</tr>
<?php
echo $this->Form->create('Attribute', array('url' => '/events/saveFreeText/' . $event_id));
foreach ($resultArray as $k => $item):
?>
<tr id="row_<?php echo $k; ?>">
<?php
echo $this->Form->input('Attribute.' . $k . '.save', array(
'label' => false,
'style' => 'display:none;',
'value' => 1,
));
echo $this->Form->input('Attribute.' . $k . '.value', array(
'label' => false,
'type' => 'hidden',
'value' => h($item['value']),
));
?>
<td><?php echo h($item['value']); ?></td>
<td class="short">
<?php
if (!isset($item['category'])) {
$default = array_search($defaultCategories[$item['default_type']], $typeCategoryMapping[$item['default_type']]);
} else {
$default = array_search($item['category'], $typeCategoryMapping[$item['default_type']]);
}
echo $this->Form->input('Attribute.' . $k . '.category', array(
'label' => false,
'style' => 'padding:0px;height:20px;margin-bottom:0px;',
'options' => $typeCategoryMapping[$item['default_type']],
'value' => $default,
));
?>
</td>
<td class="short">
<?php
if (count($item['types']) == 1) {
echo h($item['default_type']);
echo $this->Form->input('Attribute.' . $k . '.type', array(
'label' => false,
'type' => 'hidden',
'value' => $item['default_type'],
));
} else {
echo $this->Form->input('Attribute.' . $k . '.type', array(
'label' => false,
'style' => 'padding:0px;height:20px;margin-bottom:0px;',
'options' => $item['types'],
'value' => $item['default_type'],
));
}
?>
</td>
<td class="short">
<?php
echo $this->Form->input('Attribute.' . $k . '.to_ids', array(
'label' => false,
'type' => 'checkbox',
'checked' => $item['to_ids'],
));
?>
</td>
<td class="action short">
<span class="icon-remove pointer" onClick="freetextRemoveRow('<?php echo $k; ?>');"></span>
</td>
</tr>
<?php
endforeach;
?>
</table>
<?php
echo $this->Form->button('Submit', array('class' => 'btn btn-inverse'));
echo $this->Form->end();
?>
</div>
<?php
echo $this->element('side_menu', array('menuList' => 'regexp', 'menuItem' => 'index'));
?>

View File

@ -3,7 +3,6 @@ $mayModify = (($isAclModify && $event['Event']['user_id'] == $me['id'] && $event
$mayPublish = ($isAclPublish && $event['Event']['orgc'] == $me['org']);
?>
<?php
echo $this->Html->script('ajaxification');
echo $this->element('side_menu', array('menuList' => 'event', 'menuItem' => 'viewEvent', 'mayModify' => $mayModify, 'mayPublish' => $mayPublish));
?>
<div class="events view">
@ -103,11 +102,19 @@ $mayPublish = ($isAclPublish && $event['Event']['orgc'] == $me['org']);
<?php echo nl2br(h($event['Event']['info'])); ?>
&nbsp;
</dd>
<?php if ($isAclPublish && $event['Event']['published'] == 0) :?>
<dt class="visibleDL">Published</dt>
<dd class="visibleDL">
<?php echo ($event['Event']['published'] == 1 ? 'Yes' : 'No'); ?>
&nbsp;
</dd>
<?php else: ?>
<dt>Published</dt>
<dd style="color: red;">
<dd style="color: <?php echo ($event['Event']['published'] == 1 ? 'green' : 'red'); ?>">
<b><?php echo ($event['Event']['published'] == 1 ? 'Yes' : 'No'); ?></b>
&nbsp;
</dd>
<?php endif; ?>
</dl>
</div>
@ -158,7 +165,7 @@ $mayPublish = ($isAclPublish && $event['Event']['orgc'] == $me['org']);
<div id="pivots_div">
<?php if (sizeOf($allPivots) > 1) echo $this->element('pivot'); ?>
</div>
<div id="attribute_add_form" class="attribute_add_form"></div>
<div id="popover_form" class="ajax_popover_form"></div>
<div id="confirmation_box" class="confirmation_box"></div>
<div id="attribute_creation_div" style="display:none;">
<?php

View File

@ -0,0 +1,25 @@
<?php
/**
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.View.Layouts
* @since CakePHP(tm) v 0.10.0.1076
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
?>
<?php
//echo $this->Html->script('jquery-2.1.0.min');
echo $this->Html->css('jquery-ui-1.10.4.min');
//echo $this->Html->css('bootstrap');
//echo $this->Html->css('main');
echo $this->Html->script('jquery-ui-1.10.4.min');
echo $content_for_layout; ?>

View File

@ -65,6 +65,7 @@
echo $this->Html->script('bootstrap-datepicker');
echo $this->Html->script('bootstrap-colorpicker.min');
echo $this->Html->script('main');
echo $this->Html->script('ajaxification');
?>
</div>
<div id = "ajax_success_container" class="ajax_container">

View File

@ -0,0 +1,24 @@
<?php
/**
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.View.Layouts
* @since CakePHP(tm) v 0.10.0.1076
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
?>
<?php
echo $this->Html->css('bootstrap');
echo $this->Html->css('main');
echo $this->Html->script('jquery-2.1.0.min');
echo $this->Html->script('ajaxification');
echo $content_for_layout; ?>

View File

@ -14,6 +14,7 @@
<?php echo $this->Form->input('perm_site_admin', array('type' => 'checkbox', 'checked' => false));?>
<?php echo $this->Form->input('perm_regexp_access', array('type' => 'checkbox', 'checked' => false));?>
<?php echo $this->Form->input('perm_tagger', array('type' => 'checkbox', 'checked' => false));?>
<?php echo $this->Form->input('perm_template', array('type' => 'checkbox', 'checked' => false));?>
</fieldset>
<?php
echo $this->Form->button('Add', array('class' => 'btn btn-primary'));

View File

@ -14,6 +14,7 @@
<?php echo $this->Form->input('perm_site_admin', array('type' => 'checkbox'));?>
<?php echo $this->Form->input('perm_regexp_access', array('type' => 'checkbox'));?>
<?php echo $this->Form->input('perm_tagger', array('type' => 'checkbox'));?>
<?php echo $this->Form->input('perm_template', array('type' => 'checkbox'));?>
</fieldset>
<?php
echo $this->Form->button('Edit', array('class' => 'btn btn-primary'));

View File

@ -26,6 +26,7 @@
<th><?php echo $this->Paginator->sort('perm_regexp', 'Regexp Actions');?></th>
<th><?php echo $this->Paginator->sort('perm_auth', 'Auth Key Access');?></th>
<th><?php echo $this->Paginator->sort('perm_tagger', 'Tag Editor');?></th>
<th><?php echo $this->Paginator->sort('perm_template', 'Template Editor');?></th>
<th><?php echo $this->Paginator->sort('perm_admin', 'Admin');?></th>
<th><?php echo $this->Paginator->sort('perm_site_admin', 'Site Admin');?></th>
<th class="actions"><?php echo __('Actions');?></th>
@ -40,6 +41,7 @@ foreach ($list as $item): ?>
<td class="short"><?php echo h($item['Role']['perm_regexp_access']); ?>&nbsp;</td>
<td class="short"><?php echo h($item['Role']['perm_auth']); ?>&nbsp;</td>
<td class="short"><?php echo h($item['Role']['perm_tagger']); ?>&nbsp;</td>
<td class="short"><?php echo h($item['Role']['perm_template']); ?>&nbsp;</td>
<td class="short"><?php echo h($item['Role']['perm_admin']); ?>&nbsp;</td>
<td class="short"><?php echo h($item['Role']['perm_site_admin']); ?>&nbsp;</td>
<td class="short action-links">

View File

@ -1,8 +1,7 @@
<? echo $this->Html->script('ajaxification');?>
<div class="shadow_attributes <? if (!$ajax) echo 'form';?>">
<?php echo $this->Form->create('ShadowAttribute');?>
<legend><?php echo __('Add Proposal'); ?></legend>
<fieldset>
<legend><?php echo __('Add Proposal'); ?></legend>
<div id="formWarning" class="message ajaxMessage"></div>
<div class="add_attribute_fields">
<?php
@ -176,7 +175,7 @@ $('#ShadowAttributeType').prop('disabled', true);
<?php if ($ajax): ?>
$('#cancel_attribute_add').click(function() {
$('#gray_out').fadeOut();
$('#attribute_add_form').fadeOut();
$('#popover_form').fadeOut();
});
<?php endif; ?>

View File

@ -0,0 +1,3 @@
<?php
echo $this->element('ajaxTemplateTag', array('editable' => 'yes'));
?>

View File

@ -0,0 +1,38 @@
<div id="ajaxTemplateElementsIndex">
<h2>Template Elements</h2>
<ul <?php if($mayModify): ?> id="sortable" <?php endif; ?> style="list-style:none; margin:0px;">
<?php
foreach ($elements as $k => $element):
echo $this->element('templateElements/templateRow' . ucfirst($element['TemplateElement']['element_definition']), array('element' => $element, 'element_id' => $element['TemplateElement']['id']));
endforeach;
?>
</ul>
<?php if($mayModify): ?>
<div id="AddTemplateElementDiv" class="addTemplateElement useCursorPointer" onClick="templateAddElementClicked(<?php echo $id; ?>);">+</div>
<?php endif; ?>
</div>
<script type="text/javascript">
$(function() {
//Return a helper with preserved width of cells
var fixHelper = function(e, ui) {
ui.children().each(function() {
$(this).width($(this).width());
});
return ui;
};
$("#sortable").sortable({
helper: fixHelper,
update: function () {
var order = [];
$("#sortable").children().each(function (i) {
var li = $(this);
order[i] = li.attr("id");
});
saveElementSorting(JSON.stringify(order));
}
}).disableSelection();
});
</script>

View File

@ -0,0 +1,24 @@
<div class="confirmation">
<?php
echo $this->Form->create('TemplateElement', array('style' => 'margin:0px;', 'id' => 'PromptForm'));
?>
<legend>Template Element Deletion</legend>
<div style="padding-left:5px;padding-right:5px;padding-bottom:5px;">
<p>Are you sure you want to delete Template Element #<?php echo $id?>?</p>
<table>
<tr>
<td style="vertical-align:top">
<span id="PromptYesButton" class="btn btn-primary" onClick="submitDeletion(<?php echo $template_id; ?>, 'delete', 'template_elements', <?php echo $id;?>)">Yes</span>
</td>
<td style="width:540px;">
</td>
<td style="vertical-align:top;">
<span class="btn btn-inverse" id="PromptNoButton" onClick="cancelPrompt();">No</span>
</td>
</tr>
</table>
</div>
<?php
echo $this->Form->end();
?>
</div>

View File

@ -0,0 +1,149 @@
<div class="template_element_add_attribute">
<?php
echo $this->Form->create('TemplateElementAttribute', array('id'));
?>
<legend><?php echo __('Add Attribute Element To Template'); ?></legend>
<fieldset>
<div id="formWarning" class="message ajaxMessage"></div>
<div class="add_attribute_fields">
<?php
echo $this->Form->input('name', array(
'type' => 'text',
'error' => array('escape' => false),
'div' => 'input clear',
'class' => 'input-xxlarge'
));
echo $this->Form->input('description', array(
'type' => 'textarea',
'error' => array('escape' => false),
'div' => 'input clear',
'class' => 'input-xxlarge'
));
?>
<div class="input clear"></div>
<?php
echo $this->Form->input('category', array(
'options' => array($categories),
'label' => 'Category',
'empty' => 'Select Category'
));
?>
<div id='typeToggle'>
<?php
echo $this->Form->input('type', array(
'options' => array(),
'label' => 'Type',
'empty' => 'Select Type'
));
?>
</div>
<div class="input clear"></div>
<div id='complexToggle' style="display:none;" title="Some categories can use complex types. A complex type can define attributes that can be described by various different types, the system will parse the user's entry and determine the most suitable type for the found attributes. The list of valid types for the chosen complex type is shown below.">
<?php
echo $this->Form->input('complex', array(
'checked' => false,
'label' => 'Use complex types',
));
?>
</div>
<div class="input clear"></div>
<div id="typeJSON" style="display:none"></div>
<div class="input clear" style="width:100%;display:none" id="outerTypes">
Types allowed based on the above setting:
<div class="templateTypeContainerInner" id="innerTypes">&nbsp;</div>
</div>
<div class="input clear"></div>
<div title="When checked, attributes created using this element will automatically be marked for IDSes.">
<?php
echo $this->Form->input('to_ids', array(
'checked' => false,
'label' => 'Automatically mark for IDS',
));
?>
</div>
<div class="input clear"></div>
<div title="This setting will make this element mandatory.">
<?php
echo $this->Form->input('mandatory', array(
'checked' => false,
'label' => 'Mandatory element',
));
?>
<div>
<div class="input clear"></div>
<div title="If this checkbox is checked, then the resulting field in the form will allow several values to be entered (separated by a linebreak).">
<?php
echo $this->Form->input('batch', array(
'checked' => false,
'label' => 'Batch import element',
));
?>
</div>
</div>
</fieldset>
<div class="overlay_spacing">
<table>
<tr>
<td style="vertical-align:top">
<span id="submitButton" class="btn btn-primary" onClick="submitPopoverForm('<?php echo $id;?>', 'addAttributeElement')">Submit</span>
</td>
<td style="width:540px;">
<p style="color:red;font-weight:bold;display:none;text-align:center" id="warning-message">Warning: You are about to share data that is of a classified nature (Attribution / targeting data). Make sure that you are authorised to share this.</p>
</td>
<td style="vertical-align:top;">
<span class="btn btn-inverse" id="cancel_attribute_add" onClick="cancelPopoverForm();">Cancel</span>
</td>
</tr>
</table>
</div>
<?php
echo $this->Form->end();
?>
</div>
<script type="text/javascript">
var categoryTypes = new Array();
var typeGroupCategoryMapping = <?php echo json_encode($typeGroupCategoryMapping); ?>;
var complexTypes = <?php echo json_encode($validTypeGroups); ?>;
var currentTypes = new Array();
var fieldsArray = new Array('TemplateElementAttributeName', 'TemplateElementAttributeDescription', 'TemplateElementAttributeCategory', 'TemplateElementAttributeToIds', 'TemplateElementAttributeMandatory', 'TemplateElementAttributeBatch', 'TemplateElementAttributeType', 'TemplateElementAttributeComplex');
$(document).ready(function() {
<?php
foreach ($categoryDefinitions as $k => $cat) {
echo 'categoryTypes[\'' . $k . '\'] = [';
foreach ($cat['types'] as $k => $type) {
if ($k != 0) echo ', ';
echo '"' . $type . '"';
}
echo '];';
}
foreach ($typeGroupCategoryMapping as $k => $mapping) {
echo 'typeGroupCategoryMapping["' . $k . '"] = [';
foreach ($mapping as $l => $map) {
if ($l != 0) echo ', ';
echo '"' . $map . '"';
}
echo '];';
}
?>
});
$("#TemplateElementAttributeCategory").change(function() {
var category = $(this).val();
templateElementAttributeCategoryChange(category);
});
$("#TemplateElementAttributeComplex").change(function() {
populateTemplateTypeDropdown();
templateUpdateAvailableTypes();
});
$("#TemplateElementAttributeType").change(function() {
templateElementAttributeTypeChange();
});
</script>

View File

@ -0,0 +1,7 @@
<div class="popover_choice">
<legend><?php echo __('Choose element type'); ?></legend>
<div class="templateChoiceButton" onClick="templateAddElement('attribute', '<?php echo $id;?>');">Attribute</div>
<div class="templateChoiceButton" onClick="templateAddElement('file', '<?php echo $id;?>');">File</div>
<div class="templateChoiceButton" onClick="templateAddElement('text', '<?php echo $id;?>');">Text</div>
<div class="templateChoiceButton templateChoiceButtonLast" onClick="cancelPopoverForm();">Cancel</div>
</div>

View File

@ -0,0 +1,104 @@
<div class="template_element_add_file">
<?php
echo $this->Form->create('TemplateElementFile', array('id'));
?>
<legend><?php echo __('Add File Element To Template'); ?></legend>
<fieldset>
<div id="formWarning" class="message ajaxMessage"></div>
<div class="add_attribute_fields">
<?php
echo $this->Form->input('name', array(
'type' => 'text',
'error' => array('escape' => false),
'div' => 'input clear',
'class' => 'input-xxlarge'
));
echo $this->Form->input('description', array(
'type' => 'textarea',
'error' => array('escape' => false),
'div' => 'input clear',
'class' => 'input-xxlarge'
));
?>
<div class="input clear"></div>
<?php
echo $this->Form->input('category', array(
'options' => array($categories),
'label' => 'Category',
'empty' => 'Select Category'
));
?>
<div class="input clear"></div>
<div id='malwareToggle' title="If a file is flagged as malicious then it will automatically be encrypted.">
<?php
echo $this->Form->input('malware', array(
'checked' => false,
'label' => 'Malware',
));
?>
</div>
<div class="input clear"></div>
<div title="This setting will make this element mandatory.">
<?php
echo $this->Form->input('mandatory', array(
'checked' => false,
'label' => 'Mandatory element',
));
?>
<div>
<div class="input clear"></div>
<div title="If this checkbox is checked, then the resulting field in the form will allow several files to be uploaded.">
<?php
echo $this->Form->input('batch', array(
'checked' => false,
'label' => 'Batch import element',
));
?>
</div>
</div>
</fieldset>
<div class="overlay_spacing">
<table>
<tr>
<td style="vertical-align:top">
<span id="submitButton" class="btn btn-primary" onClick="submitPopoverForm('<?php echo $id;?>', 'addFileElement');">Submit</span>
</td>
<td style="width:540px;">
<p style="color:red;font-weight:bold;display:none;text-align:center" id="warning-message">Warning: You are about to share data that is of a classified nature (Attribution / targeting data). Make sure that you are authorised to share this.</p>
</td>
<td style="vertical-align:top;">
<span class="btn btn-inverse" id="cancel_attribute_add" onClick="cancelPopoverForm();">Cancel</span>
</td>
</tr>
</table>
</div>
<?php
echo $this->Form->end();
?>
</div>
<script type="text/javascript">
var fieldsArray = new Array('TemplateElementFileName', 'TemplateElementFileDescription', 'TemplateElementFileCategory', 'TemplateElementFileMalware', 'TemplateElementFileMandatory', 'TemplateElementFileBatch');
var categoryArray = new Array();
$(document).ready(function() {
<?php
foreach ($categoryArray as $k => $cat) {
echo 'categoryArray[\'' . $k . '\'] = [';
foreach ($cat as $l => $type) {
if ($l != 0) echo ', ';
echo '"' . $type . '"';
}
echo '];';
}
?>
templateElementFileCategoryChange($("#TemplateElementFileCategory").val());
});
$("#TemplateElementFileCategory").change(function() {
var category = $("#TemplateElementFileCategory").val();
templateElementFileCategoryChange(category);
});
</script>

View File

@ -0,0 +1,46 @@
<div class="template_element_add_text">
<?php
echo $this->Form->create('TemplateElementText', array('id'));
?>
<legend><?php echo __('Add Text Element To Template'); ?></legend>
<fieldset>
<div class="add_attribute_fields">
<?php
echo $this->Form->input('name', array(
'type' => 'text',
'error' => array('escape' => false),
'div' => 'input clear',
'class' => 'input-xxlarge'
));
echo $this->Form->input('text', array(
'type' => 'textarea',
'error' => array('escape' => false),
'div' => 'input clear',
'class' => 'input-xxlarge'
));
?>
</div>
</fieldset>
<div class="overlay_spacing">
<table>
<tr>
<td style="vertical-align:top">
<span id="submitButton" class="btn btn-primary" onClick="submitPopoverForm('<?php echo $id;?>', 'addTextElement')">Submit</span>
</td>
<td style="width:540px;">
<p style="color:red;font-weight:bold;display:none;text-align:center" id="warning-message">Warning: You are about to share data that is of a classified nature (Attribution / targeting data). Make sure that you are authorised to share this.</p>
</td>
<td style="vertical-align:top;">
<span class="btn btn-inverse" id="cancel_attribute_add" onClick="cancelPopoverForm();">Cancel</span>
</td>
</tr>
</table>
</div>
<?php
echo $this->Form->end();
?>
</div>
<script type="text/javascript">
var fieldsArray = new Array('TemplateElementTextName', 'TemplateElementTextText');
</script>

View File

@ -0,0 +1,148 @@
<div class="template_element_add_attribute">
<?php
echo $this->Form->create('TemplateElementAttribute', array('id'));
?>
<legend><?php echo __('Edit Attribute Element'); ?></legend>
<fieldset>
<div id="formWarning" class="message ajaxMessage"></div>
<div class="add_attribute_fields">
<?php
echo $this->Form->input('name', array(
'type' => 'text',
'error' => array('escape' => false),
'div' => 'input clear',
'class' => 'input-xxlarge'
));
echo $this->Form->input('description', array(
'type' => 'textarea',
'error' => array('escape' => false),
'div' => 'input clear',
'class' => 'input-xxlarge'
));
?>
<div class="input clear"></div>
<?php
echo $this->Form->input('category', array(
'options' => array($categories),
'label' => 'Category',
'empty' => 'Select Category'
));
?>
<div id='typeToggle'>
<?php
echo $this->Form->input('type', array(
'options' => array($initialTypes),
'label' => 'Type',
'default' => $initialValues['type'],
));
?>
</div>
<div class="input clear"></div>
<div id='complexToggle' <?php if (!$initialValues['complex']) echo 'style="display:none;"'; ?> title="Some categories can use complex types. A complex type can define attributes that can be described by various different types, the system will parse the user's entry and determine the most suitable type for the found attributes. The list of valid types for the chosen complex type is shown below.">
<?php
echo $this->Form->input('complex', array(
'checked' => $initialValues['complex'],
'label' => 'Use complex types',
));
?>
</div>
<div class="input clear"></div>
<div id="typeJSON" style="display:none"></div>
<div class="input clear" style="width:100%;display:none" id="outerTypes">
Types allowed based on the above setting:
<div class="templateTypeContainerInner" id="innerTypes">&nbsp;</div>
</div>
<div class="input clear"></div>
<div title="When checked, attributes created using this element will automatically be marked for IDSes.">
<?php
echo $this->Form->input('to_ids', array(
'label' => 'Automatically mark for IDS',
));
?>
</div>
<div class="input clear"></div>
<div title="This setting will make this element mandatory.">
<?php
echo $this->Form->input('mandatory', array(
'label' => 'Mandatory element',
));
?>
<div>
<div class="input clear"></div>
<div title="If this checkbox is checked, then the resulting field in the form will allow several values to be entered (separated by a linebreak).">
<?php
echo $this->Form->input('batch', array(
'label' => 'Batch import element',
));
?>
</div>
</div>
</fieldset>
<div class="overlay_spacing">
<table>
<tr>
<td style="vertical-align:top">
<span id="submitButton" class="btn btn-primary" onClick="submitPopoverForm('<?php echo $id;?>', 'editAttributeElement', '<?php echo $template_id; ?>')">Submit</span>
</td>
<td style="width:540px;">
<p style="color:red;font-weight:bold;display:none;text-align:center" id="warning-message">Warning: You are about to share data that is of a classified nature (Attribution / targeting data). Make sure that you are authorised to share this.</p>
</td>
<td style="vertical-align:top;">
<span class="btn btn-inverse" id="cancel_attribute_add" onClick="cancelPopoverForm();">Cancel</span>
</td>
</tr>
</table>
</div>
<?php
echo $this->Form->end();
?>
</div>
<script type="text/javascript">
var categoryTypes = new Array();
var typeGroupCategoryMapping = <?php echo json_encode($typeGroupCategoryMapping); ?>;
var complexTypes = <?php echo json_encode($validTypeGroups); ?>;
var currentTypes = new Array();
if (<?php echo ($initialValues['complex'] == true ? 1 : 0); ?> == 1) {
currentTypes = complexTypes["<?php echo $initialValues['type']; ?>"]['types'];
}
var fieldsArray = new Array('TemplateElementAttributeName', 'TemplateElementAttributeDescription', 'TemplateElementAttributeCategory', 'TemplateElementAttributeToIds', 'TemplateElementAttributeMandatory', 'TemplateElementAttributeBatch', 'TemplateElementAttributeType', 'TemplateElementAttributeComplex');
$(document).ready(function() {
<?php
foreach ($categoryDefinitions as $k => $cat) {
echo 'categoryTypes[\'' . $k . '\'] = [';
foreach ($cat['types'] as $k => $type) {
if ($k != 0) echo ', ';
echo '"' . $type . '"';
}
echo '];';
}
foreach ($typeGroupCategoryMapping as $k => $mapping) {
echo 'typeGroupCategoryMapping["' . $k . '"] = [';
foreach ($mapping as $l => $map) {
if ($l != 0) echo ', ';
echo '"' . $map . '"';
}
echo '];';
}
?>
templateUpdateAvailableTypes();
});
$("#TemplateElementAttributeCategory").change(function() {
var category = $(this).val();
templateElementAttributeCategoryChange(category);
});
$("#TemplateElementAttributeComplex").change(function() {
populateTemplateTypeDropdown();
templateUpdateAvailableTypes();
});
$("#TemplateElementAttributeType").change(function() {
templateElementAttributeTypeChange();
});
</script>

View File

@ -0,0 +1,104 @@
<div class="template_element_add_file">
<?php
echo $this->Form->create('TemplateElementFile', array('id'));
?>
<legend><?php echo __('Edit File Element'); ?></legend>
<fieldset>
<div id="formWarning" class="message ajaxMessage"></div>
<div class="add_attribute_fields">
<?php
echo $this->Form->input('name', array(
'type' => 'text',
'error' => array('escape' => false),
'div' => 'input clear',
'class' => 'input-xxlarge'
));
echo $this->Form->input('description', array(
'type' => 'textarea',
'error' => array('escape' => false),
'div' => 'input clear',
'class' => 'input-xxlarge'
));
?>
<div class="input clear"></div>
<?php
echo $this->Form->input('category', array(
'options' => array($categories),
'label' => 'Category',
'empty' => 'Select Category'
));
?>
<div class="input clear"></div>
<div id='malwareToggle' title="If a file is flagged as malicious then it will automatically be encrypted.">
<?php
echo $this->Form->input('malware', array(
'checked' => false,
'label' => 'Malware',
));
?>
</div>
<div class="input clear"></div>
<div title="This setting will make this element mandatory.">
<?php
echo $this->Form->input('mandatory', array(
'checked' => false,
'label' => 'Mandatory element',
));
?>
<div>
<div class="input clear"></div>
<div title="If this checkbox is checked, then the resulting field in the form will allow several files to be uploaded.">
<?php
echo $this->Form->input('batch', array(
'checked' => false,
'label' => 'Batch import element',
));
?>
</div>
</div>
</fieldset>
<div class="overlay_spacing">
<table>
<tr>
<td style="vertical-align:top">
<span id="submitButton" class="btn btn-primary" onClick="submitPopoverForm('<?php echo $id;?>', 'editFileElement', '<?php echo $template_id; ?>');">Submit</span>
</td>
<td style="width:540px;">
<p style="color:red;font-weight:bold;display:none;text-align:center" id="warning-message">Warning: You are about to share data that is of a classified nature (Attribution / targeting data). Make sure that you are authorised to share this.</p>
</td>
<td style="vertical-align:top;">
<span class="btn btn-inverse" id="cancel_attribute_add" onClick="cancelPopoverForm();">Cancel</span>
</td>
</tr>
</table>
</div>
<?php
echo $this->Form->end();
?>
</div>
<script type="text/javascript">
var fieldsArray = new Array('TemplateElementFileName', 'TemplateElementFileDescription', 'TemplateElementFileCategory', 'TemplateElementFileMalware', 'TemplateElementFileMandatory', 'TemplateElementFileBatch');
var categoryArray = new Array();
$(document).ready(function() {
<?php
foreach ($categoryArray as $k => $cat) {
echo 'categoryArray[\'' . $k . '\'] = [';
foreach ($cat as $l => $type) {
if ($l != 0) echo ', ';
echo '"' . $type . '"';
}
echo '];';
}
?>
templateElementFileCategoryChange($("#TemplateElementFileCategory").val());
});
$("#TemplateElementFileCategory").change(function() {
var category = $("#TemplateElementFileCategory").val();
templateElementFileCategoryChange(category);
});
</script>

View File

@ -0,0 +1,46 @@
<div class="template_element_add_text">
<?php
echo $this->Form->create('TemplateElementText', array('id'));
?>
<legend><?php echo __('Add Text Element To Template'); ?></legend>
<fieldset>
<div class="add_attribute_fields">
<?php
echo $this->Form->input('name', array(
'type' => 'text',
'error' => array('escape' => false),
'div' => 'input clear',
'class' => 'input-xxlarge'
));
echo $this->Form->input('text', array(
'type' => 'textarea',
'error' => array('escape' => false),
'div' => 'input clear',
'class' => 'input-xxlarge'
));
?>
</div>
</fieldset>
<div class="overlay_spacing">
<table>
<tr>
<td style="vertical-align:top">
<span id="submitButton" class="btn btn-primary" onClick="submitPopoverForm('<?php echo $id;?>', 'editTextElement', '<?php echo $template_id; ?>')">Submit</span>
</td>
<td style="width:540px;">
<p style="color:red;font-weight:bold;display:none;text-align:center" id="warning-message">Warning: You are about to share data that is of a classified nature (Attribution / targeting data). Make sure that you are authorised to share this.</p>
</td>
<td style="vertical-align:top;">
<span class="btn btn-inverse" id="cancel_attribute_add" onClick="cancelPopoverForm();">Cancel</span>
</td>
</tr>
</table>
</div>
<?php
echo $this->Form->end();
?>
</div>
<script type="text/javascript">
var fieldsArray = new Array('TemplateElementTextName', 'TemplateElementTextText');
</script>

View File

@ -0,0 +1,64 @@
<div class="templates form">
<?php
echo $this->Form->create('Template');
?>
<fieldset>
<legend><?php echo __('Create Template'); ?></legend>
<?php
echo ($this->Form->input('name', array('div' => 'clear')));
echo ($this->Form->input('tags', array('id' => 'hiddenTags','div' => 'clear', 'label' => false, 'type' => 'text', 'value' => '[]', 'style' => 'display:none;')));
?>
<div id ="tagList">
<label>Tags</label>
<table>
<tr>
<td><table><tr id = "tags"></tr></table></td>
<td id = "addTagButtonTD">
<span onClick="activateTagField()" id="addTagButton" class="btn btn-inverse noPrint" style="line-height:10px; padding: 4px 4px;">+</span>
</td>
<td id = "addTagFieldTD">
<?php
echo $this->Form->input('tagsPusher', array(
'div' => 'clear',
'id' => 'addTagField',
'options' => array($tags),
'label' => false,
'onChange' => 'tagFieldChange()',
'style' => "height:22px;padding:0px;margin-bottom:0px;display:none;",
'empty' => 'Add a tag',
));
?>
</td>
</tr>
</table>
</div><br />
<?php
echo $this->Form->input('description', array(
'label' => 'Event Description',
'div' => 'clear',
'type' => 'textarea',
'class' => 'form-control span6',
'placeholder' => 'A description of the template'
));
echo $this->Form->input('share', array(
'label' => 'Share this template with others',
));
?>
</fieldset>
<?php echo $this->Form->button(__('Create'), array('class' => 'btn btn-primary'));
echo $this->Form->end();?>
</div>
<?php
echo $this->element('side_menu', array('menuList' => 'templates', 'menuItem' => 'add'));
?>
<script type="text/javascript">
var selectedTags = [];
var allTags = [
<?php
foreach ($tagInfo as $tag) {
echo "{'id' : '" . $tag['Tags']['id'] . "', 'name' : '" . $tag['Tags']['name'] . "', 'colour' : '" . $tag['Tags']['colour'] . "'},";
}
?>
];
</script>
<?php echo $this->Js->writeBuffer();

View File

@ -0,0 +1,28 @@
<div class="popover_choice">
<legend><?php echo __('Choose element type'); ?></legend>
<div class="popover_choice_main" id ="popover_choice_main">
<?php foreach ($templates as $k => $template): ?>
<div class="templateChoiceButton" style="width:100%;" title="<?php echo h($template['Template']['description']); ?>" onClick="document.location.href ='/templates/populateEventFromTemplate/<?php echo $template['Template']['id'];?>/<?php echo $id; ?>'">
<div style="float:left;">
<?php
$imgRelativePath = 'orgs' . DS . h($template['Template']['org']) . '.png';
$imgAbsolutePath = APP . WEBROOT_DIR . DS . 'img' . DS . $imgRelativePath;
if (file_exists($imgAbsolutePath)) echo $this->Html->image('orgs/' . h($template['Template']['org']) . '.png', array('alt' => h($template['Template']['org']), 'title' => h($template['Template']['org']), 'style' => 'width:24px; height:24px'));
else echo $this->Html->tag('span', h($template['Template']['org']), array('class' => 'welcome', 'style' => 'float:left;'));
?>
</div>
<div><span style="position:relative;left:-12px;"><?php echo h($template['Template']['name']);?></span></div>
</div>
<?php endforeach; ?>
</div>
<div class="templateChoiceButton templateChoiceButtonLast" onClick="cancelPopoverForm();">Cancel</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
resizePopoverBody();
});
$(window).resize(function() {
resizePopoverBody();
});
</script>

View File

@ -0,0 +1,76 @@
<div class="templates form">
<?php
echo $this->Form->create('Template');
?>
<fieldset>
<legend><?php echo __('Edit Template'); ?></legend>
<?php
echo ($this->Form->input('name', array('div' => 'clear')));
echo ($this->Form->input('tags', array('id' => 'hiddenTags','div' => 'clear', 'label' => false, 'type' => 'text', 'value' => '[]', 'style' => 'display:none;')));
?>
<div id ="tagList">
<label>Tags</label>
<table>
<tr>
<td><table><tr id = "tags"></tr></table></td>
<td id = "addTagButtonTD">
<span onClick="activateTagField()" id="addTagButton" class="btn btn-inverse noPrint" style="line-height:10px; padding: 4px 4px;">+</span>
</td>
<td id = "addTagFieldTD">
<?
echo $this->Form->input('tagsPusher', array(
'div' => 'clear',
'id' => 'addTagField',
'options' => array($tags),
'label' => false,
'onChange' => 'tagFieldChange()',
'style' => "height:22px;padding:0px;margin-bottom:0px;display:none;",
'empty' => 'Add a tag',
));
?>
</td>
</tr>
</table>
</div><br />
<?php
echo $this->Form->input('description', array(
'label' => 'Event Description',
'div' => 'clear',
'type' => 'textarea',
'class' => 'form-control span6',
'placeholder' => 'A description of the template'
));
echo $this->Form->input('share', array(
'label' => 'Share this template with others',
));
?>
</fieldset>
<?php echo $this->Form->button(__('Edit'), array('class' => 'btn btn-primary'));
echo $this->Form->end();?>
</div>
<?php
echo $this->element('side_menu', array('menuList' => 'templates', 'menuItem' => 'edit', 'id' => $id, 'mayModify' => $mayModify));
?>
<script type="text/javascript">
var selectedTags = [
<?php
foreach ($currentTags as $k => $t) {
if ($k != 0) echo ', ';
echo '"' . $t['Tag']['name'] . '"';
}
?>
];
var allTags = [
<?php
foreach ($tagInfo as $tag) {
echo "{'id' : '" . $tag['Tags']['id'] . "', 'name' : '" . $tag['Tags']['name'] . "', 'colour' : '" . $tag['Tags']['colour'] . "'},";
}
?>
];
$(document).ready( function () {
for (var i = 0, len = selectedTags.length; i < len; i++) {
appendTemplateTag(selectedTags[i], 'yes');
}
});
</script>
<?php echo $this->Js->writeBuffer();

View File

@ -0,0 +1,66 @@
<div class="templates index">
<h2>Templates</h2>
<div class="pagination">
<ul>
<?php
$this->Paginator->options(array(
'update' => '.span12',
'evalScripts' => true,
'before' => '$(".progress").show()',
'complete' => '$(".progress").hide()',
));
echo $this->Paginator->prev('&laquo; ' . __('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') . ' &raquo;', 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('org');?></th>
<th><?php echo $this->Paginator->sort('share');?></th>
<th><?php echo $this->Paginator->sort('name');?></th>
<th><?php echo $this->Paginator->sort('description');?></th>
<?php if ($isAclTemplate): ?>
<th class="actions"><?php echo __('Actions');?></th>
<?php endif; ?>
</tr><?php
foreach ($list as $item): ?>
<tr>
<td class="short" onclick="document.location.href ='/templates/view/<?php echo $item['Template']['id']; ?>'"><?php echo h($item['Template']['id']); ?>&nbsp;</td>
<td class="short" onclick="document.location.href ='/templates/view/<?php echo $item['Template']['id']; ?>'"><?php echo h($item['Template']['org']); ?>&nbsp;</td>
<td class="short" onclick="document.location.href ='/templates/view/<?php echo $item['Template']['id']; ?>'"><?php if ($item['Template']['share']) echo 'Yes'; else echo 'No'; ?>&nbsp;</td>
<td onclick="document.location.href ='/templates/view/<?php echo $item['Template']['id']; ?>'"><?php echo h($item['Template']['name']); ?>&nbsp;</td>
<td onclick="document.location.href ='/templates/view/<?php echo $item['Template']['id']; ?>'"><?php echo h($item['Template']['description']); ?>&nbsp;</td>
<?php if ($isAclTagger): ?>
<td class="short action-links">
<?php echo $this->Html->link('', array('action' => 'edit', $item['Template']['id']), array('class' => 'icon-edit', 'title' => 'Edit'));?>
<?php echo $this->Form->postLink('', array('action' => 'delete', $item['Template']['id']), array('class' => 'icon-trash', 'title' => 'Delete'), __('Are you sure you want to delete Template #' . $item['Template']['id'] . '?'));?>
</td>
<?php endif; ?>
</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('&laquo; ' . __('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') . ' &raquo;', 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' => 'templates', 'menuItem' => 'index'));
?>

View File

@ -0,0 +1,35 @@
<div class="populate_from_template form">
<?php echo $this->Form->create('', array('type' => 'file'));?>
<fieldset>
<div id="populate_template_info" class="templateTableRow templateTableRow80">
<?php
echo $this->element('templateElements/populateTemplateDescription');
?>
</div>
<?php
foreach ($templateData['TemplateElement'] as $k => $element) {
echo $this->element('templateElements/populateTemplate' . ucfirst($element['element_definition']), array('element' => $element['TemplateElement' . ucfirst($element['element_definition'])][0], 'k' => $k, 'element_id' => $element['id'], 'value' => ''));
}
echo $this->Form->input('fileArray', array(
'label' => false,
'style' => 'display:none;',
'value' => '[]',
));
?>
</fieldset>
<?php
echo $this->Form->button('Add', array('class' => 'btn btn-primary'));
echo $this->Form->end();
?>
</div>
<?php
echo $this->element('side_menu', array('menuList' => 'event', 'menuItem' => 'populateFromtemplate', 'event' => array('Event' => array('id' => $event_id)), 'template_id' => $template_id));
?>
<script type="text/javascript">
$(document).ready(function() {
<?php if (isset($fileArray)): ?>
populateTemplateHiddenFileDiv(<?php echo $fileArray; ?>);
<?php endif; ?>
populateTemplateFileBubbles();
});
</script>

View File

@ -0,0 +1,80 @@
<div class="index">
<h2>Populate From Template Results</h2>
<p>Below you can see the attributes that are to be created based on the data that you have entered into the template. If you are satisfied with the result, click "Finalise". Otherwise, click "Modify".</p>
<table class="table table-striped table-hover table-condensed">
<tr>
<th>Category</th>
<th>Type</th>
<th>Value</th>
<th>Comment</th>
<th>IDS</th>
<th>Distribution</th>
</tr><?php
foreach ($attributes as $item):?>
<tr>
<td><?php echo h($item['category']); ?></td>
<td><?php echo h($item['type']); ?></td>
<td><?php echo h($item['value']); ?></td>
<td><?php echo h($item['comment']); ?></td>
<td><?php echo ($item['to_ids'] ? 'Yes' : 'No'); ?></td>
<td><?php echo $distributionLevels[$item['distribution']]; ?></td>
</tr><?php
endforeach;?>
</table>
<div style="float:left;">
<?php echo $this->Form->create('Template', array('url' => '/templates/submitEventPopulation/' . $template_id . '/' . $event_id));?>
<fieldset>
<?php
echo $this->Form->input('attributes', array(
'id' => 'attributes',
'label' => false,
'type' => 'hidden',
'value' => serialize($attributes),
));
?>
</fieldset>
<?php
echo $this->Form->button('Finalise', array('class' => 'btn btn-primary'));
echo $this->Form->end();
?>
</div>
<div style="float:left;width:10px;">&nbsp;</div>
<div>
<?php echo $this->Form->create('Template');?>
<fieldset>
<?php
foreach ($template['Template'] as $k => $v) {
if (strpos($k, 'ile_')) $v = serialize($v);
echo $this->Form->input($k, array(
'label' => false,
'type' => 'hidden',
'value' => $v,
));
}
echo $this->Form->input('modify', array(
'label' => false,
'type' => 'hidden',
'value' => true,
));
echo $this->Form->input('errors', array(
'label' => false,
'type' => 'hidden',
'value' => serialize($errors),
));
echo $this->Form->input('fileArray', array(
'label' => false,
'type' => 'hidden',
'value' => $fileArray,
));
?>
</fieldset>
<?php
echo $this->Form->button('Modify', array('class' => 'btn btn-inverse'));
echo $this->Form->end();
?>
</div>
</div>
<?php
echo $this->element('side_menu', array('menuList' => 'regexp', 'menuItem' => 'index'));
?>

View File

@ -0,0 +1,4 @@
<?php
echo $this->Form->create('', array('type' => 'file'));
echo $this->Form->end();
?>

View File

@ -0,0 +1,31 @@
<?php
if ($batch == 'yes') {
$buttonText = 'Upload Files';
$multiple = true;
} else {
$multiple = false;
if (isset($filenames)) {
$buttonText = 'Replace File';
} else {
$buttonText = 'Upload File';
}
}
?>
<div style="display:none;">
<?php
echo $this->Form->create('', array('id' => 'upload_' . $element_id, 'type' => 'file'));
echo $this->Form->input('file.', array('id' => 'upload_' . $element_id . '_file', 'type' => 'file', 'label' => false, 'multiple' => $multiple, 'onChange' => 'this.form.submit()'));
echo $this->Form->end();
?>
</div>
<span id="fileUploadButton_<?php echo $element_id; ?>" class="btn btn-primary" onClick="templateFileUploadTriggerBrowse('<?php echo $element_id; ?>');"><?php echo $buttonText; ?></span>
<script type="text/javascript">
$(document).ready(function() {
<?php if (isset($filenames)): ?>
var fileArray = JSON.parse('<?php echo $fileArray;?>');
templateFileHiddenAdd(fileArray, '<?php echo $element_id; ?>', '<?php echo $batch; ?>');
showMessage('<?php echo $upload_error ? 'fail' : 'success'; ?>', '<?php echo $result; ?>', 'iframe');
<?php endif; ?>
});
</script>

View File

@ -0,0 +1,58 @@
<div class="templates view">
<h2><?php echo __('Template');?></h2>
<dl>
<dt><?php echo __('Id'); ?></dt>
<dd>
<?php echo $template['Template']['id']; ?>
&nbsp;
</dd>
<dt><?php echo __('Name'); ?></dt>
<dd>
<?php echo h($template['Template']['name']); ?>
&nbsp;
</dd>
<dt><?php echo __('Description'); ?></dt>
<dd>
<?php echo h($template['Template']['description']); ?>
&nbsp;
</dd>
<dt><?php echo __('Tags'); ?></dt>
<dd>
<table>
<tr id = "tags">
<?php
if (!empty($template['TemplateTag'])) {
foreach ($template['TemplateTag'] as $tag) {
echo $this->element('ajaxTemplateTag', array('tag' => $tag, 'editable' => 'no'));
}
} else echo '&nbsp';
?>
</tr>
</table>
</dd>
<dt><?php echo __('Organisation'); ?></dt>
<dd>
<?php echo h($template['Template']['org']); ?>
&nbsp;
</dd>
<dt><?php echo __('Shareable'); ?></dt>
<dd>
<?php
if ($template['Template']['share']) echo 'Yes';
else echo 'No';
?>
</dd>
</dl>
<div id="templateElements">
</div>
<div id="popover_form" class="ajax_popover_form"></div>
<div id="confirmation_box" class="confirmation_box"></div>
</div>
<?php
echo $this->element('side_menu', array('menuList' => 'templates', 'menuItem' => 'view', 'mayModify' => $mayModify));
?>
<script type="text/javascript">
$(document).ready( function () {
updateIndex(<?php echo $template['Template']['id']?>, 'template');
});
</script>

View File

@ -1,4 +1,3 @@
<?php echo $this->Html->script('ajaxification'); ?>
<div class="users index">
<h2>Members</h2>
<table class="table table-striped table-condensed table-bordered" style="width:300px;">

0
app/tmp/files/empty Normal file
View File

File diff suppressed because one or more lines are too long

View File

@ -692,6 +692,18 @@ a.proposal_link_red:hover {
color:white;
}
.tagComplete {
display: inline-block;
padding:2px 4px;
font-size: 12px;
font-weight: bold;
line-height: 14px;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
box-shadow: 3px 3px 3px #888888;
}
.topGap {
padding-top:100px;
}
@ -729,7 +741,7 @@ a.proposal_link_red:hover {
color:white;
}
.attribute_add_form {
.ajax_popover_form {
display:none;
width: 700px;
top:150px;
@ -741,7 +753,7 @@ a.proposal_link_red:hover {
z-index:5;
}
.attribute_add_form legend {
.ajax_popover_form legend {
border-radius: 10px 10px 0px 0px;
padding-left:10px;
margin-bottom:5px;
@ -750,7 +762,7 @@ a.proposal_link_red:hover {
color:white;
}
.attribute_add_form form {
.ajax_popover_form form {
margin: 0 0 5px;
}
@ -759,15 +771,15 @@ a.proposal_link_red:hover {
padding-right:10px !important;
}
.attribute_add_form .input-xxlarge {
.ajax_popover_form .input-xxlarge {
width:665px;
}
.attribute_add_form textarea {
.ajax_popover_form textarea {
height:120px !important;
}
.attribute_add_form .add_attribute_fields {
.ajax_popover_form .add_attribute_fields {
padding-left:10px;
}
@ -880,7 +892,6 @@ a.proposal_link_red:hover {
position:absolute;
top:-21px;
height:20px;
margin-left:5px;
padding-left:10px;
padding-right:10px;
-webkit-border-radius: 4px 4px 0 0;
@ -892,6 +903,14 @@ a.proposal_link_red:hover {
border-collapse: separate !important;
}
.tabMenuEditBlock {
margin-left:5px;
}
.tabMenuToolsBlock {
margin-left:200px;
}
.tabMenu [class^="icon-"] {
vertical-align:baseline;
margin-top:3px;
@ -946,6 +965,258 @@ a.proposal_link_red:hover {
cursor: hand;
}
.template_general {
display:inline-block;
width: 100%;
margin-bottom: 20px;
border-bottom: 1px solid #e5e5e5;
}
.templateTable {
border-collapse:collapse;
border-spacing:0px 10px;
width:100%;
}
.templateTableRow {
width:100%;
display:inline-block;
box-shadow: 4px 2px 4px 2px #aaa;
margin: 0 0 15px 0;
background-color: #FFFFFF;
padding:0px !important;
padding-right:0px !important;
border: 1px solid black !important;
-webkit-radius: 8px;
-moz-border-radius: 8px;
border-radius: 8px;
}
.templateTableRow80 {
width:80% !important;
}
.templateTableArea {
display:block;
float:left;
padding-top:4px;
padding-bottom:4px;
}
.templateTableTDName {
width: calc(15% - 6px) !important;
padding-left:5px;
}
.templateTableTDDescription {
width: 35% !important;
}
.templateTableTDCategory {
width: 10% !important;
}
.templateTableTDDescriptionFile {
width: 55% !important;
}
.templateTableTDText {
width: 80%;
}
.templateTableTDShort {
width: 5% !important;
}
.templateTableTDActions {
width: 5% !important;
}
.templateTableTDTypes {
width: 20% !important;
}
.templateTableNormal {
width: 10% !important;
}
.templateTableCellFirst {
box-sizing:border-box;
display:inline-block;
padding-left:8px !important;
}
.templateTableCell {
padding-top:4px !important;
padding-bottom:4px !important;
display:inline-block;
padding-left:0px !important;
padding-right:0px !important;
border-top:0px !important;
}
.templateTableHeader {
display:inline-block;
}
.templateTableColumnName {
color:#0077bb;
font-weight:bold;
text-decoration:underline;
}
.templateElementHeader {
background:#0088cc;
color:white;
font-weight:bold;
height:25px;
-moz-border-radius: 0px;
-webkit-border-radius: 7px 7px 0px 0px;
border-radius: 7px 7px 0px 0px;
}
.templateElementHeaderText {
position: absolute;
padding-left:8px;
padding-top:4px;
}
.templateGlass {
width: 100%;
height: 100%;
position: absolute;
padding: 0;
-webkit-border-radius: 7px 7px 0px 0px;
-moz-border-radius: 7px 7px 0px 0px;
border-radius: 7px 7px 0px 0px;
background: rgba(0,0,0,0.1.25);
box-shadow: 0 2px 6px rgba(0,0,0,0.5),
inset 0 1px rgba(255,255,255,0.3),
inset 0 10px rgba(255,255,255,0.1),
inset 0 10px 20px rgba(255,255,255,0.3),
inset 0 -15px 30px rgba(0,0,0,0.3);
}
.addTemplateElement {
position:relative;
box-shadow: 4px 2px 4px 2px #aaa;
margin: 0 0 15px 0;
height:40px;
line-height:40px;
background-color: #FFFFFF;
padding:0px !important;
padding-right:0px !important;
border: 1px dashed black !important;
-webkit-radius: 8px;
-moz-border-radius: 8px;
border-radius: 8px;
text-align:center;
vertical-align:middle;
font-weight:bold;
color:#0088cc;
font-size:200%;
z-index:0;
}
.popover_choice legend {
margin-bottom:0px !important;
border-bottom:0px !important;
}
.popover_choice form {
margin-bottom:0px !important;
border-bottom:0px !important;
}
.popover_choice_main {
max-height:400px;
overflow-y:auto;
}
.templateChoiceButton {
text-align:center;
width:100%;
line-height:30px;
border-top:1px solid black;
}
.templateChoiceButton:hover {
background-color:#0088cc !important;
color:white;
}
.templateChoiceButtonLast {
border-radius:0 0 10px 10px;
color:white;
background-color:black;
}
.templateTypeBox {
float:left;
margin-right:5px;
padding-left:2px;
padding-right:2px;
margin-bottom:3px;
border-radius: 5px;
box-shadow: 1px 1px 1px 1px #888888;
border:1px solid #0088cc;
background-color:white;
color:#0088cc;
}
.populate_template_div_body {
padding:8px;
}
.populate_template_div_body .left {
float:left;
width:200px;
color:#0088cc;
font-weight:bold;
margin-bottom:5px;
}
.populate_template_div_body .right {
float:left;
width:calc(100% - 200px);
margin-bottom:5px;
}
.template_mandatory {
font-weight:bold;
}
.template_file_box {
background-color:#0088cc;
color:white;
white-space:nowrap;
}
.template_file_box_container {
float:left;
padding:3px;
}
.drop {
min-height: 150px;
width: 250px;
border: 1px solid blue;
margin: 10px;
padding: 10px;
}
.visibleDL {
background-color: red !important;
color: white;
font-weight: bold;
}
.red {
color: red;
}
@-webkit-keyframes rotation {
from {-webkit-transform: rotate(0deg);}
to {-webkit-transform: rotate(359deg);}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 491 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 387 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 278 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 336 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 421 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 280 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 353 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 401 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

File diff suppressed because one or more lines are too long

View File

@ -1,43 +1,20 @@
function deleteObject2(type, id, event) {
var typeMessage, name, action;
if (type == 'attributes') {
action = 'delete';
typeMessage = 'Attribute';
name = '#Attribute' + '_' + id + '_delete';
}
if (type == 'shadow_attributes') {
action = 'discard';
typeMessage = 'Proposal';
name = '#ShadowAttribute' + '_' + id + '_delete';
}
if (confirm("Are you sure you want to delete " + typeMessage + " #" + id + "?")) {
var formData = $(name).serialize();
$.ajax({
data: formData,
success:function (data, textStatus) {
updateAttributeIndexOnSuccess(event);
handleGenericAjaxResponse(data);
},
type:"post",
cache: false,
url:"/" + type + "/" + action + "/" + id,
});
}
}
function deleteObject(type, action, id, event) {
var destination = 'attributes';
if (type == 'shadow_attributes') destination = 'shadow_attributes';
if (type == 'template_elements') destination = 'template_elements';
$.get( "/" + destination + "/" + action + "/" + id, function(data) {
$("#confirmation_box").fadeIn();
$("#gray_out").fadeIn();
$("#confirmation_box").html(data);
$(window).bind('keypress', function(e) {
var code = e.keyCode || e.which;
if (code == 13) {
submitDeletion(event, action, type, id);
}
});
});
}
function editTemplateElement(type, id) {
$.get( "/template_elements/edit/" + type + "/" + id, function(data) {
$("#popover_form").fadeIn();
$("#gray_out").fadeIn();
$("#popover_form").html(data);
});
}
@ -47,7 +24,9 @@ function cancelPrompt() {
$("#confirmation_box").empty();
}
function submitDeletion(event, action, type, id) {
function submitDeletion(context_id, action, type, id) {
var context = 'event';
if (type == 'template_elements') context = 'template';
var formData = $('#PromptForm').serialize();
$.ajax({
beforeSend: function (XMLHttpRequest) {
@ -55,7 +34,7 @@ function submitDeletion(event, action, type, id) {
},
data: formData,
success:function (data, textStatus) {
updateAttributeIndexOnSuccess(event);
updateIndex(context_id, context);
handleGenericAjaxResponse(data);
},
complete:function() {
@ -75,7 +54,7 @@ function acceptObject(type, id, event) {
$.ajax({
data: formData,
success:function (data, textStatus) {
updateAttributeIndexOnSuccess(event);
updateIndex(event, 'event');
handleGenericAjaxResponse(data);
},
type:"post",
@ -84,7 +63,16 @@ function acceptObject(type, id, event) {
});
}
function updateAttributeIndexOnSuccess(event) {
function updateIndex(id, context) {
var url, div;
if (context == 'event') {
url = "/events/view/" + id + "/attributesPage:1";
div = "#attributes_div";
}
if (context == 'template') {
url = "/template_elements/index/" + id;
div = "#templateElements";
}
$.ajax({
beforeSend: function (XMLHttpRequest) {
$(".loading").show();
@ -93,9 +81,9 @@ function updateAttributeIndexOnSuccess(event) {
cache: false,
success:function (data, textStatus) {
$(".loading").hide();
$("#attributes_div").html(data);
$(div).html(data);
},
url:"/events/view/" + event + "/attributesPage:1",
url: url,
});
}
@ -220,7 +208,7 @@ function submitForm(type, id, field, event) {
},
error:function() {
showMessage('fail', 'Request failed for an unknown reason.');
updateAttributeIndexOnSuccess(event);
updateIndex(event, 'event');
},
type:"post",
url:"/" + object_type + "/editField/" + id
@ -266,12 +254,16 @@ function handleAjaxEditResponse(data, name, type, id, field, event) {
}
}
if (type == 'ShadowAttribute') {
updateAttributeIndexOnSuccess(event);
updateIndex(event, 'event');
}
}
function handleGenericAjaxResponse(data) {
responseArray = JSON.parse(data);
if (typeof data == 'string') {
responseArray = JSON.parse(data);
} else {
responseArray = data;
}
if (responseArray.saved) {
showMessage('success', responseArray.success);
} else {
@ -299,8 +291,8 @@ function deleteSelectedAttributes(event) {
var selected = [];
$(".select_attribute").each(function() {
if ($(this).is(":checked")) {
var test = $(this).data("id");
selected.push(test);
var temp= $(this).data("id");
selected.push(temp);
}
});
$('#AttributeIds').attr('value', JSON.stringify(selected));
@ -311,7 +303,7 @@ function deleteSelectedAttributes(event) {
type:"POST",
url:"/attributes/deleteSelected/" + event,
success:function (data, textStatus) {
updateAttributeIndexOnSuccess(event);
updateIndex(event, 'event');
handleGenericAjaxResponse(data);
},
});
@ -321,9 +313,9 @@ function deleteSelectedAttributes(event) {
function editSelectedAttributes(event) {
$.get("/attributes/editSelected/"+event, function(data) {
$("#attribute_add_form").fadeIn();
$("#popover_form").fadeIn();
$("#gray_out").fadeIn();
$("#attribute_add_form").html(data);
$("#popover_form").html(data);
});
}
@ -377,27 +369,74 @@ function clickCreateButton(event, type) {
var destination = 'attributes';
if (type == 'Proposal') destination = 'shadow_attributes';
$.get( "/" + destination + "/add/" + event, function(data) {
$("#attribute_add_form").fadeIn();
$("#popover_form").fadeIn();
$("#gray_out").fadeIn();
$("#attribute_add_form").html(data);
$("#popover_form").html(data);
});
}
function submitPopoverForm(event, referer) {
function submitPopoverForm(context_id, referer, update_context_id) {
var url = null;
if (referer == 'add') url = "/attributes/add/" + event;
if (referer == 'propose') url = "/shadow_attributes/add/" + event;
if (referer == 'massEdit') url = "/attributes/editSelected/" + event;
var context = 'event';
var contextNamingConvention = 'Attribute';
switch (referer) {
case 'add':
url = "/attributes/add/" + context_id;
break;
case 'propose':
url = "/shadow_attributes/add/" + context_id;
break;
case 'massEdit':
url = "/attributes/editSelected/" + context_id;
break;
case 'addTextElement':
url = "/templateElements/add/text/" + context_id;
context = 'template';
contextNamingConvention = 'TemplateElementText';
break;
case 'editTextElement':
url = "/templateElements/edit/text/" + context_id;
context = 'template';
context_id = update_context_id;
contextNamingConvention = 'TemplateElementText';
break;
case 'addAttributeElement':
url = "/templateElements/add/attribute/" + context_id;
context = 'template';
contextNamingConvention = 'TemplateElementAttribute';
break;
case 'editAttributeElement':
url = "/templateElements/edit/attribute/" + context_id;
context = 'template';
context_id = update_context_id;
contextNamingConvention = 'TemplateElementAttribute';
break;
case 'addFileElement':
url = "/templateElements/add/file/" + context_id;
context = 'template';
contextNamingConvention = 'TemplateElementFile';
break;
case 'editFileElement':
url = "/templateElements/edit/file/" + context_id;
context = 'template';
context_id = update_context_id;
contextNamingConvention = 'TemplateElementFile';
break;
case 'replaceAttributes':
url = "/attributes/attributeReplace/" + context_id;
break;
}
if (url !== null) {
$.ajax({
beforeSend: function (XMLHttpRequest) {
$(".loading").show();
$("#gray_out").fadeOut();
$("#attribute_add_form").fadeOut();
$("#popover_form").fadeOut();
},
data: $("#submitButton").closest("form").serialize(),
success:function (data, textStatus) {
handleAjaxPopoverResponse(data, event, url, referer);
handleAjaxPopoverResponse(data, context_id, url, referer, context, contextNamingConvention);
$(".loading").show();
},
type:"post",
@ -406,14 +445,11 @@ function submitPopoverForm(event, referer) {
}
};
function handleAjaxPopoverResponse(response, event, url, referer) {
function handleAjaxPopoverResponse(response, context_id, url, referer, context, contextNamingConvention) {
responseArray = JSON.parse(response);
var message = null;
if (responseArray.saved) {
//if (referer == 'add') message = "Attribute added.";
//if (referer == 'propose') message = "Proposal added.";
//if (referer == 'massEdit') message = "Attributes updated.";
updateAttributeIndexOnSuccess(event);
updateIndex(context_id, context);
if (responseArray.success) {
showMessage("success", responseArray.success);
}
@ -427,12 +463,13 @@ function handleAjaxPopoverResponse(response, event, url, referer) {
dataType:"html",
success:function (data, textStatus) {
$("#gray_out").fadeIn();
$("#attribute_add_form").fadeIn();
$("#attribute_add_form").html(data);
handleValidationErrors(responseArray.errors);
$("#popover_form").fadeIn();
$("#popover_form").html(data);
var error_context = context.charAt(0).toUpperCase() + context.slice(1);
handleValidationErrors(responseArray.errors, context, contextNamingConvention);
if (!isEmpty(responseArray)) {
$("#formWarning").show();
$("#formWarning").html('The attribute(s) could not be saved. Please, try again.');
$("#formWarning").html('The object(s) could not be saved. Please, try again.');
}
recoverValuesFromPersistance(savedArray);
$(".loading").hide();
@ -453,23 +490,23 @@ function isEmpty(obj) {
//before we update the form (in case the action failed), we want to retrieve the data from every field, so that we can set the fields in the new form that we fetch
function saveValuesForPersistance() {
var formPersistanceArray = new Array();
for (i = 0; i < fieldsArrayAttribute.length; i++) {
formPersistanceArray[fieldsArrayAttribute[i]] = document.getElementById(fieldsArrayAttribute[i]).value;
for (i = 0; i < fieldsArray.length; i++) {
formPersistanceArray[fieldsArray[i]] = document.getElementById(fieldsArray[i]).value;
}
return formPersistanceArray;
}
function recoverValuesFromPersistance(formPersistanceArray) {
for (i = 0; i < fieldsArrayAttribute.length; i++) {
document.getElementById(fieldsArrayAttribute[i]).value = formPersistanceArray[fieldsArrayAttribute[i]];
for (i = 0; i < fieldsArray.length; i++) {
document.getElementById(fieldsArray[i]).value = formPersistanceArray[fieldsArray[i]];
}
}
function handleValidationErrors(responseArray) {
function handleValidationErrors(responseArray, context, contextNamingConvention) {
for (var k in responseArray) {
var elementName = k.charAt(0).toUpperCase() + k.slice(1);
$("#Attribute" + elementName).parent().addClass("error");
$("#Attribute" + elementName).parent().append("<div class=\"error-message\">" + responseArray[k] + "</div>");
$("#" + contextNamingConvention + elementName).parent().addClass("error");
$("#" + contextNamingConvention + elementName).parent().append("<div class=\"error-message\">" + responseArray[k] + "</div>");
}
}
@ -500,9 +537,332 @@ function updateHistogram(selected) {
});
}
function showMessage(success, message) {
function showMessage(success, message, context) {
if (typeof context !== "undefined") {
$("#ajax_" + success, window.parent.document).html(message);
var duration = 1000 + (message.length * 40);
$("#ajax_" + success + "_container", window.parent.document).fadeIn("slow");
$("#ajax_" + success + "_container", window.parent.document).delay(duration).fadeOut("slow");
}
$("#ajax_" + success).html(message);
var duration = 1000 + (message.length * 40);
$("#ajax_" + success + "_container").fadeIn("slow");
$("#ajax_" + success + "_container").delay(duration).fadeOut("slow");
}
}
function cancelPopoverForm() {
$("#popover_form").empty();
$('#gray_out').fadeOut();
$('#popover_form').fadeOut();
}
function activateTagField() {
$("#addTagButton").hide();
$("#addTagField").show();
}
function tagFieldChange() {
if ($("#addTagField :selected").val() > 0) {
var selected = $("#addTagField :selected").text();
if ($.inArray(selected, selectedTags)==-1) {
selectedTags.push(selected);
appendTemplateTag(selected);
}
}
$("#addTagButton").show();
$("#addTagField").hide();
}
function appendTemplateTag(selected) {
var selectedTag;
allTags.forEach(function(tag) {
if (tag.name == selected) {
$.ajax({
beforeSend: function (XMLHttpRequest) {
$(".loading").show();
},
dataType:"html",
cache: false,
success:function (data, textStatus) {
$(".loading").hide();
$("#tags").append(data);
},
url:"/tags/viewTag/" + tag.id,
});
updateSelectedTags();
}
});
}
function addAllTags(tagArray) {
parsedTagArray = JSON.parse(tagArray);
parsedTagArray.forEach(function(tag) {
appendTemplateTag(tag);
});
}
function removeTemplateTag(id, name) {
selectedTags.forEach(function(tag) {
if (tag == name) {
var index = selectedTags.indexOf(name);
if (index > -1) {
selectedTags.splice(index, 1);
updateSelectedTags();
}
}
});
$('#tag_bubble_' + id).remove();
}
function updateSelectedTags() {
$('#hiddenTags').attr("value", JSON.stringify(selectedTags));
}
function saveElementSorting(order) {
$.ajax({
data: order,
dataType:"json",
contentType: "application/json",
cache: false,
success:function (data, textStatus) {
handleGenericAjaxResponse(data);
},
type:"post",
cache: false,
url:"/templates/saveElementSorting/",
});
}
function templateAddElementClicked(id) {
$("#gray_out").fadeIn();
$.ajax({
beforeSend: function (XMLHttpRequest) {
$(".loading").show();
},
dataType:"html",
cache: false,
success:function (data, textStatus) {
$(".loading").hide();
$("#popover_form").html(data);
$("#popover_form").fadeIn();
},
url:"/template_elements/templateElementAddChoices/" + id,
});
}
function templateAddElement(type, id) {
$.ajax({
dataType:"html",
cache: false,
success:function (data, textStatus) {
$("#popover_form").html(data);
},
url:"/template_elements/add/" + type + "/" + id,
});
}
function templateUpdateAvailableTypes() {
$("#innerTypes").empty();
var type = $("#TemplateElementAttributeType option:selected").text();
var complex = $('#TemplateElementAttributeComplex:checked').val();
if (complex && type != 'Select Type') {
currentTypes.forEach(function(entry) {
$("#innerTypes").append("<div class=\"templateTypeBox\" id=\"" + entry + "TypeBox\">" + entry + "</div>");
});
$('#outerTypes').show();
}
else $('#outerTypes').hide();
}
function populateTemplateTypeDropdown() {
var cat = $("#TemplateElementAttributeCategory option:selected").text();
currentTypes = [];
if (cat == 'Select Category') {
$('#TemplateElementAttributeType').html("<option>Select Type</option>");
} else {
var complex = $('#TemplateElementAttributeComplex:checked').val();
if (cat in typeGroupCategoryMapping) {
$('#TemplateElementAttributeType').html("<option>Select Type</option>");
typeGroupCategoryMapping[cat].forEach(function(entry) {
$('#TemplateElementAttributeType').append("<option>" + entry + "</option>");
});
} else {
complex = false;
}
if (!complex) {
$('#TemplateElementAttributeType').html("<option>Select Type</option>");
categoryTypes[cat].forEach(function(entry) {
$('#TemplateElementAttributeType').append("<option>" + entry + "</option>");
});
}
}
}
function templateElementAttributeTypeChange() {
var complex = $('#TemplateElementAttributeComplex:checked').val();
var type = $("#TemplateElementAttributeType option:selected").text();
currentTypes = [];
if (type != 'Select Type') {
if (complex) {
complexTypes[type]["types"].forEach(function(entry) {
currentTypes.push(entry);
});
} else {
currentTypes.push(type);
}
} else {
currentTypes = [];
}
$("#typeJSON").html(JSON.stringify(currentTypes));
templateUpdateAvailableTypes();
}
function templateElementAttributeCategoryChange(category) {
if (category in typeGroupCategoryMapping) {
$('#complexToggle').show();
} else {
$('#complexToggle').hide();
}
if (category != 'Select Type') {
populateTemplateTypeDropdown();
}
templateUpdateAvailableTypes();
}
function templateElementFileCategoryChange(category) {
if (category == '') {
$("#TemplateElementFileMalware")[0].disabled = true;
$("#TemplateElementFileMalware")[0].checked = false;
} else {
if (categoryArray[category].length == 2) {
$("#TemplateElementFileMalware")[0].disabled = false;
$("#TemplateElementFileMalware")[0].checked = true;
} else {
$("#TemplateElementFileMalware")[0].disabled = true;
if (categoryArray[category] == 'attachment') $("#TemplateElementFileMalware")[0].checked = false;
else $("#TemplateElementFileMalware")[0].checked = true;
}
}
}
function getPopup(id, context, target) {
$("#gray_out").fadeIn();
$.ajax({
beforeSend: function (XMLHttpRequest) {
$(".loading").show();
},
dataType:"html",
cache: false,
success:function (data, textStatus) {
$(".loading").hide();
$("#popover_form").html(data);
$("#popover_form").fadeIn();
},
url:"/" + context + "/" + target + "/" + id,
//url:"/templates/templateChoices/" + id,
});
}
function resizePopoverBody() {
var bodyheight = $(window).height();
bodyheight = 3 * bodyheight / 4 - 150;
$("#popover_choice_main").css({"max-height": bodyheight});
}
function populateTemplateHiddenFileDiv(files) {
$('#TemplateFileArray').val(JSON.stringify(files));
}
function populateTemplateFileBubbles() {
var fileObjectArray = JSON.parse($('#TemplateFileArray').val());
fileObjectArray.forEach(function(entry) {
templateAddFileBubble(entry.element_id, false, entry.filename, entry.tmp_name, 'yes');
});
}
function templateFileHiddenAdd(files, element_id, batch) {
var fileArray = $.parseJSON($('#TemplateFileArray', window.parent.document).val());
var contained = false;
for (var j=0; j< files.length; j++) {
for (var i=0; i< fileArray.length; i++) {
if (fileArray[i].filename == files[j].filename) {
contained = true;
}
if (batch == 'no' && fileArray[i].element_id == element_id) {
templateDeleteFileBubble(fileArray[i].filename, fileArray[i].tmp_name, fileArray[i].element_id, 'iframe', batch);
contained = false;
var removeId = i;
}
}
if (batch == 'no') fileArray.splice(removeId, 1);
if (contained == false) {
fileArray.push(files[j]);
templateAddFileBubble(element_id, true, files[j].filename, files[j].tmp_name, batch);
$('#TemplateFileArray', window.parent.document).val(JSON.stringify(fileArray));
}
}
}
function templateAddFileBubble(element_id, iframe, filename, tmp_name, batch) {
if (batch == 'no') {
if (iframe == true) {
$('#filenames_' + element_id, window.parent.document).html('<div id ="' + tmp_name + '_container" class ="template_file_box_container"><span class="tagFirstHalf template_file_box">' + filename + '</span><span onClick="templateDeleteFileBubble(\'' + filename + '\', \'' + tmp_name + '\', \'' + element_id + '\', \'normal\', \'no\');" class="tagSecondHalf useCursorPointer">x</span></div>');
} else {
$('#filenames_' + element_id).html('<div id ="' + tmp_name + '_container" class ="template_file_box_container"><span class="tagFirstHalf template_file_box">' + filename + '</span><span onClick="templateDeleteFileBubble(\'' + filename + '\', \'' + tmp_name + '\', \'' + element_id + '\', \'normal\', \'no\');" class="tagSecondHalf useCursorPointer">x</span></div>');
}
} else {
if (iframe == true) {
$('#filenames_' + element_id, window.parent.document).append('<div id ="' + tmp_name + '_container" class ="template_file_box_container"><span class="tagFirstHalf template_file_box">' + filename + '</span><span onClick="templateDeleteFileBubble(\'' + filename + '\', \'' + tmp_name + '\', \'' + element_id + '\', \'normal\', \'yes\');" class="tagSecondHalf useCursorPointer">x</span></div>');
} else {
$('#filenames_' + element_id).append('<div id ="' + tmp_name + '_container" class ="template_file_box_container"><span class="tagFirstHalf template_file_box">' + filename + '</span><span onClick="templateDeleteFileBubble(\'' + filename + '\', \'' + tmp_name + '\', \'' + element_id + '\', \'normal\', \'yes\');" class="tagSecondHalf useCursorPointer">x</span></div>');
}
}
}
function templateDeleteFileBubble(filename, tmp_name, element_id, context, batch) {
$(".loading").show();
$.ajax({
type:"post",
cache: false,
url:"/templates/deleteTemporaryFile/" + tmp_name,
});
var c = this;
if (context == 'iframe') {
$('#' + tmp_name + '_container', window.parent.document).remove();
var oldArray = JSON.parse($('#TemplateFileArray', window.parent.document).val());
} else {
$('#' + tmp_name + '_container').remove();
var oldArray = JSON.parse($('#TemplateFileArray').val());
}
var newArray = [];
oldArray.forEach(function(entry) {
if (batch == 'no') {
if (entry.element_id != element_id) {
newArray.push(entry);
}
} else {
if (entry.tmp_name != tmp_name) {
newArray.push(entry);
}
}
});
if (batch == 'no') {
$('#fileUploadButton_' + element_id, $('#iframe_' + element_id).contents()).html('Upload File');
}
if (context == 'iframe') {
$('#TemplateFileArray', window.parent.document).val(JSON.stringify(newArray));
} else {
$('#TemplateFileArray').val(JSON.stringify(newArray));
}
$(".loading").hide();
}
function templateFileUploadTriggerBrowse(id) {
$('#upload_' + id + '_file').click();
}
function freetextRemoveRow(id) {
$('#row_' + id).hide();
$('#Attribute' + id + 'Save').attr("value", "0");
}

File diff suppressed because one or more lines are too long