mirror of https://github.com/MISP/MISP
Further work on the sync filters
parent
a4ab089f50
commit
a9c737ff2b
|
@ -239,6 +239,19 @@ class ServersController extends AppController {
|
|||
$this->set('organisationOptions', $organisationOptions);
|
||||
$this->set('localOrganisations', $localOrganisations);
|
||||
$this->set('externalOrganisations', $externalOrganisations);
|
||||
|
||||
// list all orgs for the rule picker
|
||||
$temp = $localOrganisations + $externalOrganisations;
|
||||
$allOrgs = array();
|
||||
foreach ($temp as $k => $v) $allOrgs[] = array('id' => $k, 'name' => $v);
|
||||
$this->set('allOrganisations', $allOrgs);
|
||||
|
||||
// list all tags for the rule picker
|
||||
$this->loadModel('Tag');
|
||||
$temp = $this->Tag->find('all', array('recursive' => -1));
|
||||
$allTags = array();
|
||||
foreach ($temp as $t) $allTags[] = array('id' => $t['Tag']['id'], 'name' => $t['Tag']['name']);
|
||||
$this->set('allTags', $allTags);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -79,13 +79,13 @@
|
|||
<span id="push_tags_blocked" style="display:none;">Events with the following tags blocked: <span id="push_tags_blocked_text" style="color:red;"></span><br /></span>
|
||||
<span id="push_orgs_allowed" style="display:none;">Events with the following organisations allowed: <span id="push_orgs_allowed_text" style="color:green;"></span><br /></span>
|
||||
<span id="push_orgs_blocked" style="display:none;">Events with the following organisations blocked: <span id="push_orgs_blocked_text" style="color:red;"></span><br /></span>
|
||||
<span class="btn btn-inverse" style="line-height:10px; padding: 4px 4px;">Modify</span><br /><br />
|
||||
<span id="push_modify" class="btn btn-inverse" style="line-height:10px; padding: 4px 4px;">Modify</span><br /><br />
|
||||
<b>Pull rules:</b><br />
|
||||
<span id="pull_tags_allowed" style="display:none;">Events with the following tags allowed: <span id="pull_tags_allowed_text" style="color:green;"></span><br /></span>
|
||||
<span id="pull_tags_blocked" style="display:none;">Events with the following tags blocked: <span id="pull_tags_blocked_text" style="color:red;"></span><br /></span>
|
||||
<span id="pull_orgs_allowed" style="display:none;">Events with the following organisations allowed: <span id="pull_orgs_allowed_text" style="color:green;"></span><br /></span>
|
||||
<span id="pull_orgs_blocked" style="display:none;">Events with the following organisations blocked: <span id="pull_orgs_blocked_text" style="color:red;"></span><br /></span>
|
||||
<span class="btn btn-inverse" style="line-height:10px; padding: 4px 4px;">Modify</span><br /><br />
|
||||
<span id="pull_modify" class="btn btn-inverse" style="line-height:10px; padding: 4px 4px;">Modify</span><br /><br />
|
||||
<?php
|
||||
echo $this->Form->input('push_rules', array('style' => 'display:none;', 'label' => false, 'div' => false));
|
||||
echo $this->Form->input('pull_rules', array('style' => 'display:none;', 'label' => false, 'div' => false));
|
||||
|
@ -97,6 +97,10 @@
|
|||
echo $this->Form->end();
|
||||
?>
|
||||
</div>
|
||||
<div id="hiddenRuleForms">
|
||||
<?php echo $this->element('serverRuleElements/push'); ?>
|
||||
<?php echo $this->element('serverRuleElements/pull'); ?>
|
||||
</div>
|
||||
<?php
|
||||
echo $this->element('side_menu', array('menuList' => 'sync', 'menuItem' => 'edit'));
|
||||
?>
|
||||
|
@ -115,6 +119,12 @@ var formInfoValues = {
|
|||
'ServerSelfSigned' : "Click this, if you would like to allow a connection despite the other instance using a self-signed certificate (not recommended)."
|
||||
};
|
||||
|
||||
var rules = {"push": {"tags": {"allowed":[], "blocked":[]}, "orgs": {"allowed":[], "blocked":[]}}, "pull": {"tags": {"allowed":[], "blocked":[]}, "orgs": {"allowed":[], "blocked":[]}}};
|
||||
var validOptions = ['pull', 'push'];
|
||||
var validFields = ['tags', 'orgs'];
|
||||
var tags = <?php echo json_encode($allTags); ?>;
|
||||
var orgs = <?php echo json_encode($allOrganisations); ?>;
|
||||
|
||||
$(document).ready(function() {
|
||||
serverOrgTypeChange();
|
||||
$('#ServerOrganisationType').change(function() {
|
||||
|
@ -134,7 +144,14 @@ $(document).ready(function() {
|
|||
content: formInfoValues[e.currentTarget.id],
|
||||
}).popover('show');
|
||||
});
|
||||
convertServerFilterRulesToHTML("push");
|
||||
convertServerFilterRulesToHTML("pull");
|
||||
rules = convertServerFilterRules("push", rules);
|
||||
rules = convertServerFilterRules("pull", rules);
|
||||
serverRulePopulateTagPicklist();
|
||||
$("#push_modify").click(function() {
|
||||
serverRuleFormActivate('push');
|
||||
});
|
||||
$("#pull_modify").click(function() {
|
||||
serverRuleFormActivate('pull');
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
|
|
@ -1895,39 +1895,107 @@ function zeroMQServerAction(action) {
|
|||
});
|
||||
}
|
||||
|
||||
function convertServerFilterRulesToHTML(type) {
|
||||
validOptions = ['pull', 'push'];
|
||||
validFields = ['tags', 'orgs'];
|
||||
function convertServerFilterRules(type, rules) {
|
||||
if ($.inArray(type, validOptions) == -1) return false;
|
||||
container = "#Server" + type.ucfirst() + "Rules";
|
||||
var rules = {};
|
||||
var tempJson = JSON.parse($(container).val());
|
||||
validFields.forEach(function(field){
|
||||
var allowed = [];
|
||||
var blocked = [];
|
||||
if (typeof tempJson[field] != 'undefined') {
|
||||
var allowed = [];
|
||||
var blocked = [];
|
||||
tempJson[field].forEach(function(item) {
|
||||
if (item.charAt(0) == '!') blocked.push(item);
|
||||
if (item.charAt(0) == '!') blocked.push(item.substr(1));
|
||||
else allowed.push(item);
|
||||
});
|
||||
if (allowed.length > 0) {
|
||||
$('#' + type + '_' + field + '_allowed').show();
|
||||
var t = '';
|
||||
allowed.forEach(function(item) {
|
||||
if (t.length > 0) t += ', ';
|
||||
t += item;
|
||||
});
|
||||
$('#' + type + '_' + field + '_allowed_text').text(t);
|
||||
}
|
||||
if (blocked.length > 0) {
|
||||
$('#' + type + '_' + field + '_blocked').show();
|
||||
var t = '';
|
||||
blocked.forEach(function(item) {
|
||||
if (t.length > 0) t += ', ';
|
||||
t += item.substring(1);
|
||||
});
|
||||
$('#' + type + '_' + field + '_blocked_text').text(t);
|
||||
}
|
||||
}
|
||||
rules[type][field]["allowed"] = allowed;
|
||||
rules[type][field]["blocked"] = blocked;
|
||||
});
|
||||
serverRuleUpdate();
|
||||
return rules;
|
||||
}
|
||||
|
||||
function serverRuleUpdate() {
|
||||
var statusOptions = ["allowed", "blocked"];
|
||||
validOptions.forEach(function(type) {
|
||||
validFields.forEach(function(field) {
|
||||
statusOptions.forEach(function(status) {
|
||||
if (rules[type][field][status].length > 0) {
|
||||
$('#' + type + '_' + field + '_' + status).show();
|
||||
var t = '';
|
||||
rules[type][field][status].forEach(function(item) {
|
||||
if (t.length > 0) t += ', ';
|
||||
t += item;
|
||||
});
|
||||
$('#' + type + '_' + field + '_' + status + '_text').text(t);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
serverRuleGenerateJSON();
|
||||
}
|
||||
|
||||
function serverRuleFormActivate(type) {
|
||||
if (type != 'pull' && type != 'push') return false;
|
||||
$('.server_rule_popover').hide();
|
||||
$('#gray_out').fadeIn();
|
||||
$('#server_' + type + '_rule_popover').show();
|
||||
}
|
||||
|
||||
function serverRuleCancel() {
|
||||
$("#gray_out").fadeOut();
|
||||
$(".server_rule_popover").fadeOut();
|
||||
}
|
||||
|
||||
function serverRuleGenerateJSON() {
|
||||
jsonObject = {"push":{"tags":[], "orgs":[]}, "pull":{"tags":[], "orgs":[]}};
|
||||
validOptions.forEach(function(type) {
|
||||
validFields.forEach(function(field) {
|
||||
if (rules[type][field]["allowed"].length > 0) {
|
||||
rules[type][field]["allowed"].forEach(function(value) {
|
||||
jsonObject[type][field].push(value);
|
||||
});
|
||||
}
|
||||
if (rules[type][field]["blocked"].length > 0) {
|
||||
rules[type][field]["blocked"].forEach(function(value) {
|
||||
jsonObject[type][field].push("!" + value);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
$('#ServerJson').val(JSON.stringify(jsonObject));
|
||||
}
|
||||
|
||||
function serverRulePopulateTagPicklist() {
|
||||
var fields = ["tags", "orgs"];
|
||||
fields.forEach(function(field) {
|
||||
var target = "";
|
||||
window[field].forEach(function(element) {
|
||||
if ($.inArray(element.name, rules["push"][field]["allowed"]) != -1) target = "#" + field + "LeftValues";
|
||||
else if ($.inArray(element.name, rules["push"][field]["blocked"]) != -1) target = "#" + field + "RightValues";
|
||||
else target = "#" + field + "MiddleValues";
|
||||
$(target).append($('<option/>', {
|
||||
value: element.name,
|
||||
text : element.name
|
||||
}));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function submitServerRulePopulateTagPicklistValues(context) {
|
||||
if (context == "push") {
|
||||
validFields.forEach(function(field) {
|
||||
rules["push"][field]["allowed"] = [];
|
||||
$("#" + field + "LeftValues option").each(function() {
|
||||
rules["push"][field]["allowed"].push($(this).val());
|
||||
});
|
||||
rules["push"][field]["blocked"] = [];
|
||||
$("#" + field + "RightValues option").each(function() {
|
||||
rules["push"][field]["blocked"].push($(this).val());
|
||||
});
|
||||
});
|
||||
}
|
||||
$('#server_push_rule_popover').fadeOut();
|
||||
$('#gray_out').fadeOut();
|
||||
serverRuleUpdate();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue