added basic upload functions
This commit is contained in:
parent
4ec2a4ef4f
commit
9d3e4353d9
|
@ -147,8 +147,110 @@ class posixAccount extends baseModule {
|
|||
'posixAccount_pwdHash' => _("Password hash type"),
|
||||
)
|
||||
);
|
||||
// upload
|
||||
$return['upload_preDepends'] = array('inetOrgPerson');
|
||||
// user specific upload options
|
||||
if ($this->scope == 'user') {
|
||||
$return['upload_columns'] = array(
|
||||
array(
|
||||
'name' => 'posixAccount_userName',
|
||||
'description' => _('User name'),
|
||||
'help' => 'userName', // TODO
|
||||
'example' => _('smiller'),
|
||||
'required' => true,
|
||||
'unique' => true
|
||||
),
|
||||
array(
|
||||
'name' => 'posixAccount_uid',
|
||||
'description' => _('UID number'),
|
||||
'help' => 'uid', // TODO
|
||||
'example' => _('1234')
|
||||
),
|
||||
array(
|
||||
'name' => 'posixAccount_group',
|
||||
'description' => _('Primary group'),
|
||||
'help' => 'group', // TODO
|
||||
'example' => _('users'),
|
||||
'required' => true
|
||||
),
|
||||
array(
|
||||
'name' => 'posixAccount_additionalGroups',
|
||||
'description' => _('Additional groups'),
|
||||
'help' => 'additionalGroups', // TODO
|
||||
'example' => _('group01,group02')
|
||||
),
|
||||
array(
|
||||
'name' => 'posixAccount_homedir',
|
||||
'description' => _('Home directory'),
|
||||
'help' => 'homedir', // TODO
|
||||
'example' => _('/home/smiller'),
|
||||
'default' => '/home/<i><posixAccount_userName></i>'
|
||||
),
|
||||
array(
|
||||
'name' => 'posixAccount_shell',
|
||||
'description' => _('Login shell'),
|
||||
'help' => 'shell', // TODO
|
||||
'example' => _('/bin/bash'),
|
||||
'values' => implode(", ", getshells()),
|
||||
'default' => '/bin/bash'
|
||||
),
|
||||
array(
|
||||
'name' => 'posixAccount_password',
|
||||
'description' => _('Password'),
|
||||
'help' => 'password', // TODO
|
||||
'example' => _('secret')
|
||||
),
|
||||
array(
|
||||
'name' => 'posixAccount_passwordDisabled',
|
||||
'description' => _('Lock password'),
|
||||
'help' => 'passwordDisabled', // TODO
|
||||
'example' => _('false'),
|
||||
'values' => 'true, false',
|
||||
'default' => 'false'
|
||||
),
|
||||
array(
|
||||
'name' => 'posixAccount_gecos',
|
||||
'description' => _('GECOS'),
|
||||
'help' => 'gecos',
|
||||
'example' => _('Steve Miller,Room 2.14,123-123-1234,123-123-1234')
|
||||
)
|
||||
);
|
||||
}
|
||||
// host specific upload options
|
||||
elseif ($this->scope == 'host') {
|
||||
$return['upload_columns'] = array(
|
||||
array(
|
||||
'name' => 'posixAccount_hostName',
|
||||
'description' => _('Host name'),
|
||||
'help' => 'hostName', // TODO
|
||||
'example' => _('pc01$'),
|
||||
'required' => true,
|
||||
'unique' => true
|
||||
),
|
||||
array(
|
||||
'name' => 'posixAccount_uid',
|
||||
'description' => _('UID number'),
|
||||
'help' => 'uid', // TODO
|
||||
'example' => _('1234')
|
||||
),
|
||||
array(
|
||||
'name' => 'posixAccount_group',
|
||||
'description' => _('Primary group'),
|
||||
'help' => 'group', // TODO
|
||||
'example' => _('machines'),
|
||||
'required' => true
|
||||
),
|
||||
array(
|
||||
'name' => 'posixAccount_gecos',
|
||||
'description' => _('GECOS'),
|
||||
'help' => 'gecos',
|
||||
'example' => _('pc01,Room 2.34')
|
||||
)
|
||||
);
|
||||
}
|
||||
// available PDF fields
|
||||
$return['PDF_fields'] = array( 'uid',
|
||||
$return['PDF_fields'] = array(
|
||||
'uid',
|
||||
'uidNumber',
|
||||
'gidNumber',
|
||||
'gecos',
|
||||
|
@ -218,7 +320,8 @@ class posixAccount extends baseModule {
|
|||
'gidNumber' => array(
|
||||
"ext" => "FALSE",
|
||||
"Headline" => _("Primary group"),
|
||||
"Text" => _("The Primary group the host should be member of."))));
|
||||
"Text" => _("The Primary group the host should be member of."))
|
||||
));
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
@ -228,6 +331,7 @@ class posixAccount extends baseModule {
|
|||
// call parent init
|
||||
parent::init($base);
|
||||
$groups = $_SESSION['cache']->findgroups(); // list of all groupnames
|
||||
// TODO better error handling
|
||||
if (count($groups)==0) trigger_error(_('No groups found in ldap.'), E_USER_WARNING);
|
||||
$this->createhomedir=false;
|
||||
}
|
||||
|
@ -899,6 +1003,131 @@ class posixAccount extends baseModule {
|
|||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* In this function the LDAP account is built up.
|
||||
*
|
||||
* @param array $rawAccounts list of hash arrays (name => value) from user input
|
||||
* @param array $partialAccounts list of hash arrays (name => value) which are later added to LDAP
|
||||
* @param array $ids list of IDs for column position (e.g. "posixAccount_uid" => 5)
|
||||
* @return array list of error messages if any
|
||||
*/
|
||||
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts) {
|
||||
$errors = array();
|
||||
for ($i = 0; $i < sizeof($rawAccounts); $i++) {
|
||||
if (!in_array("posixAccount", $partialAccounts[$i]['objectClass'])) $partialAccounts[$i]['objectClass'][] = "posixAccount";
|
||||
// UID
|
||||
if ($rawAccounts[$i][$ids['posixAccount_uid']] == "") {
|
||||
// TODO autoGID
|
||||
$partialAccounts[$i]['uidNumber'] = 42;
|
||||
}
|
||||
elseif (get_preg($rawAccounts[$i][$ids['posixAccount_uid']], 'digit')) {
|
||||
$partialAccounts[$i]['uidNumber'] = $rawAccounts[$i][$ids['posixAccount_uid']];
|
||||
}
|
||||
else {
|
||||
$errMsg = $this->messages['uidNumber'][8]; // TODO
|
||||
array_push($errMsg, array($i));
|
||||
$errors[] = $errMsg;
|
||||
}
|
||||
// GID number
|
||||
if (get_preg($rawAccounts[$i][$ids['posixAccount_group']], 'digit')) {
|
||||
$partialAccounts[$i]['gidNumber'] = $rawAccounts[$i][$ids['posixAccount_group']];
|
||||
}
|
||||
if (get_preg($rawAccounts[$i][$ids['posixAccount_group']], 'groupname')) {
|
||||
$partialAccounts[$i]['gidNumber'] = 42;
|
||||
//$partialAccounts[$i]['gidNumber'] = $rawAccounts[$i][$ids['posixAccount_group']];
|
||||
// TODO group name => GID number
|
||||
}
|
||||
else {
|
||||
$errMsg = $this->messages['gidNumber'][8]; // TODO
|
||||
array_push($errMsg, array($i));
|
||||
$errors[] = $errMsg;
|
||||
}
|
||||
// GECOS // TODO fill default values
|
||||
if (($rawAccounts[$i][$ids['posixAccount_gecos']] != "") && (get_preg($rawAccounts[$i][$ids['posixAccount_gecos']], 'gecos'))) {
|
||||
$partialAccounts[$i]['gecos'] = $rawAccounts[$i][$ids['posixAccount_gecos']];
|
||||
}
|
||||
else {
|
||||
$errMsg = $this->messages['gecos'][1]; // TODO
|
||||
array_push($errMsg, array($i));
|
||||
$errors[] = $errMsg;
|
||||
}
|
||||
// user specific attributes
|
||||
if ($this->scope == 'user') {
|
||||
// user name
|
||||
if (get_preg($rawAccounts[$i][$ids['posixAccount_userName']], 'username')) {
|
||||
$partialAccounts[$i]['uid'] = $rawAccounts[$i][$ids['posixAccount_userName']];
|
||||
}
|
||||
else {
|
||||
$errMsg = $this->messages['username'][1]; // TODO
|
||||
array_push($errMsg, array($i));
|
||||
$errors[] = $errMsg;
|
||||
}
|
||||
// home directory
|
||||
if ($rawAccounts[$i][$ids['posixAccount_homedir']] == "") {
|
||||
$partialAccounts[$i]['homeDirectory'] = '/home/' . $partialAccounts[$i]['uid'];
|
||||
}
|
||||
elseif (get_preg($rawAccounts[$i][$ids['posixAccount_homedir']], 'homeDirectory')) {
|
||||
$partialAccounts[$i]['homeDirectory'] = $rawAccounts[$i][$ids['posixAccount_homedir']];
|
||||
}
|
||||
else {
|
||||
$errMsg = $this->messages['homedir'][8]; // TODO
|
||||
array_push($errMsg, array($i));
|
||||
$errors[] = $errMsg;
|
||||
}
|
||||
// login shell
|
||||
if ($rawAccounts[$i][$ids['posixAccount_shell']] == "") {
|
||||
$partialAccounts[$i]['loginShell'] = '/bin/bash';
|
||||
}
|
||||
elseif (in_array($rawAccounts[$i][$ids['posixAccount_shell']], getshells())) {
|
||||
$partialAccounts[$i]['loginShell'] = $rawAccounts[$i][$ids['posixAccount_shell']];
|
||||
}
|
||||
else {
|
||||
$errMsg = $this->messages['loginshell'][8]; // TODO
|
||||
array_push($errMsg, array($i));
|
||||
$errors[] = $errMsg;
|
||||
}
|
||||
$pwd_enabled = true;
|
||||
// password enabled/disabled
|
||||
if ($rawAccounts[$i][$ids['posixAccount_passwordDisabled']] == "") {
|
||||
$pwd_enabled = true;
|
||||
}
|
||||
elseif (in_array($rawAccounts[$i][$ids['posixAccount_passwordDisabled']], array('true', 'false'))) {
|
||||
if ($rawAccounts[$i][$ids['posixAccount_passwordDisabled']] == 'true') $pwd_enabled = false;
|
||||
else $pwd_enabled = true;
|
||||
}
|
||||
else {
|
||||
$errMsg = $this->messages['passwordDisabled'][8]; // TODO
|
||||
array_push($errMsg, array($i));
|
||||
$errors[] = $errMsg;
|
||||
}
|
||||
// password
|
||||
if (($rawAccounts[$i][$ids['posixAccount_password']] != "") && (get_preg($rawAccounts[$i][$ids['posixAccount_password']], 'password'))) {
|
||||
$partialAccounts[$i]['userPassword'] = pwd_hash($rawAccounts[$i][$ids['posixAccount_password']], $pwd_enabled, $this->moduleSettings['posixAccount_pwdHash'][0]);
|
||||
}
|
||||
else {
|
||||
$errMsg = $this->messages['password'][8]; // TODO
|
||||
array_push($errMsg, array($i));
|
||||
$errors[] = $errMsg;
|
||||
}
|
||||
}
|
||||
// host specific attributes
|
||||
elseif ($this->scope == 'host') {
|
||||
// host name
|
||||
if (get_preg($rawAccounts[$i][$ids['posixAccount_hostName']], 'hostname')) {
|
||||
$partialAccounts[$i]['uid'] = $rawAccounts[$i][$ids['posixAccount_hostName']];
|
||||
}
|
||||
else {
|
||||
$errMsg = $this->messages['hostname'][1]; // TODO
|
||||
array_push($errMsg, array($i));
|
||||
$errors[] = $errMsg;
|
||||
}
|
||||
$partialAccounts[$i]['homeDirectory'] = '/dev/null';
|
||||
$partialAccounts[$i]['loginShell'] = '/bin/false';
|
||||
}
|
||||
}
|
||||
return $errors;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue