file upload
This commit is contained in:
parent
147b033522
commit
07863e5c9a
|
@ -70,13 +70,9 @@ class nisNetGroupUser extends baseModule {
|
||||||
$return['PDF_fields']['memberships'] = _('NIS net groups');
|
$return['PDF_fields']['memberships'] = _('NIS net groups');
|
||||||
// help Entries
|
// help Entries
|
||||||
$return['help'] = array(
|
$return['help'] = array(
|
||||||
'addgroup' => array(
|
'memberships_upload' => array(
|
||||||
'Headline' => _('Groups of names'),
|
"Headline" => _('NIS net groups'),
|
||||||
'Text' => _("Hold the CTRL-key to (de)select multiple groups."). ' '. _("Can be left empty.")
|
"Text" => _("Here you can enter a list of net groups. Group blocks are separated by comma in format GROUP#HOST#DOMAIN. Host and domain are optional.")
|
||||||
),
|
|
||||||
'addgroup_upload' => array(
|
|
||||||
"Headline" => _("Groups of names"),
|
|
||||||
"Text" => _("Here you can enter a list of additional group memberships. The group names are separated by commas.")
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
// upload columns
|
// upload columns
|
||||||
|
@ -84,7 +80,7 @@ class nisNetGroupUser extends baseModule {
|
||||||
'name' => 'nisNetGroupUser_memberships',
|
'name' => 'nisNetGroupUser_memberships',
|
||||||
'description' => _('Memberships'),
|
'description' => _('Memberships'),
|
||||||
'help' => 'memberships_upload',
|
'help' => 'memberships_upload',
|
||||||
'example' => 'group1##host##domain,group2##host##domain'
|
'example' => 'group1#host#domain,group2#host#domain'
|
||||||
);
|
);
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
@ -455,19 +451,20 @@ class nisNetGroupUser extends baseModule {
|
||||||
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules) {
|
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules) {
|
||||||
$errors = array();
|
$errors = array();
|
||||||
// get list of existing group of names
|
// get list of existing group of names
|
||||||
$gons = $this->findGroupOfNames();
|
$groups = $this->findGroups();
|
||||||
$gonList = array();
|
$groupNames = array();
|
||||||
foreach ($gons as $dn => $attr) {
|
foreach ($groups as $group) {
|
||||||
$gonList[] = $attr['cn'][0];
|
$groupNames[] = $group['cn'][0];
|
||||||
}
|
}
|
||||||
// check input
|
// check input
|
||||||
for ($i = 0; $i < sizeof($rawAccounts); $i++) {
|
for ($i = 0; $i < sizeof($rawAccounts); $i++) {
|
||||||
// group of names
|
// group names
|
||||||
if ($rawAccounts[$i][$ids['groupOfNamesUser_gon']] != "") {
|
if (!empty($rawAccounts[$i][$ids['nisNetGroupUser_memberships']])) {
|
||||||
$groups = explode(",", $rawAccounts[$i][$ids['groupOfNamesUser_gon']]);
|
$triples = preg_split('/,[ ]*/', $rawAccounts[$i][$ids['nisNetGroupUser_memberships']]);
|
||||||
for ($g = 0; $g < sizeof($groups); $g++) {
|
foreach ($triples as $triple) {
|
||||||
if (!in_array($groups[$g], $gonList)) {
|
$parts = explode('#', $triple);
|
||||||
$errors[] = array('ERROR', _('Unable to find group in LDAP.'), $groups[$g]);
|
if (!in_array($parts[0], $groupNames)) {
|
||||||
|
$errors[] = array('ERROR', _('Unable to find group in LDAP.'), $parts[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -496,52 +493,66 @@ class nisNetGroupUser extends baseModule {
|
||||||
}
|
}
|
||||||
// on first call generate list of LDAP operations
|
// on first call generate list of LDAP operations
|
||||||
if (!isset($temp['counter'])) {
|
if (!isset($temp['counter'])) {
|
||||||
$temp['dn_gon'] = array();
|
$temp['groups'] = array();
|
||||||
$temp['counter'] = 0;
|
$temp['counter'] = 0;
|
||||||
// get list of existing group of names
|
// get list of existing groups
|
||||||
$gonList = $this->findGroupOfNames();
|
$groupList = $this->findGroups();
|
||||||
$gonMap = array();
|
$groupMap = array();
|
||||||
foreach ($gonList as $dn => $attr) {
|
foreach ($groupList as $group) {
|
||||||
$gonMap[$attr['cn'][0]] = $dn;
|
$groupMap[$group['cn'][0]] = $group['dn'];
|
||||||
}
|
}
|
||||||
for ($i = 0; $i < sizeof($data); $i++) {
|
for ($i = 0; $i < sizeof($data); $i++) {
|
||||||
if (in_array($i, $failed)) continue; // ignore failed accounts
|
if (in_array($i, $failed)) continue; // ignore failed accounts
|
||||||
if (isset($ids['groupOfNamesUser_gon']) && ($data[$i][$ids['groupOfNamesUser_gon']] != "")) {
|
if (empty($accounts[$i]['uid'])) {
|
||||||
$gons = explode(",", $data[$i][$ids['groupOfNamesUser_gon']]);
|
continue;
|
||||||
$memberAttr = 'member';
|
}
|
||||||
for ($g = 0; $g < sizeof($gons); $g++) {
|
$uid = $accounts[$i]['uid'];
|
||||||
if (in_array('groupOfUniqueNames', $gonList[$gonMap[$gons[$g]]]['objectclass'])) {
|
if (!empty($data[$i][$ids['nisNetGroupUser_memberships']])) {
|
||||||
$memberAttr = 'uniqueMember';
|
$triples = preg_split('/,[ ]*/', $data[$i][$ids['nisNetGroupUser_memberships']]);
|
||||||
}
|
foreach ($triples as $triple) {
|
||||||
$temp['dn_gon'][$gonMap[$gons[$g]]][$memberAttr][] = $accounts[$i]['dn'];
|
$parts = explode('#', $triple);
|
||||||
|
$group = $parts[0];
|
||||||
|
$host = empty($parts[1]) ? '' : $parts[1];
|
||||||
|
$domain = empty($parts[2]) ? '' : $parts[2];
|
||||||
|
$temp['groups'][$groupMap[$group]][] = '(' . $host . ',' . $uid . ',' . $domain . ')';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$temp['dn_gon_keys'] = array_keys($temp['dn_gon']);
|
$temp['groupDNs'] = array_keys($temp['groups']);
|
||||||
return array(
|
return array(
|
||||||
'status' => 'inProgress',
|
'status' => 'inProgress',
|
||||||
'progress' => 0,
|
'progress' => 0,
|
||||||
'errors' => array()
|
'errors' => array()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// add users to group of names
|
// add users to groups
|
||||||
elseif ($temp['counter'] < sizeof($temp['dn_gon'])) {
|
elseif ($temp['counter'] < sizeof($temp['groupDNs'])) {
|
||||||
$gonDn = $temp['dn_gon_keys'][$temp['counter']];
|
|
||||||
$gonAttr = $temp['dn_gon'][$gonDn];
|
|
||||||
$success = @ldap_mod_add($_SESSION['ldap']->server(), $gonDn, $gonAttr);
|
|
||||||
$errors = array();
|
$errors = array();
|
||||||
|
$dn = $temp['groupDNs'][$temp['counter']];
|
||||||
|
$current = ldapGetDN($dn, array('nisnetgrouptriple'));
|
||||||
|
if (empty($current)) {
|
||||||
|
$errors[] = array('ERROR', sprintf(_('Was unable to modify attributes of DN: %s.'), $dn));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$triples = empty($current['nisnetgrouptriple']) ? array() : $current['nisnetgrouptriple'];
|
||||||
|
$triples = array_merge($temp['groups'][$dn], $triples);
|
||||||
|
$triples = array_values(array_unique($triples));
|
||||||
|
$attributes = array(
|
||||||
|
'nisnetgrouptriple' => $triples
|
||||||
|
);
|
||||||
|
$success = @ldap_mod_replace($_SESSION['ldap']->server(), $dn, $attributes);
|
||||||
if (!$success) {
|
if (!$success) {
|
||||||
$errors[] = array(
|
$errors[] = array(
|
||||||
"ERROR",
|
"ERROR",
|
||||||
_("LAM was unable to modify group memberships for group: %s"),
|
_("LAM was unable to modify group memberships for group: %s"),
|
||||||
getDefaultLDAPErrorString($_SESSION['ldap']->server()),
|
getDefaultLDAPErrorString($_SESSION['ldap']->server()),
|
||||||
array($temp['groups'][$temp['counter']])
|
array($dn)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$temp['counter']++;
|
$temp['counter']++;
|
||||||
return array (
|
return array (
|
||||||
'status' => 'inProgress',
|
'status' => 'inProgress',
|
||||||
'progress' => ($temp['counter'] * 100) / sizeof($temp['dn_gon']),
|
'progress' => ($temp['counter'] * 100) / sizeof($temp['groupDNs']),
|
||||||
'errors' => $errors
|
'errors' => $errors
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue