Merge branch 'develop' of github.com:MISP/MISP into feature-galaxy-cluster-wipe-default

pull/7360/head
mokaddem 2021-04-23 09:06:08 +02:00
commit ec746fa064
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
15 changed files with 689 additions and 471 deletions

View File

@ -491,6 +491,7 @@ class ACLComponent extends Component
'fetchServersForSG' => array('perm_sharing_group'),
'filterEventIndex' => array(),
'getApiInfo' => array('*'),
'getAvailableSyncFilteringRules' => array('*'),
'getInstanceUUID' => array('perm_sync'),
'getPyMISPVersion' => array('*'),
'getRemoteUser' => array(),
@ -513,6 +514,7 @@ class ACLComponent extends Component
'pull' => array(),
'purgeSessions' => array(),
'push' => array(),
'queryAvailableSyncFilteringRules' => array('*'),
'releaseUpdateLock' => array(),
'resetRemoteAuthKey' => array(),
'removeOrphanedCorrelations' => array('perm_site_admin'),

View File

@ -395,7 +395,7 @@ class FeedsController extends AppController
} else {
$message = __('Feed could not be updated. Reason: %s', json_encode($this->Feed->validationErrors));
if ($this->_isRest()) {
return $this->RestResponse->saveFailResponse('Feeds', 'add', false, $message, $this->response->type());
return $this->RestResponse->saveFailResponse('Feeds', 'edit', false, $message, $this->response->type());
}
$this->Flash->error($message);
}

View File

@ -2505,4 +2505,26 @@ misp.direct_call(relative_path, body)
$this->redirect(array('action' => 'serverSettings', 'diagnostics'));
}
}
public function queryAvailableSyncFilteringRules($serverID)
{
if (!$this->_isRest()) {
throw new MethodNotAllowedException(__('This method can only be access via REST'));
}
$server = $this->Server->find('first', ['conditions' => ['Server.id' => $serverID]]);
if (!$server) {
throw new NotFoundException(__('Invalid server'));
}
$syncFilteringRules = $this->Server->queryAvailableSyncFilteringRules($server);
return $this->RestResponse->viewData($syncFilteringRules);
}
public function getAvailableSyncFilteringRules()
{
if (!$this->_isRest()) {
throw new MethodNotAllowedException(__('This method can only be access via REST'));
}
$syncFilteringRules = $this->Server->getAvailableSyncFilteringRules($this->Auth->user());
return $this->RestResponse->viewData($syncFilteringRules);
}
}

View File

@ -4450,6 +4450,44 @@ class Server extends AppModel
return $success;
}
public function queryAvailableSyncFilteringRules($server)
{
$HttpSocket = $this->setupHttpSocket($server, null);
$uri = $server['Server']['url'] . '/servers/getAvailableSyncFilteringRules';
$request = $this->setupSyncRequest($server);
$response = $HttpSocket->get($uri, false, $request);
if ($response === false) {
throw new Exception(__('Connection failed for unknown reason.'));
}
$syncFilteringRules = [];
if ($response->isOk()) {
$syncFilteringRules = $this->jsonDecode($response->body());
} else {
throw new Exception(__('Reponse was not OK. (HTTP code: %s)', $response->code));
}
return $syncFilteringRules;
}
public function getAvailableSyncFilteringRules($user)
{
$this->Organisation = ClassRegistry::init('Organisation');
$this->Tag = ClassRegistry::init('Tag');
$organisations = [];
if ($user['Role']['perm_sharing_group'] || !Configure::read('Security.hide_organisation_index_from_users')) {
$organisations = $this->Organisation->find('list', [
'fields' => 'name'
]);
}
$tags = $this->Tag->find('list', [
'fields' => 'name'
]);
return [
'organisations' => array_values($organisations),
'tags' => array_values($tags),
];
}
/**
* Generate just when required
* @return array[]

View File

@ -11,6 +11,10 @@
* - code: Code snipet to be displayed - copy pastable (optional)
* - type: Controls the size of the modal (`xl` or `lg`)
* - class: A class to be applied on the modal (For reference or customization)
* - confirm: array to defined the submit button (optional)
* - title: Title in the submit button (default: `Submit`)
* - onclick: The function to be called when clicking the button (default: [close modal])
* - class: The class string to be applied on the button (default: `btn btn-primary`)
*/
$contents = '';
foreach ($data['content'] as $content) {
@ -24,6 +28,23 @@
}
$action = $this->request->params['action'];
$controller = $this->request->params['controller'];
$dataConfirmButton = [
'title' => isset($confirm['title']) ? $confirm['title'] : __('Submit'),
'onclick' => isset($confirm['onclick']) ? $confirm['onclick'] : '',
'class' => isset($confirm['class']) ? $confirm['class'] : 'btn btn-primary',
];
$confirmButton = '';
if (!empty($confirm)) {
$confirmButton = sprintf('<button class="%s" data-dismiss="modal" aria-hidden="true" onClick="%s">%s</button>',
$dataConfirmButton['class'],
$dataConfirmButton['onclick'],
h($dataConfirmButton['title'])
);
}
$cancelButton = sprintf('<button class="btn" data-dismiss="modal" aria-hidden="true" onClick="%s">%s</button>',
'cancelPopoverForm();',
__('Cancel')
);
echo sprintf(
'<div id="genericModal" class="modal %s hide fade %s" tabindex="-1" role="dialog" aria-labelledby="genericModalLabel" aria-hidden="true">%s%s%s</div>',
isset($type) ? sprintf('modal-%s', $type) : '',
@ -40,9 +61,9 @@
$contents
),
sprintf(
'<div class="modal-footer"><button class="btn" data-dismiss="modal" aria-hidden="true" onClick="%s">%s</button></div>',
'cancelPopoverForm();',
__('Cancel')
'<div class="modal-footer">%s%s</div>',
$confirmButton,
$cancelButton
)
);
?>

View File

