Esempio n. 1
0
 /**
  * Crear el usuario admin de sysPass.
  * Esta función crea el grupo, perfil y usuario 'admin' para utilizar sysPass.
  *
  * @throws SPException
  */
 private static function createAdminAccount()
 {
     // Datos del grupo
     Groups::$groupName = "Admins";
     Groups::$groupDescription = "Admins";
     if (!Groups::addGroup()) {
         self::rollback();
         throw new SPException(SPException::SP_CRITICAL, _('Error al crear el grupo "admin"'), _('Informe al desarrollador'));
     }
     $User = new User();
     // Establecer el id de grupo del usuario al recién creado
     $User->setUserGroupId(Groups::$queryLastId);
     $Profile = new Profile();
     $Profile->setName('Admin');
     $Profile->setAccAdd(true);
     $Profile->setAccView(true);
     $Profile->setAccViewPass(true);
     $Profile->setAccViewHistory(true);
     $Profile->setAccEdit(true);
     $Profile->setAccEditPass(true);
     $Profile->setAccDelete(true);
     $Profile->setConfigGeneral(true);
     $Profile->setConfigEncryption(true);
     $Profile->setConfigBackup(true);
     $Profile->setMgmCategories(true);
     $Profile->setMgmCustomers(true);
     $Profile->setMgmUsers(true);
     $Profile->setMgmGroups(true);
     $Profile->setMgmProfiles(true);
     $Profile->setEvl(true);
     if (!$Profile->profileAdd()) {
         self::rollback();
         throw new SPException(SPException::SP_CRITICAL, _('Error al crear el perfil "admin"'), _('Informe al desarrollador'));
     }
     // Datos del usuario
     $User->setUserLogin(self::$_username);
     $User->setUserPass(self::$_password);
     $User->setUserName('Admin');
     $User->setUserProfileId($Profile->getId());
     $User->setUserIsAdminApp(true);
     $User->setUserIsAdminAcc(false);
     $User->setUserIsDisabled(false);
     if (!$User->addUser()) {
         self::rollback();
         throw new SPException(SPException::SP_CRITICAL, _('Error al crear el usuario "admin"'), _('Informe al desarrollador'));
     }
     // Guardar el hash de la clave maestra
     ConfigDB::setCacheConfigValue('masterPwd', Crypt::mkHashPassword(self::$_masterPassword));
     ConfigDB::setCacheConfigValue('lastupdatempass', time());
     ConfigDB::writeConfig(true);
     if (!$User->updateUserMPass(self::$_masterPassword)) {
         self::rollback();
         throw new SPException(SPException::SP_CRITICAL, _('Error al actualizar la clave maestra del usuario "admin"'), _('Informe al desarrollador'));
     }
 }