general_dn = substr($account_new->general_dn, strpos($account_new->general_dn, ',')+1); $final_changegids = ''; // Display general-page $select_local = 'general'; } // Startcondition. groupedit.php was called from outside to create a new group else if (count($_POST)==0) { // Create new account object with settings from default profile $account_new = loadGroupProfile('default'); $account_new ->type = 'group'; if ($config_intern->scriptServer) { // load quotas and check if quotas from profile are valid $values = getquotas('group'); if (isset($account_new->quota[0])) { // check quotas from profile $i=0; // check quota settings, loop for every partition with quotas while (isset($account_new->quota[$i])) { // search if quotas from profile fit to a real quota $found = (-1); for ($j=0; $jquota); $j++) if ($values->quota[$j][0]==$account_new->quota[$i][0]) $found = $j; // unset quota from profile if quotas (mointpoint) doesn't exists anymore if ($found==-1) unset($account_new->quota[$i]); else { // Set missing part in quota-array $account_new->quota[$i][1] = $values->quota[$found][1]; $account_new->quota[$i][5] = $values->quota[$found][5]; $account_new->quota[$i][4] = $values->quota[$found][4]; $account_new->quota[$i][8] = $values->quota[$found][8]; $i++; } } // Beautify array, repair index $account_new->quota = array_values($account_new->quota); } else { // No quotas saved in profile // Display quotas for new users (Quota set to 0) if (is_object($values)) { while (list($key, $val) = each($values)) // Set only defined values if (isset($val)) $account_new->$key = $val; } } } // Display general-page $select_local = 'general'; } switch ($_POST['select']) { /* Select which part of page should be loaded and check values * groupmembers = page with all users which are additional members of group * general = startpage, general account paramters * samba = page with all samba-related parameters e.g. smbpassword * quota = page with all quota-related parameters e.g. hard file quota * personal = page with all personal-related parametergs, e.g. phone number * final = last page shown before account is created/modified * finish = page shown after account has been created/modified */ case 'groupmembers': do { // X-Or, only one if() can be true if (isset($_POST['users']) && isset($_POST['add'])) { // Add users to list // Add new user $account_new->unix_memberUid = array_merge($account_new->unix_memberUid, $_POST['users']); // remove doubles $account_new->unix_memberUid = array_flip($account_new->unix_memberUid); array_unique($account_new->unix_memberUid); $account_new->unix_memberUid = array_flip($account_new->unix_memberUid); // sort user sort($account_new->unix_memberUid); break; } if (isset($_POST['members']) && isset($_POST['remove'])) { // remove users fromlist $account_new->unix_memberUid = array_delete($_POST['members'], $account_new->unix_memberUid); break; } } while(0); // display groupmembers page $select_local = 'groupmembers'; break; case 'general': // Write all general attributes into $account_new if no profile should be loaded if (!$_POST['load']) { $account_new->general_dn = $_POST['f_general_suffix']; $account_new->general_username = $_POST['f_general_username']; $account_new->general_uidNumber = $_POST['f_general_uidNumber']; $account_new->general_gecos = $_POST['f_general_gecos']; // Check if values are OK and set automatic values. if not error-variable will be set // Check if Groupname contains only valid characters if ( !ereg('^([a-z]|[0-9]|[.]|[-]|[_])*$', $account_new->general_username)) $errors[] = array('ERROR', _('Groupname'), _('Groupname contains invalid characters. Valid characters are: a-z, 0-9 and .-_ !')); if ($account_new->general_gecos=='') { $account_new->general_gecos = $account_new->general_username ; $errors[] = array('INFO', _('Gecos'), _('Inserted groupname in gecos-field.')); } // Create automatic groupaccount with number if original group already exists // Reset name to original name if new name is in use if (ldapexists($account_new, $account_old) && is_object($account_old)) $account_new->general_username = $account_old->general_username; while ($temp = ldapexists($account_new, $account_old)) { // get last character of username $lastchar = substr($account_new->general_username, strlen($account_new->general_username)-1, 1); // Last character is no number if ( !ereg('^([0-9])+$', $lastchar)) /* Last character is no number. Therefore we only have to * add "2" to it. */ $account_new->general_username = $account_new->general_username . '2'; else { /* Last character is a number -> we have to increase the number until we've * found a groupname with trailing number which is not in use. * * $i will show us were we have to split groupname so we get a part * with the groupname and a part with the trailing number */ $i=strlen($account_new->general_username)-1; $mark = false; // Set $i to the last character which is a number in $account_new->general_username while (!$mark) { if (ereg('^([0-9])+$',substr($account_new->general_username, $i, strlen($account_new->general_username)-$i))) $i--; else $mark=true; } // increase last number with one $firstchars = substr($account_new->general_username, 0, $i+1); $lastchars = substr($account_new->general_username, $i+1, strlen($account_new->general_username)-$i); // Put groupname together $account_new->general_username = $firstchars . (intval($lastchars)+1); } } // Show warning if lam has changed groupname if ($account_new->general_username != $_POST['f_general_username']) $errors[] = array('WARN', _('Groupname'), _('Groupname already in use. Selected next free groupname.')); // Check if UID is valid. If none value was entered, the next useable value will be inserted $temp = explode(':', checkid($account_new, $account_old)); $account_new->general_uidNumber = $temp[0]; // true if checkid has returned an error if ($temp[1]!='') $errors[] = explode(';',$temp[1]); // Check if Name-length is OK. minLength=3, maxLength=20 if ( !ereg('.{3,20}', $account_new->general_username)) $errors[] = array('ERROR', _('Name'), _('Name must contain between 3 and 20 characters.')); // Check if Name starts with letter if ( !ereg('^([a-z]|[A-Z]).*$', $account_new->general_username)) $errors[] = array('ERROR', _('Name'), _('Name contains invalid characters. First character must be a letter')); } break; case 'samba': // Write all samba attributes into $account_new // Get all domains $samba3domains = $ldap_intern->search_domains($config_intern->get_domainSuffix()); // Search the corrct domain in array unset($account_new->smb_domain); $i = 0; while (!is_object($account_new->smb_domain) && isset($samba3domains[$i])) { if ($_POST['f_smb_domain'] == $samba3domains[$i]->name) $account_new->smb_domain = $samba3domains[$i]; else $i++; } $account_new->smb_displayName = $_POST['f_smb_displayName']; // Check if group SID should be mapped to a well known SID switch ($_POST['f_smb_mapgroup']) { case '*'._('Domain Guests'): $account_new->smb_mapgroup = $account_new->smb_domain->SID . "-" . '514'; break; case '*'._('Domain Users'): $account_new->smb_mapgroup = $account_new->smb_domain->SID . "-" . '513'; break; case '*'._('Domain Admins'): $account_new->smb_mapgroup = $account_new->smb_domain->SID . "-" . '512'; break; case $account_new->general_username: $account_new->smb_mapgroup = $account_new->smb_domain->SID . "-". (2 * getgid($account_new->general_username) + $account_new->smb_domain->RIDbase +1); break; } // Check if values are OK and set automatic values. if not error-variable will be set if (($account_new->smb_displayName=='') && isset($account_new->general_gecos)) { $account_new->smb_displayName = $account_new->general_gecos; $errors[] = array('INFO', _('Display name'), _('Inserted gecos-field as display name.')); } break; case 'quota': // Write all general values into $account_new $i=0; // loop for every mointpoint with quotas while ($account_new->quota[$i][0]) { $account_new->quota[$i][2] = $_POST['f_quota_'.$i.'_2']; $account_new->quota[$i][3] = $_POST['f_quota_'.$i.'_3']; $account_new->quota[$i][6] = $_POST['f_quota_'.$i.'_6']; $account_new->quota[$i][7] = $_POST['f_quota_'.$i.'_7']; // Check if values are OK and set automatic values. if not error-variable will be set if (!ereg('^([0-9])*$', $account_new->quota[$i][2])) $errors[] = array('ERROR', _('Block soft quota'), _('Block soft quota contains invalid characters. Only natural numbers are allowed')); if (!ereg('^([0-9])*$', $account_new->quota[$i][3])) $errors[] = array('ERROR', _('Block hard quota'), _('Block hard quota contains invalid characters. Only natural numbers are allowed')); if (!ereg('^([0-9])*$', $account_new->quota[$i][6])) $errors[] = array('ERROR', _('Inode soft quota'), _('Inode soft quota contains invalid characters. Only natural numbers are allowed')); if (!ereg('^([0-9])*$', $account_new->quota[$i][7])) $errors[] = array('ERROR', _('Inode hard quota'), _('Inode hard quota contains invalid characters. Only natural numbers are allowed')); $i++; } break; case 'final': // Ask if we should change gidNumber of every user which is member of the group if ($_POST['f_final_changegids']) $final_changegids = $_POST['f_final_changegids'] ; break; case 'finish': // Check if pdf-file should be created if ($_POST['outputpdf']) { // Load quotas if not yet done because they are needed for the pdf-file if ($config_intern->scriptServer && !isset($account_new->quota[0])) { // load quotas $values = getquotas('group', $account_old->general_username); if (is_object($values)) { while (list($key, $val) = each($values)) // Set only defined values if (isset($val)) $account_new->$key = $val; } if (is_object($values) && isset($account_old)) { while (list($key, $val) = each($values)) // Set only defined values if (isset($val)) $account_old->$key = $val; } } // Create / display PDf-file createGroupPDF(array($account_new)); // Stop script die; } break; } do { // X-Or, only one if() can be true if ($_POST['next_members']) { // Go from groupmembers to next page if no error did ocour if (!is_array($errors)) $select_local='groupmembers'; else $select_local=$_POST['select']; break; } if ($_POST['next_general']) { // Go from general to next page if no error did ocour if (!is_array($errors)) $select_local='general'; else $select_local=$_POST['select']; break; } if ($_POST['next_samba']) { // Go from samba to next page if no error did ocour if (!is_array($errors)) $select_local='samba'; else $select_local=$_POST['select']; break; } if ($_POST['next_quota']) { // Go from quota to next page if no error did ocour if (!is_array($errors)) $select_local='quota'; else $select_local=$_POST['select']; break; } if ($_POST['next_final']) { // Check if objectclasses are OK if ($config_intern->is_samba3() && !isset($account_new->smb_domain)) // Samba page not viewed; can not create group because if missing options $errors[] = array("ERROR", _("Samba Options not set!"), _("Please check settings on samba page.")); if (isset($account_old->general_objectClass)) { if (($config_intern->is_samba3()) && (!in_array('sambaGroupMapping', $account_old->general_objectClass))) $errors[] = array('WARN', _('ObjectClass sambaGroupMapping not found.'), _('Have to add objectClass sambaGroupMapping.')); if (!in_array('posixGroup', $account_old->general_objectClass)) $errors[] = array('WARN', _('ObjectClass posixGroup not found.'), _('Have to add objectClass posixGroup.')); } // Show info if gidNumber has changed if (($account_old) && ($account_new->general_uidNumber != $account_old->general_uidNumber)) $errors[] = array('INFO', _('GID-number has changed. You have to run the following command as root in order to change existing file-permissions:'), 'find / -gid ' . $account_old->general_uidNumber . ' -exec chgrp ' . $account_new->general_uidNumber . ' {} \;'); // Go from final to next page if no error did ocour if (!isset($errors)) $select_local='final'; else $select_local=$_POST['select']; break; } // Reset account to original settings if undo-button was pressed if ($_POST['next_reset']) { $account_new = $account_old; $account_new->general_dn = substr($account_new->general_dn, strpos($account_new->general_dn, ',')+1); $select_local = $_POST['select']; break; } // Create-Button was pressed if ( $_POST['create'] ) { // Create or modify an account if ($account_old) $result = modifygroup($account_new,$account_old); else $result = creategroup($account_new); // account.inc if ( $result==4 || $result==5 ) $select_local = 'final'; else $select_local = 'finish'; break; } // Load Profile and reset all attributes to settings in profile if ($_POST['createagain']) { $select_local='general'; unset ($_SESSION['account_'.$varkey.'_account_new']); unset($account_new); $_SESSION['account_'.$varkey.'_account_new'] = loadGroupProfile('default'); $account_new =& $_SESSION['account_'.$varkey.'_account_new']; $account_new ->type = 'group'; break; } // Go back to listgroups.php if ($_POST['backmain']) { metaRefresh("../lists/listgroups.php"); if (isset($_SESSION['account_'.$varkey.'_account_new'])) unset($_SESSION['account_'.$varkey.'_account_new']); if (isset($_SESSION['account_'.$varkey.'_account_old'])) unset($_SESSION['account_'.$varkey.'_account_old']); if (isset($_SESSION['account_'.$varkey.'_final_changegids'])) unset($_SESSION['account_'.$varkey.'_final_changegids']); die; break; } // Load Profile and reset all attributes to settings in profile if ($_POST['load']) { $account_new->general_dn = $_POST['f_general_suffix']; $account_new->general_username = $_POST['f_general_username']; $account_new->general_uidNumber = $_POST['f_general_uidNumber']; $account_new->general_gecos = $_POST['f_general_gecos']; // load profile if ($_POST['f_general_selectprofile']!='') $values = loadGroupProfile($_POST['f_general_selectprofile']); if (is_object($values)) { while (list($key, $val) = each($values)) // Set only defined values if (isset($val)) $account_new->$key = $val; } if ($config_intern->scriptServer) { // load quotas and check if quotas from profile are valid $values = getquotas('group'); if (isset($account_new->quota[0])) { // check quotas from profile $i=0; // check quota settings, loop for every partition with quotas while (isset($account_new->quota[$i])) { // search if quotas from profile fit to a real quota $found = (-1); for ($j=0; $jquota); $j++) if ($values->quota[$j][0]==$account_new->quota[$i][0]) $found = $j; // unset quota from profile if quotas (mointpoint) doesn't exists anymore if ($found==-1) unset($account_new->quota[$i]); else { // Set missing part in quota-array $account_new->quota[$i][1] = $values->quota[$found][1]; $account_new->quota[$i][5] = $values->quota[$found][5]; $account_new->quota[$i][4] = $values->quota[$found][4]; $account_new->quota[$i][8] = $values->quota[$found][8]; $i++; } } // Beautify array, repair index $account_new->quota = array_values($account_new->quota); } else { // No quotas saved in profile // Display quotas for new users (Quota set to 0) if (is_object($values)) { while (list($key, $val) = each($values)) // Set only defined values if (isset($val)) $account_new->$key = $val; } } } // select general page after group has been loaded $select_local='general'; break; } // Save Profile if ($_POST['save']) { // save profile if ($_POST['f_finish_safeProfile']=='') $errors[] = array('ERROR', _('Save profile'), _('No profilename given.')); else { saveGroupProfile($account_new, $_POST['f_finish_safeProfile']); $errors[] = array('INFO', _('Save profile'), _('New profile created.')); } // select last page displayed before user is created $select_local='final'; break; } if ($_POST['groupmembers']) { $select_local='groupmembers'; break; } } while(0); // Write HTML-Header echo $header_intern; echo ""; echo _("Create new Account"); echo "\n". "\n". "\n". "\n". "\n". "
\n". "\n"; // Display errir-messages if (is_array($errors)) for ($i=0; $iunix_memberUid, $users); /* Now we have to remove all users from list who are primary member of group * At the moment lam is doing an extra ldap-search. In future this should be done * via cache-array **** fixme */ // Do a ldap-search if (isset($account_old->general_uidNumber)) $result = ldap_search($_SESSION['ldap']->server(), $_SESSION['config']->get_UserSuffix(), "(&(objectClass=PosixAccount)(gidNumber=$account_old->general_uidNumber))", array('cn')); else $result = ldap_search($_SESSION['ldap']->server(), $_SESSION['config']->get_UserSuffix(), "(&(objectClass=PosixAccount)(gidNumber=$account_new->general_uidNumber))", array('cn')); $entry = ldap_first_entry($_SESSION['ldap']->server(), $result); // loop for every user which is primary member of group while ($entry) { $attr = ldap_get_attributes($_SESSION['ldap']->server(), $entry); if (isset($attr['cn'][0])) { // Remove user from user list $users = @array_flip($users); unset ($users[$attr['cn'][0]]); $users = @array_flip($users); } // Go to next entry $entry = ldap_next_entry($_SESSION['ldap']->server(), $entry); } echo "\n"; echo "\n\n\n
"; echo "
"; echo _('Please select page:'); echo "\n"; echo "\n
"; echo "\n
"; // samba 2.2 doesn't have any settings for groups if ($config_intern->is_samba3()) { echo "\n
"; } echo "scriptPath)) echo " disabled "; echo "value=\""; echo _('Quota'); echo "\">\n
"; echo ""; if (isset($account_old)) { echo "