@ -1,80 +1,186 @@
<div id="server_pull_rule_popover" class="ajax_popover_form server_rule_popover">
<div class="confirmation">
<legend><?php echo __('Set pull rules');?></legend>
<div style="padding-left:5px;padding-right:5px;padding-bottom:5px;">
<div style="padding:10px;">
<table>
<tr>
<td style="width:120px;">
<p style="color:green;font-weight:bold;"><?php echo __('Allowed Tags (OR)');?></p>
<select id="tagspullLeftValues" size="5" multiple style="width:185px;">
</select>
</td>
<td style="width:50px;text-align:center;">
<span title="<?php echo __('Move tag to the list of tags to allow');?>" role="button" tabindex="0" aria-label="<?php echo __('Move tag to the list of tags to allow');?>" class="btn btn-inverse" id="tagspullLeftLeft" style="padding:2px;" onClick="serverRuleMoveFilter('pull', 'tags', 'Middle', 'Left');">&lt;&lt;</span>
<span title="<?php echo __('Remove tag from the list of tags to allow');?>" role="button" tabindex="0" aria-label="<?php echo __('Remove tag from the list of tags to allow');?>" class="btn btn-inverse" id="tagspullLeftRight" style="padding:2px;" onClick="serverRuleMoveFilter('pull', 'tags', 'Left', 'Middle');">&gt;&gt;</span>
</td>
<td style="width:120px;">
<input id="tagspullNewValue" style="width:180px;">
</td>
<td style="width:50px;text-align:center;">
<span title="<?php echo __('Remove tag from the list of tags to block');?>" role="button" tabindex="0" aria-label="<?php echo __('Remove tag from the list of tags to block');?>" class="btn btn-inverse" id="tagspullRightLeft" style="padding:2px;" onClick="serverRuleMoveFilter('pull', 'tags', 'Right', 'Middle');">&lt;&lt;</span>
<span title="<?php echo __('Move tag to the list of tags to block');?>" role="button" tabindex="0" aria-label="<?php echo __('Move tag to the list of tags to block');?>" class="btn btn-inverse" id="tagspullRightRight" style="padding:2px;" onClick="serverRuleMoveFilter('pull', 'tags', 'Middle', 'Right');">&gt;&gt;</span>
</td>
<td style="width:120px;">
<p style="color:red;font-weight:bold;"><?php echo __('Blocked Tags (AND NOT)');?></p>
<select id="tagspullRightValues" size="5" multiple style="width:185px;"></select>
</td>
</tr>
<tr>
<td class="bold green center" style="padding-bottom:15px;padding-top:15px;"><?php echo __('AND');?></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td class="bold red center" style="padding-bottom:15px;padding-top:15px;"><?php echo __('AND NOT');?></td>
</tr>
<tr>
<td style="width:120px;">
<p style="color:green;font-weight:bold;"><?php echo __('Allowed Orgs (OR)');?></p>
<select id="orgspullLeftValues" size="5" multiple style="width:185px;">
</select>
</td>
<td style="width:50px;text-align:center;">
<span title="<?php echo __('Move organisation to the list of tags to allow');?>" role="button" tabindex="0" aria-label="<?php echo __('Move organisation to the list of organisations to allow');?>" class="btn btn-inverse" id="orgspullLeftLeft" style="padding:2px;" onClick="serverRuleMoveFilter('pull', 'orgs', 'Middle', 'Left');">&lt;&lt;</span>
<span title="<?php echo __('Remove organisation to the list of tags to allow');?>" role="button" tabindex="0" aria-label="<?php echo __('Remove organisation form the list of organisations to allow');?>" class="btn btn-inverse" id="orgspullLeftRight" style="padding:2px;" onClick="serverRuleMoveFilter('pull', 'orgs', 'Left', 'Middle');">&gt;&gt;</span>
</td>
<td style="width:120px;">
<input id="orgspullNewValue" style="width:180px;">
</td>
<td style="width:50px;text-align:center;">
<span title="<?php echo __('Remove organisation from the list of tags to allow');?>" role="button" tabindex="0" aria-label="<?php echo __('Remove organisation from the list of organisations to block');?>" class="btn btn-inverse" id="orgspullRightLeft" style="padding:2px;" onClick="serverRuleMoveFilter('pull', 'orgs', 'Right', 'Middle');">&lt;&lt;</span>
<span title="<?php echo __('Move organisation to the list of tags to block');?>" role="button" tabindex="0" aria-label="<?php echo __('Move organisation to the list of organisations to block');?>" class="btn btn-inverse" id="orgspullRightRight" style="padding:2px;" onClick="serverRuleMoveFilter('pull', 'orgs', 'Middle', 'Right');">&gt;&gt;</span>
</td>
<td style="width:120px;">
<p style="color:red;font-weight:bold;"><?php echo __('Blocked Orgs (AND NOT)');?></p>
<select id="orgspullRightValues" size="5" multiple style="width:185px;"></select>
</td>
</tr>
</table>
<div>
<p style="color:green;font-weight:bold;"><?php echo __('Additional sync parameters (based on the event index filters)');?></p>
<input style="width:650px;" placeholder='{"timestamp": "30d"}' type="text" value="" id="urlParams" required="required" data-original-title="" title="">
</div>
</div>
<div>
<table style="width:100%;">
<tr>
<td style="vertical-align:top">
<span title="<?php echo __('Accept changes');?>" role="button" tabindex="0" aria-label="<?php echo __('Accept changes');?>" id="PromptYesButton" class="btn btn-primary" onClick="submitServerRulePopulateTagPicklistValues('pull');"><?php echo __('Update');?></span>
</td>
<td style="width:540px;">
</td>
<td style="vertical-align:top;">
<span title="<?php echo __('Cancel');?>" role="button" tabindex="0" aria-label="<?php echo __('Cancel');?>" class="btn btn-inverse" id="PromptNoButton" onClick="serverRuleCancel();"><?php echo __('Cancel');?></span>
</td>
</tr>
</table>
</div>
<div style="display: flex; flex-direction: column;" class="server-rule-container-pull">
<?php if ($context == 'servers'): ?>
<div class="alert alert-primary notice-pull-rule-fetched">
<button type="button" class="close" data-dismiss="alert">&times;</button>
<i class="<?= $this->FontAwesome->getClass('spinner') ?> fa-spin"></i>
<?= __('Organisations and Tags are being fetched from the remote server.') ?>
</div>
<div class="alert alert-success hidden notice-pull-rule-fetched">
<button type="button" class="close" data-dismiss="alert">&times;</button>
<?= __('Organisations and Tags have been fetched from the remote server.') ?>
</div>
<div class="alert alert-warning hidden notice-pull-rule-fetched">
<button type="button" class="close" data-dismiss="alert">&times;</button>
<?= __('Issues while trying to fetch Organisations and Tags from the remote server.') ?>
<div><strong><?= __('Reason:') ?></strong></div>
<div><pre class="reason" style="margin-bottom: 0;"></pre></div>
</div>
<?php endif; ?>
<?php
$tagAllowRules = [];
$tagBlockRules = [];
$orgAllowRules = [];
$orgBlockRules = [];
$ruleUrlParams = [];
if (!empty($ruleObject)) {
$tagAllowRules = $ruleObject['tags']['OR'];
$tagBlockRules = $ruleObject['tags']['NOT'];
$orgAllowRules = $ruleObject['orgs']['OR'];
$orgBlockRules = $ruleObject['orgs']['NOT'];
$ruleUrlParams = $ruleObject['url_params'];
}
?>
<?php
echo $this->element('serverRuleElements/rules_widget', [
'scope' => 'tag',
'scopeI18n' => __('tag'),
'technique' => 'pull',
'allowEmptyOptions' => true,
'options' => $allTags,
'optionNoValue' => true,
'initAllowOptions' => $tagAllowRules,
'initBlockOptions' => $tagBlockRules
]);
?>
<div style="display: flex;">
<h4 class="bold green" style=""><?= __('AND');?></h4>
<h4 class="bold red" style="margin-left: auto;"><?= __('AND NOT');?></h4>
</div>
<?php
echo $this->element('serverRuleElements/rules_widget', [
'scope' => 'org',
'scopeI18n' => __('org'),
'technique' => 'pull',
'allowEmptyOptions' => true,
'options' => $allOrganisations,
'optionNoValue' => true,
'initAllowOptions' => $orgAllowRules,
'initBlockOptions' => $orgBlockRules
]);
?>
<div style="display: flex;">
<h4 class="bold green" style=""><?= __('AND');?></h4>
</div>
<div style="display: flex; flex-direction: column;">
<div class="bold green">
<?= __('Additional sync parameters (based on the event index filters)');?>
</div>
<div style="display: flex;">
<textarea style="width:100%;" placeholder='{"timestamp": "30d"}' type="text" value="" id="urlParams" required="required" data-original-title="" title="" rows="3"
><?= !empty($ruleUrlParams) ? json_encode(h($ruleUrlParams), JSON_PRETTY_PRINT) : '' ?></textarea>
</div>
</div>
</div>
<?php
echo $this->element('genericElements/assetLoader', array(
'js' => array(
'codemirror/codemirror',
'codemirror/modes/javascript',
'codemirror/addons/closebrackets',
'codemirror/addons/lint',
'codemirror/addons/jsonlint',
'codemirror/addons/json-lint',
),
'css' => array(
'codemirror',
'codemirror/show-hint',
'codemirror/lint',
)
));
?>
<script>
var cm;
$(function() {
var serverID = "<?= isset($id) ? $id : '' ?>"
<?php if ($context == 'servers'): ?>
addPullFilteringRulesToPicker()
<?php endif; ?>
setupCodeMirror()
function addPullFilteringRulesToPicker() {
var $rootContainer = $('div.server-rule-container-pull')
var $pickerTags = $rootContainer.find('select.rules-select-picker-tag')
var $pickerOrgs = $rootContainer.find('select.rules-select-picker-org')
if (serverID !== "") {
$pickerOrgs.parent().children().prop('disabled', true)
$pickerTags.parent().children().prop('disabled', true)
getPullFilteringRules(
function(data) {
addOptions($pickerTags, data.tags)
addOptions($pickerOrgs, data.organisations)
$('div.notice-pull-rule-fetched.alert-success').show()
},
function(errorMessage) {
showMessage('fail', '<?= __('Could not fetch remote sync filtering rules.') ?>');
$('div.notice-pull-rule-fetched.alert-warning').show().find('.reason').text(errorMessage)
$pickerTags.parent().remove()
$pickerOrgs.parent().remove()
},
function() {
$('div.notice-pull-rule-fetched.alert-primary').hide()
$pickerTags.parent().children().prop('disabled', false).trigger('chosen:updated')
$pickerOrgs.parent().children().prop('disabled', false).trigger('chosen:updated')
},
)
} else {
$('div.notice-pull-rule-fetched.alert-warning').show().find('.reason').text('<?= __('The server must first be saved in order to fetch remote synchronisation rules.') ?>')
$pickerTags.parent().remove()
$pickerOrgs.parent().remove()
$('div.notice-pull-rule-fetched.alert-primary').hide()
}
}
function getPullFilteringRules(cb, fcb, acb) {
$.getJSON('/servers/queryAvailableSyncFilteringRules/' + serverID, function(availableRules) {
cb(availableRules)
})
.fail(function(jqxhr, textStatus, error) {
fcb(jqxhr.responseJSON.message !== undefined ? jqxhr.responseJSON.message : textStatus)
})
.always(function() {
acb()
})
}
function addOptions($select, data) {
data.forEach(function(entry) {
$select.append($('<option/>', {
value: entry,
text : entry
}));
});
}
function setupCodeMirror() {
var cmOptions = {
mode: "application/json",
theme:'default',
gutters: ["CodeMirror-lint-markers"],
lint: true,
lineNumbers: true,
indentUnit: 4,
showCursorWhenSelecting: true,
lineWrapping: true,
autoCloseBrackets: true,
}
cm = CodeMirror.fromTextArea(document.getElementById('urlParams'), cmOptions);
cm.on("keyup", function (cm, event) {
$('#urlParams').val(cm.getValue())
});
}
})
</script>
<style>
div.server-rule-container-pull .CodeMirror {
height: 100px;
width: 100%;
border: 1px solid #ddd;
}
</style>

