fix: fix pull rules legend not showing on feeds/edit load.

pull/7520/head
Luciano Righetti 2021-06-24 12:07:09 +02:00
parent c1bb5cbc1d
commit c947b5556c
4 changed files with 68 additions and 64 deletions

View File

@ -307,7 +307,7 @@ class FeedsController extends AppController
'inputSources' => $inputSources
];
$this->set(compact('dropdownData'));
$this->set('defaultPullRules', json_encode(Feed::DEFAULT_FEED_PULL_RULES));
$this->set('menuData', array('menuList' => 'feeds', 'menuItem' => 'add'));
}
@ -444,6 +444,7 @@ class FeedsController extends AppController
]);
$this->set('feedId', $feedId);
$this->request->data['Feed']['pull_rules'] = $this->request->data['Feed']['rules'];
$this->render('add');
}

View File

@ -15,18 +15,18 @@ class Feed extends AppModel
);
public $belongsTo = array(
'SharingGroup' => array(
'className' => 'SharingGroup',
'foreignKey' => 'sharing_group_id',
),
'Tag' => array(
'className' => 'Tag',
'foreignKey' => 'tag_id',
),
'Orgc' => array(
'className' => 'Organisation',
'foreignKey' => 'orgc_id'
)
'SharingGroup' => array(
'className' => 'SharingGroup',
'foreignKey' => 'sharing_group_id',
),
'Tag' => array(
'className' => 'Tag',
'foreignKey' => 'tag_id',
),
'Orgc' => array(
'className' => 'Organisation',
'foreignKey' => 'orgc_id'
)
);
public $validate = array(
@ -61,6 +61,18 @@ class Feed extends AppModel
)
);
public const DEFAULT_FEED_PULL_RULES = [
'tags' => [
"OR" => [],
"NOT" => [],
],
'orgs' => [
"OR" => [],
"NOT" => [],
],
'url_params' => ''
];
/*
* Cleanup of empty belongsto relationships
*/
@ -93,8 +105,8 @@ class Feed extends AppModel
'Invalid input source. The only valid options are %s. %s',
implode(', ', $validOptions),
(!$localAllowed && $this->data['Feed']['input_source'] === 'local') ?
__('Security.disable_local_feed_access is currently enabled, local feeds are thereby not allowed.') :
''
__('Security.disable_local_feed_access is currently enabled, local feeds are thereby not allowed.') :
''
);
}
}
@ -545,7 +557,8 @@ class Feed extends AppModel
unset($sources[$k]);
}
}
} catch (Exception $e) {}
} catch (Exception $e) {
}
return $sources;
}
@ -773,9 +786,9 @@ class Feed extends AppModel
{
$this->Event = ClassRegistry::init('Event');
$existingEvent = $this->Event->find('first', array(
'conditions' => array('Event.uuid' => $event['Event']['uuid']),
'recursive' => -1,
'fields' => array('Event.uuid', 'Event.id', 'Event.timestamp')
'conditions' => array('Event.uuid' => $event['Event']['uuid']),
'recursive' => -1,
'fields' => array('Event.uuid', 'Event.id', 'Event.timestamp')
));
$result = array();
if (!empty($existingEvent)) {
@ -840,8 +853,8 @@ class Feed extends AppModel
}
if ($feed['Feed']['sharing_group_id']) {
$sg = $this->SharingGroup->find('first', array(
'recursive' => -1,
'conditions' => array('SharingGroup.id' => $feed['Feed']['sharing_group_id'])
'recursive' => -1,
'conditions' => array('SharingGroup.id' => $feed['Feed']['sharing_group_id'])
));
if (!empty($sg)) {
$event['Event']['SharingGroup'] = $sg['SharingGroup'];
@ -927,15 +940,15 @@ class Feed extends AppModel
if (empty($existingFeed)) {
$this->create();
$feed = array(
'name' => $newFeed['name'],
'provider' => $newFeed['provider'],
'url' => $newFeed['url'],
'enabled' => $newFeed['enabled'],
'caching_enabled' => !empty($newFeed['caching_enabled']) ? $newFeed['caching_enabled'] : 0,
'distribution' => 3,
'sharing_group_id' => 0,
'tag_id' => 0,
'default' => true,
'name' => $newFeed['name'],
'provider' => $newFeed['provider'],
'url' => $newFeed['url'],
'enabled' => $newFeed['enabled'],
'caching_enabled' => !empty($newFeed['caching_enabled']) ? $newFeed['caching_enabled'] : 0,
'distribution' => 3,
'sharing_group_id' => 0,
'tag_id' => 0,
'default' => true,
);
$result = $this->save($feed) && $success;
}
@ -1044,15 +1057,15 @@ class Feed extends AppModel
$orgc_id = $feed['Feed']['orgc_id'];
}
$event = array(
'info' => $feed['Feed']['name'] . ' feed',
'analysis' => 2,
'threat_level_id' => 4,
'orgc_id' => $orgc_id,
'org_id' => $user['org_id'],
'date' => date('Y-m-d'),
'distribution' => $feed['Feed']['distribution'],
'sharing_group_id' => $feed['Feed']['sharing_group_id'],
'user_id' => $user['id']
'info' => $feed['Feed']['name'] . ' feed',
'analysis' => 2,
'threat_level_id' => 4,
'orgc_id' => $orgc_id,
'org_id' => $user['org_id'],
'date' => date('Y-m-d'),
'distribution' => $feed['Feed']['distribution'],
'sharing_group_id' => $feed['Feed']['sharing_group_id'],
'user_id' => $user['id']
);
$result = $this->Event->save($event);
if (!$result) {
@ -1592,7 +1605,8 @@ class Feed extends AppModel
return $cardinality;
}
public function getAllCachingEnabledFeeds($feedId, $intersectingOnly = false) {
public function getAllCachingEnabledFeeds($feedId, $intersectingOnly = false)
{
if ($intersectingOnly) {
$redis = $this->setupRedis();
}
@ -1923,13 +1937,13 @@ class Feed extends AppModel
$this->Log = ClassRegistry::init('Log');
$this->Log->create();
$this->Log->save(array(
'org' => 'SYSTEM',
'model' => 'Feed',
'model_id' => $id,
'email' => $user['email'],
'action' => 'purge_events',
'title' => __('Events related to feed %s purged.', $id),
'change' => null,
'org' => 'SYSTEM',
'model' => 'Feed',
'model_id' => $id,
'email' => $user['email'],
'action' => 'purge_events',
'title' => __('Events related to feed %s purged.', $id),
'change' => null,
));
$feed['Feed']['fixed_event'] = 1;
$feed['Feed']['event_id'] = 0;

View File

@ -1,3 +1,4 @@
<?php echo $this->Form->input('pull_rules', array('style' => 'display:none;', 'label' => false, 'div' => false)); ?>
<b><?php echo __('Filter rules'); ?>:</b><br />
<span id="pull_tags_OR" style="display:none;"><?php echo __('Events with the following tags allowed'); ?>: <span id="pull_tags_OR_text" style="color:green;"></span><br /></span>
<span id="pull_tags_NOT" style="display:none;"><?php echo __('Events with the following tags blocked'); ?>: <span id="pull_tags_NOT_text" style="color:red;"></span><br /></span>
@ -8,9 +9,7 @@
<div id="hiddenRuleForms">
<?php
$pullRules = json_decode($fieldData['pull_rules'], true);
$pullRules['url_params'] = json_decode($fieldData['pull_rules'], true);
echo $this->Form->input('pull_rules', array('style' => 'display:none;', 'label' => false, 'div' => false));
$pullRules['url_params'] = json_decode($pullRules['url_params'], true);
$modalData = [
'data' => [
@ -41,23 +40,13 @@
</div>
<script type="text/javascript">
var rules = {
"pull": {
"tags": {
"OR": [],
"NOT": []
},
"orgs": {
"OR": [],
"NOT": []
}
}
};
var rules = {};
var validOptions = ['pull'];
var validFields = ['tags', 'orgs'];
var modelContext = '<?= $this->Form->defaultModel ?>';
$(document).ready(function() {
rules = convertServerFilterRules(rules);
$("#pull_modify").click(function() {
$('#genericModal.pull-rule-modal').modal()
.on('shown', function() {

View File

@ -3,7 +3,7 @@ $modelForForm = 'Feeds';
$edit = $this->request->params['action'] === 'edit' ? true : false;
echo $this->element('genericElements/Form/genericForm', [
'data' => [
'title' => isset($edit) ? __('Edit MISP feed') : __('Add MISP feed'),
'title' => $edit ? __('Edit MISP feed') : __('Add MISP feed'),
'description' => __('Add a new MISP feed source.'),
'model' => 'Feed',
'fields' => [
@ -80,7 +80,7 @@ echo $this->element('genericElements/Form/genericForm', [
'type' => 'pullRules',
'tags' => $dropdownData['tags'],
'orgs' => $dropdownData['orgs'],
'pull_rules' => $entity['Feed']['rules']
'pull_rules' => $edit ? $entity['Feed']['rules'] : $defaultPullRules
],
],
'submit' => [