"; echo _("Reset all changes."); echo "
"; echo "\n"; } echo "
"; echo "
". _('Additional group members') . "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n\n
"; echo _('Group members'); echo ""; // display all users which are additional members of group if (count($account_new->unix_memberUid)!=0) { echo "\n"; } echo "
"; echo " "; echo "\">

"; echo ""._('Help')."
"; echo _('Available users'); echo "\n"; // Display all users which are not member of group in any way if ((count($users)!=0) && is_array($users)) { echo "\n"; } echo "
\n
\n
\n"; break; case 'general': // General Account Settings // load list of profiles $profilelist = getGroupProfiles(); // Show page info echo "\n"; echo "\n\n
"; echo "
"; echo _('Please select page:'); echo "\n"; echo "\n
"; echo "\n
"; // samba 2.2 doesn't have any settings for groups if ($config_intern->is_samba3()) { echo "\n
"; } echo "scriptPath)) echo " disabled "; echo "value=\""; echo _('Quota'); echo "\">\n
"; echo ""; if (isset($account_old)) { echo "

"; echo _("Reset all changes."); echo "
"; echo "\n"; } echo "
"; echo "\n\n\n
"; echo "
"; echo _("General properties"); echo "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n". "\n\n\n\n\n\n\n
"; echo _("Groupname")."*"; echo "". "general_username."\">". ""._('Help')."
"; echo _('GID number'); echo "general_uidNumber."\">". ""._('Help'). "
"; echo _('Description'); echo "general_gecos."\">"._('Help')."
"; echo _('Suffix'); echo ""._('Help'). "
"; echo _('Values with * are required'); echo "
\n
"; // Show fieldset with list of all group profiles if (count($profilelist)!=0) { echo "
"; echo _("Load profile"); echo "\n\n\n\n\n
"; echo "\n". ""; echo _('Help')."
\n
\n"; } echo "
\n
\n"; break; case 'samba': // Samba Settings // samba 2.2 doesn't have any settings for groups $samba3domains = $ldap_intern->search_domains($config_intern->get_domainSuffix()); echo "\n"; echo "\n\n\n
"; echo "
"; echo _('Please select page:'); echo "\n"; echo "\n
"; echo "\n
"; echo "\n
"; echo "scriptPath)) echo " disabled "; echo "value=\""; echo _('Quota'); echo "\">\n
"; echo ""; if (isset($account_old)) { echo "

