Merge remote-tracking branch 'origin/develop' into inbox-misp-sync

pull/59/head
mokaddem 2021-06-14 14:11:07 +02:00
commit 169ebac9ab
4 changed files with 149 additions and 15 deletions

View File

@ -71,6 +71,17 @@ class MispConnector extends CommonConnectorTools
'value'
],
'redirect' => 'serverSettingsAction'
],
'serversAction' => [
'type' => 'index',
'scope' => 'child',
'params' => [
'quickFilter',
'limit',
'page',
'sort',
'direction'
]
]
];
public $version = '0.1';
@ -93,13 +104,20 @@ class MispConnector extends CommonConnectorTools
{
$settings = json_decode($connection->settings, true);
$http = new Client();
$response = $http->post($settings['url'] . '/users/view/me.json', '{}', [
'headers' => [
'AUTHORIZATION' => $settings['authkey'],
'Accept' => 'Application/json',
'Content-type' => 'Application/json'
]
]);
try {
$response = $http->post($settings['url'] . '/users/view/me.json', '{}', [
'headers' => [
'AUTHORIZATION' => $settings['authkey'],
'Accept' => 'Application/json',
'Content-type' => 'Application/json'
]
]);
} catch (\Exception $e) {
return [
'status' => 0,
'message' => __('Connection issue.')
];
}
$responseCode = $response->getStatusCode();
if ($response->isOk()) {
$status = 1;
@ -248,6 +266,7 @@ class MispConnector extends CommonConnectorTools
'name' => __('Value'),
'sort' => 'value',
'data_path' => 'value',
'options' => 'options'
],
[
'name' => __('Type'),
@ -288,6 +307,96 @@ class MispConnector extends CommonConnectorTools
}
}
public function serversAction(array $params): array
{
$params['validParams'] = [
'limit' => 'limit',
'page' => 'page',
'quickFilter' => 'searchall'
];
$urlParams = h($params['connection']['id']) . '/serversAction';
$response = $this->getData('/servers/index', $params);
$data = $response->getJson();
if (!empty($data)) {
return [
'type' => 'index',
'data' => [
'data' => $data,
'skip_pagination' => 1,
'top_bar' => [
'children' => [
[
'type' => 'search',
'button' => __('Filter'),
'placeholder' => __('Enter value to search'),
'data' => '',
'searchKey' => 'value',
'additionalUrlParams' => $urlParams,
'quickFilter' => 'value'
]
]
],
'fields' => [
[
'name' => 'Id',
'sort' => 'Server.id',
'data_path' => 'Server.id',
],
[
'name' => 'Name',
'sort' => 'Server.name',
'data_path' => 'Server.name',
],
[
'name' => 'Url',
'sort' => 'Server.url',
'data_path' => 'Server.url'
],
[
'name' => 'Pull',
'sort' => 'Server.pull',
'element' => 'function',
'function' => function($row, $context) {
$pull = $context->Hash->extract($row, 'Server.pull')[0];
$pull_rules = $context->Hash->extract($row, 'Server.pull_rules')[0];
$pull_rules = json_encode(json_decode($pull_rules, true), JSON_PRETTY_PRINT);
echo sprintf(
'<span title="%s" class="fa fa-%s"></span>',
h($pull_rules),
$pull ? 'check' : 'times'
);
}
],
[
'name' => 'Push',
'element' => 'function',
'function' => function($row, $context) {
$push = $context->Hash->extract($row, 'Server.push')[0];
$push_rules = $context->Hash->extract($row, 'Server.push_rules')[0];
$push_rules = json_encode(json_decode($push_rules, true), JSON_PRETTY_PRINT);
echo sprintf(
'<span title="%s" class="fa fa-%s"></span>',
h($push_rules),
$push ? 'check' : 'times'
);
}
],
[
'name' => 'Caching',
'element' => 'boolean',
'data_path' => 'Server.caching_enabled'
]
],
'title' => false,
'description' => false,
'pull' => 'right'
]
];
} else {
return [];
}
}
public function organisationsAction(array $params): array
{
$params['validParams'] = [
@ -515,14 +624,27 @@ class MispConnector extends CommonConnectorTools
'boolean' => 'checkbox',
'numeric' => 'number'
];
$fields = [
[
'field' => 'value',
'label' => __('Value'),
'default' => h($response['value']),
'type' => $types[$response['type']]
],
];
if (!empty($response['options'])) {
$fields = [
[
'field' => 'value',
'label' => __('Value'),
'default' => h($response['value']),
'type' => 'dropdown',
'options' => $response['options'],
]
];
} else {
$fields = [
[
'field' => 'value',
'label' => __('Value'),
'default' => h($response['value']),
'type' => $types[$response['type']]
]
];
}
return [
'data' => [
'title' => __('Modify server setting'),

View File

@ -0,0 +1,3 @@
<?php
echo $field['function']($row, $this);
?>

View File

@ -18,6 +18,12 @@
);
} else {
$data = h($data);
if (!empty($field['options'])) {
$options = $this->Hash->extract($row, $field['options']);
if (!empty($options)) {
$data = h($options[$data]);
}
}
if (!empty($field['privacy'])) {
$data = sprintf(
'<span class="privacy-value" data-hidden-value="%s">****************************************</span> <i class="privacy-toggle fas fa-eye useCursorPointer"></i>',

View File

@ -12,6 +12,9 @@
* - id: element ID for the input field - defaults to quickFilterField
*/
if (!isset($data['requirement']) || $data['requirement']) {
if (!empty($data['quickFilter'])) {
$quickFilter = $data['quickFilter'];
}
$filterEffective = !empty($quickFilter); // No filters will be picked up, thus rendering the filtering useless
$filteringButton = '';
if (!empty($data['allowFilering'])) {