View File

@ -1,78 +1,55 @@
<div id="server_push_rule_popover" class="ajax_popover_form server_rule_popover">
<div class="confirmation">
<legend><?php echo __('Set push rules');?></legend>
<div style="padding-left:5px;padding-right:5px;padding-bottom:5px;">
<div style="padding:10px;">
<table>
<tr>
<td style="width:120px;">
<p style="color:green;font-weight:bold;"><?php echo __('Allowed Tags (OR)');?></p>
<select id="tagspushLeftValues" size="5" multiple style="width:185px;">
</select>
</td>
<td style="width:50px;text-align:center;">
<span title="<?php echo __('Move tag to the list of tags to allow');?>" role="button" tabindex="0" aria-label="<?php echo __('Move tag to the list of tags to allow');?>" class="btn btn-inverse" id="tagspushLeftLeft" onClick="serverRuleMoveFilter('push', 'tags', 'Middle', 'Left');" style="padding:2px;">&lt;&lt;</span>
<span title="<?php echo __('Remove tag from the list of tags to allow');?>" role="button" tabindex="0" aria-label="<?php echo __('Remove tag from the list of tags to allow');?>" class="btn btn-inverse" id="tagspushLeftRight" onClick="serverRuleMoveFilter('push', 'tags', 'Left', 'Middle');" style="padding:2px;">&gt;&gt;</span>
</td>
<td style="width:120px;">
<p style="font-weight:bold;"><?php echo __('Available Tags');?></p>
<select id="tagspushMiddleValues" size="5" multiple style="width:185px;">
</select>
</td>
<td style="width:50px;text-align:center;">
<span title="<?php echo __('Remove tag from the list of tags to block');?>" role="button" tabindex="0" aria-label="<?php echo __('Remove tag from the list of tags to block');?>" class="btn btn-inverse" id="tagspushRightLeft" style="padding:2px;" onClick="serverRuleMoveFilter('push', 'tags', 'Right', 'Middle');">&lt;&lt;</span>
<span title="<?php echo __('Move tag to the list of tags to block');?>" role="button" tabindex="0" aria-label="<?php echo __('Move tag to the list of tags to block');?>" class="btn btn-inverse" id="tagspushRightRight" style="padding:2px;" onClick="serverRuleMoveFilter('push', 'tags', 'Middle', 'Right');">&gt;&gt;</span>
</td>
<td style="width:120px;">
<p style="color:red;font-weight:bold;"><?php echo __('Blocked Tags (AND NOT)');?></p>
<select id="tagspushRightValues" size="5" multiple style="width:185px;"></select>
</td>
</tr>
<tr>
<td class="bold green center" style="padding-bottom:15px;padding-top:15px;"><?php echo __('AND');?></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td class="bold red center" style="padding-bottom:15px;padding-top:15px;"><?php echo __('AND NOT');?></td>
</tr>
<tr>
<td style="width:120px;">
<p style="color:green;font-weight:bold;"><?php echo __('Allowed Orgs (OR)');?></p>
<select id="orgspushLeftValues" size="5" multiple style="width:185px;">
</select>
</td>
<td style="width:50px;text-align:center;">
<span title="<?php echo __('Move organisation to the list of organisations to allow');?>" role="button" tabindex="0" aria-label="<?php echo __('Move organisation to the list of organisations to allow');?>" class="btn btn-inverse" id="orgspushLeftLeft" onClick="serverRuleMoveFilter('push', 'orgs', 'Middle', 'Left');" style="padding:2px;">&lt;&lt;</span>
<span title="<?php echo __('Remove organisation from the list of organisations to allow');?>" role="button" tabindex="0" aria-label="<?php echo __('Remove organisation from the list of organisations to allow');?>" class="btn btn-inverse" id="orgspushLeftRight" onClick="serverRuleMoveFilter('push', 'orgs', 'Left', 'Middle');" style="padding:2px;">&gt;&gt;</span>
</td>
<td style="width:120px;">
<p style="font-weight:bold;"><?php echo __('Available Organisations');?></p>
<select id="orgspushMiddleValues" size="5" multiple style="width:185px;">
</select>
</td>
<td style="width:50px;text-align:center;">
<span title="<?php echo __('Remove organisation from the list of organisations to block');?>" role="button" tabindex="0" aria-label="<?php echo __('Remove organisation from the list of organisations to block');?>" class="btn btn-inverse" id="orgspushRightLeft" onClick="serverRuleMoveFilter('push', 'orgs', 'Right', 'Middle');" style="padding:2px;">&lt;&lt;</span>
<span title="<?php echo __('Move organisation to the list of organisations to block');?>" role="button" tabindex="0" aria-label="<?php echo __('Move organisation to the list of organisations to block');?>" class="btn btn-inverse" id="orgspushRightRight" onClick="serverRuleMoveFilter('push', 'orgs', 'Middle', 'Right');" style="padding:2px;">&gt;&gt;</span>
</td>
<td style="width:120px;">
<p style="color:red;font-weight:bold;"><?php echo __('Blocked Orgs (AND NOT)');?></p>
<select id="orgspushRightValues" size="5" multiple style="width:185px;"></select>
</td>
</tr>
</table>
</div>
<table>
<tr>
<td style="vertical-align:top">
<span id="PromptYesButton" class="btn btn-primary" onClick="submitServerRulePopulateTagPicklistValues('push');"><?php echo __('Update');?></span>
</td>
<td style="width:540px;">
</td>
<td style="vertical-align:top;">
<span class="btn btn-inverse" id="PromptNoButton" onClick="serverRuleCancel();"><?php echo __('Cancel');?></span>
</td>
</tr>
</table>
</div>
<div style="display: flex; flex-direction: column;" class="server-rule-container-push">
<?php
$tagAllowRules = [];
$tagBlockRules = [];
$orgAllowRules = [];
$orgBlockRules = [];
if (!empty($ruleObject)) {
$tagAllowRules = mapIDsToObject($allTags, $ruleObject['tags']['OR']);
$tagBlockRules = mapIDsToObject($allTags, $ruleObject['tags']['NOT']);
$orgAllowRules = mapIDsToObject($allOrganisations, $ruleObject['orgs']['OR']);
$orgBlockRules = mapIDsToObject($allOrganisations, $ruleObject['orgs']['NOT']);
}
function mapIDsToObject($data, $ids) {
$result = [];
foreach ($ids as $id) {
foreach ($data as $i => $entry) {
if ($id == $entry['id']) {
$result[] = $entry;
unset($data[$i]);
break;
}
}
}
return $result;
}
?>
<?php
echo $this->element('serverRuleElements/rules_widget', [
'scope' => 'tag',
'scopeI18n' => __('tag'),
'technique' => 'push',
'options' => $allTags,
'initAllowOptions' => $tagAllowRules,
'initBlockOptions' => $tagBlockRules
]);
?>
<div style="display: flex;">
<h4 class="bold green" style=""><?= __('AND');?></h4>
<h4 class="bold red" style="margin-left: auto;"><?= __('AND NOT');?></h4>
</div>
<?php
echo $this->element('serverRuleElements/rules_widget', [
'scope' => 'org',
'scopeI18n' => __('org'),
'technique' => 'push',
'options' => $allOrganisations,
'initAllowOptions' => $orgAllowRules,
'initBlockOptions' => $orgBlockRules,
'disableFreeText' => true
]);
?>
<div style="height: 50px;"></div>
</div>