"; echo _("Reset all changes."); echo "
"; echo "\n"; } echo "
"; echo "
"._('Samba properties')."\n"; echo "\n\n\n\n\n\n\n'."\n".'\n\n"; echo "
"; echo _("Display name"); echo "". "smb_displayName."\">". ""._('Help')."
"; echo _('Windows groupname'); echo "". ''._('Help').''. '
'; echo _('Domain'); echo ''; // select which domain name should be displayed if (count($samba3domains)!=0) { echo ''; } echo ""._('Help')."
\n
\n
\n"; break; case 'quota': // Quota Settings // Load quotas if not yet done if ($config_intern->scriptServer && !isset($account_new->quota[0]) ) { // load quotas $values = getquotas('group', $account_new->general_username); if (is_object($values)) { while (list($key, $val) = each($values)) // Set only defined values if (isset($val)) $account_new->$key = $val; } if (is_object($values) && isset($account_old)) { while (list($key, $val) = each($values)) // Set only defined values if (isset($val)) $account_old->$key = $val; } } echo "\n"; echo "\n\n\n
"; echo "
"; echo _('Please select page:'); echo "\n"; echo "\n
"; echo "\n
"; // samba 2.2 doesn't have any settings for groups if ($config_intern->is_samba3()) { echo "\n
"; } echo "\n
"; echo ""; if (isset($account_old)) { echo "

