forked from MISP/MISP
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '2.4' of github.com:MISP/MISP into 2.4
- Loading branch information
Showing
40 changed files
with
762 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule PyMISP
updated
8 files
+1 −1 | .github/workflows/codeql-analysis.yml | |
+1 −1 | .github/workflows/pytest.yml | |
+20 −0 | CHANGELOG.txt | |
+368 −368 | poetry.lock | |
+1 −1 | pymisp/__init__.py | |
+12 −9 | pymisp/api.py | |
+1 −1 | pymisp/data/misp-objects | |
+5 −5 | pyproject.toml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"major":2, "minor":4, "hotfix":175} | ||
{"major":2, "minor":4, "hotfix":177} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,13 @@ | |
* arg0 = email | ||
* arg1 = new password | ||
*/ | ||
|
||
App::uses('File', 'Utility'); | ||
|
||
|
||
class TrainingShell extends AppShell { | ||
|
||
public $uses = array('User', 'Organisation', 'Server'); | ||
public $uses = array('User', 'Organisation', 'Server', 'Authkey'); | ||
|
||
private $__currentUrl = false; | ||
private $__currentAuthKey = false; | ||
|
@@ -115,6 +119,119 @@ public function setup() | |
$this->__printReport('Setup complete. Please find the modifications below:' . PHP_EOL . PHP_EOL); | ||
} | ||
|
||
public function createOrganisationsFromConfig() | ||
{ | ||
$rawConfig = file_get_contents(APP . 'Console/Command/config_orgs.json'); | ||
$config = json_decode($rawConfig, true); | ||
$createdOrgs = []; | ||
foreach ($config as $org) { | ||
$filepath = APP . 'Console/Command/' . $org['Organisation']['logo_path']; | ||
$file = new File($filepath, false); | ||
if ($file->exists()) { | ||
$org['Organisation']['logo'] = [ | ||
'name' => $file->name(), | ||
'type' => $file->mime(), | ||
'tmp_name' => $filepath, | ||
'error' => 0, | ||
'size' => $file->size(), | ||
]; | ||
} | ||
$file->close(); | ||
$date = date('Y-m-d H:i:s'); | ||
$org['Organisation']['date_created'] = $date; | ||
$org['Organisation']['date_modified'] = $date; | ||
$this->Organisation->create(); | ||
$this->Organisation->save($org); | ||
$filename = $this->Organisation->id . '.' . ($file->ext() === 'svg' ? 'svg' : 'png'); | ||
$file->copy(APP . 'webroot/img/orgs/' . $filename); | ||
$createdOrg = $this->Organisation->find('first', ['conditions' => ['id' => $this->Organisation->id]]); | ||
$createdOrgs[$createdOrg['Organisation']['uuid']] = $createdOrg['Organisation']; | ||
} | ||
return $createdOrgs; | ||
} | ||
|
||
public function createUsersFromConfig($createdOrgs) | ||
{ | ||
$rawConfig = file_get_contents(APP . 'Console/Command/config_users.json'); | ||
$config = json_decode($rawConfig, true); | ||
$createdUsers = []; | ||
foreach ($config as $user) { | ||
$user['org_id'] = $createdOrgs[$user['org_uuid']]['id']; | ||
$existingUser = $this->User->find('first', [ | ||
'recursive' => -1, | ||
'conditions' => ['User.email' => $user['email']], | ||
]); | ||
if (empty($existingUser)) { | ||
$this->User->create(); | ||
} else { | ||
$user['id'] = $existingUser['User']['id']; | ||
} | ||
$this->User->save($user); | ||
$createdUser = $this->User->find('first', ['id' => $this->User->id]); | ||
$createdUsers[] = $createdUser; | ||
} | ||
return $createdUsers; | ||
} | ||
|
||
public function setSettingsFromConfig($createdOrgs) | ||
{ | ||
$rawConfig = file_get_contents(APP . 'Console/Command/config_settings.json'); | ||
$config = json_decode($rawConfig, true); | ||
$cli_user = ['id' => 0, 'email' => 'SYSTEM', 'Organisation' => ['name' => 'SYSTEM']]; | ||
foreach ($config as $setting_name => $value) { | ||
if ($setting_name == 'MISP.host_org_id') { | ||
$value = $createdOrgs[$value]['id']; | ||
} | ||
$setting = $this->Server->getSettingData($setting_name); | ||
if (empty($setting)) { | ||
$this->error(__('Setting change rejected.')); | ||
} | ||
$result = $this->Server->serverSettingsEditValue($cli_user, $setting, $value, true); | ||
if (empty($result)) { | ||
$this->error(__('Setting change rejected.')); | ||
} | ||
} | ||
} | ||
|
||
public function createRemoteServersFromConfig($createdOrgs, $createdUsers) | ||
{ | ||
$rawConfig = file_get_contents(APP . 'Console/Command/config_syncs.json'); | ||
$config = json_decode($rawConfig, true); | ||
$createdServers = []; | ||
foreach ($config as $sync) { | ||
$sync['org_id'] = $createdOrgs[$sync['org_uuid']]['id']; | ||
$sync['remote_org_id'] = $createdOrgs[$sync['remote_org_uuid']]['id']; | ||
$this->Server->create(); | ||
$this->Server->save($sync); | ||
$createdServer = $this->User->find('first', ['id' => $this->User->id]); | ||
$createdServers[] = $createdServer; | ||
} | ||
return $createdServers; | ||
} | ||
|
||
public function createAllFromConfig() | ||
{ | ||
$createdOrgs = $this->createOrganisationsFromConfig(); | ||
$createdUsers = $this->createUsersFromConfig($createdOrgs); | ||
$this->setSettingsFromConfig($createdOrgs); | ||
$this->createRemoteServersFromConfig($createdOrgs, $createdUsers); | ||
} | ||
|
||
public function WipeAllSyncs() | ||
{ | ||
$this->Server->deleteAll(['Server.id !=' => 0]); | ||
} | ||
|
||
public function WipeAllUsers() | ||
{ | ||
$this->User->deleteAll(['User.email !=' => '[email protected]']); | ||
} | ||
|
||
public function WipeAllOrgs() | ||
{ | ||
$this->Organisation->deleteAll(['Organisation.name !=' => 'ORGNAME']); | ||
} | ||
|
||
private function __createOrgFromBlueprint($id) | ||
{ | ||
$org = str_replace('$ID', $id, $this->__config['org_blueprint']); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.