multi edit tool
This commit is contained in:
parent
ba135d33e2
commit
bbda539377
|
@ -1,7 +1,8 @@
|
||||||
December 2013 4.4
|
December 2013 4.4
|
||||||
- PyKota support: users, groups, printers, billing codes
|
- PyKota support: users, groups, printers, billing codes
|
||||||
- Kolab shared folder support
|
- Kolab shared folder support
|
||||||
- allow to set a custom label for each account type
|
- New tool "Multi edit" allows LDAP operations on a large number of entries (e.g. adding attributes)
|
||||||
|
- Allow to set a custom label for each account type
|
||||||
- Unix: switch also additional membership if primary group is changed (RFE 108)
|
- Unix: switch also additional membership if primary group is changed (RFE 108)
|
||||||
- Windows: fixed user name handling, sAMAccountName now optional
|
- Windows: fixed user name handling, sAMAccountName now optional
|
||||||
- Apache 2.4 support (requires Apache "version" module)
|
- Apache 2.4 support (requires Apache "version" module)
|
||||||
|
|
|
@ -111,7 +111,7 @@ function displayStartPage() {
|
||||||
$container->addElement($suffixGroup);
|
$container->addElement($suffixGroup);
|
||||||
$container->addElement(new htmlHelpLink('700'), true);
|
$container->addElement(new htmlHelpLink('700'), true);
|
||||||
// LDAP filter
|
// LDAP filter
|
||||||
$valFilter = empty($_POST['filter']) ? '' : $_POST['filter'];
|
$valFilter = empty($_POST['filter']) ? '(objectClass=inetOrgPerson)' : $_POST['filter'];
|
||||||
$container->addElement(new htmlTableExtendedInputField(_('LDAP filter'), 'filter', $valFilter, '701'), true);
|
$container->addElement(new htmlTableExtendedInputField(_('LDAP filter'), 'filter', $valFilter, '701'), true);
|
||||||
// operation fields
|
// operation fields
|
||||||
$container->addElement(new htmlSubTitle(_('Operations')), true);
|
$container->addElement(new htmlSubTitle(_('Operations')), true);
|
||||||
|
@ -273,6 +273,7 @@ function runAjaxActions() {
|
||||||
$jsonReturn = generateActions();
|
$jsonReturn = generateActions();
|
||||||
break;
|
break;
|
||||||
case STAGE_ACTIONS_CALCULATED:
|
case STAGE_ACTIONS_CALCULATED:
|
||||||
|
case STAGE_WRITING:
|
||||||
if ($_SESSION['multiEdit_dryRun']) {
|
if ($_SESSION['multiEdit_dryRun']) {
|
||||||
$jsonReturn = dryRun();
|
$jsonReturn = dryRun();
|
||||||
}
|
}
|
||||||
|
@ -313,11 +314,7 @@ function readLDAPData() {
|
||||||
else {
|
else {
|
||||||
$msg = new htmlStatusMessage('ERROR', _('No objects found!'));
|
$msg = new htmlStatusMessage('ERROR', _('No objects found!'));
|
||||||
}
|
}
|
||||||
$tabindex = 0;
|
$content = getMessageHTML($msg);
|
||||||
ob_start();
|
|
||||||
parseHtml(null, $msg, array(), true, $tabindex, 'user');
|
|
||||||
$content = ob_get_contents();
|
|
||||||
ob_end_clean();
|
|
||||||
return array(
|
return array(
|
||||||
'status' => STAGE_FINISHED,
|
'status' => STAGE_FINISHED,
|
||||||
'progress' => 120,
|
'progress' => 120,
|
||||||
|
@ -390,7 +387,8 @@ function generateActions() {
|
||||||
* @return array status
|
* @return array status
|
||||||
*/
|
*/
|
||||||
function dryRun() {
|
function dryRun() {
|
||||||
$ldif = '';
|
$pro = isLAMProVersion() ? ' Pro' : '';
|
||||||
|
$ldif = '# LDAP Account Manager' . $pro . ' ' . LAMVersion() . "\n\nversion: 1\n\n";
|
||||||
$log = '';
|
$log = '';
|
||||||
// fill LDIF and log file
|
// fill LDIF and log file
|
||||||
$lastDN = '';
|
$lastDN = '';
|
||||||
|
@ -462,3 +460,83 @@ function dryRun() {
|
||||||
'content' => $content
|
'content' => $content
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs the actual modifications.
|
||||||
|
*
|
||||||
|
* @return array status
|
||||||
|
*/
|
||||||
|
function doModify() {
|
||||||
|
// initial action index
|
||||||
|
if (!isset($_SESSION['multiEdit_status']['index'])) {
|
||||||
|
$_SESSION['multiEdit_status']['index'] = 0;
|
||||||
|
}
|
||||||
|
// initial content
|
||||||
|
if (!isset($_SESSION['multiEdit_status']['modContent'])) {
|
||||||
|
$_SESSION['multiEdit_status']['modContent'] = '';
|
||||||
|
}
|
||||||
|
// run 10 modifications in each call
|
||||||
|
$localCount = 0;
|
||||||
|
while (($localCount < 10) && ($_SESSION['multiEdit_status']['index'] < sizeof($_SESSION['multiEdit_status']['actions']))) {
|
||||||
|
$action = $_SESSION['multiEdit_status']['actions'][$_SESSION['multiEdit_status']['index']];
|
||||||
|
$opType = $action[0];
|
||||||
|
$dn = $action[1];
|
||||||
|
$attr = $action[2];
|
||||||
|
$val = $action[3];
|
||||||
|
$_SESSION['multiEdit_status']['modContent'] .= htmlspecialchars($dn) . "<br>";
|
||||||
|
// run LDAP commands
|
||||||
|
$success = false;
|
||||||
|
switch ($opType) {
|
||||||
|
case ADD:
|
||||||
|
$success = @ldap_mod_add($_SESSION['ldap']->server(), $dn, array($attr => array($val)));
|
||||||
|
break;
|
||||||
|
case DEL:
|
||||||
|
if (empty($val)) {
|
||||||
|
$success = ldap_modify($_SESSION['ldap']->server(), $dn, array($attr => array()));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$success = ldap_mod_del($_SESSION['ldap']->server(), $dn, array($attr => array($val)));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case MOD:
|
||||||
|
$success = ldap_modify($_SESSION['ldap']->server(), $dn, array($attr => array($val)));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!$success) {
|
||||||
|
$msg = new htmlStatusMessage('ERROR', getDefaultLDAPErrorString($_SESSION['ldap']->server()));
|
||||||
|
$_SESSION['multiEdit_status']['modContent'] .= getMessageHTML($msg);
|
||||||
|
}
|
||||||
|
$localCount++;
|
||||||
|
$_SESSION['multiEdit_status']['index']++;
|
||||||
|
}
|
||||||
|
// check if finished
|
||||||
|
if ($_SESSION['multiEdit_status']['index'] == sizeof($_SESSION['multiEdit_status']['actions'])) {
|
||||||
|
$_SESSION['multiEdit_status']['modContent'] .= '<br><br>' . _('Finished all operations.');
|
||||||
|
return array(
|
||||||
|
'status' => STAGE_FINISHED,
|
||||||
|
'progress' => 120,
|
||||||
|
'content' => $_SESSION['multiEdit_status']['modContent']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// return current status
|
||||||
|
return array(
|
||||||
|
'status' => STAGE_WRITING,
|
||||||
|
'progress' => 20 + (($_SESSION['multiEdit_status']['index'] / sizeof($_SESSION['multiEdit_status']['actions'])) * 100),
|
||||||
|
'content' => $_SESSION['multiEdit_status']['modContent']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the HTML code for a htmlStatusMessage
|
||||||
|
*
|
||||||
|
* @param htmlStatusMessage $msg message
|
||||||
|
* @return String HTML code
|
||||||
|
*/
|
||||||
|
function getMessageHTML($msg) {
|
||||||
|
$tabindex = 0;
|
||||||
|
ob_start();
|
||||||
|
parseHtml(null, $msg, array(), true, $tabindex, 'user');
|
||||||
|
$content = ob_get_contents();
|
||||||
|
ob_end_clean();
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue