fix: Fixes to the internal server setup

- Only allow enabling internal mode if the host organisation is set and it is chosen as the remote organisation when adding the server sync
- This ensures that internal sync only happens when the same organisation owns both instances
pull/1486/head
iglocska 2016-08-28 21:56:56 +02:00
parent cdf890cfc6
commit 48d46c1b0c
5 changed files with 26 additions and 8 deletions

View File

@ -45,7 +45,7 @@ class AppController extends Controller {
public $helpers = array('Utility');
private $__jsVersion = '2.4.50';
private $__jsVersion = '2.4.51';
public $phpmin = '5.5.9';
public $phprec = '5.6.0';

View File

@ -257,6 +257,7 @@ class ServersController extends AppController {
$allTags = array();
foreach ($temp as $t) $allTags[] = array('id' => $t['Tag']['id'], 'name' => $t['Tag']['name']);
$this->set('allTags', $allTags);
$this->set('host_org_id', Configure::read('MISP.host_org_id'));
}
public function edit($id = null) {
@ -386,6 +387,7 @@ class ServersController extends AppController {
foreach ($temp as $t) $allTags[] = array('id' => $t['Tag']['id'], 'name' => $t['Tag']['name']);
$this->set('allTags', $allTags);
$this->set('server', $s);
$this->set('host_org_id', Configure::read('MISP.host_org_id'));
}
public function delete($id = null) {

View File

@ -11,18 +11,17 @@
));
if (!empty($host_org_id)):
?>
<div class = "input clear" style="width:100%;">
<div id="InternalDiv" class = "input clear" style="width:100%;">
<hr />
<p class="red" style="width:50%;">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
<?php
echo $this->Form->input('internal', array(
'label' => 'Internal instance',
'type' => 'checkbox',
'disabled' => empty($host_org_id) ? 1 : 0
));
?>
</div>
<?php
<?php
endif;
?>
<div class="input clear" style="width:100%;">
@ -140,6 +139,7 @@ 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() {
@ -169,5 +169,9 @@ $(document).ready(function() {
$("#pull_modify").click(function() {
serverRuleFormActivate('pull');
});
$('#ServerOrganisationType, #ServerLocal').change(function() {
serverOwnerOrganisationChange(host_org_id);
});
});
</script>

View File

@ -9,16 +9,15 @@
echo $this->Form->input('name', array(
'label' => 'Instance name',
));
if (!empty($host_org_id)):
if (!empty($host_org_id) && $this->request->data['Server']['remote_org_id'] == $host_org_id):
?>
<div class = "input clear" style="width:100%;">
<div id="InternalDiv" class = "input clear" style="width:100%;">
<hr />
<p class="red" style="width:50%;">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. This also requires that the current instance's host organisation and the remote sync organisation are the same.</p>
<?php
echo $this->Form->input('internal', array(
'label' => 'Internal instance',
'type' => 'checkbox',
'disabled' => empty($host_org_id) ? 1 : 0
));
?>
</div>
@ -184,6 +183,7 @@ var tags = <?php echo json_encode($allTags); ?>;
var orgs = <?php echo json_encode($allOrganisations); ?>;
var delete_cert = false;
var delete_client_cert = false;
var host_org_id = "<?php echo h($host_org_id); ?>";
var modelContext = 'Server';
$(document).ready(function() {
@ -236,5 +236,9 @@ $(document).ready(function() {
$('#serverEditClientCertValue').html('<span class="green bold">Not set.</span>');
$('#ServerDeleteClientCert').prop('checked', true);
});
$('#ServerOrganisationType, #ServerLocal').change(function() {
serverOwnerOrganisationChange(host_org_id);
});
});
</script>

View File

@ -2489,3 +2489,11 @@ $(".queryPopover").click(function() {
});
});
function serverOwnerOrganisationChange(host_org_id) {
if ($('#ServerOrganisationType').val() == "0" && $('#ServerLocal').val() == host_org_id) {
$('#InternalDiv').show();
} else {
$('#ServerInternal').prop("checked", false);
$('#InternalDiv').hide();
}
}