2015-09-10 00:30:34 +02:00
|
|
|
<?php
|
|
|
|
class UserInitShell extends AppShell {
|
2015-12-30 09:54:43 +01:00
|
|
|
public $uses = array('User', 'Role', 'Organisation');
|
2015-09-10 00:30:34 +02:00
|
|
|
public function main() {
|
|
|
|
$this->Role->Behaviors->unload('SysLogLogable.SysLogLogable');
|
|
|
|
$this->User->Behaviors->unload('SysLogLogable.SysLogLogable');
|
|
|
|
// populate the DB with the first role (site admin) if it's empty
|
|
|
|
if ($this->Role->find('count') == 0 ) {
|
|
|
|
$siteAdmin = array('Role' => array(
|
|
|
|
'id' => 1,
|
|
|
|
'name' => 'Site Admin',
|
|
|
|
'permission' => 3,
|
2015-12-30 09:54:43 +01:00
|
|
|
'perm_add' => 1,
|
|
|
|
'perm_modify' => 1,
|
|
|
|
'perm_modify_org' => 1,
|
|
|
|
'perm_publish' => 1,
|
2015-09-10 00:30:34 +02:00
|
|
|
'perm_sync' => 1,
|
|
|
|
'perm_admin' => 1,
|
|
|
|
'perm_audit' => 1,
|
|
|
|
'perm_auth' => 1,
|
|
|
|
'perm_site_admin' => 1,
|
|
|
|
'perm_regexp_access' => 1,
|
2015-12-30 09:54:43 +01:00
|
|
|
'perm_sharing_group' => 1,
|
2015-09-10 00:30:34 +02:00
|
|
|
'perm_tagger' => 1,
|
2016-07-07 15:14:07 +02:00
|
|
|
'perm_template' => 1
|
2015-09-10 00:30:34 +02:00
|
|
|
));
|
|
|
|
$this->Role->save($siteAdmin);
|
|
|
|
}
|
2015-12-30 09:54:43 +01:00
|
|
|
|
|
|
|
$org_id = 0;
|
|
|
|
if ($this->Organisation->find('count', array('conditions' => array('Organisation.local' => true))) == 0) {
|
|
|
|
$org = array('Organisation' => array(
|
|
|
|
'id' => 1,
|
|
|
|
'name' => !empty(Configure::read('MISP.org')) ? Configure::read('MISP.org') : 'ADMIN',
|
|
|
|
'description' => 'Automatically generated admin organisation',
|
|
|
|
'type' => 'ADMIN',
|
2016-07-08 14:50:00 +02:00
|
|
|
'uuid' => $this->Organisation->generateUuid(),
|
2015-12-30 09:54:43 +01:00
|
|
|
'local' => 1
|
|
|
|
));
|
|
|
|
$this->Organisation->save($org);
|
|
|
|
$org_id = $this->Organisation->id;
|
|
|
|
} else {
|
|
|
|
$hostOrg = $this->Organisation->find('first', array('conditions' => array('Organisation.name' => Configure::read('MISP.org')), 'recursive' => -1));
|
|
|
|
if (!empty($hostOrg)) $org_id = $hostOrg['Organisation']['id'];
|
|
|
|
else {
|
|
|
|
$firstOrg = $this->Organisation->find('first', array('conditions' => array('Organisation.local' => true), 'order' => 'Organisation.id ASC'));
|
|
|
|
$org_id = $firstOrg['Organisation']['id'];
|
|
|
|
}
|
|
|
|
}
|
2016-06-04 01:08:16 +02:00
|
|
|
|
2015-09-10 00:30:34 +02:00
|
|
|
// populate the DB with the first user if it's empty
|
|
|
|
if ($this->User->find('count') == 0 ) {
|
|
|
|
$authkey = $this->User->generateAuthKey();
|
|
|
|
$admin = array('User' => array(
|
|
|
|
'id' => 1,
|
|
|
|
'email' => 'admin@admin.test',
|
2015-12-30 09:54:43 +01:00
|
|
|
'org_id' => $org_id,
|
2015-09-10 00:30:34 +02:00
|
|
|
'password' => 'admin',
|
|
|
|
'confirm_password' => 'admin',
|
|
|
|
'authkey' => $authkey,
|
|
|
|
'nids_sid' => 4000000,
|
2016-05-20 01:17:26 +02:00
|
|
|
'newsread' => 0,
|
2015-09-10 00:30:34 +02:00
|
|
|
'role_id' => 1,
|
|
|
|
'change_pw' => 0,
|
|
|
|
'termsaccepted' => 1
|
|
|
|
));
|
|
|
|
$this->User->validator()->remove('password'); // password is to simple, remove validation
|
|
|
|
$this->User->save($admin);
|
|
|
|
echo $authkey . PHP_EOL;
|
|
|
|
} else {
|
2016-06-04 01:10:45 +02:00
|
|
|
echo 'Script aborted: MISP instance already initialised.' . PHP_EOL;
|
2015-09-10 00:30:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|