mirror of https://github.com/MISP/MISP
chg: [internal] Cleanup AdminShell::{updateJSON,runUpdates}
parent
6c223a62e6
commit
fdf6f5ca9e
|
@ -136,23 +136,17 @@ class AdminShell extends AppShell
|
|||
|
||||
public function updateJSON()
|
||||
{
|
||||
$this->ConfigLoad->execute();
|
||||
echo 'Updating all JSON structures.' . PHP_EOL;
|
||||
$this->out('Updating all JSON structures.');
|
||||
$results = $this->Server->updateJSON();
|
||||
foreach ($results as $type => $result) {
|
||||
$type = Inflector::pluralize(Inflector::humanize($type));
|
||||
if ($result !== false) {
|
||||
echo sprintf(
|
||||
__('%s updated.') . PHP_EOL,
|
||||
Inflector::pluralize(Inflector::humanize($type))
|
||||
);
|
||||
$this->out(__('%s updated.', $type));
|
||||
} else {
|
||||
echo sprintf(
|
||||
__('Could not update %s.') . PHP_EOL,
|
||||
Inflector::pluralize(Inflector::humanize($type))
|
||||
);
|
||||
$this->out(__('Could not update %s.', $type));
|
||||
}
|
||||
}
|
||||
echo 'All JSON structures updated. Thank you and have a very safe and productive day.' . PHP_EOL;
|
||||
$this->out('All JSON structures updated. Thank you and have a very safe and productive day.');
|
||||
}
|
||||
|
||||
public function updateGalaxies()
|
||||
|
@ -384,16 +378,18 @@ class AdminShell extends AppShell
|
|||
|
||||
public function runUpdates()
|
||||
{
|
||||
$this->ConfigLoad->execute();
|
||||
$whoami = exec('whoami');
|
||||
$osuser = Configure::read('MISP.osuser');
|
||||
if ($whoami === 'httpd' || $whoami === 'www-data' || $whoami === 'apache' || $whoami === 'wwwrun' || $whoami === 'travis' || $whoami === 'www' || $whoami === $osuser) {
|
||||
echo 'Executing all updates to bring the database up to date with the current version.' . PHP_EOL;
|
||||
if (function_exists('posix_getpwuid') && function_exists('posix_geteuid')) {
|
||||
$whoami = posix_getpwuid(posix_geteuid())['name'];
|
||||
} else {
|
||||
$whoami = exec('whoami');
|
||||
}
|
||||
if (in_array($whoami, ['httpd', 'www-data', 'apache', 'wwwrun', 'travis', 'www'], true) || $whoami === Configure::read('MISP.osuser')) {
|
||||
$this->out('Executing all updates to bring the database up to date with the current version.');
|
||||
$processId = empty($this->args[0]) ? false : $this->args[0];
|
||||
$this->Server->runUpdates(true, false, $processId);
|
||||
echo 'All updates completed.' . PHP_EOL;
|
||||
$this->out('All updates completed.');
|
||||
} else {
|
||||
die('This OS user is not allowed to run this command.'. PHP_EOL. 'Run it under `www-data` or `httpd` or `apache` or `wwwrun` or set MISP.osuser in the configuration.' . PHP_EOL . 'You tried to run this command as: ' . $whoami . PHP_EOL);
|
||||
$this->error('This OS user is not allowed to run this command.', 'Run it under `www-data` or `httpd` or `apache` or `wwwrun` or set MISP.osuser in the configuration.' . PHP_EOL . 'You tried to run this command as: ' . $whoami);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -426,7 +422,7 @@ class AdminShell extends AppShell
|
|||
$result = $this->Bruteforce->deleteAll($conditions, false, false);
|
||||
$target = empty($this->args[0]) ? 'all users' : $this->args[0];
|
||||
if ($result) {
|
||||
echo 'Brutefoce entries for ' . $target . ' deleted.' . PHP_EOL;
|
||||
echo 'Bruteforce entries for ' . $target . ' deleted.' . PHP_EOL;
|
||||
} else {
|
||||
echo 'Something went wrong, could not delete bruteforce entries for ' . $target . '.' . PHP_EOL;
|
||||
}
|
||||
|
|
|
@ -2001,7 +2001,7 @@ class AppModel extends Model
|
|||
$tables = $db->listSources();
|
||||
$requiresLogout = false;
|
||||
// if we don't even have an admin table, time to create it.
|
||||
if (!in_array('admin_settings', $tables)) {
|
||||
if (!in_array('admin_settings', $tables, true)) {
|
||||
$this->updateDatabase('adminTable');
|
||||
$requiresLogout = true;
|
||||
} else {
|
||||
|
@ -2054,7 +2054,6 @@ class AppModel extends Model
|
|||
if ($useWorker && Configure::read('MISP.background_jobs')) {
|
||||
$workerIssueCount = 0;
|
||||
$workerDiagnostic = $this->Server->workerDiagnostics($workerIssueCount);
|
||||
$workerType = '';
|
||||
if (isset($workerDiagnostic['update']['ok']) && $workerDiagnostic['update']['ok']) {
|
||||
$workerType = 'update';
|
||||
} else { // update worker not running, doing the update inline
|
||||
|
@ -2115,7 +2114,7 @@ class AppModel extends Model
|
|||
}
|
||||
if (!empty($job)) {
|
||||
$job['Job']['progress'] = floor($update_done / count($updates) * 100);
|
||||
$job['Job']['message'] = sprintf(__('Running update %s'), $update);
|
||||
$job['Job']['message'] = __('Running update %s', $update);
|
||||
$this->Job->save($job);
|
||||
}
|
||||
$dbUpdateSuccess = $this->updateMISP($update);
|
||||
|
@ -2141,7 +2140,7 @@ class AppModel extends Model
|
|||
$this->__queueCleanDB();
|
||||
} else {
|
||||
if (!empty($job)) {
|
||||
$job['Job']['message'] = __('Update done in another worker. Gracefuly stopping.');
|
||||
$job['Job']['message'] = __('Update done in another worker. Gracefully stopping.');
|
||||
}
|
||||
}
|
||||
// mark current worker as done, as well as queued workers than manages to pass the locks
|
||||
|
@ -2347,7 +2346,6 @@ class AppModel extends Model
|
|||
|
||||
private function __runCleanDB()
|
||||
{
|
||||
$this->AdminSetting = ClassRegistry::init('AdminSetting');
|
||||
$cleanDB = $this->AdminSetting->find('first', array('conditions' => array('setting' => 'clean_db')));
|
||||
if (empty($cleanDB) || $cleanDB['AdminSetting']['value'] == 1) {
|
||||
$this->cleanCacheFiles();
|
||||
|
|
Loading…
Reference in New Issue