mirror of https://github.com/MISP/MISP
Merge branch '2.4' of github.com:MISP/MISP into 2.4
commit
f52f847445
|
@ -45,6 +45,21 @@ class AdminShell extends AppShell
|
|||
echo PHP_EOL . 'Workers restarted.' . PHP_EOL;
|
||||
}
|
||||
|
||||
public function updateAfterPull() {
|
||||
$this->loadModel('Job');
|
||||
$this->loadModel('Server');
|
||||
$submodule_name = $this->args[0];
|
||||
$jobId = $this->args[1];
|
||||
$userId = $this->args[2];
|
||||
$this->Job->id = $jobId;
|
||||
$result = $this->Server->updateAfterPull($submodule_name, $userId);
|
||||
$this->Job->saveField('progress', 100);
|
||||
$this->Job->saveField('date_modified', date("y-m-d H:i:s"));
|
||||
if ($result) {
|
||||
$this->Job->saveField('message', __('Database updated: ' . $submodule_name));
|
||||
} else {
|
||||
$this->Job->saveField('message', __('Could not update the database: ' . $submodule_name));
|
||||
}
|
||||
public function restartWorker()
|
||||
{
|
||||
if (empty($this->args[0]) || !is_numeric($this->args[0])) {
|
||||
|
|
|
@ -1555,7 +1555,7 @@ class ServersController extends AppController
|
|||
if ($this->request->is('post')) {
|
||||
$request = $this->request->data;
|
||||
$submodule = $request['Server']['submodule'];
|
||||
$res = $this->Server->updateSubmodule($submodule);
|
||||
$res = $this->Server->updateSubmodule($this->Auth->user(), $submodule);
|
||||
return new CakeResponse(array('body'=> json_encode($res), 'type' => 'json'));
|
||||
} else {
|
||||
throw new MethodNotAllowedException();
|
||||
|
|
|
@ -3841,7 +3841,7 @@ class Event extends AppModel
|
|||
}
|
||||
}
|
||||
|
||||
private function __getPrioWorkerIfPossible()
|
||||
public function __getPrioWorkerIfPossible()
|
||||
{
|
||||
$this->ResqueStatus = new ResqueStatus\ResqueStatus(Resque::redis());
|
||||
$workers = $this->ResqueStatus->getWorkers();
|
||||
|
|
|
@ -4648,24 +4648,90 @@ class Server extends AppModel
|
|||
return $status;
|
||||
}
|
||||
|
||||
public function updateSubmodule($submodule_name=false) {
|
||||
public function updateSubmodule($user, $submodule_name=false) {
|
||||
$path = APP . '../';
|
||||
if ($submodule_name == false) {
|
||||
$command = sprintf('cd %s; git submodule update 2>&1', $path);
|
||||
exec($command, $output, $return_code);
|
||||
$output = implode("\n", $output);
|
||||
$res = array('status' => ($return_code==0 ? true : false), 'output' => $output);
|
||||
if ($return_code == 0) { // update all DB
|
||||
$res = array_merge($res, $this->updateDatabaseAfterPullRouter($submodule_name, $user));
|
||||
}
|
||||
} else if ($this->_isAcceptedSubmodule($submodule_name)) {
|
||||
$command = sprintf('cd %s; git submodule update -- %s 2>&1', $path, $submodule_name);
|
||||
exec($command, $output, $return_code);
|
||||
$output = implode("\n", $output);
|
||||
$res = array('status' => ($return_code==0 ? true : false), 'output' => $output);
|
||||
if ($return_code == 0) { // update DB if necessary
|
||||
$res = array_merge($res, $this->updateDatabaseAfterPullRouter($submodule_name, $user));
|
||||
}
|
||||
} else {
|
||||
$res = array('status' => false, 'output' => __('Invalid submodule.'));
|
||||
$res = array('status' => false, 'output' => __('Invalid submodule.'), 'job_sent' => false, 'sync_result' => __('unknown'));
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function updateDatabaseAfterPullRouter($submodule_name, $user) {
|
||||
if (Configure::read('MISP.background_jobs')) {
|
||||
$job = ClassRegistry::init('Job');
|
||||
$job->create();
|
||||
$eventModel = ClassRegistry::init('Event');
|
||||
$data = array(
|
||||
'worker' => $eventModel->__getPrioWorkerIfPossible(),
|
||||
'job_type' => __('update_after_pull'),
|
||||
'job_input' => __('Updating: ' . $submodule_name),
|
||||
'status' => 0,
|
||||
'retries' => 0,
|
||||
'org_id' => $user['org_id'],
|
||||
'org' => $user['Organisation']['name'],
|
||||
'message' => 'Update database after PULL.',
|
||||
);
|
||||
$job->save($data);
|
||||
$jobId = $job->id;
|
||||
$process_id = CakeResque::enqueue(
|
||||
'prio',
|
||||
'AdminShell',
|
||||
array('updateAfterPull', $submodule_name, $jobId, $user['id']),
|
||||
true
|
||||
);
|
||||
$job->saveField('process_id', $process_id);
|
||||
return array('job_sent' => true, 'sync_result' => __('unknown'));
|
||||
} else {
|
||||
$result = $this->updateAfterPull($submodule_name, $user['id']);
|
||||
return array('job_sent' => false, 'sync_result' => $result);
|
||||
}
|
||||
}
|
||||
|
||||
public function updateAfterPull($submodule_name, $userId) {
|
||||
$user = $this->User->getAuthUser($userId);
|
||||
$result = array();
|
||||
if ($user['Role']['perm_site_admin']) {
|
||||
$updateAll = empty($submodule_name);
|
||||
if ($submodule_name == 'app/files/misp-galaxy' || $updateAll) {
|
||||
$this->Galaxy = ClassRegistry::init('Galaxy');
|
||||
$result[] = ($this->Galaxy->update() ? 'Update `' . h($submodule_name) . '` Sucessful.' : 'Update `'. h($submodule_name) . '` failed.') . PHP_EOL;
|
||||
}
|
||||
if ($submodule_name == 'app/files/misp-objects' || $updateAll) {
|
||||
$this->ObjectTemplate = ClassRegistry::init('ObjectTemplate');
|
||||
$result[] = ($this->ObjectTemplate->update($user, false, false) ? 'Update `' . h($submodule_name) . '` Sucessful.' : 'Update `'. h($submodule_name) . '` failed.') . PHP_EOL;
|
||||
}
|
||||
if ($submodule_name == 'app/files/noticelists' || $updateAll) {
|
||||
$this->Noticelist = ClassRegistry::init('Noticelist');
|
||||
$result[] = ($this->Noticelist->update() ? 'Update `' . h($submodule_name) . '` Sucessful.' : 'Update `'. h($submodule_name) . '` failed.') . PHP_EOL;
|
||||
}
|
||||
if ($submodule_name == 'app/files/taxonomies' || $updateAll) {
|
||||
$this->Taxonomy = ClassRegistry::init('Taxonomy');
|
||||
$result[] = ($this->Taxonomy->update() ? 'Update `' . h($submodule_name) . '` Sucessful.' : 'Update `'. h($submodule_name) . '` failed.') . PHP_EOL;
|
||||
}
|
||||
if ($submodule_name == 'app/files/warninglists' || $updateAll) {
|
||||
$this->Warninglist = ClassRegistry::init('Warninglist');
|
||||
$result[] = ($this->Warninglist->update() ? 'Update `' . h($submodule_name) . '` Sucessful.' : 'Update `'. h($submodule_name) . '` failed.') . PHP_EOL;
|
||||
}
|
||||
}
|
||||
return implode('\n', $result);
|
||||
}
|
||||
|
||||
public function update($status)
|
||||
{
|
||||
$final = '';
|
||||
|
|
|
@ -368,13 +368,26 @@
|
|||
});
|
||||
|
||||
$('#refreshSubmoduleStatus').click(function() { updateSubModulesStatus(); });
|
||||
function updateSubModulesStatus(message) {
|
||||
function updateSubModulesStatus(message, job_sent, sync_result) {
|
||||
job_sent = job_sent === undefined ? false : job_sent;
|
||||
sync_result = sync_result === undefined ? '' : sync_result;
|
||||
$('#divSubmoduleVersions').empty().append('<it class="fa fa-spin fa-spinner" style="font-size: large; left: 50%; top: 50%;"></it>');
|
||||
$.get('<?php echo $baseurl . '/servers/getSubmodulesStatus/'; ?>', function(html){
|
||||
$('#divSubmoduleVersions').html(html);
|
||||
if (message !== undefined) {
|
||||
$('#submoduleGitResultDiv').show();
|
||||
$('#submoduleGitResult').text(message);
|
||||
|
||||
var $clone = $('#submoduleGitResultDiv').clone();
|
||||
$clone.find('strong').text('Synchronization result:');
|
||||
if (job_sent) {
|
||||
$clone.find('#submoduleGitResult')
|
||||
.html('> Synchronizing DB with <a href="/jobs/index/" target="_blank">workers</a>...');
|
||||
} else {
|
||||
$clone.find('#submoduleGitResult')
|
||||
.text(sync_result);
|
||||
}
|
||||
$clone.appendTo($('#submoduleGitResultDiv').parent());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -3746,7 +3746,9 @@ function submitSubmoduleUpdate(clicked) {
|
|||
data: formData,
|
||||
success:function (data, textStatus) {
|
||||
if (data.status) {
|
||||
updateSubModulesStatus(data.output);
|
||||
var job_sent = data.job_sent !== undefined ? data.job_sent : false;
|
||||
var sync_result = data.sync_result !== undefined ? data.sync_result : '';
|
||||
updateSubModulesStatus(data.output, job_sent, sync_result);
|
||||
} else {
|
||||
showMessage('error', 'Something went wrong');
|
||||
$('#submoduleGitResultDiv').show();
|
||||
|
|
Loading…
Reference in New Issue