new: [config load task] Added a task that will reload the settings on any console shell execution, fixes #5498

- helps with background workers being forced to fetch new settings whenever they start a new job
pull/5616/head
iglocska 2020-02-10 15:15:59 +01:00
parent 90009b963b
commit af881189e5
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
9 changed files with 265 additions and 130 deletions

View File

@ -4,7 +4,11 @@ class AdminShell extends AppShell
{
public $uses = array('Event', 'Post', 'Attribute', 'Job', 'User', 'Task', 'Whitelist', 'Server', 'Organisation', 'AdminSetting', 'Galaxy', 'Taxonomy', 'Warninglist', 'Noticelist', 'ObjectTemplate', 'Bruteforce', 'Role', 'Feed');
public function jobGenerateCorrelation() {
public $tasks = array('ConfigLoad');
public function jobGenerateCorrelation()
{
$this->ConfigLoad->execute();
$jobId = $this->args[0];
$this->loadModel('Job');
$this->Job->id = $jobId;
@ -15,7 +19,9 @@ class AdminShell extends AppShell
$this->Job->saveField('status', 4);
}
public function jobPurgeCorrelation() {
public function jobPurgeCorrelation()
{
$this->ConfigLoad->execute();
$jobId = $this->args[0];
$this->loadModel('Job');
$this->Job->id = $jobId;
@ -26,7 +32,9 @@ class AdminShell extends AppShell
$this->Job->saveField('status', 4);
}
public function jobGenerateShadowAttributeCorrelation() {
public function jobGenerateShadowAttributeCorrelation()
{
$this->ConfigLoad->execute();
$jobId = $this->args[0];
$this->loadModel('Job');
$this->Job->id = $jobId;
@ -34,18 +42,23 @@ class AdminShell extends AppShell
$this->ShadowAttribute->generateCorrelation($jobId);
}
public function updateMISP() {
public function updateMISP()
{
$this->ConfigLoad->execute();
$status = array('branch' => '2.4');
echo $this->Server->update($status) . PHP_EOL;
}
public function restartWorkers()
{
$this->ConfigLoad->execute();
$this->Server->restartWorkers();
echo PHP_EOL . 'Workers restarted.' . PHP_EOL;
}
public function updateAfterPull() {
public function updateAfterPull()
{
$this->ConfigLoad->execute();
$this->loadModel('Job');
$this->loadModel('Server');
$submodule_name = $this->args[0];
@ -64,6 +77,7 @@ class AdminShell extends AppShell
public function restartWorker()
{
$this->ConfigLoad->execute();
if (empty($this->args[0]) || !is_numeric($this->args[0])) {
echo 'Usage: ' . APP . '/cake ' . 'Admin restartWorker [PID]' . PHP_EOL;
}
@ -84,6 +98,7 @@ class AdminShell extends AppShell
public function killWorker()
{
$this->ConfigLoad->execute();
if (empty($this->args[0]) || !is_numeric($this->args[0])) {
echo 'Usage: ' . APP . '/cake ' . 'Admin killWorker [PID]' . PHP_EOL;
die();
@ -100,6 +115,7 @@ class AdminShell extends AppShell
public function startWorker()
{
$this->ConfigLoad->execute();
if (empty($this->args[0])) {
echo 'Usage: ' . APP . '/cake ' . 'Admin startWorker [queue]' . PHP_EOL;
die();
@ -114,7 +130,9 @@ class AdminShell extends AppShell
);
}
public function updateJSON() {
public function updateJSON()
{
$this->ConfigLoad->execute();
echo 'Updating all JSON structures.' . PHP_EOL;
$results = $this->Server->updateJSON();
foreach ($results as $type => $result) {
@ -133,7 +151,9 @@ class AdminShell extends AppShell
echo 'All JSON structures updated. Thank you and have a very safe and productive day.' . PHP_EOL;
}
public function updateGalaxies() {
public function updateGalaxies()
{
$this->ConfigLoad->execute();
// The following is 7.x upwards only
//$value = $this->args[0] ?? $this->args[0] ?? 0;
$value = empty($this->args[0]) ? null : $this->args[0];
@ -150,7 +170,9 @@ class AdminShell extends AppShell
}
# FIXME: Make Taxonomy->update() return a status string on API if successful
public function updateTaxonomies() {
public function updateTaxonomies()
{
$this->ConfigLoad->execute();
$result = $this->Taxonomy->update();
if ($result) {
echo 'Taxonomies updated' . PHP_EOL;
@ -161,13 +183,16 @@ class AdminShell extends AppShell
public function updateWarningLists()
{
$this->ConfigLoad->execute();
$result = $this->Warninglist->update();
$success = count($result['success']);
$fails = count($result['fails']);
echo "$success warninglists updated, $fails fails" . PHP_EOL;
}
public function updateNoticeLists() {
public function updateNoticeLists()
{
$this->ConfigLoad->execute();
$result = $this->Noticelist->update();
if ($result) {
echo 'Notice lists updated' . PHP_EOL;
@ -177,7 +202,9 @@ class AdminShell extends AppShell
}
# FIXME: Fails to pass userId/orgId properly, global update works.
public function updateObjectTemplates() {
public function updateObjectTemplates()
{
$this->ConfigLoad->execute();
if (empty($this->args[0])) {
echo 'Usage: ' . APP . '/cake ' . 'Admin updateObjectTemplates [user_id]' . PHP_EOL;
} else {
@ -203,7 +230,9 @@ class AdminShell extends AppShell
}
}
public function jobUpgrade24() {
public function jobUpgrade24()
{
$this->ConfigLoad->execute();
$jobId = $this->args[0];
$user_id = $this->args[1];
$this->loadModel('Job');
@ -215,7 +244,9 @@ class AdminShell extends AppShell
$this->Job->saveField('status', 4);
}
public function prune_update_logs() {
public function prune_update_logs()
{
$this->ConfigLoad->execute();
$jobId = $this->args[0];
$user_id = $this->args[1];
$user = $this->User->getAuthUser($user_id);
@ -228,7 +259,9 @@ class AdminShell extends AppShell
$this->Job->saveField('status', 4);
}
public function getWorkers() {
public function getWorkers()
{
$this->ConfigLoad->execute();
$result = $this->Server->workerDiagnostics($workerIssueCount);
$query = 'all';
if (!empty($this->args[0])) {
@ -252,7 +285,9 @@ class AdminShell extends AppShell
echo json_encode($result, JSON_PRETTY_PRINT) . PHP_EOL;
}
public function getSetting() {
public function getSetting()
{
$this->ConfigLoad->execute();
$param = empty($this->args[0]) ? 'all' : $this->args[0];
$settings = $this->Server->serverSettingsRead();
$result = $settings;
@ -268,7 +303,9 @@ class AdminShell extends AppShell
echo json_encode($result, JSON_PRETTY_PRINT) . PHP_EOL;
}
public function setSetting() {
public function setSetting()
{
$this->ConfigLoad->execute();
$setting_name = !isset($this->args[0]) ? null : $this->args[0];
$value = !isset($this->args[1]) ? null : $this->args[1];
if ($value === 'false') $value = 0;
@ -292,7 +329,9 @@ class AdminShell extends AppShell
echo PHP_EOL;
}
public function setDatabaseVersion() {
public function setDatabaseVersion()
{
$this->ConfigLoad->execute();
if (empty($this->args[0])) echo 'Invalid parameters. Usage: ' . APP . 'Console/cake Admin setDatabaseVersion [db_version]' . PHP_EOL;
else {
$db_version = $this->AdminSetting->find('first', array(
@ -308,7 +347,9 @@ class AdminShell extends AppShell
}
}
public function runUpdates() {
public function runUpdates()
{
$this->ConfigLoad->execute();
$whoami = exec('whoami');
if ($whoami === 'httpd' || $whoami === 'www-data' || $whoami === 'apache' || $whoami === 'wwwrun' || $whoami === 'travis') {
echo 'Executing all updates to bring the database up to date with the current version.' . PHP_EOL;
@ -320,7 +361,9 @@ class AdminShell extends AppShell
}
}
public function getAuthkey() {
public function getAuthkey()
{
$this->ConfigLoad->execute();
if (empty($this->args[0])) {
echo 'Invalid parameters. Usage: ' . APP . 'Console/cake Admin getAuthkey [user_email]' . PHP_EOL;
} else {
@ -339,6 +382,7 @@ class AdminShell extends AppShell
public function clearBruteforce()
{
$this->ConfigLoad->execute();
$conditions = array('Bruteforce.username !=' => '');
if (!empty($this->args[0])) {
$conditions = array('Bruteforce.username' => $this->args[0]);
@ -354,6 +398,7 @@ class AdminShell extends AppShell
public function setDefaultRole()
{
$this->ConfigLoad->execute();
if (empty($this->args[0]) || !is_numeric($this->args[0])) {
$roles = $this->Role->find('list', array(
'fields' => array('id', 'name')
@ -385,6 +430,7 @@ class AdminShell extends AppShell
public function change_authkey()
{
$this->ConfigLoad->execute();
if (empty($this->args[0])) {
echo 'MISP apikey command line tool.' . PHP_EOL . 'To assign a new random API key for a user: ' . APP . 'Console/cake Password [email]' . PHP_EOL . 'To assign a fixed API key: ' . APP . 'Console/cake Password [email] [authkey]' . PHP_EOL;
die();
@ -412,7 +458,9 @@ class AdminShell extends AppShell
echo 'Updated, new key:' . PHP_EOL . $authKey . PHP_EOL;
}
public function getOptionParser() {
public function getOptionParser()
{
$this->ConfigLoad->execute();
$parser = parent::getOptionParser();
$parser->addSubcommand('updateJSON', array(
'help' => __('Update the JSON definitions of MISP.'),
@ -427,6 +475,7 @@ class AdminShell extends AppShell
public function recoverSinceLastSuccessfulUpdate()
{
$this->ConfigLoad->execute();
$this->loadModel('Log');
$logs = $this->Log->find('all', array(
'conditions' => array(
@ -465,6 +514,7 @@ class AdminShell extends AppShell
public function cleanCaches()
{
$this->ConfigLoad->execute();
echo 'Cleaning caches...' . PHP_EOL;
$this->Server->cleanCacheFiles();
echo '...caches lost in time, like tears in rain.' . PHP_EOL;
@ -472,6 +522,7 @@ class AdminShell extends AppShell
public function resetSyncAuthkeys()
{
$this->ConfigLoad->execute();
if (empty($this->args[0])) {
echo sprintf(
__("MISP mass sync authkey reset command line tool.\n\nUsage: %sConsole/cake resetSyncAuthkeys [user_id]") . "\n\n",
@ -498,6 +549,7 @@ class AdminShell extends AppShell
public function purgeFeedEvents()
{
$this->ConfigLoad->execute();
if (
(empty($this->args[0]) || !is_numeric($this->args[0])) ||
(empty($this->args[1]) || !is_numeric($this->args[1]))
@ -517,6 +569,7 @@ class AdminShell extends AppShell
public function dumpCurrentDatabaseSchema()
{
$this->ConfigLoad->execute();
$dbActualSchema = $this->Server->getActualDBSchema();
$dbVersion = $this->AdminSetting->find('first', array(
'conditions' => array('setting' => 'db_version')

View File

@ -27,8 +27,11 @@ App::uses('AppModel', 'Model');
* @package app.Console.Command
*/
class AppShell extends Shell {
public function perform() {
$this->initialize();
$this->{array_shift($this->args)}();
}
public $tasks = array('ConfigLoad');
public function perform() {
$this->initialize();
$this->{array_shift($this->args)}();
}
}

View File

@ -7,37 +7,41 @@
*/
class AuthkeyShell extends AppShell {
public $uses = array('User', 'Log');
public $uses = array('User', 'Log');
public function main() {
if (!isset($this->args[0]) || empty($this->args[0])) echo 'MISP authkey reset command line tool.' . PHP_EOL . 'To assign a new authkey for a user:' . PHP_EOL . APP . 'Console/cake Authkey [email]' . PHP_EOL;
else {
// get the users that need their password hashed
$user = $this->User->find('first', array('conditions' => array('email' => $this->args[0]), 'recursive' => -1, 'contain' => 'Organisation'));
if (empty($user)) {
echo 'User not found. Make sure you use the correct syntax: /var/www/MISP/app/Console/cake Authkey [email]' . PHP_EOL;
exit;
}
$this->User->id = $user['User']['id'];
$newkey = $this->User->generateAuthKey();
if ($this->User->saveField('authkey', $newkey)) {
$this->Log->create();
$this->Log->save(array(
'org' => $user['Organisation']['name'],
'model' => 'User',
'model_id' => $user['User']['id'],
'email' => 'SYSTEM',
'action' => 'reset_auth_key',
'title' => 'Authentication key for user ' . $user['User']['id'] . ' (' . $user['User']['email'] . ')',
'change' => 'authkey(' . $user['User']['authkey'] . ') => (' . $newkey . ')'
));
echo $newkey . PHP_EOL;
} else {
echo 'Could not update account for User.id = ', $user['User']['id'], PHP_EOL;
echo json_encode($this->User->validationErrors) . PHP_EOL;
$this->out(print_r($this->User->invalidFields(), true));
}
}
exit;
}
public $tasks = array('ConfigLoad');
public function main()
{
$this->ConfigLoad->execute();
if (!isset($this->args[0]) || empty($this->args[0])) echo 'MISP authkey reset command line tool.' . PHP_EOL . 'To assign a new authkey for a user:' . PHP_EOL . APP . 'Console/cake Authkey [email]' . PHP_EOL;
else {
// get the users that need their password hashed
$user = $this->User->find('first', array('conditions' => array('email' => $this->args[0]), 'recursive' => -1, 'contain' => 'Organisation'));
if (empty($user)) {
echo 'User not found. Make sure you use the correct syntax: /var/www/MISP/app/Console/cake Authkey [email]' . PHP_EOL;
exit;
}
$this->User->id = $user['User']['id'];
$newkey = $this->User->generateAuthKey();
if ($this->User->saveField('authkey', $newkey)) {
$this->Log->create();
$this->Log->save(array(
'org' => $user['Organisation']['name'],
'model' => 'User',
'model_id' => $user['User']['id'],
'email' => 'SYSTEM',
'action' => 'reset_auth_key',
'title' => 'Authentication key for user ' . $user['User']['id'] . ' (' . $user['User']['email'] . ')',
'change' => 'authkey(' . $user['User']['authkey'] . ') => (' . $newkey . ')'
));
echo $newkey . PHP_EOL;
} else {
echo 'Could not update account for User.id = ', $user['User']['id'], PHP_EOL;
echo json_encode($this->User->validationErrors) . PHP_EOL;
$this->out(print_r($this->User->invalidFields(), true));
}
}
exit;
}
}

View File

@ -6,16 +6,18 @@
*/
class BaseurlShell extends AppShell {
public $uses = array('Server');
public $uses = array('Server');
public function main() {
$baseurl = $this->args[0];
$result = $this->Server->testBaseURL($baseurl);
if (true !== $result) {
echo $result . PHP_EOL;
} else {
$this->Server->serverSettingsSaveValue('MISP.baseurl', $baseurl);
echo 'Baseurl updated. Have a very safe and productive day.', PHP_EOL;
}
}
public function main()
{
$this->ConfigLoad->execute();
$baseurl = $this->args[0];
$result = $this->Server->testBaseURL($baseurl);
if (true !== $result) {
echo $result . PHP_EOL;
} else {
$this->Server->serverSettingsSaveValue('MISP.baseurl', $baseurl);
echo 'Baseurl updated. Have a very safe and productive day.', PHP_EOL;
}
}
}

View File

@ -6,7 +6,11 @@ class EventShell extends AppShell
{
public $uses = array('Event', 'Post', 'Attribute', 'Job', 'User', 'Task', 'Whitelist', 'Server', 'Organisation');
public function doPublish() {
public $tasks = array('ConfigLoad');
public function doPublish()
{
$this->ConfigLoad->execute();
$id = $this->args[0];
$this->Event->id = $id;
if (!$this->Event->exists()) {
@ -34,7 +38,9 @@ class EventShell extends AppShell
$this->Job->saveField('message', 'Job done.');
}
public function cache() {
public function cache()
{
$this->ConfigLoad->execute();
$timeStart = time();
$userId = $this->args[0];
$id = $this->args[1];
@ -70,6 +76,7 @@ class EventShell extends AppShell
private function __runCaching($user, $typeData, $id, $export_type, $subType = '')
{
$this->ConfigLoad->execute();
$export_type = strtolower($typeData['type']);
$final = $this->{$typeData['scope']}->restSearch($user, $typeData['params']['returnFormat'], $typeData['params'], false, $id);
$dir = new Folder(APP . 'tmp/cached_exports/' . $export_type, true, 0750);
@ -84,7 +91,9 @@ class EventShell extends AppShell
return true;
}
public function cachexml() {
public function cachexml()
{
$this->ConfigLoad->execute();
$timeStart = time();
$userId = $this->args[0];
$id = $this->args[1];
@ -118,7 +127,9 @@ class EventShell extends AppShell
$this->Job->saveField('date_modified', date("Y-m-d H:i:s"));
}
public function cachejson() {
public function cachejson()
{
$this->ConfigLoad->execute();
$timeStart = time();
$userId = $this->args[0];
$id = $this->args[1];
@ -152,7 +163,9 @@ class EventShell extends AppShell
$this->Job->saveField('date_modified', date("Y-m-d H:i:s"));
}
public function cachestix() {
public function cachestix()
{
$this->ConfigLoad->execute();
$timeStart = time();
$userId = $this->args[0];
$id = $this->args[1];
@ -180,7 +193,9 @@ class EventShell extends AppShell
}
}
public function cachehids() {
public function cachehids()
{
$this->ConfigLoad->execute();
$timeStart = time();
$userId = $this->args[0];
$user = $this->User->getAuthUser($userId);
@ -211,7 +226,9 @@ class EventShell extends AppShell
$this->Job->saveField('date_modified', date("Y-m-d H:i:s"));
}
public function cacherpz() {
public function cacherpz()
{
$this->ConfigLoad->execute();
$timeStart = time();
$userId = $this->args[0];
$user = $this->User->getAuthUser($userId);
@ -252,7 +269,9 @@ class EventShell extends AppShell
$this->Job->saveField('date_modified', date("Y-m-d H:i:s"));
}
public function cachecsv() {
public function cachecsv()
{
$this->ConfigLoad->execute();
$timeStart = time();
$userId = $this->args[0];
$user = $this->User->getAuthUser($userId);
@ -291,7 +310,9 @@ class EventShell extends AppShell
$this->Job->saveField('date_modified', date("Y-m-d H:i:s"));
}
public function cachetext() {
public function cachetext()
{
$this->ConfigLoad->execute();
$timeStart = time();
$userId = $this->args[0];
$user = $this->User->getAuthUser($userId);
@ -320,7 +341,9 @@ class EventShell extends AppShell
$this->Job->saveField('date_modified', date("Y-m-d H:i:s"));
}
public function cachenids() {
public function cachenids()
{
$this->ConfigLoad->execute();
$timeStart = time();
$userId = $this->args[0];
$user = $this->User->getAuthUser($userId);
@ -358,6 +381,7 @@ class EventShell extends AppShell
public function cachebro()
{
$this->ConfigLoad->execute();
$timeStart = time();
$userId = $this->args[0];
$user = $this->User->getAuthUser($userId);
@ -392,7 +416,9 @@ class EventShell extends AppShell
$this->Job->saveField('date_modified', date("Y-m-d H:i:s"));
}
public function alertemail() {
public function alertemail()
{
$this->ConfigLoad->execute();
$userId = $this->args[0];
$processId = $this->args[1];
$job = $this->Job->read(null, $processId);
@ -406,7 +432,9 @@ class EventShell extends AppShell
$this->Job->save($job);
}
public function contactemail() {
public function contactemail()
{
$this->ConfigLoad->execute();
$id = $this->args[0];
$message = $this->args[1];
$all = $this->args[2];
@ -421,7 +449,9 @@ class EventShell extends AppShell
if ($result != true) $this->Job->saveField('message', 'Job done.');
}
public function postsemail() {
public function postsemail()
{
$this->ConfigLoad->execute();
$userId = $this->args[0];
$postId = $this->args[1];
$eventId = $this->args[2];
@ -436,7 +466,9 @@ class EventShell extends AppShell
$this->Job->save($job);
}
public function enqueueCaching() {
public function enqueueCaching()
{
$this->ConfigLoad->execute();
$timestamp = $this->args[0];
$task = $this->Task->findByType('cache_exports');
@ -487,7 +519,9 @@ class EventShell extends AppShell
$this->Task->saveField('message', $i . ' job(s) started at ' . date('d/m/Y - H:i:s') . '.');
}
public function publish() {
public function publish()
{
$this->ConfigLoad->execute();
$id = $this->args[0];
$passAlong = $this->args[1];
$jobId = $this->args[2];
@ -509,7 +543,9 @@ class EventShell extends AppShell
$log->createLogEntry($user, 'publish', 'Event', $id, 'Event (' . $id . '): published.', 'published () => (1)');
}
public function publish_sightings() {
public function publish_sightings()
{
$this->ConfigLoad->execute();
$id = $this->args[0];
$passAlong = $this->args[1];
$jobId = $this->args[2];
@ -531,7 +567,9 @@ class EventShell extends AppShell
$log->createLogEntry($user, 'publish_sightings', 'Event', $id, 'Sightings for event (' . $id . '): published.', 'publish_sightings updated');
}
public function enrichment() {
public function enrichment()
{
$this->ConfigLoad->execute();
if (empty($this->args[0]) || empty($this->args[1]) || empty($this->args[2])) {
die('Usage: ' . $this->Server->command_line_functions['enrichment'] . PHP_EOL);
}
@ -581,7 +619,9 @@ class EventShell extends AppShell
$log->createLogEntry($user, 'enrichment', 'Event', $eventId, 'Event (' . $eventId . '): enriched.', 'enriched () => (1)');
}
public function processfreetext() {
public function processfreetext()
{
$this->ConfigLoad->execute();
$inputFile = $this->args[0];
$tempdir = new Folder(APP . 'tmp/cache/ingest', true, 0750);
$tempFile = new File(APP . 'tmp/cache/ingest' . DS . $inputFile);
@ -602,6 +642,7 @@ class EventShell extends AppShell
public function processmoduleresult()
{
$this->ConfigLoad->execute();
$inputFile = $this->args[0];
$tempDir = new Folder(APP . 'tmp/cache/ingest', true, 0750);
$tempFile = new File(APP . 'tmp/cache/ingest' . DS . $inputFile);

View File

@ -6,16 +6,18 @@
*/
class LiveShell extends AppShell {
public $uses = array('Server');
public $uses = array('Server');
public function main() {
$live = $this->args[0];
if ($live != 0 && $live != 1) {
echo 'Invalid parameters. Usage: /var/www/MISP/app/Console/cake Live [0|1]';
} else {
$this->Server->serverSettingsSaveValue('MISP.live', $live==1);
}
$status = $live ? 'MISP is now live. Users can now log in.' : 'MISP is now disabled. Only site admins can log in.';
echo $status;
}
public function main()
{
$this->ConfigLoad->execute();
$live = $this->args[0];
if ($live != 0 && $live != 1) {
echo 'Invalid parameters. Usage: /var/www/MISP/app/Console/cake Live [0|1]';
} else {
$this->Server->serverSettingsSaveValue('MISP.live', $live==1);
}
$status = $live ? 'MISP is now live. Users can now log in.' : 'MISP is now disabled. Only site admins can log in.';
echo $status;
}
}

View File

@ -7,36 +7,39 @@
*/
class PasswordShell extends AppShell {
public $uses = array('User');
public $uses = array('User');
public function main() {
if (!isset($this->args[0]) || empty($this->args[0]) || !isset($this->args[1]) || empty($this->args[1])) echo 'MISP password reset command line tool.' . PHP_EOL . 'To assign a new password for a user:' . PHP_EOL . APP . 'Console/cake Password [email] [password]' . PHP_EOL;
else {
// get the users that need their password hashed
$results = $this->User->find('first', array('conditions' => array('email' => $this->args[0]), 'recursive' => -1));
if (empty($results)) {
echo 'User not found. Make sure you use the correct syntax: /var/www/MISP/app/Console/cake Password [email] [password]' . PHP_EOL;
exit;
}
$results['User']['password'] = $this->args[1];
$results['User']['confirm_password'] = $this->args[1];
public function main()
{
$this->ConfigLoad->execute();
if (!isset($this->args[0]) || empty($this->args[0]) || !isset($this->args[1]) || empty($this->args[1])) echo 'MISP password reset command line tool.' . PHP_EOL . 'To assign a new password for a user:' . PHP_EOL . APP . 'Console/cake Password [email] [password]' . PHP_EOL;
else {
// get the users that need their password hashed
$results = $this->User->find('first', array('conditions' => array('email' => $this->args[0]), 'recursive' => -1));
if (empty($results)) {
echo 'User not found. Make sure you use the correct syntax: /var/www/MISP/app/Console/cake Password [email] [password]' . PHP_EOL;
exit;
}
$results['User']['password'] = $this->args[1];
$results['User']['confirm_password'] = $this->args[1];
$change_pw = 1;
if (!empty($this->params['override_password_change'])) {
$change_pw = 0;
}
$results['User']['change_pw'] = $change_pw;
if (!$this->User->save($results)) {
echo 'Could not update account for User.id = ', $results['User']['id'], PHP_EOL;
echo json_encode($this->User->validationErrors) . PHP_EOL;
$this->out(print_r($this->User->invalidFields(), true));
}
echo 'Updated ', PHP_EOL;
}
exit;
}
$results['User']['change_pw'] = $change_pw;
if (!$this->User->save($results)) {
echo 'Could not update account for User.id = ', $results['User']['id'], PHP_EOL;
echo json_encode($this->User->validationErrors) . PHP_EOL;
$this->out(print_r($this->User->invalidFields(), true));
}
echo 'Updated ', PHP_EOL;
}
exit;
}
public function getOptionParser()
{
$this->ConfigLoad->execute();
$parser = parent::getOptionParser();
$parser->addOption('override_password_change', array(
'short' => 'o',

View File

@ -6,9 +6,10 @@ class ServerShell extends AppShell
{
public $uses = array('Server', 'Task', 'Job', 'User', 'Feed');
public function listServers() {
public function listServers()
{
$this->ConfigLoad->execute();
$res = ['servers'=>[]];
$servers = $this->Server->find('all', [
'fields' => ['Server.id', 'Server.name', 'Server.url'],
'recursive' => 0
@ -19,7 +20,9 @@ class ServerShell extends AppShell
echo json_encode($res) . PHP_EOL;
}
public function test() {
public function test()
{
$this->ConfigLoad->execute();
if (empty($this->args[0])) {
die('Usage: ' . $this->Server->command_line_functions['console_automation_tasks']['data']['Test'] . PHP_EOL);
}
@ -32,7 +35,9 @@ class ServerShell extends AppShell
echo json_encode($res) . PHP_EOL;
}
public function pull() {
public function pull()
{
$this->ConfigLoad->execute();
if (empty($this->args[0]) || empty($this->args[1])) {
die('Usage: ' . $this->Server->command_line_functions['console_automation_tasks']['data']['pull'] . PHP_EOL);
}
@ -83,7 +88,9 @@ class ServerShell extends AppShell
echo $message . PHP_EOL;
}
public function push() {
public function push()
{
$this->ConfigLoad->execute();
if (empty($this->args[0]) || empty($this->args[1])) {
die('Usage: ' . $this->Server->command_line_functions['console_automation_tasks']['data']['push'] . PHP_EOL);
}
@ -131,7 +138,9 @@ class ServerShell extends AppShell
}
public function fetchFeed() {
public function fetchFeed()
{
$this->ConfigLoad->execute();
if (empty($this->args[0]) || empty($this->args[1])) {
die('Usage: ' . $this->Server->command_line_functions['console_automation_tasks']['data']['Fetch feeds as local data'] . PHP_EOL);
}
@ -209,7 +218,9 @@ class ServerShell extends AppShell
echo $outcome['message'] . PHP_EOL;
}
public function cacheServer() {
public function cacheServer()
{
$this->ConfigLoad->execute();
if (empty($this->args[0]) || empty($this->args[1])) {
die('Usage: ' . $this->Server->command_line_functions['console_automation_tasks']['data']['cacheServer'] . PHP_EOL);
}
@ -257,7 +268,9 @@ class ServerShell extends AppShell
}
public function cacheFeed() {
public function cacheFeed()
{
$this->ConfigLoad->execute();
if (empty($this->args[0]) || empty($this->args[1])) {
die('Usage: ' . $this->Server->command_line_functions['console_automation_tasks']['data']['Cache feeds for quick lookups'] . PHP_EOL);
}
@ -310,7 +323,9 @@ class ServerShell extends AppShell
echo $message . PHP_EOL;
}
public function enqueuePull() {
public function enqueuePull()
{
$this->ConfigLoad->execute();
$timestamp = $this->args[0];
$userId = $this->args[1];
$taskId = $this->args[2];
@ -369,7 +384,9 @@ class ServerShell extends AppShell
$this->Task->saveField('message', count($servers) . ' job(s) completed at ' . date('d/m/Y - H:i:s') . '. Failed jobs: ' . $failCount . '/' . $count);
}
public function enqueueFeedFetch() {
public function enqueueFeedFetch()
{
$this->ConfigLoad->execute();
$timestamp = $this->args[0];
$userId = $this->args[1];
$taskId = $this->args[2];
@ -413,7 +430,9 @@ class ServerShell extends AppShell
$this->Task->saveField('message', count($feeds) . ' job(s) completed at ' . date('d/m/Y - H:i:s') . '. Failed jobs: ' . $failCount . '/' . count($feeds));
}
public function enqueueFeedCache() {
public function enqueueFeedCache()
{
$this->ConfigLoad->execute();
$timestamp = $this->args[0];
$userId = $this->args[1];
$taskId = $this->args[2];
@ -460,7 +479,9 @@ class ServerShell extends AppShell
$this->Task->saveField('message', 'Job completed at ' . date('d/m/Y - H:i:s'));
}
public function enqueuePush() {
public function enqueuePush()
{
$this->ConfigLoad->execute();
$timestamp = $this->args[0];
$taskId = $this->args[1];
$userId = $this->args[2];
@ -496,5 +517,4 @@ class ServerShell extends AppShell
$this->Task->id = $task['Task']['id'];
$this->Task->saveField('message', count($servers) . ' job(s) completed at ' . date('d/m/Y - H:i:s') . '.');
}
}

View File

@ -0,0 +1,7 @@
<?php
class ConfigLoadTask extends Shell {
public function execute() {
Configure::load('config');
}
}
?>