mirror of https://github.com/MISP/MISP
chg: [workflows:import] Added import endpoint
parent
cfdb4d5002
commit
3705b7e9b4
|
@ -54,7 +54,9 @@ class WorkflowsController extends AppController
|
|||
$currentUser = $this->Auth->user();
|
||||
$params = [
|
||||
'beforeSave' => function ($data) use ($currentUser) {
|
||||
$data['Workflow']['uuid'] = CakeText::uuid();
|
||||
if (empty($data['Workflow']['uuid'])) {
|
||||
$data['Workflow']['uuid'] = CakeText::uuid();
|
||||
}
|
||||
$data['Workflow']['user_id'] = $currentUser['id'];
|
||||
$data['Workflow']['org_id'] = $currentUser['org_id'];
|
||||
if (!isset($data['Workflow']['description'])) {
|
||||
|
@ -188,6 +190,27 @@ class WorkflowsController extends AppController
|
|||
$this->set('menuData', ['menuList' => 'workflows', 'menuItem' => 'view_trigger']);
|
||||
}
|
||||
|
||||
public function import()
|
||||
{
|
||||
if ($this->request->is('post') || $this->request->is('put')) {
|
||||
$data = $this->request->data['Workflow'];
|
||||
$text = FileAccessTool::getTempUploadedFile($data['submittedjson'], $data['json']);
|
||||
$workflow = JsonTool::decode($text);
|
||||
if ($workflow === null) {
|
||||
throw new MethodNotAllowedException(__('Error while decoding JSON'));
|
||||
}
|
||||
$workflow['Workflow']['enabled'] = false;
|
||||
$workflow['Workflow']['data'] = JsonTool::encode($workflow['Workflow']['data']);
|
||||
$this->request->data = $workflow;
|
||||
$this->add();
|
||||
}
|
||||
}
|
||||
|
||||
public function export($id)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function rearrangeExecutionOrder($trigger_id)
|
||||
{
|
||||
$trigger = $this->Workflow->getModuleByID($trigger_id);
|
||||
|
|
|
@ -1628,6 +1628,11 @@ $divider = $this->element('/genericElements/SideMenu/side_menu_divider');
|
|||
'text' => __('Add Workflow'),
|
||||
'url' => '/workflows/add',
|
||||
));
|
||||
echo $this->element('/genericElements/SideMenu/side_menu_link', array(
|
||||
'element_id' => 'import',
|
||||
'text' => __('Import Workflow'),
|
||||
'url' => '/workflows/import',
|
||||
));
|
||||
}
|
||||
if ($menuItem === 'view' || $menuItem === 'edit') {
|
||||
echo $this->element('/genericElements/SideMenu/side_menu_link', array(
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
echo $this->element('genericElements/Form/genericForm', [
|
||||
'form' => $this->Form,
|
||||
'formOptions' => [
|
||||
'enctype' => 'multipart/form-data',
|
||||
],
|
||||
'data' => [
|
||||
'model' => 'Workflow',
|
||||
'title' => __('Import Workflow'),
|
||||
'description' => __('Paste a JSON of a Workflow to import or provide a JSON file below.'),
|
||||
'fields' => [
|
||||
[
|
||||
'field' => 'json',
|
||||
'type' => 'text',
|
||||
'class' => 'input span6',
|
||||
'div' => 'input clear',
|
||||
'label' => __('JSON'),
|
||||
'placeholder' => __('Workflow JSON'),
|
||||
'rows' => 18
|
||||
],
|
||||
[
|
||||
'field' => 'submittedjson',
|
||||
'label' => __('JSON file'),
|
||||
'type' => 'file',
|
||||
],
|
||||
],
|
||||
'submit' => [
|
||||
'action' => $this->request->params['action'],
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
||||
echo $this->element('/genericElements/SideMenu/side_menu', array('menuList' => 'workflows', 'menuItem' => 'import'));
|
Loading…
Reference in New Issue