mirror of
https://github.com/nuxsmin/sysPass.git
synced 2026-03-06 08:34:16 +01:00
* [DEV] New LDAP users synchronization feature
This commit is contained in:
@@ -457,16 +457,6 @@ if ($actionId === ActionsInterface::ACTION_CFG_GENERAL
|
||||
|
||||
$Json->setDescription($Log->getDescription());
|
||||
Json::returnJson($Json);
|
||||
} elseif ($actionId === ActionsInterface::ACTION_USR_SYNC_LDAP) {
|
||||
if (UserLdapSync::run()) {
|
||||
$Json->setStatus(0);
|
||||
$Json->setDescription(_('Sincronización de usuarios de LDAP realizada'));
|
||||
} else {
|
||||
$Json->setDescription(_('Error al sincronizar usuarios de LDAP'));
|
||||
}
|
||||
|
||||
$Json->addMessage(_('Revise el registro de eventos para más detalles'));
|
||||
Json::returnJson($Json);
|
||||
} else {
|
||||
$Json->setDescription(_('Acción Inválida'));
|
||||
Json::returnJson($Json);
|
||||
|
||||
@@ -32,6 +32,7 @@ use SP\Core\ActionsInterface;
|
||||
use SP\Core\SessionUtil;
|
||||
use SP\Core\DiFactory;
|
||||
use SP\Core\UI\ThemeIconsBase;
|
||||
use SP\Html\Assets\FontIcon;
|
||||
use SP\Html\DataGrid\DataGridAction;
|
||||
use SP\Html\DataGrid\DataGridActionSearch;
|
||||
use SP\Html\DataGrid\DataGridActionType;
|
||||
@@ -446,6 +447,17 @@ class Grids implements ActionsInterface
|
||||
$GridActionEditPass->setOnClickFunction('appMgmt/show');
|
||||
$GridActionEditPass->setFilterRowSource('user_isLdap');
|
||||
|
||||
$SyncLdapIcon = new FontIcon('get_app');
|
||||
|
||||
$GridActionLdapSync = new DataGridAction();
|
||||
$GridActionLdapSync->setId(self::ACTION_USR_SYNC_LDAP);
|
||||
$GridActionLdapSync->setType(DataGridActionType::NEW_ITEM);
|
||||
$GridActionLdapSync->setName(_('Importar usuarios de LDAP'));
|
||||
$GridActionLdapSync->setTitle(_('Importar usuarios de LDAP'));
|
||||
$GridActionLdapSync->setIcon($SyncLdapIcon);
|
||||
$GridActionLdapSync->setSkip(true);
|
||||
$GridActionLdapSync->setOnClickFunction('appMgmt/ldapSync');
|
||||
|
||||
$GridHeaders = new DataGridHeader();
|
||||
$GridHeaders->addHeader(_('Nombre'));
|
||||
$GridHeaders->addHeader(_('Login'));
|
||||
@@ -470,6 +482,7 @@ class Grids implements ActionsInterface
|
||||
$Grid->setDataPagerTemplate('datagrid-nav-full', 'grid');
|
||||
$Grid->setDataActions($GridActionSearch);
|
||||
$Grid->setDataActions($GridActionNew);
|
||||
$Grid->setDataActions($GridActionLdapSync);
|
||||
$Grid->setDataActions($GridActionView);
|
||||
$Grid->setDataActions($GridActionEdit);
|
||||
$Grid->setDataActions($GridActionEditPass);
|
||||
|
||||
@@ -53,6 +53,7 @@ use SP\Mgmt\Profiles\Profile;
|
||||
use SP\Mgmt\PublicLinks\PublicLink;
|
||||
use SP\Mgmt\Tags\Tag;
|
||||
use SP\Mgmt\Users\User;
|
||||
use SP\Mgmt\Users\UserLdapSync;
|
||||
use SP\Util\Json;
|
||||
|
||||
/**
|
||||
@@ -191,6 +192,9 @@ class ItemActionController
|
||||
case ActionsInterface::ACTION_ACC_FAVORITES_DELETE:
|
||||
$this->favoriteAction();
|
||||
break;
|
||||
case ActionsInterface::ACTION_USR_SYNC_LDAP:
|
||||
$this->ldapImportAction();
|
||||
break;
|
||||
default:
|
||||
$this->invalidAction();
|
||||
}
|
||||
@@ -645,4 +649,21 @@ class ItemActionController
|
||||
|
||||
$this->jsonResponse->setStatus(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Importar usuarios de LDAP
|
||||
*/
|
||||
private function ldapImportAction()
|
||||
{
|
||||
if (UserLdapSync::run()) {
|
||||
$this->jsonResponse->setStatus(0);
|
||||
$this->jsonResponse->setDescription(_('Importación de usuarios de LDAP realizada'));
|
||||
$this->jsonResponse->addMessage(sprintf(_('Usuarios importados %d/%d'), UserLdapSync::$syncedObjects, UserLdapSync::$totalObjects));
|
||||
$this->jsonResponse->addMessage(sprintf(_('Errores: %d'), UserLdapSync::$errorObjects));
|
||||
} else {
|
||||
$this->jsonResponse->setDescription(_('Error al importar usuarios de LDAP'));
|
||||
}
|
||||
|
||||
$this->jsonResponse->addMessage(_('Revise el registro de eventos para más detalles'));
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,19 @@ use SP\Util\Util;
|
||||
|
||||
class UserLdapSync
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public static $totalObjects = 0;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public static $syncedObjects = 0;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public static $errorObjects = 0;
|
||||
|
||||
/**
|
||||
* Sincronizar usuarios de LDAP
|
||||
*
|
||||
@@ -23,11 +36,11 @@ class UserLdapSync
|
||||
$Ldap = Config::getConfig()->isLdapAds() ? new LdapMsAds() : new LdapStd();
|
||||
|
||||
$ldapObjects = $Ldap->findObjects();
|
||||
$numObjects = count($ldapObjects);
|
||||
self::$totalObjects = count($ldapObjects);
|
||||
|
||||
$Log->addDescription(sprintf(_('Objetos encontrados: %s'), $numObjects));
|
||||
$Log->addDescription(sprintf(_('Objetos encontrados: %s'), self::$totalObjects));
|
||||
|
||||
if ($numObjects > 0) {
|
||||
if (self::$totalObjects > 0) {
|
||||
$UserData = new UserData();
|
||||
|
||||
foreach ($ldapObjects as $result) {
|
||||
@@ -48,7 +61,7 @@ class UserLdapSync
|
||||
$User->setUserLogin(strtolower($value));
|
||||
break;
|
||||
case 'mail':
|
||||
$User->setUserEmail($value);
|
||||
$User->setUserEmail(strtolower($value));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -58,7 +71,10 @@ class UserLdapSync
|
||||
try {
|
||||
$Log->addDescription(sprintf(_('Creando usuario \'%s (%s)\''), $User->getUserName(), $User->getUserLogin()));
|
||||
UserLdap::getItem($User)->add();
|
||||
|
||||
self::$syncedObjects++;
|
||||
} catch (SPException $e) {
|
||||
self::$errorObjects++;
|
||||
$Log->addDescription($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,9 +263,9 @@
|
||||
|
||||
<div class="action">
|
||||
<button type="button" class="btn-action mdl-button mdl-js-button mdl-button--fab mdl-button--mini-fab mdl-button--colored"
|
||||
data-onclick="config/ldapSync"
|
||||
data-onclick="appMgmt/ldapSync"
|
||||
data-action-id="<?php echo \SP\Core\ActionsInterface::ACTION_USR_SYNC_LDAP; ?>"
|
||||
title="<?php echo _('Sincronizar usuarios de LDAP'); ?>">
|
||||
title="<?php echo _('Importar usuarios de LDAP'); ?>">
|
||||
<i class="material-icons">get_app</i>
|
||||
</button>
|
||||
<button type="button" class="btn-action mdl-button mdl-js-button mdl-button--fab mdl-button--mini-fab mdl-button--colored <?php echo $icons->getIconCheck()->getClassButton(); ?>"
|
||||
|
||||
@@ -414,21 +414,6 @@ sysPass.Actions = function (Common) {
|
||||
doAction({actionId: $obj.data("nextaction-id"), itemId: $obj.data("activetab")});
|
||||
}
|
||||
});
|
||||
},
|
||||
ldapSync: function ($obj) {
|
||||
log.info("config:ldapSync");
|
||||
|
||||
var opts = Common.appRequests().getRequestOpts();
|
||||
opts.url = ajaxUrl.config.save;
|
||||
opts.data = {
|
||||
actionId: $obj.data("action-id"),
|
||||
sk: Common.sk.get(),
|
||||
isAjax: 1
|
||||
};
|
||||
|
||||
Common.appRequests().getActionCall(opts, function (json) {
|
||||
Common.msg.out(json);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -946,6 +931,32 @@ sysPass.Actions = function (Common) {
|
||||
$form.find("[name='sk']").val(Common.sk.get());
|
||||
|
||||
appMgmt.search($form);
|
||||
},
|
||||
ldapSync: function ($obj) {
|
||||
log.info("appMgmt:ldapSync");
|
||||
|
||||
var atext = "<div id=\"alert\"><p id=\"alert-text\">" + Common.config().LANG[57] + "</p></div>";
|
||||
|
||||
alertify
|
||||
.okBtn(Common.config().LANG[43])
|
||||
.cancelBtn(Common.config().LANG[44])
|
||||
.confirm(atext, function (e) {
|
||||
var opts = Common.appRequests().getRequestOpts();
|
||||
opts.url = ajaxUrl.appMgmt.save;
|
||||
opts.data = {
|
||||
actionId: $obj.data("action-id"),
|
||||
sk: Common.sk.get(),
|
||||
isAjax: 1
|
||||
};
|
||||
|
||||
Common.appRequests().getActionCall(opts, function (json) {
|
||||
Common.msg.out(json);
|
||||
});
|
||||
}, function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
alertify.error(Common.config().LANG[44]);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -79,5 +79,6 @@ $stringsJsLang = array(
|
||||
53 => _('Mostrar Todos'),
|
||||
54 => _('Ayuda'),
|
||||
55 => _('Sin cambios'),
|
||||
56 => _('Ahora')
|
||||
56 => _('Ahora'),
|
||||
57 => _('Este proceso importará los usuarios de LDAP detectados. Desea continuar?')
|
||||
);
|
||||
Reference in New Issue
Block a user