allow to hide gecos, posix groups and group of names

This commit is contained in:
Roland Gruber 2013-03-24 10:03:35 +00:00
parent dd9314931c
commit 6657436544
1 changed files with 145 additions and 95 deletions

View File

@ -221,6 +221,26 @@ class posixAccount extends baseModule implements passwordService {
array('SSHA'), _("Password hash type"), 'pwdHash'), true); array('SSHA'), _("Password hash type"), 'pwdHash'), true);
$configOptionsContainer->addElement(new htmlTableExtendedInputCheckbox('posixAccount_primaryGroupAsSecondary', false, _('Set primary group as memberUid'), 'primaryGroupAsSecondary'), true); $configOptionsContainer->addElement(new htmlTableExtendedInputCheckbox('posixAccount_primaryGroupAsSecondary', false, _('Set primary group as memberUid'), 'primaryGroupAsSecondary'), true);
$configOptionsContainer->addElement(new htmlTableExtendedInputTextarea('posixAccount_shells', implode("\r\n", $this->getShells()), 30, 4, _('Login shells'), 'loginShells'), true); $configOptionsContainer->addElement(new htmlTableExtendedInputTextarea('posixAccount_shells', implode("\r\n", $this->getShells()), 30, 4, _('Login shells'), 'loginShells'), true);
$hiddenOptionsContainer = new htmlGroup();
$hiddenOptionsContainer->colspan = 5;
$hiddenOptionsContainerHead = new htmlTable();
$hiddenOptionsContainerHead->addElement(new htmlOutputText(_('Hidden options')));
$hiddenOptionsContainerHead->addElement(new htmlHelpLink('hiddenOptions'));
$hiddenOptionsContainer->addElement($hiddenOptionsContainerHead);
$configContainerOptions = new htmlTable();
$configContainerOptions->addElement(new htmlTableExtendedInputCheckbox('posixAccount_hidegecos', false, _('Gecos'), null, false));
if (isset($_SESSION['conf_config'])) {
$confActiveGONModules = array_merge($_SESSION['conf_config']->get_AccountModules('group'), $_SESSION['conf_config']->get_AccountModules('gon'));
if (in_array('groupOfNames', $confActiveGONModules) || in_array('groupOfUniqueNames', $confActiveGONModules)) {
$configContainerOptions->addElement(new htmlOutputText(' '));
$configContainerOptions->addElement(new htmlTableExtendedInputCheckbox('posixAccount_hidegon', false, _('Groups of names'), null, false));
$configContainerOptions->addElement(new htmlOutputText(' '));
$configContainerOptions->addElement(new htmlTableExtendedInputCheckbox('posixAccount_hideposixGroups', false, _('Unix groups'), null, false));
}
}
$hiddenOptionsContainer->addElement($configContainerOptions);
$configOptionsContainer->addElement($hiddenOptionsContainer);
$return['config_options']['all'] = $configOptionsContainer; $return['config_options']['all'] = $configOptionsContainer;
// upload // upload
$return['upload_preDepends'] = array('inetOrgPerson'); $return['upload_preDepends'] = array('inetOrgPerson');
@ -296,17 +316,19 @@ class posixAccount extends baseModule implements passwordService {
'values' => 'true, false', 'values' => 'true, false',
'default' => 'false' 'default' => 'false'
), ),
array( );
if (!$this->isBooleanConfigOptionSet('posixAccount_hidegecos')) {
$return['upload_columns'][] = array(
'name' => 'posixAccount_gecos', 'name' => 'posixAccount_gecos',
'description' => _('Gecos'), 'description' => _('Gecos'),
'help' => 'gecos', 'help' => 'gecos',
'example' => _('Steve Miller,Room 2.14,123-123-1234,123-123-1234') 'example' => _('Steve Miller,Room 2.14,123-123-1234,123-123-1234')
)
); );
}
if (self::areGroupOfNamesActive()) { if (self::areGroupOfNamesActive()) {
$return['upload_columns'][] = array( $return['upload_columns'][] = array(
'name' => 'posixAccount_gon', 'name' => 'posixAccount_gon',
'description' => _('Group of names'), 'description' => _('Groups of names'),
'help' => 'addgroup_upload', 'help' => 'addgroup_upload',
'example' => _('group01,group02') 'example' => _('group01,group02')
); );
@ -336,14 +358,16 @@ class posixAccount extends baseModule implements passwordService {
'example' => _('machines'), 'example' => _('machines'),
'required' => true 'required' => true
), ),
array( );
if (!$this->isBooleanConfigOptionSet('posixAccount_hidegecos')) {
$return['upload_columns'][] = array(
'name' => 'posixAccount_gecos', 'name' => 'posixAccount_gecos',
'description' => _('Gecos'), 'description' => _('Gecos'),
'help' => 'gecos', 'help' => 'gecos',
'example' => _('pc01,Room 2.34') 'example' => _('pc01,Room 2.34')
)
); );
} }
}
// available PDF fields // available PDF fields
if ($this->get_scope() == 'host') { if ($this->get_scope() == 'host') {
$return['PDF_fields'] = array('uid' => _('Host name')); $return['PDF_fields'] = array('uid' => _('Host name'));
@ -354,7 +378,6 @@ class posixAccount extends baseModule implements passwordService {
$return['PDF_fields'] = array_merge($return['PDF_fields'], array( $return['PDF_fields'] = array_merge($return['PDF_fields'], array(
'uidNumber' => _('UID number'), 'uidNumber' => _('UID number'),
'gidNumber' => _('GID number'), 'gidNumber' => _('GID number'),
'gecos' => _('Gecos'),
'primaryGroup' => _('Primary group'), 'primaryGroup' => _('Primary group'),
'additionalGroups' => _('Additional groups'), 'additionalGroups' => _('Additional groups'),
'homeDirectory' => _('Home directory'), 'homeDirectory' => _('Home directory'),
@ -362,11 +385,18 @@ class posixAccount extends baseModule implements passwordService {
'cn' => _('Common name'), 'cn' => _('Common name'),
'userPassword' => _('Password') 'userPassword' => _('Password')
)); ));
if (!$this->isBooleanConfigOptionSet('posixAccount_hidegecos')) {
$return['PDF_fields']['gecos'] = _('Gecos');
}
if (self::areGroupOfNamesActive()) { if (self::areGroupOfNamesActive()) {
$return['PDF_fields']['gon'] = _('Group of names'); $return['PDF_fields']['gon'] = _('Groups of names');
} }
// help Entries // help Entries
$return['help'] = array( $return['help'] = array(
'hiddenOptions' => array(
"Headline" => _("Hidden options"),
"Text" => _("The selected options will not be managed inside LAM. You can use this to reduce the number of displayed input fields.")
),
'primaryGroupAsSecondary' => array( 'primaryGroupAsSecondary' => array(
'Headline' => _('Set primary group as memberUid'), 'Headline' => _('Set primary group as memberUid'),
'Text' => _('Usually, users are not added to groups as memberUid if they have this group as primary group. If your application ignores primary groups then you can select this option to override this behaviour.') 'Text' => _('Usually, users are not added to groups as memberUid if they have this group as primary group. If your application ignores primary groups then you can select this option to override this behaviour.')
@ -828,7 +858,9 @@ class posixAccount extends baseModule implements passwordService {
if (isset($_POST['loginShell'])) { if (isset($_POST['loginShell'])) {
$this->attributes['loginShell'][0] = $_POST['loginShell']; $this->attributes['loginShell'][0] = $_POST['loginShell'];
} }
if (!$this->isBooleanConfigOptionSet('posixAccount_hidegecos')) {
if (isset($_POST['gecos'])) $this->attributes['gecos'][0] = $_POST['gecos']; if (isset($_POST['gecos'])) $this->attributes['gecos'][0] = $_POST['gecos'];
}
if (isset($this->orig['uid'][0]) && ($this->orig['uid'][0] != '') && ($_POST['uid'] != $this->attributes['uid'][0])) { if (isset($this->orig['uid'][0]) && ($this->orig['uid'][0] != '') && ($_POST['uid'] != $this->attributes['uid'][0])) {
$errors[] = $this->messages['uid'][0]; $errors[] = $this->messages['uid'][0];
} }
@ -966,7 +998,10 @@ class posixAccount extends baseModule implements passwordService {
$this->attributes['loginShell'][0] = '/bin/false'; $this->attributes['loginShell'][0] = '/bin/false';
} }
} }
$attributeList = array('gecos', 'homeDirectory'); $attributeList = array('homeDirectory');
if (!$this->isBooleanConfigOptionSet('posixAccount_hidegecos')) {
$attributeList[] = 'gecos';
}
for ($i = 0; $i < sizeof($attributeList); $i++) { for ($i = 0; $i < sizeof($attributeList); $i++) {
if (isset($this->attributes[$attributeList[$i]][0])) { if (isset($this->attributes[$attributeList[$i]][0])) {
$value = $this->attributes[$attributeList[$i]][0]; $value = $this->attributes[$attributeList[$i]][0];
@ -1014,6 +1049,7 @@ class posixAccount extends baseModule implements passwordService {
*/ */
function process_group() { function process_group() {
// Unix groups // Unix groups
if (!$this->isBooleanConfigOptionSet('posixAccount_hideposixGroups')) {
if (isset($_POST['addgroups']) && isset($_POST['addgroups_button'])) { // Add groups to list if (isset($_POST['addgroups']) && isset($_POST['addgroups_button'])) { // Add groups to list
// add new group // add new group
$this->groups = @array_merge($this->groups, $_POST['addgroups']); $this->groups = @array_merge($this->groups, $_POST['addgroups']);
@ -1021,8 +1057,9 @@ class posixAccount extends baseModule implements passwordService {
elseif (isset($_POST['removegroups']) && isset($_POST['removegroups_button'])) { // remove groups from list elseif (isset($_POST['removegroups']) && isset($_POST['removegroups_button'])) { // remove groups from list
$this->groups = array_delete($_POST['removegroups'], $this->groups); $this->groups = array_delete($_POST['removegroups'], $this->groups);
} }
}
// group of names // group of names
if (self::areGroupOfNamesActive()) { if (self::areGroupOfNamesActive() && !$this->isBooleanConfigOptionSet('posixAccount_hidegon')) {
if (isset($_POST['addgons']) && isset($_POST['addgons_button'])) { // Add groups to list if (isset($_POST['addgons']) && isset($_POST['addgons_button'])) { // Add groups to list
// add new group // add new group
$this->gonList = @array_merge($this->gonList, $_POST['addgons']); $this->gonList = @array_merge($this->gonList, $_POST['addgons']);
@ -1167,9 +1204,11 @@ class posixAccount extends baseModule implements passwordService {
$uidNumberInput->setFieldMaxLength(20); $uidNumberInput->setFieldMaxLength(20);
$uidNumberInput->setValidationRule(htmlElement::VALIDATE_NUMERIC); $uidNumberInput->setValidationRule(htmlElement::VALIDATE_NUMERIC);
$return->addElement($uidNumberInput, true); $return->addElement($uidNumberInput, true);
if (!$this->isBooleanConfigOptionSet('posixAccount_hidegecos')) {
$gecos = ''; $gecos = '';
if (isset($this->attributes['gecos'][0])) $gecos = $this->attributes['gecos'][0]; if (isset($this->attributes['gecos'][0])) $gecos = $this->attributes['gecos'][0];
$return->addElement(new htmlTableExtendedInputField(_('Gecos'), 'gecos', $gecos, 'gecos'), true); $return->addElement(new htmlTableExtendedInputField(_('Gecos'), 'gecos', $gecos, 'gecos'), true);
}
$primaryGroup = array(); $primaryGroup = array();
if (isset($this->attributes['gidNumber'][0])) { if (isset($this->attributes['gidNumber'][0])) {
$primaryGroup[] = $this->attributes['gidNumber'][0]; $primaryGroup[] = $this->attributes['gidNumber'][0];
@ -1180,9 +1219,11 @@ class posixAccount extends baseModule implements passwordService {
if ($this->get_scope()=='user') { if ($this->get_scope()=='user') {
// additional groups // additional groups
if (!$this->isBooleanConfigOptionSet('posixAccount_hidegon') || !$this->isBooleanConfigOptionSet('posixAccount_hideposixGroups')) {
$return->addElement(new htmlOutputText(_('Additional groups'))); $return->addElement(new htmlOutputText(_('Additional groups')));
$return->addElement(new htmlAccountPageButton(get_class($this), 'group', 'open', _('Edit groups'))); $return->addElement(new htmlAccountPageButton(get_class($this), 'group', 'open', _('Edit groups')));
$return->addElement(new htmlHelpLink('addgroup'), true); $return->addElement(new htmlHelpLink('addgroup'), true);
}
// home directory // home directory
$homedirInput = new htmlTableExtendedInputField(_('Home directory'), 'homeDirectory', $this->attributes['homeDirectory'][0], 'homeDirectory'); $homedirInput = new htmlTableExtendedInputField(_('Home directory'), 'homeDirectory', $this->attributes['homeDirectory'][0], 'homeDirectory');
$homedirInput->setRequired(true); $homedirInput->setRequired(true);
@ -1257,6 +1298,7 @@ class posixAccount extends baseModule implements passwordService {
*/ */
function display_html_group() { function display_html_group() {
$return = new htmlTable(); $return = new htmlTable();
if (!$this->isBooleanConfigOptionSet('posixAccount_hideposixGroups')) {
// load list with all groups // load list with all groups
$groups = $this->findGroups(); $groups = $this->findGroups();
for ($i = 0; $i < sizeof($groups); $i++) { for ($i = 0; $i < sizeof($groups); $i++) {
@ -1294,15 +1336,18 @@ class posixAccount extends baseModule implements passwordService {
$unixContainer->addNewLine(); $unixContainer->addNewLine();
$return->addElement($unixContainer); $return->addElement($unixContainer);
}
if (self::areGroupOfNamesActive()) { if (self::areGroupOfNamesActive() && !$this->isBooleanConfigOptionSet('posixAccount_hidegon')) {
if (!$this->isBooleanConfigOptionSet('posixAccount_hideposixGroups')) {
$return->addElement(new htmlSpacer('100px', null)); $return->addElement(new htmlSpacer('100px', null));
}
$gons = $this->findGroupOfNames(); $gons = $this->findGroupOfNames();
$gonContainer = new htmlTable(); $gonContainer = new htmlTable();
$gonContainer->alignment = htmlElement::ALIGN_TOP; $gonContainer->alignment = htmlElement::ALIGN_TOP;
$gonContainer->addElement(new htmlSubTitle(_("Group of names")), true); $gonContainer->addElement(new htmlSubTitle(_("Groups of names")), true);
$gonContainer->addElement(new htmlOutputText(_("Selected groups"))); $gonContainer->addElement(new htmlOutputText(_("Selected groups")));
$gonContainer->addElement(new htmlOutputText('')); $gonContainer->addElement(new htmlOutputText(''));
$gonContainer->addElement(new htmlOutputText(_("Available groups"))); $gonContainer->addElement(new htmlOutputText(_("Available groups")));
@ -1341,10 +1386,13 @@ class posixAccount extends baseModule implements passwordService {
} }
$return->addNewLine(); $return->addNewLine();
$return->addElement(new htmlSpacer(null, '10px'), true);
$backGroup = new htmlGroup();
$backGroup->colspan = 10;
$backGroup->addElement(new htmlSpacer(null, '10px'), true);
$backButton = new htmlAccountPageButton(get_class($this), 'attributes', 'back', _('Back')); $backButton = new htmlAccountPageButton(get_class($this), 'attributes', 'back', _('Back'));
$return->addElement($backButton); $backGroup->addElement($backButton);
$return->addElement($backGroup);
return $return; return $return;
} }
@ -1448,7 +1496,7 @@ class posixAccount extends baseModule implements passwordService {
foreach ($gons as $dn => $attr) { foreach ($gons as $dn => $attr) {
$gonList[$attr['cn'][0]] = $dn; $gonList[$attr['cn'][0]] = $dn;
} }
$gonSelect = new htmlTableExtendedSelect('posixAccount_gon', $gonList, array(), _('Group of names'), 'addgroup', 10); $gonSelect = new htmlTableExtendedSelect('posixAccount_gon', $gonList, array(), _('Groups of names'), 'addgroup', 10);
$gonSelect->setHasDescriptiveElements(true); $gonSelect->setHasDescriptiveElements(true);
$gonSelect->setMultiSelect(true); $gonSelect->setMultiSelect(true);
$gonSelect->setTransformSingleSelect(false); $gonSelect->setTransformSingleSelect(false);
@ -1558,7 +1606,7 @@ class posixAccount extends baseModule implements passwordService {
$gons[] = $allGons[$this->gonList[$i]]['cn'][0]; $gons[] = $allGons[$this->gonList[$i]]['cn'][0];
} }
} }
$return['posixAccount_gon'] = array('<block><key>' . _('Group of names') . '</key><value>' . implode(", ", $gons) . '</value></block>'); $return['posixAccount_gon'] = array('<block><key>' . _('Groups of names') . '</key><value>' . implode(", ", $gons) . '</value></block>');
} }
if (isset($this->clearTextPassword)) { if (isset($this->clearTextPassword)) {
$return['posixAccount_userPassword'] = array('<block><key>' . _('Password') . '</key><value>' . $this->clearTextPassword . '</value></block>'); $return['posixAccount_userPassword'] = array('<block><key>' . _('Password') . '</key><value>' . $this->clearTextPassword . '</value></block>');
@ -1729,6 +1777,7 @@ class posixAccount extends baseModule implements passwordService {
$errors[] = $errMsg; $errors[] = $errMsg;
} }
// GECOS // GECOS
if (!$this->isBooleanConfigOptionSet('posixAccount_hidegecos')) {
if ($rawAccounts[$i][$ids['posixAccount_gecos']] != "") { if ($rawAccounts[$i][$ids['posixAccount_gecos']] != "") {
if (get_preg($rawAccounts[$i][$ids['posixAccount_gecos']], 'gecos')) { if (get_preg($rawAccounts[$i][$ids['posixAccount_gecos']], 'gecos')) {
$partialAccounts[$i]['gecos'] = $this->checkASCII($rawAccounts[$i][$ids['posixAccount_gecos']]); $partialAccounts[$i]['gecos'] = $this->checkASCII($rawAccounts[$i][$ids['posixAccount_gecos']]);
@ -1754,6 +1803,7 @@ class posixAccount extends baseModule implements passwordService {
$partialAccounts[$i]['gecos'] = $this->checkASCII($gecos); $partialAccounts[$i]['gecos'] = $this->checkASCII($gecos);
} }
} }
}
// user specific attributes // user specific attributes
if ($this->get_scope() == 'user') { if ($this->get_scope() == 'user') {
// additional groups // additional groups