chg: [sharingGroupsTemplate:add] Various improvements/fix to support edition

3.x-ui-sharinggroups
Sami Mokaddem 2023-08-03 11:17:00 +02:00
parent defb3d7a8d
commit 5944d7ba70
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
3 changed files with 341 additions and 510 deletions

View File

@ -84,7 +84,7 @@ class SharingGroupsController extends AppController
$id = $this->SharingGroups->captureSG($sg, $this->ACL->getUser()->toArray());
if ($id) {
if (empty($sg['roaming']) && empty($sg['SharingGroupServer'])) {
$sharingGroupServerEntity = new SharingGroupServer(
$sharingGroupServerEntity = $this->SharingGroups->SharingGroupServers->newEntity(
[
'sharing_group_id' => $id,
'server_id' => 0,
@ -119,14 +119,12 @@ class SharingGroupsController extends AppController
$sg['organisation_uuid'] = $this->ACL->getUser()->Organisation->uuid;
$sg['local'] = 1;
$sg['org_id'] = $this->ACL->getUser()->org_id;
$sg['created'] = $sg['created'] ?? time();
$sg['modified'] = $sg['modified'] ?? time();
$sharingGroupEntity = new SharingGroup($sg);
$sharingGroupEntity = $this->SharingGroups->newEntity($sg, ['associated' => []]);
if ($this->SharingGroups->save($sharingGroupEntity)) {
if ($this->SharingGroups->save($sharingGroupEntity, ['associated' => []])) { // Association will be saved manually
if (!empty($sg['Organisation'])) {
foreach ($sg['Organisation'] as $org) {
$sharingGroupOrgEntity = new SharingGroupOrg(
$sharingGroupOrgEntity = $this->SharingGroups->SharingGroupOrgs->newEntity(
[
'sharing_group_id' => $sharingGroupEntity->id,
'org_id' => $org['id'],
@ -134,11 +132,12 @@ class SharingGroupsController extends AppController
]
);
$this->SharingGroups->SharingGroupOrgs->save($sharingGroupOrgEntity);
$sharingGroupEntity->organisations[] = $sharingGroupOrgEntity;
}
}
if (empty($sg['roaming']) && !empty($sg['Server'])) {
foreach ($sg['Server'] as $server) {
$sharingGroupServerEntity = new SharingGroupServer(
$sharingGroupServerEntity = $this->SharingGroups->SharingGroupServers->newEntity(
[
'sharing_group_id' => $sharingGroupEntity->id,
'server_id' => $server['id'],
@ -146,22 +145,19 @@ class SharingGroupsController extends AppController
]
);
$this->SharingGroups->SharingGroupServers->save($sharingGroupServerEntity);
$sharingGroupEntity->servers[] = $sharingGroupServerEntity;
}
}
$this->redirect('/sharing-groups/view/' . $sharingGroupEntity->id);
} else {
$validationReplacements = [
'notempty' => 'This field cannot be left empty.',
];
$validationErrors = $this->SharingGroups->validationErrors;
$failedField = array_keys($validationErrors)[0];
$reason = reset($this->SharingGroups->validationErrors)[0];
foreach ($validationReplacements as $k => $vR) {
if ($reason == $k) {
$reason = $vR;
}
}
$this->Flash->error('The sharing group could not be added. ' . ucfirst($failedField) . ': ' . $reason);
$validationErrors = $sharingGroupEntity->getErrors();
$validationMessage = $this->CRUD->prepareValidationMessage($validationErrors);
$message = __(
'{0} could not be added.{1}',
$this->SharingGroups->getAlias(),
empty($validationMessage) ? '' : PHP_EOL . __('Reason: {0}', $validationMessage)
);
$this->Flash->error($message);
}
} elseif ($this->ParamHandler->isRest()) {
return $this->RestResponse->describe('SharingGroup', 'add');
@ -192,7 +188,7 @@ class SharingGroupsController extends AppController
'contain' => [
'SharingGroupOrgs' => [
'Organisations' => [
'fields' => ['name', 'local', 'id']
'fields' => ['name', 'local', 'id', 'uuid']
]
],
'SharingGroupServers' => [
@ -205,44 +201,45 @@ class SharingGroupsController extends AppController
],
],
]
)->disableHydration()->first();
)->first();
if (empty($sharingGroup)) {
throw new NotFoundException('Invalid sharing group.');
}
if (!$this->SharingGroups->checkIfAuthorisedExtend($this->ACL->getUser()->toArray(), $sharingGroup['id'])) {
if (!$this->SharingGroups->checkIfAuthorisedExtend($this->ACL->getUser()->toArray(), $sharingGroup->id)) {
throw new MethodNotAllowedException('Action not allowed.');
}
if ($this->request->is('post')) {
if ($this->request->is('post') || $this->request->is('put')) {
if ($this->ParamHandler->isRest()) {
if (!empty($this->request->getData('SharingGroup'))) {
$data = $this->request->getData('SharingGroup');
} else {
$data = $this->request->getData();
}
$data['uuid'] = $sharingGroup['uuid'];
$data['uuid'] = $sharingGroup->uuid;
$id = $this->SharingGroups->captureSG($data, $this->ACL->getUser()->toArray());
if ($id) {
$sg = $this->SharingGroups->fetchAllAuthorised($this->ACL->getUser()->toArray(), 'simplified', false, $id);
return $this->RestResponse->viewData($sg[0]);
} else {
return $this->RestResponse->saveFailResponse('SharingGroup', 'add', false, 'Could not save sharing group.');
return $this->RestResponse->saveFailResponse('SharingGroup', 'edit', false, 'Could not save sharing group.');
}
} else {
$json = json_decode($this->request->getData('json'), true);
$sg = $json['sharingGroup'];
$sg['id'] = $sharingGroup['id'];
$sg['id'] = $sharingGroup->id;
$fields = ['name', 'releasability', 'description', 'active', 'roaming'];
$existingSG = $this->SharingGroups->find('all', ['recursive' => -1, 'conditions' => ['SharingGroup.id' => $sharingGroup['id']]])->disableHydration()->first();
foreach ($fields as $field) {
$existingSG[$field] = $sg[$field];
}
$existingSG = $sharingGroup;
$existingSG = $this->SharingGroups->patchEntity($existingSG, $sg, ['fields' => $fields, 'associated' => []]);
unset($existingSG['modified']);
if ($this->SharingGroups->save($existingSG)) {
$this->SharingGroups->SharingGroupOrgs->updateOrgsForSG($sharingGroup['id'], $json['organisations'], $sharingGroup['SharingGroupOrg'], $this->ACL->getUser()->toArray());
$this->SharingGroups->SharingGroupServers->updateServersForSG($sharingGroup['id'], $json['servers'], $sharingGroup['SharingGroupServer'], $json['sharingGroup']['roaming'], $this->ACL->getUser()->toArray());
$this->redirect('/sharing-groups/view/' . $sharingGroup['id']);
$existingSG = $this->SharingGroups->save($existingSG);
if ($existingSG) {
$existingSGArray = $existingSG->toArray();
$this->SharingGroups->SharingGroupOrgs->updateOrgsForSG($existingSG->id, $json['organisations'], $existingSGArray['SharingGroupOrg'], $this->ACL->getUser()->toArray());
$this->SharingGroups->SharingGroupServers->updateServersForSG($existingSG->id, $json['servers'], $existingSGArray['SharingGroupServer'], $json['sharingGroup']['roaming'], $this->ACL->getUser()->toArray());
$this->redirect('/sharing-groups/view/' . $sharingGroup->id);
} else {
$validationReplacements = [
'notempty' => 'This field cannot be left empty.',
@ -261,21 +258,17 @@ class SharingGroupsController extends AppController
} elseif ($this->ParamHandler->isRest()) {
return $this->RestResponse->describe('SharingGroup', 'edit', false);
}
$orgs = $this->SharingGroups->Organisations->find(
'all',
[
'conditions' => ['local' => 1],
'recursive' => -1,
'fields' => ['id', 'name']
]
)->disableHydration()->toArray();
$this->set('entity', $sharingGroup);
$this->set('id', $sharingGroup['id']);
$this->set('orgs', $orgs);
$this->set('id', $sharingGroup->id);
$organisations = $this->SharingGroups->Organisations->find()->all()->toList();
$this->set('organisations', $organisations);
$mispInstances = []; // TODO: [3.x-MIGRATION] Fill with servers when Server model is migrated
$this->set('mispInstances', $mispInstances);
$this->set('localInstance', empty(Configure::read('MISP.external_baseurl')) ? Configure::read('MISP.baseurl') : Configure::read('MISP.external_baseurl'));
// We just pass true and allow the user to edit, since he/she is just about to create the SG. This is needed to reuse the view for the edit
$this->set('user', $this->ACL->getUser()->toArray());
$this->render('add');
}
public function delete($id)
@ -431,11 +424,11 @@ class SharingGroupsController extends AppController
$customContextFilters = [
[
'label' => __('Active Sharing Groups'),
'filterCondition' => ['active' => 0]
'filterCondition' => ['active' => 1]
],
[
'label' => __('Passive Sharing Groups'),
'filterCondition' => ['active' => 1]
'filterCondition' => ['active' => 0]
]
];
@ -516,6 +509,7 @@ class SharingGroupsController extends AppController
unset($contain['SharingGroupServers']);
}
// TODO: Move to using entity instead of array
$sg = $this->SharingGroups->find(
'all',
[

View File

@ -1,241 +1,284 @@
<?php
use Cake\Utility\Hash;
use Cake\Core\Configure;
?>
<h2 class="fw-light"><?= __('New Sharing Group') ?></h2>
<?php
$toggleNextTabButton = $this->Bootstrap->button([
'onclick' => 'toggleNextTab()',
'text' => __('Next page'),
'variant' => 'secondary',
]);
$toggleNextTabDiv = $this->Bootstrap->node('div', ['class' => 'mt-2'], $toggleNextTabButton);
<div class="container-md ms-0">
<?php
$toggleNextTabButton = $this->Bootstrap->button([
'onclick' => 'toggleNextTab()',
'text' => __('Next page'),
'variant' => 'secondary',
]);
$toggleNextTabDiv = $this->Bootstrap->node('div', ['class' => 'mt-2'], $toggleNextTabButton);
$formGeneral = $this->element('genericElements/Form/genericForm', [
'data' => [
'model' => 'SharingGroups',
'fields' => [
[
'field' => 'uuid',
'label' => 'UUID',
'type' => 'uuid',
'placeholder' => __('If not provided, random UUID will be generated'),
],
[
'field' => 'name',
'placeholder' => __('Example: Multinational sharing group'),
],
[
'field' => 'releasability',
'label' => __('Releasable to'),
'placeholder' => __('Example: Community1, Organisation1, Organisation2'),
],
[
'field' => 'description',
'type' => 'textarea',
'placeholder' => __('A description of the sharing group.'),
],
[
'field' => 'active',
'label' => __('Make the sharing group selectable (active)'),
'type' => 'checkbox',
'default' => 1,
'tooltip' => __('Active sharing groups can be selected by users of the local instance when creating events. Generally, sharing groups received through synchronisation will have this disabled until manually enabled.'),
],
],
],
'raw' => true,
]);
$formGeneral = $this->element('genericElements/Form/genericForm', [
'data' => [
'model' => 'SharingGroups',
'fields' => [
[
'field' => 'uuid',
'label' => 'UUID',
'type' => 'uuid',
'placeholder' => __('If not provided, random UUID will be generated'),
$formOrgs = $this->element('genericElements/Form/genericForm', [
'data' => [
'model' => 'SharingGroups',
'fields' => [
[
'field' => 'local_orgs',
'label' => __('Local Organisations'),
'placeholder' => __('Add local organisation(s) to the sharing group'),
'type' => 'dropdown',
'multiple' => false,
'select2' => [
'placeholder' => __('Select a local organisation'),
],
[
'field' => 'name',
'placeholder' => __('Example: Multinational sharing group'),
'options' => ['' => ''] + Hash::combine(
array_filter($organisations, fn ($org) => $org['local']),
'{n}.id',
'{n}.name'
),
],
[
'field' => 'remote_orgs',
'label' => __('Remote Organisations'),
'placeholder' => __('Add remote organisation(s) to the sharing group'),
'type' => 'dropdown',
'multiple' => false,
'select2' => [
'placeholder' => __('Select a remote organisation'),
],
[
'field' => 'releasability',
'label' => __('Releasable to'),
'placeholder' => __('Example: Community1, Organisation1, Organisation2'),
'options' => ['' => ''] + Hash::combine(
array_filter($organisations, fn ($org) => !$org['local']),
'{n}.id',
'{n}.name'
),
],
],
],
'raw' => true,
]);
$orgTable = $this->Bootstrap->table(
[
'id' => 'organisations_table',
'condensed' => true,
'striped' => true,
'borderless' => true,
],
[
'fields' => [
__('Type'),
__('Name'),
__('UUID'),
__('Extend'),
__('Actions'),
],
'items' => [],
]
);
$formServers = $this->element('genericElements/Form/genericForm', [
'data' => [
'model' => 'SharingGroups',
'fields' => [
[
'field' => 'roaming',
'label' => __('Enable roaming mode'),
'type' => 'checkbox',
'default' => false,
'tooltip' => __('Roaming mode will allow the sharing group and associated data to be passed to any instance where the remote recipient is contained in the organisation list.'),
'div' => [
'class' => 'mb-3',
],
[
'field' => 'description',
'type' => 'textarea',
'placeholder' => __('A description of the sharing group.'),
],
[
'field' => 'active',
'label' => __('Make the sharing group selectable (active)'),
'type' => 'checkbox',
'default' => 1,
'tooltip' => __('Active sharing groups can be selected by users of the local instance when creating events. Generally, sharing groups received through synchronisation will have this disabled until manually enabled.'),
],
[
'field' => 'misp_instances',
'label' => __('MISP instances'),
'placeholder' => __('Add instance(s) to the sharing group'),
'type' => 'dropdown',
'multiple' => true,
'select2' => true,
'options' => Hash::combine(
$mispInstances,
'{n}.id',
'{n}.name'
),
'div' => [
'id' => 'server-picker-container',
],
],
],
'raw' => true,
]);
$formOrgs = $this->element('genericElements/Form/genericForm', [
'data' => [
'model' => 'SharingGroups',
'fields' => [
[
'field' => 'local_orgs',
'label' => __('Local Organisations'),
'placeholder' => __('Add local organisation(s) to the sharing group'),
'type' => 'dropdown',
'multiple' => true,
'select2' => true,
'options' => Hash::combine(
array_filter($organisations, fn ($org) => $org['local']),
'{n}.id',
'{n}.name'
),
'value' => h($user['Organisation']['id']),
],
[
'field' => 'remote_orgs',
'label' => __('Remote Organisations'),
'placeholder' => __('Add remote organisation(s) to the sharing group'),
'type' => 'dropdown',
'multiple' => true,
'select2' => true,
'options' => Hash::combine(
array_filter($organisations, fn ($org) => !$org['local']),
'{n}.id',
'{n}.name'
),
],
],
'raw' => true,
]);
$serverTable = $this->Bootstrap->table(
[
'id' => 'servers_table',
'condensed' => true,
'striped' => true,
'borderless' => true,
],
[
'fields' => [
__('Name'),
__('URL'),
__('All orgs'),
__('Actions'),
],
'items' => [],
]
);
$formSummary = $this->element('genericElements/Form/genericForm', [
'data' => [
'model' => 'SharingGroups',
'fields' => [
[
'field' => 'json',
'type' => 'text',
],
],
'raw' => true,
]);
$orgTable = $this->Bootstrap->table(
[
'id' => 'organisations_table',
'condensed' => true,
'striped' => true,
'borderless' => true,
],
'raw' => true,
]);
$summaryText = '<p>' . $this->Bootstrap->render(
'<b>' . __('General') . '</b>: ' .
__('You are about to create the {{title_container}} sharing group, which is intended to be releasable to {{releasable_container}}.'),
[
'title_container' => '<strong id="summarytitle" class="text-danger">XX</strong>',
'releasable_container' => '<strong id="summaryreleasable" class="text-danger">XX</strong>',
]
) . '</p>';
$summaryText .= '<p>' . $this->Bootstrap->render(
'<b>' . __('Local organisations') . '</b>: ' .
__('It will be visible to {{local}}, from which {{extend}} can extend the sharing group.'),
[
'local' => '<strong id="summarylocal" class="text-danger"></strong>',
'extend' => ' <strong id="summarylocalextend" class="text-danger"></strong>',
]
) . '</p>';
$summaryText .= '<p>' . $this->Bootstrap->render(
'<b>' . __('External organisations') . '</b>: ' .
__('It will also be visible to {{external}}, out of which {{extend}} can extend the sharing group.'),
[
'external' => '<strong id="summaryexternal" class="text-danger"></strong>',
'extend' => '<strong id="summaryexternalextend" class="text-danger"></strong>',
]
) . '</p>';
$summaryText .= '<p>' . $this->Bootstrap->render(
'<b>' . __('Synchronisation') . '</b>: ' .
__('Furthermore, events are automatically pushed to: {{servers}}'),
[
'servers' => '<strong id="summaryservers" class="text-danger"></strong>',
]
) . '</p>';
$summaryText .= $this->Bootstrap->alert([
'text' => __('You can edit this information by going back to one of the previous pages.'),
'dismissible' => false,
]);
$formSummary = $this->Bootstrap->node('div', ['class' => 'd-none'], $formSummary);
$formSummary .= $summaryText;
$formSummary .= $this->Bootstrap->node('div', ['class' => 'mt-2'], $this->Bootstrap->button([
'text' => $this->request->getParam('action') == 'edit' ? __('Edit sharing group') : __('Create sharing group'),
'onclick' => 'sgSubmitForm()',
]));
$formGeneral .= $toggleNextTabDiv;
$formOrgs .= $orgTable . $toggleNextTabDiv;
$formServers .= $serverTable . $toggleNextTabDiv;
$bsTabs = $this->Bootstrap->tabs([
'id' => 'tabs-sg-form',
'card' => !false,
'content-class' => ['p-3'],
'data' => [
'navs' => [
['text' => __('General'), 'active' => true],
['text' => __('Organisations'),],
['text' => __('Instances'),],
['text' => __('Summary & Save'), 'id' => 'tab-summary-and-save'],
],
[
'fields' => [
__('Type'),
__('Name'),
__('UUID'),
__('Extend'),
__('Actions'),
],
'items' => [],
]
);
$formServers = $this->element('genericElements/Form/genericForm', [
'data' => [
'model' => 'SharingGroups',
'fields' => [
[
'field' => 'roaming',
'label' => __('Enable roaming mode'),
'type' => 'checkbox',
'default' => false,
'tooltip' => __('Roaming mode will allow the sharing group and associated data to be passed to any instance where the remote recipient is contained in the organisation list.'),
'div' => [
'class' => 'mb-3',
],
],
[
'field' => 'misp_instances',
'label' => __('MISP instances'),
'placeholder' => __('Add instance(s) to the sharing group'),
'type' => 'dropdown',
'multiple' => true,
'select2' => true,
'options' => Hash::combine(
$mispInstances,
'{n}.id',
'{n}.name'
),
'div' => [
'id' => 'server-picker-container',
],
],
],
'content' => [
$formGeneral,
$formOrgs,
$formServers,
$formSummary,
],
'raw' => true,
]
]);
if (!empty($ajax)) {
$seedModal = 'mseed-' . mt_rand();
echo $this->Bootstrap->modal([
'title' => __('New Sharing group'),
'bodyHtml' => $bsTabs,
'size' => 'lg',
'type' => 'cancel',
'modalClass' => $seedModal,
]);
$serverTable = $this->Bootstrap->table(
[
'id' => 'servers_table',
'condensed' => true,
'striped' => true,
'borderless' => true,
],
[
'fields' => [
__('Name'),
__('URL'),
__('All orgs'),
__('Actions'),
],
'items' => [],
]
);
} else {
$page = sprintf('<h2 class="fw-light">%s</h2>', __('New Sharing Group'));
$page .= $bsTabs;
echo $page;
}
$formSummary = $this->element('genericElements/Form/genericForm', [
'data' => [
'model' => 'SharingGroups',
'fields' => [
[
'field' => 'json',
'type' => 'text',
],
],
],
'raw' => true,
]);
$existingSharingGroupOrgs = [];
foreach ($entity->SharingGroupOrg as $org) {
$existingSharingGroupOrgs[] = [
'id' => h($org['org_id']),
'type' => ($org['Organisation']['local'] == 1 ? 'local' : 'remote'),
'name' => h($org['Organisation']['name']),
'extend' => h($org['extend']),
'uuid' => h($org['Organisation']['uuid']),
'removable' => $entity->Organisation->id != $org['org_id'],
];
}
$summaryText = '<p>' . $this->Bootstrap->render(
'<b>' . __('General') . '</b>: ' .
__('You are about to create the {{title_container}} sharing group, which is intended to be releasable to {{releasable_container}}.'),
[
'title_container' => '<strong id="summarytitle" class="text-danger">XX</strong>',
'releasable_container' => '<strong id="summaryreleasable" class="text-danger">XX</strong>',
]
) . '</p>';
$summaryText .= '<p>' . $this->Bootstrap->render(
'<b>' . __('Local organisations') . '</b>: ' .
__('It will be visible to {{local}}, from which {{extend}} can extend the sharing group.'),
[
'local' => '<strong id="summarylocal" class="text-danger"></strong>',
'extend' => ' <strong id="summarylocalextend" class="text-danger"></strong>',
]
) . '</p>';
$summaryText .= '<p>' . $this->Bootstrap->render(
'<b>' . __('External organisations') . '</b>: ' .
__('It will also be visible to {{external}}, out of which {{extend}} can extend the sharing group.'),
[
'external' => '<strong id="summaryexternal" class="text-danger"></strong>',
'extend' => '<strong id="summaryexternalextend" class="text-danger"></strong>',
]
) . '</p>';
$summaryText .= '<p>' . $this->Bootstrap->render(
'<b>' . __('Synchronisation') . '</b>: ' .
__('Furthermore, events are automatically pushed to: {{servers}}'),
[
'servers' => '<strong id="summaryservers" class="text-danger"></strong>',
]
) . '</p>';
$summaryText .= $this->Bootstrap->alert([
'text' => __('You can edit this information by going back to one of the previous pages.'),
'dismissible' => false,
]);
$existingSharingGroupServers = [];
foreach ($entity->SharingGroupServer as $server) {
if ($server['server_id'] == 0) {
continue;
}
$existingSharingGroupServers[] = [
'id' => h($server['server_id']),
'name' => h($server['Server']['name']),
'url' => h($server['Server']['url']),
'all_orgs' => h($server['all_orgs']),
'removable' => 1,
];
}
$formSummary = $this->Bootstrap->node('div', ['class' => 'd-none'], $formSummary);
$formSummary .= $summaryText;
$formSummary .= $this->Bootstrap->node('div', ['class' => 'mt-2'], $this->Bootstrap->button([
'text' => __('Create sharing group'),
'onclick' => 'sgSubmitForm()',
]));
$formGeneral .= $toggleNextTabDiv;
$formOrgs .= $orgTable . $toggleNextTabDiv;
$formServers .= $serverTable . $toggleNextTabDiv;
echo $this->Bootstrap->tabs([
'id' => 'tabs-sg-form',
'card' => !false,
'content-class' => ['p-3'],
'data' => [
'navs' => [
['text' => __('General'), 'active' => true],
['text' => __('Organisations'),],
['text' => __('Instances'),],
['text' => __('Summary & Save'), 'id' => 'tab-summary-and-save'],
],
'content' => [
$formGeneral,
$formOrgs,
$formServers,
$formSummary,
],
]
]);
?>
?>
</div>
<script>
@ -248,17 +291,28 @@ use Cake\Utility\Hash;
uuid: '',
removable: 0
}];
var orgids = ['<?php echo h($user['Organisation']['id']) ?>'];
var orgids = [];
var servers = [{
id: '0',
name: '<?php echo __('Local instance'); ?>',
url: '<?php echo h($localInstance); ?>',
all_orgs: false,
url: '<?php echo h(empty(Configure::read('MISP.external_baseurl')) ? Configure::read('MISP.baseurl') : Configure::read('MISP.external_baseurl')); ?>',
all_orgs: true,
removable: 0
}];
var serverids = [0];
$(document).ready(function() {
var existingSharingGroupOrgs = <?= json_encode($existingSharingGroupOrgs) ?>;
var existingSharingGroupServers = <?= json_encode($existingSharingGroupServers) ?>;
if (existingSharingGroupOrgs.length > 0) {
organisations = existingSharingGroupOrgs
}
if (existingSharingGroupServers.length > 0) {
servers = servers.concat(servers, existingSharingGroupServers)
}
orgids = organisations.map((org) => org.id.toString())
$('#roaming-field').change(function() {
toggleServerTableVisibility()
});
@ -275,11 +329,13 @@ use Cake\Utility\Hash;
$('#local_orgs-field').on('select2:select', function(e) {
const data = $(this).select2('data');
refreshPickedOrgList('local', data)
refreshPickedOrgList('local', data);
$(this).val(null).trigger('change');
});
$('#remote_orgs-field').on('select2:select', function(e) {
const data = $(this).select2('data');
refreshPickedOrgList('remote', data)
refreshPickedOrgList('remote', data);
$(this).val(null).trigger('change');
});
$('#misp_instances-field').on('select2:select', function(e) {
const data = $(this).select2('data');
@ -336,12 +392,12 @@ use Cake\Utility\Hash;
'organisations': organisations,
'servers': servers,
'sharingGroup': {
'uuid': $('#SharingGroupUuid').val(),
'name': $('#SharingGroupName').val(),
'releasability': $('#SharingGroupReleasability').val(),
'description': $('#SharingGroupDescription').val(),
'active': $('#SharingGroupActive').is(":checked"),
'roaming': $('#SharingGroupRoaming').is(":checked"),
'uuid': $('#uuid-field').val(),
'name': $('#name-field').val(),
'releasability': $('#releasability-field').val(),
'description': $('#description-field').val(),
'active': $('#active-field').is(":checked"),
'roaming': $('#roaming-field').is(":checked"),
}
};
$('#json-field').val(JSON.stringify(ajaxData));
@ -413,16 +469,15 @@ use Cake\Utility\Hash;
function sharingGroupPopulateOrganisations() {
$('.orgRow').remove();
var id = 0;
var html = '';
organisations.forEach(function(org) {
html = '<tr id="orgRow' + id + '" class="orgRow">';
organisations.forEach(function(org, i) {
html = '<tr id="orgRow' + i + '" class="orgRow">';
html += '<td class="short">' + org.type + '&nbsp;</td>';
html += '<td>' + $('<div>').text(org.name).html() + '&nbsp;</td>';
html += '<td>' + org.uuid + '&nbsp;</td>';
html += '<td class="short" style="text-align:center;">';
if (org.removable == 1) {
html += '<input id="orgExtend' + id + '" type="checkbox" onClick="sharingGroupExtendOrg(' + id + ')" ';
html += '<input id="orgExtend' + i + '" type="checkbox" onClick="sharingGroupExtendOrg(' + i + ')" ';
if (org.extend) html += 'checked';
html += '>';
} else {
@ -430,10 +485,9 @@ use Cake\Utility\Hash;
}
html += '</td>';
html += '<td class="actions short">';
if (org.removable == 1) html += '<span class="icon-trash" onClick="sharingGroupRemoveOrganisation(' + id + ')"></span>';
if (org.removable == 1) html += '<span class="<?= $this->FontAwesome->getClass('trash') ?>" onClick="sharingGroupRemoveOrganisation(' + i + ')"></span>';
html += '&nbsp;</td></tr>';
$('#organisations_table tbody').append(html);
id++;
});
}
@ -458,6 +512,18 @@ use Cake\Utility\Hash;
});
}
function sharingGroupPopulateFromJson() {
var jsonparsed = JSON.parse($('#json-field').val());
organisations = jsonparsed.organisations;
servers = jsonparsed.servers;
if (jsonparsed.sharingGroup.active == 1) {
$("#active-field").prop("checked", true);
}
if (jsonparsed.sharingGroup.roaming == 1) {
$("#roaming-field").prop("checked", true);
}
}
function sharingGroupExtendOrg(id) {
organisations[id].extend = $('#orgExtend' + id).is(":checked");
}
@ -481,8 +547,4 @@ use Cake\Utility\Hash;
serverids.splice(id, 1);
sharingGroupPopulateServers();
}
</script>
<br />
<br />
</script>

View File

@ -1,225 +0,0 @@
<?php
use App\Model\Entity\SharingGroup;
use Cake\Core\Configure;
?>
<div class="users form">
<fieldset>
<legend><?php echo __('Edit Sharing Group'); ?></legend>
<?php
$data = [
'children' => [
[
'children' => [
[
'text' => __('General'),
'title' => __('General tab'),
'class' => 'progress_tab',
'id' => 'page1_tab',
'active' => true,
'onClick' => 'simpleTabPage',
'onClickParams' => [1]
],
[
'text' => __('Organisations'),
'title' => __('Organisations tab'),
'class' => 'progress_tab',
'id' => 'page2_tab',
'onClick' => 'simpleTabPage',
'onClickParams' => [2]
],
[
'text' => __('MISP Instances'),
'title' => __('MISP instances tab'),
'class' => 'progress_tab',
'id' => 'page3_tab',
'onClick' => 'simpleTabPage',
'onClickParams' => [3]
],
[
'text' => __('Summary and Save'),
'title' => __('Sharing group summary'),
'class' => 'progress_tab',
'id' => 'page4_tab',
'onClick' => 'simpleTabPage',
'onClickParams' => [4]
]
]
]
],
];
if (!$ajax) {
echo $this->element(
'/genericElements/ListTopBar/scaffold',
[
'data' => $data,
'table_data' => [],
'tableRandomValue' => Cake\Utility\Security::randomString(8)
]
);
}
?>
<div id="page1_content" class="multi-page-form-div tabContent" style="width:544px;">
<label for="SharingGroupName"><?php echo __('Name'); ?></label>
<input type="text" class="input-xxlarge" placeholder="<?php echo __('Example: Multinational sharing group'); ?>" id="SharingGroupName" value="<?php echo h($entity['name']); ?>">
<label for="SharingGroupReleasability"><?php echo __('Releasable to'); ?></label>
<input type="text" class="input-xxlarge" placeholder="<?php echo __('Example: Community1, Organisation1, Organisation2'); ?>" id="SharingGroupReleasability" value="<?php echo h($entity['releasability']); ?>">
<label for="SharingGroupDescription"><?php echo __('Description'); ?></label>
<textarea class="input-xxlarge" placeholder="<?php echo __('A description of the sharing group.'); ?>" cols="30" rows="6" id="SharingGroupDescription"><?php echo h($entity['description']); ?></textarea>
<div style="display:block;">
<input type="checkbox" style="float:left;" title="<?php echo __('Active sharing groups can be selected by users of the local instance when creating events. Generally, sharing groups received through synchronisation will have this disabled until manually enabled.'); ?>" <?php if ($entity['active']) echo "checked"; ?> id="SharingGroupActive">
<label for="SharingGroupActive" style="padding-left:20px;"><?php echo __('Make the sharing group selectable (active)'); ?></label>
</div>
<span role="button" tabindex="0" aria-label="<?php echo __('Next page'); ?>" title="<?php echo __('Next page'); ?>" class="btn btn-inverse" onClick="simpleTabPage(2);"><?php echo __('Next page'); ?></span>
</div>
<div id="page2_content" class="multi-page-form-div tabContent" style="display:none;width:544px;">
<div class="tabMenuFixedContainer">
<span role="button" tabindex="0" aria-label="<?php echo __('Add local organisation(s) to the sharing group'); ?>" title="<?php echo __('Add local organisation(s) to the sharing group'); ?>" class="tabMenuFixed tabMenuFixedCenter tabMenuSides useCursorPointer" onClick="sharingGroupAdd('organisation', 'local');"><?php echo __('Add local organisation'); ?></span>
<span role="button" tabindex="0" aria-label="<?php echo __('Add remote organisations to the sharing group'); ?>" title="<?php echo __('Add remote organisations to the sharing group'); ?>" class="tabMenuFixed tabMenuFixedCenter tabMenuSides useCursorPointer" onClick="sharingGroupAdd('organisation', 'remote');"><?php echo __('Add remote organisation'); ?></span>
</div>
<table id="organisations_table" class="table table-striped table-hover table-condensed">
<tr id="organisations_table_header">
<th><?php echo __('Type'); ?></th>
<th><?php echo __('Name'); ?></th>
<th><?php echo __('UUID'); ?></th>
<th><?php echo __('Extend'); ?></th>
<th><?php echo __('Actions'); ?></th>
</tr>
</table>
<span role="button" tabindex="0" aria-label="<?php echo __('Previous page'); ?>" title="<?php echo __('Previous page'); ?>" class="btn btn-inverse" onClick="simpleTabPage(1);"><?php echo __('Previous page'); ?></span>
<span role="button" tabindex="0" aria-label="<?php echo __('Next page'); ?>" title="<?php echo __('Next page'); ?>" class="btn btn-inverse" onClick="simpleTabPage(3);"><?php echo __('Next page'); ?></span>
</div>
<div id="page3_content" class="multi-page-form-div tabContent" style="display:none;width:544px;">
<?php
$serverDivVisibility = "";
$checked = "";
if ($entity['roaming']) {
$serverDivVisibility = 'style="display:none;"';
$checked = "checked";
}
?>
<div style="display:block;">
<input type="checkbox" style="float:left;" title="<?php echo __('Enable roaming mode for this sharing group. Roaming mode will allow the sharing group to be passed to any instance where the remote recipient is contained in the organisation list. It is preferred to list the recipient instances instead.'); ?>" <?php echo $checked; ?> id="SharingGroupRoaming">
<label for="SharingGroupRoaming" style="padding-left:20px;"><?php echo __('<b>Enable roaming mode</b> for this sharing group (pass the event to any connected instance where the sync connection is tied to an organisation contained in the SG organisation list).'); ?></label>
</div>
<div id="serverList" <?php echo $serverDivVisibility; ?>>
<div class="tabMenuFixedContainer">
<span role="button" tabindex="0" aria-label="<?php echo __('Add instance'); ?>" title="<?php echo __('Add instance'); ?>" class="tabMenuFixed tabMenuFixedCenter tabMenuSides useCursorPointer" onClick="sharingGroupAdd('server');"><?php echo __('Add instance'); ?></span>
</div>
<table id="servers_table" class="table table-striped table-hover table-condensed">
<tr>
<th><?php echo __('Name'); ?></th>
<th><?php echo __('URL'); ?></th>
<th><?php echo __('All orgs'); ?></th>
<th><?php echo __('Actions'); ?></th>
</tr>
</table>
</div>
<span role="button" tabindex="0" aria-label="<?php echo __('Previous page'); ?>" title="<?php echo __('Previous page'); ?>" class="btn btn-inverse" onClick="simpleTabPage(2);"><?php echo __('Previous page'); ?></span>
<span role="button" tabindex="0" aria-label="<?php echo __('Next page'); ?>" title="<?php echo __('Next page'); ?>" class="btn btn-inverse" onClick="simpleTabPage(4);"><?php echo __('Next page'); ?></span>
</div>
</fieldset>
<div id="page4_content" class="multi-page-form-div tabContent" style="display:none;width:544px;">
<p><?php echo __(
'<span class="bold">General: </span>You are about to create the <span id="summarytitle" class="red bold"></span> sharing group, which is intended to be releasable to <span id="summaryreleasable" class="red bold"></span>. </p>
<p id="localText"><span class="bold">Local organisations: </span>It will be visible to <span id="summarylocal" class="red bold"></span>, from which <span id="summarylocalextend" class="red bold"></span> can extend the sharing group. </p>
<p id="externalText"><span class="bold">External organisations: </span>It will also be visible to <span id="summaryexternal" class="red bold"></span>, out of which <span id="summaryexternalextend" class="red bold"></span> can extend the sharing group.'
); ?></p>
<p id="synchronisationText"><span class="bold"><?php echo __('Synchronisation: </span>Furthermore, events are automatically pushed to: <span id="summaryservers" class="red bold"></span>'); ?></p>
<p><?php echo __('You can edit this information by going back to one of the previous pages, or if you agree with the above mentioned information, click Submit to create the Sharing group.'); ?></p>
<?php
$sharingGroup = new SharingGroup();
echo $this->Form->create($sharingGroup);
echo $this->Form->input('json', ['style' => 'display:none;', 'label' => false, 'div' => false]);
//echo $this->Form->button(__('Submit'), array('class' => 'btn btn-primary'));
echo $this->Form->end();
?>
<span role="button" tabindex="0" aria-label="<?php echo __('Previous page'); ?>" title="<?php echo __('Previous page'); ?>" class="btn btn-inverse" onClick="simpleTabPage(3);"><?php echo __('Previous page'); ?></span>
<span role="button" tabindex="0" aria-label="<?php echo __('Submit and create sharing group'); ?>" title="<?php echo __('Submit and create sharing group'); ?>" class="btn btn-primary" onClick="sgSubmitForm('Edit');">Submit</span>
</div>
</div>
<?php
// TODO: [3.x-MIGRATION]
// echo $this->element('/genericElements/SideMenu/side_menu', ['menuList' => 'globalActions', 'menuItem' => 'editSG']);
?>
<script type="text/javascript">
var lastPage = 4;
var organisations = [];
var orgids = ['<?php echo h($user['Organisation']['id']) ?>'];
var servers = [];
var serverids = [0];
<?php
if (empty($entity['SharingGroupServer'])) :
?>
var servers = [{
id: '0',
name: 'Local instance',
url: '<?php echo h($localInstance); ?>',
all_orgs: true,
removable: 0
}];
var serverids = [0];
<?php
else :
foreach ($entity['SharingGroupServer'] as $s) :
?>
serverids.push(<?php echo h($s['server_id']); ?>);
<?php
if ($s['server_id'] == 0) :
?>
servers.push({
id: '<?php echo h($s['server_id']); ?>',
name: 'Local instance',
url: '<?php echo empty(Configure::read('MISP.external_baseurl')) ? Configure::read('MISP.baseurl') : Configure::read('MISP.external_baseurl'); ?>',
all_orgs: '<?php echo h($s['all_orgs']); ?>',
removable: 0,
});
<?php
else :
?>
servers.push({
id: '<?php echo h($s['server_id']); ?>',
name: '<?php echo h($s['Server']['name']); ?>',
url: '<?php echo h($s['Server']['url']); ?>',
all_orgs: '<?php echo h($s['all_orgs']); ?>',
removable: 1,
});
<?php
endif;
endforeach;
endif;
?>
<?php
foreach ($entity['SharingGroupOrg'] as $s) :
?>
orgids.push(<?php echo h($s['org_id']); ?>);
var removable = 1;
if (<?php echo h($entity['Organisation']['id']); ?> == <?php echo h($s['org_id']) ?>) removable = 0;
organisations.push({
id: '<?php echo h($s['org_id']); ?>',
type: '<?php echo ($s['Organisation']['local'] == 1 ? 'local' : 'remote'); ?>',
name: '<?php echo h($s['Organisation']['name']) ?>',
extend: '<?php echo h($s['extend']); ?>',
uuid: '',
removable: removable
});
<?php
endforeach;
?>
$(function() {
if ($('#SharingGroupJson').val()) sharingGroupPopulateFromJson();
sharingGroupPopulateOrganisations();
sharingGroupPopulateServers();
});
$('#SharingGroupRoaming').change(function() {
if ($(this).is(":checked")) {
$('#serverList').hide();
} else {
$('#serverList').show();
}
});
</script>