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 $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]; $jobId = $this->args[0];
$this->loadModel('Job'); $this->loadModel('Job');
$this->Job->id = $jobId; $this->Job->id = $jobId;
@ -15,7 +19,9 @@ class AdminShell extends AppShell
$this->Job->saveField('status', 4); $this->Job->saveField('status', 4);
} }
public function jobPurgeCorrelation() { public function jobPurgeCorrelation()
{
$this->ConfigLoad->execute();
$jobId = $this->args[0]; $jobId = $this->args[0];
$this->loadModel('Job'); $this->loadModel('Job');
$this->Job->id = $jobId; $this->Job->id = $jobId;
@ -26,7 +32,9 @@ class AdminShell extends AppShell
$this->Job->saveField('status', 4); $this->Job->saveField('status', 4);
} }
public function jobGenerateShadowAttributeCorrelation() { public function jobGenerateShadowAttributeCorrelation()
{
$this->ConfigLoad->execute();
$jobId = $this->args[0]; $jobId = $this->args[0];
$this->loadModel('Job'); $this->loadModel('Job');
$this->Job->id = $jobId; $this->Job->id = $jobId;
@ -34,18 +42,23 @@ class AdminShell extends AppShell
$this->ShadowAttribute->generateCorrelation($jobId); $this->ShadowAttribute->generateCorrelation($jobId);
} }
public function updateMISP() { public function updateMISP()
{
$this->ConfigLoad->execute();
$status = array('branch' => '2.4'); $status = array('branch' => '2.4');
echo $this->Server->update($status) . PHP_EOL; echo $this->Server->update($status) . PHP_EOL;
} }
public function restartWorkers() public function restartWorkers()
{ {
$this->ConfigLoad->execute();
$this->Server->restartWorkers(); $this->Server->restartWorkers();
echo PHP_EOL . 'Workers restarted.' . PHP_EOL; echo PHP_EOL . 'Workers restarted.' . PHP_EOL;
} }
public function updateAfterPull() { public function updateAfterPull()
{
$this->ConfigLoad->execute();
$this->loadModel('Job'); $this->loadModel('Job');
$this->loadModel('Server'); $this->loadModel('Server');
$submodule_name = $this->args[0]; $submodule_name = $this->args[0];
@ -64,6 +77,7 @@ class AdminShell extends AppShell
public function restartWorker() public function restartWorker()
{ {
$this->ConfigLoad->execute();
if (empty($this->args[0]) || !is_numeric($this->args[0])) { if (empty($this->args[0]) || !is_numeric($this->args[0])) {
echo 'Usage: ' . APP . '/cake ' . 'Admin restartWorker [PID]' . PHP_EOL; echo 'Usage: ' . APP . '/cake ' . 'Admin restartWorker [PID]' . PHP_EOL;
} }
@ -84,6 +98,7 @@ class AdminShell extends AppShell
public function killWorker() public function killWorker()
{ {
$this->ConfigLoad->execute();
if (empty($this->args[0]) || !is_numeric($this->args[0])) { if (empty($this->args[0]) || !is_numeric($this->args[0])) {
echo 'Usage: ' . APP . '/cake ' . 'Admin killWorker [PID]' . PHP_EOL; echo 'Usage: ' . APP . '/cake ' . 'Admin killWorker [PID]' . PHP_EOL;
die(); die();
@ -100,6 +115,7 @@ class AdminShell extends AppShell
public function startWorker() public function startWorker()
{ {
$this->ConfigLoad->execute();
if (empty($this->args[0])) { if (empty($this->args[0])) {
echo 'Usage: ' . APP . '/cake ' . 'Admin startWorker [queue]' . PHP_EOL; echo 'Usage: ' . APP . '/cake ' . 'Admin startWorker [queue]' . PHP_EOL;
die(); 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; echo 'Updating all JSON structures.' . PHP_EOL;
$results = $this->Server->updateJSON(); $results = $this->Server->updateJSON();
foreach ($results as $type => $result) { 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; 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 // The following is 7.x upwards only
//$value = $this->args[0] ?? $this->args[0] ?? 0; //$value = $this->args[0] ?? $this->args[0] ?? 0;
$value = empty($this->args[0]) ? null : $this->args[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 # 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(); $result = $this->Taxonomy->update();
if ($result) { if ($result) {
echo 'Taxonomies updated' . PHP_EOL; echo 'Taxonomies updated' . PHP_EOL;
@ -161,13 +183,16 @@ class AdminShell extends AppShell
public function updateWarningLists() public function updateWarningLists()
{ {
$this->ConfigLoad->execute();
$result = $this->Warninglist->update(); $result = $this->Warninglist->update();
$success = count($result['success']); $success = count($result['success']);
$fails = count($result['fails']); $fails = count($result['fails']);
echo "$success warninglists updated, $fails fails" . PHP_EOL; echo "$success warninglists updated, $fails fails" . PHP_EOL;
} }
public function updateNoticeLists() { public function updateNoticeLists()
{
$this->ConfigLoad->execute();
$result = $this->Noticelist->update(); $result = $this->Noticelist->update();
if ($result) { if ($result) {
echo 'Notice lists updated' . PHP_EOL; echo 'Notice lists updated' . PHP_EOL;
@ -177,7 +202,9 @@ class AdminShell extends AppShell
} }
# FIXME: Fails to pass userId/orgId properly, global update works. # FIXME: Fails to pass userId/orgId properly, global update works.
public function updateObjectTemplates() { public function updateObjectTemplates()
{
$this->ConfigLoad->execute();
if (empty($this->args[0])) { if (empty($this->args[0])) {
echo 'Usage: ' . APP . '/cake ' . 'Admin updateObjectTemplates [user_id]' . PHP_EOL; echo 'Usage: ' . APP . '/cake ' . 'Admin updateObjectTemplates [user_id]' . PHP_EOL;
} else { } else {
@ -203,7 +230,9 @@ class AdminShell extends AppShell
} }
} }
public function jobUpgrade24() { public function jobUpgrade24()
{
$this->ConfigLoad->execute();
$jobId = $this->args[0]; $jobId = $this->args[0];
$user_id = $this->args[1]; $user_id = $this->args[1];
$this->loadModel('Job'); $this->loadModel('Job');
@ -215,7 +244,9 @@ class AdminShell extends AppShell
$this->Job->saveField('status', 4); $this->Job->saveField('status', 4);
} }
public function prune_update_logs() { public function prune_update_logs()
{
$this->ConfigLoad->execute();
$jobId = $this->args[0]; $jobId = $this->args[0];
$user_id = $this->args[1]; $user_id = $this->args[1];
$user = $this->User->getAuthUser($user_id); $user = $this->User->getAuthUser($user_id);
@ -228,7 +259,9 @@ class AdminShell extends AppShell
$this->Job->saveField('status', 4); $this->Job->saveField('status', 4);
} }
public function getWorkers() { public function getWorkers()
{
$this->ConfigLoad->execute();
$result = $this->Server->workerDiagnostics($workerIssueCount); $result = $this->Server->workerDiagnostics($workerIssueCount);
$query = 'all'; $query = 'all';
if (!empty($this->args[0])) { if (!empty($this->args[0])) {
@ -252,7 +285,9 @@ class AdminShell extends AppShell
echo json_encode($result, JSON_PRETTY_PRINT) . PHP_EOL; 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]; $param = empty($this->args[0]) ? 'all' : $this->args[0];
$settings = $this->Server->serverSettingsRead(); $settings = $this->Server->serverSettingsRead();
$result = $settings; $result = $settings;
@ -268,7 +303,9 @@ class AdminShell extends AppShell
echo json_encode($result, JSON_PRETTY_PRINT) . PHP_EOL; 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]; $setting_name = !isset($this->args[0]) ? null : $this->args[0];
$value = !isset($this->args[1]) ? null : $this->args[1]; $value = !isset($this->args[1]) ? null : $this->args[1];
if ($value === 'false') $value = 0; if ($value === 'false') $value = 0;
@ -292,7 +329,9 @@ class AdminShell extends AppShell
echo PHP_EOL; 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; if (empty($this->args[0])) echo 'Invalid parameters. Usage: ' . APP . 'Console/cake Admin setDatabaseVersion [db_version]' . PHP_EOL;
else { else {
$db_version = $this->AdminSetting->find('first', array( $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'); $whoami = exec('whoami');
if ($whoami === 'httpd' || $whoami === 'www-data' || $whoami === 'apache' || $whoami === 'wwwrun' || $whoami === 'travis') { 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; 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])) { if (empty($this->args[0])) {
echo 'Invalid parameters. Usage: ' . APP . 'Console/cake Admin getAuthkey [user_email]' . PHP_EOL; echo 'Invalid parameters. Usage: ' . APP . 'Console/cake Admin getAuthkey [user_email]' . PHP_EOL;
} else { } else {
@ -339,6 +382,7 @@ class AdminShell extends AppShell
public function clearBruteforce() public function clearBruteforce()
{ {
$this->ConfigLoad->execute();
$conditions = array('Bruteforce.username !=' => ''); $conditions = array('Bruteforce.username !=' => '');
if (!empty($this->args[0])) { if (!empty($this->args[0])) {
$conditions = array('Bruteforce.username' => $this->args[0]); $conditions = array('Bruteforce.username' => $this->args[0]);
@ -354,6 +398,7 @@ class AdminShell extends AppShell
public function setDefaultRole() public function setDefaultRole()
{ {
$this->ConfigLoad->execute();
if (empty($this->args[0]) || !is_numeric($this->args[0])) { if (empty($this->args[0]) || !is_numeric($this->args[0])) {
$roles = $this->Role->find('list', array( $roles = $this->Role->find('list', array(
'fields' => array('id', 'name') 'fields' => array('id', 'name')
@ -385,6 +430,7 @@ class AdminShell extends AppShell
public function change_authkey() public function change_authkey()
{ {
$this->ConfigLoad->execute();
if (empty($this->args[0])) { 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; 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(); die();
@ -412,7 +458,9 @@ class AdminShell extends AppShell
echo 'Updated, new key:' . PHP_EOL . $authKey . PHP_EOL; echo 'Updated, new key:' . PHP_EOL . $authKey . PHP_EOL;
} }
public function getOptionParser() { public function getOptionParser()
{
$this->ConfigLoad->execute();
$parser = parent::getOptionParser(); $parser = parent::getOptionParser();
$parser->addSubcommand('updateJSON', array( $parser->addSubcommand('updateJSON', array(
'help' => __('Update the JSON definitions of MISP.'), 'help' => __('Update the JSON definitions of MISP.'),
@ -427,6 +475,7 @@ class AdminShell extends AppShell
public function recoverSinceLastSuccessfulUpdate() public function recoverSinceLastSuccessfulUpdate()
{ {
$this->ConfigLoad->execute();
$this->loadModel('Log'); $this->loadModel('Log');
$logs = $this->Log->find('all', array( $logs = $this->Log->find('all', array(
'conditions' => array( 'conditions' => array(
@ -465,6 +514,7 @@ class AdminShell extends AppShell
public function cleanCaches() public function cleanCaches()
{ {
$this->ConfigLoad->execute();
echo 'Cleaning caches...' . PHP_EOL; echo 'Cleaning caches...' . PHP_EOL;
$this->Server->cleanCacheFiles(); $this->Server->cleanCacheFiles();
echo '...caches lost in time, like tears in rain.' . PHP_EOL; echo '...caches lost in time, like tears in rain.' . PHP_EOL;
@ -472,6 +522,7 @@ class AdminShell extends AppShell
public function resetSyncAuthkeys() public function resetSyncAuthkeys()
{ {
$this->ConfigLoad->execute();
if (empty($this->args[0])) { if (empty($this->args[0])) {
echo sprintf( echo sprintf(
__("MISP mass sync authkey reset command line tool.\n\nUsage: %sConsole/cake resetSyncAuthkeys [user_id]") . "\n\n", __("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() public function purgeFeedEvents()
{ {
$this->ConfigLoad->execute();
if ( if (
(empty($this->args[0]) || !is_numeric($this->args[0])) || (empty($this->args[0]) || !is_numeric($this->args[0])) ||
(empty($this->args[1]) || !is_numeric($this->args[1])) (empty($this->args[1]) || !is_numeric($this->args[1]))
@ -517,6 +569,7 @@ class AdminShell extends AppShell
public function dumpCurrentDatabaseSchema() public function dumpCurrentDatabaseSchema()
{ {
$this->ConfigLoad->execute();
$dbActualSchema = $this->Server->getActualDBSchema(); $dbActualSchema = $this->Server->getActualDBSchema();
$dbVersion = $this->AdminSetting->find('first', array( $dbVersion = $this->AdminSetting->find('first', array(
'conditions' => array('setting' => 'db_version') 'conditions' => array('setting' => 'db_version')

View File

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

View File

@ -7,37 +7,41 @@
*/ */
class AuthkeyShell extends AppShell { class AuthkeyShell extends AppShell {
public $uses = array('User', 'Log'); public $uses = array('User', 'Log');
public function main() { public $tasks = array('ConfigLoad');
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 { public function main()
// get the users that need their password hashed {
$user = $this->User->find('first', array('conditions' => array('email' => $this->args[0]), 'recursive' => -1, 'contain' => 'Organisation')); $this->ConfigLoad->execute();
if (empty($user)) { 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;
echo 'User not found. Make sure you use the correct syntax: /var/www/MISP/app/Console/cake Authkey [email]' . PHP_EOL; else {
exit; // get the users that need their password hashed
} $user = $this->User->find('first', array('conditions' => array('email' => $this->args[0]), 'recursive' => -1, 'contain' => 'Organisation'));
$this->User->id = $user['User']['id']; if (empty($user)) {
$newkey = $this->User->generateAuthKey(); echo 'User not found. Make sure you use the correct syntax: /var/www/MISP/app/Console/cake Authkey [email]' . PHP_EOL;
if ($this->User->saveField('authkey', $newkey)) { exit;
$this->Log->create(); }
$this->Log->save(array( $this->User->id = $user['User']['id'];
'org' => $user['Organisation']['name'], $newkey = $this->User->generateAuthKey();
'model' => 'User', if ($this->User->saveField('authkey', $newkey)) {
'model_id' => $user['User']['id'], $this->Log->create();
'email' => 'SYSTEM', $this->Log->save(array(
'action' => 'reset_auth_key', 'org' => $user['Organisation']['name'],
'title' => 'Authentication key for user ' . $user['User']['id'] . ' (' . $user['User']['email'] . ')', 'model' => 'User',
'change' => 'authkey(' . $user['User']['authkey'] . ') => (' . $newkey . ')' 'model_id' => $user['User']['id'],
)); 'email' => 'SYSTEM',
echo $newkey . PHP_EOL; 'action' => 'reset_auth_key',
} else { 'title' => 'Authentication key for user ' . $user['User']['id'] . ' (' . $user['User']['email'] . ')',
echo 'Could not update account for User.id = ', $user['User']['id'], PHP_EOL; 'change' => 'authkey(' . $user['User']['authkey'] . ') => (' . $newkey . ')'
echo json_encode($this->User->validationErrors) . PHP_EOL; ));
$this->out(print_r($this->User->invalidFields(), true)); echo $newkey . PHP_EOL;
} } else {
} echo 'Could not update account for User.id = ', $user['User']['id'], PHP_EOL;
exit; 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 { class BaseurlShell extends AppShell {
public $uses = array('Server'); public $uses = array('Server');
public function main() { public function main()
$baseurl = $this->args[0]; {
$result = $this->Server->testBaseURL($baseurl); $this->ConfigLoad->execute();
if (true !== $result) { $baseurl = $this->args[0];
echo $result . PHP_EOL; $result = $this->Server->testBaseURL($baseurl);
} else { if (true !== $result) {
$this->Server->serverSettingsSaveValue('MISP.baseurl', $baseurl); echo $result . PHP_EOL;
echo 'Baseurl updated. Have a very safe and productive day.', 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 $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]; $id = $this->args[0];
$this->Event->id = $id; $this->Event->id = $id;
if (!$this->Event->exists()) { if (!$this->Event->exists()) {
@ -34,7 +38,9 @@ class EventShell extends AppShell
$this->Job->saveField('message', 'Job done.'); $this->Job->saveField('message', 'Job done.');
} }
public function cache() { public function cache()
{
$this->ConfigLoad->execute();
$timeStart = time(); $timeStart = time();
$userId = $this->args[0]; $userId = $this->args[0];
$id = $this->args[1]; $id = $this->args[1];
@ -70,6 +76,7 @@ class EventShell extends AppShell
private function __runCaching($user, $typeData, $id, $export_type, $subType = '') private function __runCaching($user, $typeData, $id, $export_type, $subType = '')
{ {
$this->ConfigLoad->execute();
$export_type = strtolower($typeData['type']); $export_type = strtolower($typeData['type']);
$final = $this->{$typeData['scope']}->restSearch($user, $typeData['params']['returnFormat'], $typeData['params'], false, $id); $final = $this->{$typeData['scope']}->restSearch($user, $typeData['params']['returnFormat'], $typeData['params'], false, $id);
$dir = new Folder(APP . 'tmp/cached_exports/' . $export_type, true, 0750); $dir = new Folder(APP . 'tmp/cached_exports/' . $export_type, true, 0750);
@ -84,7 +91,9 @@ class EventShell extends AppShell
return true; return true;
} }
public function cachexml() { public function cachexml()
{
$this->ConfigLoad->execute();
$timeStart = time(); $timeStart = time();
$userId = $this->args[0]; $userId = $this->args[0];
$id = $this->args[1]; $id = $this->args[1];
@ -118,7 +127,9 @@ class EventShell extends AppShell
$this->Job->saveField('date_modified', date("Y-m-d H:i:s")); $this->Job->saveField('date_modified', date("Y-m-d H:i:s"));
} }
public function cachejson() { public function cachejson()
{
$this->ConfigLoad->execute();
$timeStart = time(); $timeStart = time();
$userId = $this->args[0]; $userId = $this->args[0];
$id = $this->args[1]; $id = $this->args[1];
@ -152,7 +163,9 @@ class EventShell extends AppShell
$this->Job->saveField('date_modified', date("Y-m-d H:i:s")); $this->Job->saveField('date_modified', date("Y-m-d H:i:s"));
} }
public function cachestix() { public function cachestix()
{
$this->ConfigLoad->execute();
$timeStart = time(); $timeStart = time();
$userId = $this->args[0]; $userId = $this->args[0];
$id = $this->args[1]; $id = $this->args[1];
@ -180,7 +193,9 @@ class EventShell extends AppShell
} }
} }
public function cachehids() { public function cachehids()
{
$this->ConfigLoad->execute();
$timeStart = time(); $timeStart = time();
$userId = $this->args[0]; $userId = $this->args[0];
$user = $this->User->getAuthUser($userId); $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")); $this->Job->saveField('date_modified', date("Y-m-d H:i:s"));
} }
public function cacherpz() { public function cacherpz()
{
$this->ConfigLoad->execute();
$timeStart = time(); $timeStart = time();
$userId = $this->args[0]; $userId = $this->args[0];
$user = $this->User->getAuthUser($userId); $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")); $this->Job->saveField('date_modified', date("Y-m-d H:i:s"));
} }
public function cachecsv() { public function cachecsv()
{
$this->ConfigLoad->execute();
$timeStart = time(); $timeStart = time();
$userId = $this->args[0]; $userId = $this->args[0];
$user = $this->User->getAuthUser($userId); $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")); $this->Job->saveField('date_modified', date("Y-m-d H:i:s"));
} }
public function cachetext() { public function cachetext()
{
$this->ConfigLoad->execute();
$timeStart = time(); $timeStart = time();
$userId = $this->args[0]; $userId = $this->args[0];
$user = $this->User->getAuthUser($userId); $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")); $this->Job->saveField('date_modified', date("Y-m-d H:i:s"));
} }
public function cachenids() { public function cachenids()
{
$this->ConfigLoad->execute();
$timeStart = time(); $timeStart = time();
$userId = $this->args[0]; $userId = $this->args[0];
$user = $this->User->getAuthUser($userId); $user = $this->User->getAuthUser($userId);
@ -358,6 +381,7 @@ class EventShell extends AppShell
public function cachebro() public function cachebro()
{ {
$this->ConfigLoad->execute();
$timeStart = time(); $timeStart = time();
$userId = $this->args[0]; $userId = $this->args[0];
$user = $this->User->getAuthUser($userId); $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")); $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]; $userId = $this->args[0];
$processId = $this->args[1]; $processId = $this->args[1];
$job = $this->Job->read(null, $processId); $job = $this->Job->read(null, $processId);
@ -406,7 +432,9 @@ class EventShell extends AppShell
$this->Job->save($job); $this->Job->save($job);
} }
public function contactemail() { public function contactemail()
{
$this->ConfigLoad->execute();
$id = $this->args[0]; $id = $this->args[0];
$message = $this->args[1]; $message = $this->args[1];
$all = $this->args[2]; $all = $this->args[2];
@ -421,7 +449,9 @@ class EventShell extends AppShell
if ($result != true) $this->Job->saveField('message', 'Job done.'); if ($result != true) $this->Job->saveField('message', 'Job done.');
} }
public function postsemail() { public function postsemail()
{
$this->ConfigLoad->execute();
$userId = $this->args[0]; $userId = $this->args[0];
$postId = $this->args[1]; $postId = $this->args[1];
$eventId = $this->args[2]; $eventId = $this->args[2];
@ -436,7 +466,9 @@ class EventShell extends AppShell
$this->Job->save($job); $this->Job->save($job);
} }
public function enqueueCaching() { public function enqueueCaching()
{
$this->ConfigLoad->execute();
$timestamp = $this->args[0]; $timestamp = $this->args[0];
$task = $this->Task->findByType('cache_exports'); $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') . '.'); $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]; $id = $this->args[0];
$passAlong = $this->args[1]; $passAlong = $this->args[1];
$jobId = $this->args[2]; $jobId = $this->args[2];
@ -509,7 +543,9 @@ class EventShell extends AppShell
$log->createLogEntry($user, 'publish', 'Event', $id, 'Event (' . $id . '): published.', 'published () => (1)'); $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]; $id = $this->args[0];
$passAlong = $this->args[1]; $passAlong = $this->args[1];
$jobId = $this->args[2]; $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'); $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])) { if (empty($this->args[0]) || empty($this->args[1]) || empty($this->args[2])) {
die('Usage: ' . $this->Server->command_line_functions['enrichment'] . PHP_EOL); 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)'); $log->createLogEntry($user, 'enrichment', 'Event', $eventId, 'Event (' . $eventId . '): enriched.', 'enriched () => (1)');
} }
public function processfreetext() { public function processfreetext()
{
$this->ConfigLoad->execute();
$inputFile = $this->args[0]; $inputFile = $this->args[0];
$tempdir = new Folder(APP . 'tmp/cache/ingest', true, 0750); $tempdir = new Folder(APP . 'tmp/cache/ingest', true, 0750);
$tempFile = new File(APP . 'tmp/cache/ingest' . DS . $inputFile); $tempFile = new File(APP . 'tmp/cache/ingest' . DS . $inputFile);
@ -602,6 +642,7 @@ class EventShell extends AppShell
public function processmoduleresult() public function processmoduleresult()
{ {
$this->ConfigLoad->execute();
$inputFile = $this->args[0]; $inputFile = $this->args[0];
$tempDir = new Folder(APP . 'tmp/cache/ingest', true, 0750); $tempDir = new Folder(APP . 'tmp/cache/ingest', true, 0750);
$tempFile = new File(APP . 'tmp/cache/ingest' . DS . $inputFile); $tempFile = new File(APP . 'tmp/cache/ingest' . DS . $inputFile);

View File

@ -6,16 +6,18 @@
*/ */
class LiveShell extends AppShell { class LiveShell extends AppShell {
public $uses = array('Server'); public $uses = array('Server');
public function main() { public function main()
$live = $this->args[0]; {
if ($live != 0 && $live != 1) { $this->ConfigLoad->execute();
echo 'Invalid parameters. Usage: /var/www/MISP/app/Console/cake Live [0|1]'; $live = $this->args[0];
} else { if ($live != 0 && $live != 1) {
$this->Server->serverSettingsSaveValue('MISP.live', $live==1); echo 'Invalid parameters. Usage: /var/www/MISP/app/Console/cake Live [0|1]';
} } else {
$status = $live ? 'MISP is now live. Users can now log in.' : 'MISP is now disabled. Only site admins can log in.'; $this->Server->serverSettingsSaveValue('MISP.live', $live==1);
echo $status; }
} $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 { class PasswordShell extends AppShell {
public $uses = array('User'); public $uses = array('User');
public function main() { 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 { $this->ConfigLoad->execute();
// get the users that need their password hashed 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;
$results = $this->User->find('first', array('conditions' => array('email' => $this->args[0]), 'recursive' => -1)); else {
if (empty($results)) { // get the users that need their password hashed
echo 'User not found. Make sure you use the correct syntax: /var/www/MISP/app/Console/cake Password [email] [password]' . PHP_EOL; $results = $this->User->find('first', array('conditions' => array('email' => $this->args[0]), 'recursive' => -1));
exit; 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;
$results['User']['password'] = $this->args[1]; exit;
$results['User']['confirm_password'] = $this->args[1]; }
$results['User']['password'] = $this->args[1];
$results['User']['confirm_password'] = $this->args[1];
$change_pw = 1; $change_pw = 1;
if (!empty($this->params['override_password_change'])) { if (!empty($this->params['override_password_change'])) {
$change_pw = 0; $change_pw = 0;
} }
$results['User']['change_pw'] = $change_pw; $results['User']['change_pw'] = $change_pw;
if (!$this->User->save($results)) { if (!$this->User->save($results)) {
echo 'Could not update account for User.id = ', $results['User']['id'], PHP_EOL; echo 'Could not update account for User.id = ', $results['User']['id'], PHP_EOL;
echo json_encode($this->User->validationErrors) . PHP_EOL; echo json_encode($this->User->validationErrors) . PHP_EOL;
$this->out(print_r($this->User->invalidFields(), true)); $this->out(print_r($this->User->invalidFields(), true));
} }
echo 'Updated ', PHP_EOL; echo 'Updated ', PHP_EOL;
} }
exit; exit;
} }
public function getOptionParser() public function getOptionParser()
{ {
$this->ConfigLoad->execute();
$parser = parent::getOptionParser(); $parser = parent::getOptionParser();
$parser->addOption('override_password_change', array( $parser->addOption('override_password_change', array(
'short' => 'o', 'short' => 'o',

View File

@ -6,9 +6,10 @@ class ServerShell extends AppShell
{ {
public $uses = array('Server', 'Task', 'Job', 'User', 'Feed'); public $uses = array('Server', 'Task', 'Job', 'User', 'Feed');
public function listServers() { public function listServers()
{
$this->ConfigLoad->execute();
$res = ['servers'=>[]]; $res = ['servers'=>[]];
$servers = $this->Server->find('all', [ $servers = $this->Server->find('all', [
'fields' => ['Server.id', 'Server.name', 'Server.url'], 'fields' => ['Server.id', 'Server.name', 'Server.url'],
'recursive' => 0 'recursive' => 0
@ -19,7 +20,9 @@ class ServerShell extends AppShell
echo json_encode($res) . PHP_EOL; echo json_encode($res) . PHP_EOL;
} }
public function test() { public function test()
{
$this->ConfigLoad->execute();
if (empty($this->args[0])) { if (empty($this->args[0])) {
die('Usage: ' . $this->Server->command_line_functions['console_automation_tasks']['data']['Test'] . PHP_EOL); 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; echo json_encode($res) . PHP_EOL;
} }
public function pull() { public function pull()
{
$this->ConfigLoad->execute();
if (empty($this->args[0]) || empty($this->args[1])) { if (empty($this->args[0]) || empty($this->args[1])) {
die('Usage: ' . $this->Server->command_line_functions['console_automation_tasks']['data']['pull'] . PHP_EOL); 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; echo $message . PHP_EOL;
} }
public function push() { public function push()
{
$this->ConfigLoad->execute();
if (empty($this->args[0]) || empty($this->args[1])) { if (empty($this->args[0]) || empty($this->args[1])) {
die('Usage: ' . $this->Server->command_line_functions['console_automation_tasks']['data']['push'] . PHP_EOL); 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])) { 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); 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; echo $outcome['message'] . PHP_EOL;
} }
public function cacheServer() { public function cacheServer()
{
$this->ConfigLoad->execute();
if (empty($this->args[0]) || empty($this->args[1])) { if (empty($this->args[0]) || empty($this->args[1])) {
die('Usage: ' . $this->Server->command_line_functions['console_automation_tasks']['data']['cacheServer'] . PHP_EOL); 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])) { 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); 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; echo $message . PHP_EOL;
} }
public function enqueuePull() { public function enqueuePull()
{
$this->ConfigLoad->execute();
$timestamp = $this->args[0]; $timestamp = $this->args[0];
$userId = $this->args[1]; $userId = $this->args[1];
$taskId = $this->args[2]; $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); $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]; $timestamp = $this->args[0];
$userId = $this->args[1]; $userId = $this->args[1];
$taskId = $this->args[2]; $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)); $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]; $timestamp = $this->args[0];
$userId = $this->args[1]; $userId = $this->args[1];
$taskId = $this->args[2]; $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')); $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]; $timestamp = $this->args[0];
$taskId = $this->args[1]; $taskId = $this->args[1];
$userId = $this->args[2]; $userId = $this->args[2];
@ -496,5 +517,4 @@ class ServerShell extends AppShell
$this->Task->id = $task['Task']['id']; $this->Task->id = $task['Task']['id'];
$this->Task->saveField('message', count($servers) . ' job(s) completed at ' . date('d/m/Y - H:i:s') . '.'); $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');
}
}
?>