PDF + profile
This commit is contained in:
parent
a34ec53c9c
commit
147b033522
|
@ -251,6 +251,25 @@ class nisNetGroupUser extends baseModule {
|
||||||
usort($this->groups, array($this, 'sortTriple'));
|
usort($this->groups, array($this, 'sortTriple'));
|
||||||
return $errors;
|
return $errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the user ID for this user.
|
||||||
|
*
|
||||||
|
* @return String user ID
|
||||||
|
*/
|
||||||
|
private function getUid() {
|
||||||
|
$moduleAttributes = array();
|
||||||
|
if ($this->getAccountContainer()->getAccountModule('posixAccount') != null) {
|
||||||
|
$moduleAttributes = $this->getAccountContainer()->getAccountModule('posixAccount')->getAttributes();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$moduleAttributes = $this->getAccountContainer()->getAccountModule('inetOrgPerson')->getAttributes();
|
||||||
|
}
|
||||||
|
if (empty($moduleAttributes['uid'][0])) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return $moduleAttributes['uid'][0];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs the postmodify actions.
|
* Runs the postmodify actions.
|
||||||
|
@ -262,19 +281,12 @@ class nisNetGroupUser extends baseModule {
|
||||||
* @return array array which contains status messages. Each entry is an array containing the status message parameters.
|
* @return array array which contains status messages. Each entry is an array containing the status message parameters.
|
||||||
*/
|
*/
|
||||||
public function postModifyActions($newAccount, $attributes) {
|
public function postModifyActions($newAccount, $attributes) {
|
||||||
$moduleAttributes = array();
|
$uid = $this->getUid();
|
||||||
if ($this->getAccountContainer()->getAccountModule('posixAccount') != null) {
|
if (empty($uid)) {
|
||||||
$moduleAttributes = $this->getAccountContainer()->getAccountModule('posixAccount')->getAttributes();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$moduleAttributes = $this->getAccountContainer()->getAccountModule('inetOrgPerson')->getAttributes();
|
|
||||||
}
|
|
||||||
if (empty($moduleAttributes['uid'][0])) {
|
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
$ldapUser = $_SESSION['ldap']->decrypt_login();
|
$ldapUser = $_SESSION['ldap']->decrypt_login();
|
||||||
$ldapUser = $ldapUser[0];
|
$ldapUser = $ldapUser[0];
|
||||||
$uid = $moduleAttributes['uid'][0];
|
|
||||||
$messages = array();
|
$messages = array();
|
||||||
// calculate differences
|
// calculate differences
|
||||||
$toRem = $this->groupsOrig;
|
$toRem = $this->groupsOrig;
|
||||||
|
@ -300,7 +312,7 @@ class nisNetGroupUser extends baseModule {
|
||||||
foreach ($toRem as $del) {
|
foreach ($toRem as $del) {
|
||||||
$changes[$del['dn']]['del'][] = '(' . $del['host'] . ',' . $uid . ',' . $del['domain'] . ')';
|
$changes[$del['dn']]['del'][] = '(' . $del['host'] . ',' . $uid . ',' . $del['domain'] . ')';
|
||||||
}
|
}
|
||||||
// add groups
|
// update groups
|
||||||
foreach ($changes as $dn => $changeSet) {
|
foreach ($changes as $dn => $changeSet) {
|
||||||
$current = ldapGetDN($dn, array('nisnetgrouptriple'));
|
$current = ldapGetDN($dn, array('nisnetgrouptriple'));
|
||||||
if (empty($current)) {
|
if (empty($current)) {
|
||||||
|
@ -333,8 +345,36 @@ class nisNetGroupUser extends baseModule {
|
||||||
* @return List of LDAP operations, same as for save_attributes()
|
* @return List of LDAP operations, same as for save_attributes()
|
||||||
*/
|
*/
|
||||||
function delete_attributes() {
|
function delete_attributes() {
|
||||||
|
$uid = $this->getUid();
|
||||||
|
if (empty($uid)) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
$ldapUser = $_SESSION['ldap']->decrypt_login();
|
||||||
|
$ldapUser = $ldapUser[0];
|
||||||
$return = array();
|
$return = array();
|
||||||
// remove from group of names
|
// remove from NIS netgroups
|
||||||
|
$changes = array();
|
||||||
|
foreach ($this->groups as $group) {
|
||||||
|
$changes[$group['dn']][] = '(' . $group['host'] . ',' . $uid . ',' . $group['domain'] . ')';
|
||||||
|
}
|
||||||
|
foreach ($changes as $dn => $changeSet) {
|
||||||
|
$current = ldapGetDN($dn, array('nisnetgrouptriple'));
|
||||||
|
if (empty($current)) {
|
||||||
|
$messages[] = array('ERROR', sprintf(_('Was unable to modify attributes of DN: %s.'), $dn));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$triples = empty($current['nisnetgrouptriple']) ? array() : $current['nisnetgrouptriple'];
|
||||||
|
$triples = array_delete($changeSet, $triples);
|
||||||
|
$triples = array_values(array_unique($triples));
|
||||||
|
$attributes = array(
|
||||||
|
'nisnetgrouptriple' => $triples
|
||||||
|
);
|
||||||
|
$success = @ldap_mod_replace($_SESSION['ldap']->server(), $dn, $attributes);
|
||||||
|
if (!$success) {
|
||||||
|
logNewMessage(LOG_ERR, '[' . $ldapUser .'] Unable to modify attributes of DN: ' . $dn . ' (' . ldap_error($_SESSION['ldap']->server()) . ').');
|
||||||
|
$messages[] = array('ERROR', sprintf(_('Was unable to modify attributes of DN: %s.'), $dn), getDefaultLDAPErrorString($_SESSION['ldap']->server()));
|
||||||
|
}
|
||||||
|
}
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,18 +384,22 @@ class nisNetGroupUser extends baseModule {
|
||||||
* @return profile elements
|
* @return profile elements
|
||||||
*/
|
*/
|
||||||
function get_profileOptions() {
|
function get_profileOptions() {
|
||||||
$return = new htmlTable();
|
$groups = $this->findGroups();
|
||||||
// group of names
|
$groupOptions = array('' => '');
|
||||||
$gons = $this->findGroupOfNames();
|
foreach ($groups as $group) {
|
||||||
$gonList = array();
|
$groupOptions[$group['cn'][0]] = $group['cn'][0] . '#+#' . $group['dn'];
|
||||||
foreach ($gons as $dn => $attr) {
|
}
|
||||||
$gonList[$attr['cn'][0]] = $dn;
|
$return = new htmlTable();
|
||||||
|
$return->addElement(new htmlOutputText(_('Group')));
|
||||||
|
$return->addElement(new htmlOutputText(_('Host name')));
|
||||||
|
$return->addElement(new htmlOutputText(_('Domain name')), true);
|
||||||
|
for ($i = 0; $i < 5; $i++) {
|
||||||
|
$select = new htmlSelect('nisNetGroupUser_group' . $i, $groupOptions, array(''));
|
||||||
|
$select->setHasDescriptiveElements(true);
|
||||||
|
$return->addElement($select);
|
||||||
|
$return->addElement(new htmlInputField('nisNetGroupUser_host' . $i));
|
||||||
|
$return->addElement(new htmlInputField('nisNetGroupUser_domain' . $i), true);
|
||||||
}
|
}
|
||||||
$gonSelect = new htmlTableExtendedSelect('groupOfNamesUser_gon', $gonList, array(), _('Groups of names'), 'addgroup', 10);
|
|
||||||
$gonSelect->setHasDescriptiveElements(true);
|
|
||||||
$gonSelect->setMultiSelect(true);
|
|
||||||
$gonSelect->setTransformSingleSelect(false);
|
|
||||||
$return->addElement($gonSelect, true);
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -365,13 +409,18 @@ class nisNetGroupUser extends baseModule {
|
||||||
* @param array $profile hash array with profile values (identifier => value)
|
* @param array $profile hash array with profile values (identifier => value)
|
||||||
*/
|
*/
|
||||||
function load_profile($profile) {
|
function load_profile($profile) {
|
||||||
// profile mappings in meta data
|
for ($i = 0; $i < 5; $i++) {
|
||||||
parent::load_profile($profile);
|
if (!empty($profile['nisNetGroupUser_group' . $i][0])) {
|
||||||
// special profile options
|
$parts = explode('#+#', $profile['nisNetGroupUser_group' . $i][0]);
|
||||||
// group of names
|
$this->groups[] = array(
|
||||||
if (isset($profile['groupOfNamesUser_gon'][0])) {
|
'name' => $parts[0],
|
||||||
$this->gonList = $profile['groupOfNamesUser_gon'];
|
'dn' => $parts[1],
|
||||||
|
'host' => $profile['nisNetGroupUser_host' . $i][0],
|
||||||
|
'domain' => $profile['nisNetGroupUser_domain' . $i][0],
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
usort($this->groups, array($this, 'sortTriple'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -381,16 +430,16 @@ class nisNetGroupUser extends baseModule {
|
||||||
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
|
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
|
||||||
*/
|
*/
|
||||||
function get_pdfEntries($pdfKeys) {
|
function get_pdfEntries($pdfKeys) {
|
||||||
$allGons = $this->findGroupOfNames();
|
|
||||||
$gons = array();
|
|
||||||
for ($i = 0; $i < sizeof($this->gonList); $i++) {
|
|
||||||
if (isset($allGons[$this->gonList[$i]])) {
|
|
||||||
$gons[] = $allGons[$this->gonList[$i]]['cn'][0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
natcasesort($gons);
|
|
||||||
$return = array();
|
$return = array();
|
||||||
$this->addPDFKeyValue($return, 'gon', _('Groups of names'), $gons);
|
$return[get_class($this) . '_memberships'][0] = '<block>'
|
||||||
|
. '<tr><td width="25%" align=\"L\"><b>' . _('Group') . '</b></td>'
|
||||||
|
. '<td width="25%" align=\"L\"><b>' . _('Host name') . '</b></td>'
|
||||||
|
. '<td width="25%" align=\"L\"><b>' . _('Domain name') . '</b></td></tr></block>';
|
||||||
|
foreach ($this->groups as $group) {
|
||||||
|
$return[get_class($this) . '_memberships'][] = '<block><tr><td width="25%" align=\"L\">' . $group['name'] . '</td>'
|
||||||
|
. '<td width="25%" align=\"L\">' . $group['host'] . ' </td>'
|
||||||
|
. '<td width="25%" align=\"L\">' . $group['domain'] . ' </td></tr></block>';
|
||||||
|
}
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue