MISP/app/Console/Command/UserInitShell.php

75 lines
2.5 KiB
PHP
Raw Normal View History

2015-09-10 00:30:34 +02:00
<?php
class UserInitShell extends AppShell {
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,
'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,
'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);
}
$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',
'uuid' => $this->Organisation->generateUuid(),
'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'];
}
}
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',
'org_id' => $org_id,
2015-09-10 00:30:34 +02:00
'password' => 'admin',
'confirm_password' => 'admin',
'authkey' => $authkey,
'nids_sid' => 4000000,
'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
}
}
}