"; echo _("Reset all changes."); echo "
"; echo "\n"; } echo "
"; echo ''; echo "
"._('Quota properties')."\n"; echo "'."\n".''."\n".''."\n".''."\n".''."\n".''."\n".''."\n".''."\n".''."\n"; echo ''."\n".''."\n".''."\n".''."\n".''."\n".''."\n".''."\n".''."\n".''."\n"; $i=0; // loop for every mointpoint with enabled quotas while ($account_new->quota[$i][0]) { echo ''; // used blocks echo ''; // blocks soft limit echo ''; // blocks hard limit echo ''; // block grace period echo ''; // used inodes echo ''; // inodes soft limit echo ''; // inodes hard limit echo ''; // inodes grace period $i++; } echo "
"; echo _('Mountpoint'); echo ''; echo _('Used blocks'); echo ''; echo _('Soft block limit'); echo ''; echo _('Hard block limit'); echo ''; echo _('Grace block period'); echo ''; echo _('Used inodes'); echo ''; echo _('Soft inode limit'); echo ''; echo _('Hard inode limit'); echo ''; echo _('Grace inode period'); echo '
'._('Help').''._('Help').''. ''._('Help').''._('Help').''. ''._('Help').''._('Help').''. ''._('Help').''._('Help').''. ''._('Help').'
'.$account_new->quota[$i][0].''.$account_new->quota[$i][1].''.$account_new->quota[$i][4].''.$account_new->quota[$i][5].''.$account_new->quota[$i][8].'
\n
\n
\n"; break; case 'final': // Final Settings $disabled = ""; if ($config_intern->is_samba3() && !isset($account_new->smb_domain)) // Samba page not viewed; can not create group because if missing options $disabled = "disabled"; echo ''; echo "\n"; echo "\n\n
"; echo "
"; echo _('Please select page:'); echo "\n"; echo "\n
"; echo "\n
"; if ($config_intern->is_samba3()) { echo "\n
"; } echo "scriptPath)) echo " disabled "; echo "value=\""; echo _('Quota'); echo "\">\n
"; echo ""; if (isset($account_old)) { echo "

"; echo _("Reset all changes."); echo "
"; echo "\n"; } echo "
"; echo "\n\n\n
"; echo "
"; echo _("Save profile"); echo "\n\n\n\n\n
"; echo ''; echo "'._('Help'); echo "
\n
\n
\n"; echo "
"; if ($account_old) echo _('Modify'); else echo _('Create'); echo "\n"; echo ""; // Ask if gidNumbers of primary group members should be changed if (($account_old) && ($account_new->general_uidNumber != $account_old->general_uidNumber)) { echo ''."\n"; } echo "
'; echo ''; echo _('Change GID-Number of all users in group to new value'); echo '
'."\n"; echo "
\n
\n
"; break; case 'finish': // Final Settings echo ''; echo "
"._('Success')."\n"; echo ""; echo ''."\n".''."\n".''."\n".'
'; echo _('Group').' '; echo $account_new->general_username; if ($account_old) echo ' '._('has been modified').'.'; else echo ' '._('has been created').'.'; echo '
'; if (!$account_old) { echo' '; } echo ''. ''. ''. ''. '
'; ?>