View File

@ -0,0 +1,224 @@
<?php
$seed = rand();
?>
<div>
<div style="display: flex;" class="rules-widget-container container-seed-<?= $seed ?> scope-<?= Inflector::pluralize(h($scope)) ?>" data-funname="initRuleWidgetPicker<?= $seed ?>">
<div style="flex-grow: 1;">
<div class="bold green" style="display: flex; align-items: center;">
<?= __('Allowed %s (OR)', Inflector::pluralize(h($scopeI18n)));?>
<i
class="useCursorPointer <?= $this->FontAwesome->getClass('trash') ?>"
style="margin-left: auto;"
title="<?= __('Delete selected rules') ?>"
onClick="<?= sprintf("handleDeleteButtonClick('%s', this); ", 'rules-allow') ?>"
></i>
</div>
<select
id="<?= sprintf('%s%sLeftValues', Inflector::pluralize(h($scope)), h($technique)) ?>"
size="6" multiple
style="margin-bottom: 0; width: 100%; overflow-x: auto;" class="rules-select-data rules-allow"
>
<?php foreach($initAllowOptions as $option): ?>
<?php if(is_array($option)): ?>
<option value="<?= !empty($optionNoValue) ? h($option['name']) : h($option['id']) ?>"><?= h($option['name']) ?></option>
<?php else: ?>
<option value="<?= h($option) ?>"><?= h($option) ?></option>
<?php endif; ?>
<?php endforeach; ?>
</select>
</div>
<div style="display: flex; margin: 0 0.5em; flex-shrink: 1; padding-top: 20px;">
<div style="display: flex; flex-direction: column;">
<?php if(!isset($disableFreeText) || !$disableFreeText): ?>
<div class="input-prepend input-append">
<button
class="btn"
type="button"
title="<?= __('Move %s to the list of %s to allow', h($scopeI18n), Inflector::pluralize(h($scopeI18n)));?>"
aria-label="<?= __('Move %s to the list of %s to allow', h($scopeI18n), Inflector::pluralize(h($scopeI18n)));?>"
role="button" tabindex="0"
onClick="<?= sprintf("handleFreetextButtonClick('%s', this); ", 'rules-allow') ?>"
>
<i class="<?= $this->FontAwesome->getClass('caret-left') ?>"></i>
</button>
<input type="text" style="" placeholder="<?= sprintf('Freetext %s name', h($scopeI18n)) ?>">
<button
class="btn"
type="button"
title="<?= __('Move %s to the list of %s to block', h($scopeI18n), Inflector::pluralize(h($scopeI18n)));?>"
aria-label="<?= __('Move %s to the list of %s to block', h($scopeI18n), Inflector::pluralize(h($scopeI18n)));?>"
role="button" tabindex="0"
onClick="<?= sprintf("handleFreetextButtonClick('%s', this); ", 'rules-block') ?>"
>
<i class="<?= $this->FontAwesome->getClass('caret-right') ?>"></i>
</button>
</div>
<?php endif; ?>
<?php if(!empty($options) || $allowEmptyOptions): ?>
<div class="input-prepend input-append">
<button
class="btn"
type="button"
title="<?= __('Move %s to the list of %s to allow', h($scopeI18n), Inflector::pluralize(h($scopeI18n)));?>"
aria-label="<?= __('Move %s to the list of %s to allow', h($scopeI18n), Inflector::pluralize(h($scopeI18n)));?>"
role="button" tabindex="0"
onClick="<?= sprintf("handlePickerButtonClick('%s', this); ", 'rules-allow') ?>"
>
<i class="<?= $this->FontAwesome->getClass('caret-left') ?>"></i>
</button>
<select
class="rules-select-picker rules-select-picker-<?= h($scope) ?>"
multiple
placeholder="<?= sprintf('%s name', h($scopeI18n)) ?>"
>
<?php foreach($options as $option): ?>
<?php if(is_array($option)): ?>
<option value="<?= !empty($optionNoValue) ? h($option['name']) : h($option['id']) ?>"><?= h($option['name']) ?></option>
<?php else: ?>
<option value="<?= h($option) ?>"><?= h($option) ?></option>
<?php endif; ?>
<?php endforeach; ?>
</select>
<button
class="btn"
type="button"
title="<?= __('Move %s to the list of %s to block', h($scopeI18n), Inflector::pluralize(h($scopeI18n)));?>"
aria-label="<?= __('Move %s to the list of %s to block', h($scopeI18n), Inflector::pluralize(h($scopeI18n)));?>"
role="button" tabindex="0"
onClick="<?= sprintf("handlePickerButtonClick('%s', this); ", 'rules-block') ?>"
>
<i class="<?= $this->FontAwesome->getClass('caret-right') ?>"></i>
</button>
</div>
<?php endif; ?>
</div>
</div>
<div style="flex-grow: 1;">
<div class="bold red" style="display: flex; align-items: center;">
<?php echo __('Blocked %s (AND NOT)', Inflector::pluralize(h($scopeI18n)));?>
<i
class="useCursorPointer <?= $this->FontAwesome->getClass('trash') ?>"
style="margin-left: auto;"
title="<?= __('Delete selected rules') ?>"
onClick="<?= sprintf("handleDeleteButtonClick('%s', this); ", 'rules-block') ?>"
></i>
</div>
<select
id="<?= sprintf('%s%sRightValues', Inflector::pluralize(h($scope)), h($technique)) ?>"
size="6" multiple
style="margin-bottom: 0; width: 100%; overflow-x: auto;" class="rules-select-data rules-block"
>
<?php foreach($initBlockOptions as $option): ?>
<?php if(is_array($option)): ?>
<option value="<?= !empty($optionNoValue) ? h($option['name']) : h($option['id']) ?>"><?= h($option['name']) ?></option>
<?php else: ?>
<option value="<?= h($option) ?>"><?= h($option) ?></option>
<?php endif; ?>
<?php endforeach; ?>
</select>
</div>
</div>
</div>
<script>
function initRuleWidgetPicker<?= $seed ?>() {
$('.container-seed-<?= $seed ?> select.rules-select-picker').chosen()
$('.container-seed-<?= $seed ?> select.rules-select-data').keydown(function(evt) {
var $select = $(this)
var $pickerSelect = $select.closest('.rules-widget-container').find('select.rules-select-picker')
if (evt.keyCode === 46) { // <DELETE>
deleteSelectedRules($select, $pickerSelect)
}
});
rebuildRules($('.container-seed-<?= $seed ?>'))
}
function deleteSelectedRules($select, $pickerSelect) {
$select.find(":selected").each(function() {
var $item = $(this)
if (!getValuesFromSelect($pickerSelect).includes($item.val())) {
$pickerSelect.append($('<option/>', {
value: $item.val(),
text : $item.text()
}))
}
$item.remove()
})
$pickerSelect.trigger('chosen:updated')
rebuildRules($select.closest('.rules-widget-container'))
}
function handleDeleteButtonClick(targetClass, clicked) {
var $select = $(clicked).closest('.rules-widget-container').find('select.' + targetClass)
var $pickerSelect = $select.closest('.rules-widget-container').find('select.rules-select-picker')
deleteSelectedRules($select, $pickerSelect)
}
function handleFreetextButtonClick(targetClass, clicked) {
var $target = $(clicked).closest('.rules-widget-container').find('select.' + targetClass)
var $input = $(clicked).parent().find('input');
addItemToSelect($target, $input.val())
$input.val('')
}
function handlePickerButtonClick(targetClass, clicked) {
var $select = $(clicked).parent().find('select');
var values = $select.val()
$select.children().each(function() {
if (values.includes($(this).val())) {
var $target = $select.closest('.rules-widget-container').find('select.' + targetClass)
moveItemToSelect($target, $(this))
}
});
$select.trigger('chosen:updated')
}
function moveItemToSelect($target, $source) {
if (!getValuesFromSelect($target).includes($source.val())) {
$target.append($('<option/>', {
value: $source.val(),
text : $source.text()
}));
}
$source.remove()
rebuildRules($target.closest('.rules-widget-container'))
}
function addItemToSelect($target, data) {
if (!getValuesFromSelect($target).includes(data)) {
$target.append($('<option/>', {
value: data,
text : data
}));
}
rebuildRules($target.closest('.rules-widget-container'))
}
function getValuesFromSelect($select) {
var values = []
$select.find('option').each(function() {
values.push($(this).val())
})
return values
}
function rebuildRules($ruleContainer) {
var tmpRules = {}
var $selectAllow = $ruleContainer.find('select.rules-allow')
var $selectBlock = $ruleContainer.find('select.rules-block')
tmpRules['OR'] = getValuesFromSelect($selectAllow)
tmpRules['NOT'] = getValuesFromSelect($selectBlock)
$ruleContainer.data('rules', tmpRules)
}
</script>
<style>
.rules-widget-container.container-seed-<?= $seed ?> .chosen-container .chosen-drop {
width: fit-content;
border-top: 1px solid #aaa;
}
.rules-widget-container.container-seed-<?= $seed ?> .chosen-container .search-choice > span {
white-space: normal;
}
</style>

