Progress on the sync

- pull from 2.3 -> 2.4 should work correctly now
pull/762/head
iglocska 2015-09-21 14:55:40 +02:00
parent 3ad7d4b441
commit 656a391223
8 changed files with 57 additions and 13 deletions

View File

@ -114,6 +114,7 @@ class ServersController extends AppController {
}
}
if (!$fail) {
$this->request->data['Server']['org_id'] = $this->Auth->user('org_id');
if ($this->Server->save($this->request->data)) {
if (isset($this->request->data['Server']['submitted_cert']) && $this->request->data['Server']['submitted_cert']['size'] != 0) {
$this->__saveCert($this->request->data, $this->Server->id);

View File

@ -1,9 +1,8 @@
<?php
class XMLConverterTool {
public function recursiveEcho($array) {
//debug($array);
$text = "";
foreach ($array as $k => $v) {
if (is_array($array)) foreach ($array as $k => $v) {
if (is_array($v)) {
if (empty($v)) $text .= '<' . $k . '/>';
else {
@ -43,7 +42,10 @@ class XMLConverterTool {
$event['Event']['SharingGroup'][0] = $event['SharingGroup'];
}
if (isset($event['Attribute'])) $event['Event']['Attribute'] = $event['Attribute'];
if (isset($event['ShadowAttribute'])) $event['Event']['ShadowAttribute'] = $event['ShadowAttribute'];
if (isset($event['ShadowAttribute'])) {
$event['Event']['ShadowAttribute'] = $event['ShadowAttribute'];
unset($event['ShadowAttribute']);
}
if (isset($event['RelatedEvent'])) if (isset($event['RelatedEvent'])) $event['Event']['RelatedEvent'] = $event['RelatedEvent'];
// legacy
@ -81,6 +83,8 @@ class XMLConverterTool {
$event['Event']['Attribute'][$key]['ShadowAttribute'][$skey]['value'] = str_replace($toEscape, $escapeWith, $event['Event']['Attribute'][$key]['ShadowAttribute'][$skey]['value']);
$event['Event']['Attribute'][$key]['ShadowAttribute'][$skey]['comment'] = preg_replace ('/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+/u', ' ', $event['Event']['Attribute'][$key]['ShadowAttribute'][$skey]['comment']);
$event['Event']['Attribute'][$key]['ShadowAttribute'][$skey]['comment'] = str_replace($toEscape, $escapeWith, $event['Event']['Attribute'][$key]['ShadowAttribute'][$skey]['comment']);
$event['Event']['Attribute'][$key]['ShadowAttribute'][$skey]['Org'] = array(0 => $event['Event']['Attribute'][$key]['ShadowAttribute'][$skey]['Org']);
$event['Event']['Attribute'][$key]['ShadowAttribute'][$skey]['EventOrg'] = array(0 => $event['Event']['Attribute'][$key]['ShadowAttribute'][$skey]['EventOrg']);
}
}
if (isset($event['Event']['Attribute'][$key]['SharingGroup']['SharingGroupOrg'])) {
@ -107,6 +111,8 @@ class XMLConverterTool {
$event['Event']['ShadowAttribute'][$key]['value'] = str_replace($toEscape, $escapeWith, $event['Event']['ShadowAttribute'][$key]['value']);
$event['Event']['ShadowAttribute'][$key]['comment'] = preg_replace ('/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+/u', ' ', $event['Event']['ShadowAttribute'][$key]['comment']);
$event['Event']['ShadowAttribute'][$key]['comment'] = str_replace($toEscape, $escapeWith, $event['Event']['ShadowAttribute'][$key]['comment']);
$event['Event']['ShadowAttribute'][$key]['Org'] = array(0 => $event['Event']['ShadowAttribute'][$key]['Org']);
$event['Event']['ShadowAttribute'][$key]['EventOrg'] = array(0 => $event['Event']['ShadowAttribute'][$key]['EventOrg']);
}
}

View File

@ -302,7 +302,7 @@ class Event extends AppModel {
),
'Orgc' => array(
'className' => 'Organisation',
'foreignKey' => 'org_id'
'foreignKey' => 'orgc_id'
),
'SharingGroup' => array(
'className' => 'SharingGroup',
@ -1270,6 +1270,8 @@ class Event extends AppModel {
'ShadowAttribute' => array(
'fields' => $fieldsShadowAtt,
'conditions' => array('deleted' => 0),
'Org' => array('fields' => $fieldsOrg),
'EventOrg' => array('fields' => $fieldsOrg)
),
'SharingGroup' => $fieldsSharingGroup[(($user['Role']['perm_site_admin'] || $user['Role']['perm_sync']) ? 1 : 0)],
'EventTag' => array(
@ -1688,9 +1690,14 @@ class Event extends AppModel {
// When we receive an event via REST, we might end up with organisations, sharing groups, tags that we do not know
// or which we need to update. All of that is controller in this method.
private function __captureObjects($data, $user) {
// first we want to see how the creator organisation is encoded
// The options here are either by passing an organisation object along or simply passing a string along
if (isset($data['Event']['Orgc'])) {
$data['Event']['orgc_id'] = $this->Orgc->captureOrg($data['Event']['Orgc'], $user);
unset ($data['Event']['Orgc']);
} else if (isset($data['Event']['orgc'])) {
$data['Event']['orgc_id'] = $this->Orgc->captureOrg($data['Event']['orgc'], $user);
unset($data['Event']['orgc']);
}
if (isset($data['Event']['EventTag'])) {
if (isset($data['Event']['EventTag']['id'])) {
@ -1743,7 +1750,9 @@ class Event extends AppModel {
}
// set these fields if the event is freshly created and not pushed from another instance.
// Moved out of if (!$fromXML), since we might get a restful event without the orgc/timestamp set
if (!isset ($data['Event']['orgc_id'])) $data['Event']['orgc_id'] = $data['Event']['org_id'];
if (!isset($data['Event']['orgc_id']) && !isset($data['Event']['orgc'])) {
$data['Event']['orgc_id'] = $data['Event']['org_id'];
}
if ($fromXml) {
// Workaround for different structure in XML/array than what CakePHP expects
$data = $this->cleanupEventArrayFromXML($data);
@ -1800,7 +1809,7 @@ class Event extends AppModel {
App::import('Component','Auth');
}
$localEvent = $this->find('first', array('conditions' => array('Event.id' => $id), 'recursive' => -1, 'contain' => array('Attribute', 'ThreatLevel', 'ShadowAttribute')));
if (!isset ($data['Event']['orgc_id'])) $data['Event']['orgc_id'] = $data['Event']['org_id'];
if (!isset($data['Event']['orgc_id']) && !isset($data['Event']['orgc'])) $data['Event']['orgc_id'] = $data['Event']['org_id'];
if ($localEvent['Event']['timestamp'] < $data['Event']['timestamp']) {
} else {

View File

@ -85,15 +85,26 @@ class Organisation extends AppModel{
}
public function captureOrg($org, $user) {
if (is_array($org)) {
$conditions = array('uuid' => $org['uuid']);
$uuid = $org['uuid'];
$name = $org['name'];
} else {
$conditions = array('name' => $org);
$uuid = String::uuid();
$name = $org;
}
$existingOrg = $this->find('first', array(
'recursive' => -1,
'conditions' => array('uuid' => $org['uuid'])
'recursive' => -1,
'conditions' => $conditions,
));
if (empty($existingOrg)) {
$this->create();
$organisation = array(
'uuid' => $org['uuid'],
'name' => $org['name'],
'uuid' => $uuid,
'name' => $name,
'local' => 0,
'created_by' => $user['id']
);

View File

@ -950,6 +950,15 @@ class Server extends AppModel {
if ($oldAttribute) $proposal['old_id'] = $oldAttribute['Attribute']['id'];
else $proposal['old_id'] = 0;
}
// check if this is a proposal from an old MISP instance
if (!isset($proposal['org_id']) && isset($proposal['org'])) {
$proposal['Org'] = $proposal['org'];
$proposal['EventOrg'] = $proposal['event_org'];
}
$proposal['org_id'] = $this->Organisation->captureOrg($proposal['Org'], $user);
$proposal['event_org_id'] = $this->Organisation->captureOrg($proposal['EventOrg'], $user);
unset($proposal['Org']);
unset($proposal['EventOrg']);
$shadowAttribute->create();
$shadowAttribute->save($proposal);
}

View File

@ -38,7 +38,15 @@ class ShadowAttribute extends AppModel {
'fields' => '',
'order' => '',
'counterCache' => true
)
),
'Org' => array(
'className' => 'Organisation',
'foreignKey' => 'org_id'
),
'EventOrg' => array(
'className' => 'Organisation',
'foreignKey' => 'event_org_id'
),
);
/**

View File

@ -173,7 +173,7 @@ class SharingGroup extends AppModel {
'SharingGroupServer' => array('fields' => array('id', 'server_id', 'all_orgs')),
)
));
if (empty($sg)) return array();
// if the current server is marked as "all orgs" in the sharing group, just return true
foreach ($sg['SharingGroupServer'] as $sgs) {
if ($sgs['server_id'] == 0) {

View File

@ -28,7 +28,7 @@ $mayPublish = ($isAclPublish && $event['Event']['orgc'] == $me['org']);
<th><?php echo $this->Paginator->sort('title');?></th>
<th><?php echo $this->Paginator->sort('created');?></th>
</tr>
<?php foreach ($list as $item): debug($item);?>
<?php foreach ($list as $item): ?>
<tr>
<td class="short">
<?php