View File

@ -221,7 +221,29 @@
echo $this->Form->end();
?>
<div id="hiddenRuleForms">
<?php echo $this->element('serverRuleElements/pull'); ?>
<?php
$modalData = [
'data' => [
'title' => __('Set PULL rules'),
'content' => [
[
'html' => $this->element('serverRuleElements/pull', [
'context' => 'feeds',
'allTags' => $tags,
'allOrganisations' => $orgs,
])
]
],
],
'type' => 'xl',
'class' => 'pull-rule-modal',
'confirm' => [
'title' => __('Update'),
'onclick' => "serverRulesUpdateState('pull');"
]
];
echo $this->element('genericElements/infoModal', $modalData);
?>
</div>
</div>
<?php
@ -237,7 +259,15 @@ var modelContext = 'Feed';
$(document).ready(function() {
feedDistributionChange();
$("#pull_modify").click(function() {
serverRuleFormActivate('pull');
$('#genericModal.pull-rule-modal').modal().on('shown', function () {
var $containers = $(this).find('.rules-widget-container')
$containers.each(function() {
var initFun = $(this).data('funname');
if (typeof window[initFun] === 'function') {
window[initFun]()
}
})
});
});
$("#FeedDistribution").change(function() {
feedDistributionChange();

View File

@ -215,13 +215,39 @@
<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>
<span id="pull_orgs_OR" style="display:none;"><?php echo __('Events with the following organisations allowed');?>: <span id="pull_orgs_OR_text" style="color:green;"></span><br /></span>
<span id="pull_orgs_NOT" style="display:none;"><?php echo __('Events with the following organisations blocked');?>: <span id="pull_orgs_NOT_text" style="color:red;"></span><br /></span>
<span id="pull_url_params" style="display:none;"><?php echo __('Additional parameters: ');?><span id="pull_url_params_text" style="color:green;"></span><br /></span>
<span id="pull_modify" class="btn btn-inverse" style="line-height:10px; padding: 4px 4px;"><?php echo __('Modify');?></span><br /><br />
<?php
echo $this->Form->button(__('Edit'), array('class' => 'btn btn-primary'));
echo $this->Form->end();
?>
<div id="hiddenRuleForms">
<?php echo $this->element('serverRuleElements/pull'); ?>
<?php
$pullRules = json_decode($feed['Feed']['rules'], true);
$pullRules['url_params'] = json_decode($pullRules['url_params'], true);
$modalData = [
'data' => [
'title' => __('Set PULL rules'),
'content' => [
[
'html' => $this->element('serverRuleElements/pull', [
'context' => 'feeds',
'allTags' => $tags,
'allOrganisations' => $orgs,
'ruleObject' => $pullRules
])
]
],
],
'type' => 'xl',
'class' => 'pull-rule-modal',
'confirm' => [
'title' => __('Update'),
'onclick' => "serverRulesUpdateState('pull');"
]
];
echo $this->element('genericElements/infoModal', $modalData);
?>
</div>
</div>
<?php
@ -252,10 +278,20 @@ var orgs = [];
$(document).ready(function() {
rules = convertServerFilterRules(rules);
serverRulePopulateTagPicklist();
feedDistributionChange();
$("#pull_modify").click(function() {
serverRuleFormActivate('pull');
$('#genericModal.pull-rule-modal').modal().on('shown', function () {
var $containers = $(this).find('.rules-widget-container')
$containers.each(function() {
var initFun = $(this).data('funname');
if (typeof window[initFun] === 'function') {
window[initFun]()
}
})
if (typeof window['cm'] === "object") {
window['cm'].refresh()
}
});
});
$("#FeedDistribution").change(function() {
feedDistributionChange();

View File

@ -1,206 +0,0 @@
<div class="servers form">
<?php echo $this->Form->create('Server', array('type' => 'file'));?>
<fieldset>
<legend><?php echo __('Add Server');?></legend>
<?php
echo '<h4 class="input clear">' . __('Instance identification') . '</h4>';
echo $this->Form->input('url', array(
'label' => __('Base URL'),
));
echo $this->Form->input('name', array(
'label' => __('Instance name'),
));
if (!empty($host_org_id)):
?>
<div id="InternalDiv" class = "input clear hidden" style="width:100%;">
<hr />
<p class="red" style="width:50%;"><?php echo __('You can set this instance up as an internal instance by checking the checkbox below. This means that any synchronisation between this instance and the remote will not be automatically degraded as it would in a normal synchronisation scenario. Please make sure that you own both instances and that you are OK with this otherwise dangerous change.');?></p>
<?php
echo $this->Form->input('internal', array(
'label' => __('Internal instance'),
'type' => 'checkbox',
));
?>
</div>
<?php
endif;
?>
<div class="input clear" style="width:100%;">
<hr />
<h4><?php echo __('Instance ownership and credentials'); ?></h4>
<p class="red"><?php echo __('Information about the organisation that will receive the events, typically the remote instance\'s host organisation.');?></p>
</div>
<div class = "input clear"></div>
<?php
if ($isSiteAdmin):
echo $this->Form->input('organisation_type', array(
'label' => __('Remote Sync Organisation Type'),
'options' => $organisationOptions,
));
?>
<div id="ServerExternalContainer" class="input select hiddenField" style="display:none;">
<label for="ServerExternal"><?php echo __('External Organisation');?></label>
<select id="ServerExternal">
<?php
foreach ($externalOrganisations as $k => $v) {
echo sprintf(
'<option value="%s" %s>%s</option>',
h($k),
(!empty($this->request->data['Server']['remote_org_id']) && $k == $this->request->data['Server']['remote_org_id']) ? 'selected' : '',
h($v)
);
}
?>
</select>
</div>
<div id="ServerLocalContainer" class="input select hiddenField" style="display:none;">
<label for="ServerLocal"><?php echo __('Owner of remote instance');?></label>
<select id="ServerLocal">
<?php foreach ($localOrganisations as $k => $v) echo '<option value="' . $k . '">' . h($v) . '</option>'; ?>
</select>
</div>
<div id="ServerExternalNameContainer" class="input select hiddenField" style="display:none;">
<label for="ServerExternalName"><?php echo __('Remote Organisation\'s Name');?></label>
<input type="text" id="ServerExternalName" <?php if (isset($this->request->data['Server']['external_name'])) echo 'value="' . $this->request->data['Server']['external_name'] . '"';?>>
</div>
<div id="ServerExternalUuidContainer" class="input select hiddenField" style="display:none;">
<label for="ServerExternalUuid"><?php echo __('Remote Organisation\'s UUID');?></label>
<input type="text" id="ServerExternalUuid" <?php if (isset($this->request->data['Server']['external_uuid'])) echo 'value="' . $this->request->data['Server']['external_uuid'] . '"';?>>
</div>
<div class = "input clear"></div>
<?php
endif;
echo '<div class = "input clear" style="width:100%;"><hr /></div>';
echo sprintf(
'<div id="AuthkeyContainer"><p class="red clear" style="width:50%%;">%s</p>%s</div>',
__('Ask the owner of the remote instance for a sync account on their instance, log into their MISP using the sync user\'s credentials and retrieve your API key by navigating to Global actions -> My profile. This key is used to authenticate with the remote instance.'),
$this->Form->input('authkey', array('autocomplete' => 'off'))
);
echo '<div class = "input clear" style="width:100%;"><hr /></div>';
echo '<h4 class="input clear">' . __('Enabled synchronisation methods') . '</h4>';
echo $this->Form->input('push', array());
echo $this->Form->input('pull', array());
echo $this->Form->input('push_sightings', array());
echo $this->Form->input('push_galaxy_clusters', array());
echo $this->Form->input('pull_galaxy_clusters', array());
echo $this->Form->input('caching_enabled', array());
echo '<div class = "input clear" style="width:100%;"><hr /></div>';
echo $this->Form->input('unpublish_event', array(
'type' => 'checkbox',
));
echo '<div class="input clear"></div>';
echo $this->Form->input('publish_without_email', array(
'type' => 'checkbox',
));
echo '<div class="input clear"></div>';
echo $this->Form->input('self_signed', array(
'type' => 'checkbox',
));
echo '<div class="input clear"></div>';
echo $this->Form->input('skip_proxy', array('type' => 'checkbox', 'label' => 'Skip proxy (if applicable)'));
echo $this->Form->input('Server.submitted_cert', array(
'label' => '<b>' . __('Server certificate file') . '</b>',
'type' => 'file',
'div' => 'clear'
));
echo $this->Form->input('Server.submitted_client_cert', array(
'label' => '<b>' . __('Client certificate file') . '</b>',
'type' => 'file',
'div' => 'clear'
));
?>
<br /><b><?php echo __('Push rules:');?></b><br />
<span id="push_tags_OR" style="display:none;"><?php echo __('Events with the following tags allowed: ');?><span id="push_tags_OR_text" style="color:green;"></span><br /></span>
<span id="push_tags_NOT" style="display:none;"><?php echo __('Events with the following tags blocked: ');?><span id="push_tags_NOT_text" style="color:red;"></span><br /></span>
<span id="push_orgs_OR" style="display:none;"><?php echo __('Events with the following organisations allowed: ');?><span id="push_orgs_OR_text" style="color:green;"></span><br /></span>
<span id="push_orgs_NOT" style="display:none;"><?php echo __('Events with the following organisations blocked: ');?><span id="push_orgs_NOT_text" style="color:red;"></span><br /></span>
<span id="push_modify" class="btn btn-inverse" style="line-height:10px; padding: 4px 4px;"><?php echo __('Modify');?></span><br /><br />
<b><?php echo __('Pull 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>
<span id="pull_orgs_OR" style="display:none;"><?php echo __('Events with the following organisations allowed: ');?><span id="pull_orgs_OR_text" style="color:green;"></span><br /></span>
<span id="pull_orgs_NOT" style="display:none;"><?php echo __('Events with the following organisations blocked: ');?><span id="pull_orgs_NOT_text" style="color:red;"></span><br /></span>
<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));
echo $this->Form->input('json', array('style' => 'display:none;', 'label' => false, 'div' => false));
?>
</fieldset>
<span role="button" tabindex="0" aria-label="<?php echo __('Submit');?>" title="<?php echo __('Submit');?>" class="btn btn-primary" onClick="serverSubmitForm('Add');"><?php echo __('Submit');?></span>
<?php
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('/genericElements/SideMenu/side_menu', array('menuList' => 'sync', 'menuItem' => 'add'));
?>
<script type="text/javascript">
//
var formInfoValues = {
'ServerUrl' : "<?php echo __('The base-url to the external server you want to sync with. Example: https://foo.sig.mil.be');?>",
'ServerName' : "<?php echo __('A name that will make it clear to your users what this instance is. For example: Organisation A\'s instance');?>",
'ServerOrganization' : "<?php echo __('The organization having the external server you want to sync with. Example: BE');?>",
'ServerAuthkey' : "<?php echo __('You can find the authentication key on your profile on the external server.');?>",
'ServerPush' : "<?php echo __('Allow the upload of events and their attributes.');?>",
'ServerPull' : "<?php echo __('Allow the download of events and their attributes from the server.');?>",
'ServerUnpublishEvent' : '<?php echo __('Unpublish new event (working with Pull event).');?>',
'ServerPublishWithoutEmail' : '<?php echo __('Publish new event without email (working with Push event).');?>',
'ServerSubmittedCert' : "<?php echo __('You can also upload a certificate file if the instance you are trying to connect to has its own signing authority. (*.pem)');?>",
'ServerSelfSigned' : "<?php echo __('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": {"OR":[], "NOT":[]}, "orgs": {"OR":[], "NOT":[]}}, "pull": {"tags": {"OR":[], "NOT":[]}, "orgs": {"OR":[], "NOT":[]}}};
var validOptions = ['pull', 'push'];
var validFields = ['tags', 'orgs'];
var tags = <?php echo json_encode($allTags); ?>;
var orgs = <?php echo json_encode($allOrganisations); ?>;
var host_org_id = "<?php echo h($host_org_id); ?>";
var modelContext = 'Server';
$(document).ready(function() {
serverOrgTypeChange();
$('#ServerOrganisationType').change(function() {
serverOrgTypeChange();
});
<?php
if (!empty($host_org_id)):
?>
serverOwnerOrganisationChange(host_org_id);
$('#ServerOrganisationType, #ServerLocal').change(function() {
serverOwnerOrganisationChange(host_org_id);
});
<?php
endif;
?>
$("#ServerUrl, #ServerOrganization, #ServerName, #ServerAuthkey, #ServerPush, #ServerPull, #ServerUnpublishEvent, #ServerPublishWithoutEmail, #ServerSubmittedCert, #ServerSelfSigned").on('mouseleave', function(e) {
$('#'+e.currentTarget.id).popover('destroy');
});
$("#ServerUrl, #ServerOrganization, #ServerName, #ServerAuthkey, #ServerPush, #ServerPull, #ServerUnpublishEvent, #ServerPublishWithoutEmail, #ServerSubmittedCert, #ServerSelfSigned").on('mouseover', function(e) {
var $e = $(e.target);
$('#'+e.currentTarget.id).popover('destroy');
$('#'+e.currentTarget.id).popover({
trigger: 'focus',
placement: 'right',
content: formInfoValues[e.currentTarget.id],
}).popover('show');
});
serverRulePopulateTagPicklist();
$("#push_modify").click(function() {
serverRuleFormActivate('push');
});
$("#pull_modify").click(function() {
serverRuleFormActivate('pull');
});
});
</script>

View File

@ -176,8 +176,43 @@
?>
</div>
<div id="hiddenRuleForms">
<?php echo $this->element('serverRuleElements/push'); ?>
<?php echo $this->element('serverRuleElements/pull'); ?>
<?php
$pushRules = $pullRules = [];
if (!empty($server)) {
$pushRules = json_decode($server['Server']['push_rules'], true);
$pullRules = json_decode($server['Server']['pull_rules'], true);
$pullRules['url_params'] = json_decode($pullRules['url_params'], true);
}
$modalData = [
'data' => [
'title' => __('Set PUSH rules'),
'content' => [
[
'html' => $this->element('serverRuleElements/push', [
'allTags' => $allTags,
'allOrganisations' => $allOrganisations,
'ruleObject' => $pushRules
])
]
],
],
'type' => 'xl',
'class' => 'push-rule-modal',
'confirm' => [
'title' => __('Update'),
'onclick' => "serverRulesUpdateState('push');"
]
];
echo $this->element('genericElements/infoModal', $modalData);
$modalData['data']['title'] = __('Set PULL rules');
$modalData['data']['content'][0]['html'] = $this->element('serverRuleElements/pull', [
'context' => 'servers',
'ruleObject' => $pullRules
]);
$modalData['class'] = 'pull-rule-modal';
$modalData['confirm']['onclick'] = "serverRulesUpdateState('pull');";
echo $this->element('genericElements/infoModal', $modalData);
?>
</div>
<?php
echo $this->element('/genericElements/SideMenu/side_menu', array('menuList' => 'sync', 'menuItem' => $this->action));
@ -239,12 +274,30 @@ $(document).ready(function() {
}).popover('show');
});
rules = convertServerFilterRules(rules);
serverRulePopulateTagPicklist();
$("#push_modify").click(function() {
serverRuleFormActivate('push');
$('#genericModal.push-rule-modal').modal().on('shown', function () {
var $containers = $(this).find('.rules-widget-container')
$containers.each(function() {
var initFun = $(this).data('funname');
if (typeof window[initFun] === 'function') {
window[initFun]()
}
})
});
});
$("#pull_modify").click(function() {
serverRuleFormActivate('pull');
$('#genericModal.pull-rule-modal').modal().on('shown', function () {
var $containers = $(this).find('.rules-widget-container')
$containers.each(function() {
var initFun = $(this).data('funname');
if (typeof window[initFun] === 'function') {
window[initFun]()
}
})
if (typeof window['cm'] === "object") {
window['cm'].refresh()
}
});
});
$('#add_cert_file').click(function() {

View File

@ -51,7 +51,9 @@ foreach ($servers as $server):
$ruleDescription[$syncOption] .= '<span class=\'bold\'>' . ucfirst($fieldOption) . ' ' . $typeData['text'] . '</span>: <span class=\'' . $typeData['colour'] . '\'>';
foreach ($rules[$syncOption][$fieldOption][$typeOption] as $k => $temp) {
if ($k != 0) $ruleDescription[$syncOption] .= ', ';
if ($syncOption === 'push') $temp = $collection[$fieldOption][$temp];
if ($syncOption === 'push') {
$temp = !empty($collection[$fieldOption][$temp]) ? $collection[$fieldOption][$temp] : $temp;
}
$ruleDescription[$syncOption] .= h($temp);
}
$ruleDescription[$syncOption] .= '</span><br>';

@ -1 +1 @@
Subproject commit 892ac72da4efc81531003102d5b3af446ebb44a5
Subproject commit 52b3824981309063f1d3e44d7a7cf3f75f110070

View File

@ -3506,7 +3506,9 @@ function serverRuleUpdate() {
rules[type][field][status].forEach(function(item) {
if (t.length > 0) t += ', ';
if (type === 'pull') t += item;
else t += indexedList[item];
else {
t += indexedList[item] !== undefined ? indexedList[item] : item;
}
});
$('#' + type + '_' + field + '_' + status + '_text').text(t);
} else {
@ -3526,18 +3528,6 @@ function serverRuleUpdate() {
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() {
validOptions.forEach(function(type) {
if ($('#Server' + type.ucfirst() + "Rules").length) {
@ -3548,95 +3538,18 @@ function serverRuleGenerateJSON() {
});
}
function serverRulePopulateTagPicklist() {
var fields = ["tags", "orgs"];
var target = "";
fields.forEach(function(field) {
target = "";
window[field].forEach(function(element) {
if ($.inArray(element.id, rules["push"][field]["OR"]) != -1) target = "#" + field + "pushLeftValues";
else if ($.inArray(element.id, rules["push"][field]["NOT"]) != -1) target = "#" + field + "pushRightValues";
else target = "#" + field + "pushMiddleValues";
$(target).append($('<option/>', {
value: element.id,
text : element.name
}));
});
target = "#" + field + "pullLeftValues";
rules["pull"][field]["OR"].forEach(function(t) {
$(target).append($('<option/>', {
value: t,
text : t
}));
});
target = "#" + field + "pullRightValues";
rules["pull"][field]["NOT"].forEach(function(t) {
$(target).append($('<option/>', {
value: t,
text : t
}));
});
});
$('#urlParams').val(rules["pull"]["url_params"]);
}
function submitServerRulePopulateTagPicklistValues(context) {
function serverRulesUpdateState(context) {
var $rootContainer = $('.server-rule-container-' + context)
validFields.forEach(function(field) {
rules[context][field]["OR"] = [];
$("#" + field + context + "LeftValues option").each(function() {
rules[context][field]["OR"].push($(this).val());
});
rules[context][field]["NOT"] = [];
$("#" + field + context + "RightValues option").each(function() {
rules[context][field]["NOT"].push($(this).val());
});
});
var $fieldContainer = $rootContainer.find('.scope-' + field)
rules[context][field] = $fieldContainer.data('rules')
})
if (context === 'pull') {
rules[context]["url_params"] = $('#urlParams').val();
rules[context]["url_params"] = $rootContainer.find('textarea#urlParams').val();
}
$('#server_' + context + '_rule_popover').fadeOut();
$('#gray_out').fadeOut();
serverRuleUpdate();
}
// type = pull/push, field = tags/orgs, from = Left/Middle/Right, to = Left/Middle/Right
function serverRuleMoveFilter(type, field, from, to) {
var opposites = {"Left": "Right", "Right": "Left"};
// first fetch the value
var value = "";
if (type == "pull" && from == "Middle") {
var doInsert = true;
value = $("#" + field + type + "NewValue").val();
if (value.length !== 0 && value.trim()) {
$("#" + field + type + to + "Values" + " option").each(function() {
if (value == $(this).val()) doInsert = false;
});
$("#" + field + type + opposites[to] + "Values" + " option").each(function() {
if (value == $(this).val()) $(this).remove();
});
if (doInsert) {
$("#" + field + type + to + "Values").append($('<option/>', {
value: value,
text : value
}));
}
}
$("#" + field + type + "NewValue").val('');
} else {
$("#" + field + type + from + "Values option:selected").each(function () {
if (type != "pull" || to != "Middle") {
value = $(this).val();
text = $(this).text();
$("#" + field + type + to + "Values").append($('<option/>', {
value: value,
text : text
}));
}
$(this).remove();
});
}
}
function syncUserSelected() {
if ($('#UserRoleId :selected').val() in syncRoles) {
$('#syncServers').show();