From 7b96445cfd996d4684db8b28e764d9a36a8ab6c4 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Mon, 9 Jul 2007 19:03:19 +0000 Subject: [PATCH] allow to create homedirs in upload --- lam/HISTORY | 1 + lam/lib/modules/posixAccount.inc | 46 +++++++++++++++++++++++++++----- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/lam/HISTORY b/lam/HISTORY index 184ef856..09601e76 100644 --- a/lam/HISTORY +++ b/lam/HISTORY @@ -5,6 +5,7 @@ - group list can show primary members (RFE 1517679 and patch 1722460) - more translated example texts (RFE 1702140) - inetOrgPerson: now manages homePhone, roomNumber, businessCategory + - posixAccount: allow to create home directories in file upload (RFE 1665034) - account lists: display buttons on top and bottom (RFE 1702136) - fixed bugs: -> OU editor: help images (1702132) diff --git a/lam/lib/modules/posixAccount.inc b/lam/lib/modules/posixAccount.inc index a4fa789f..4bdc4f07 100644 --- a/lam/lib/modules/posixAccount.inc +++ b/lam/lib/modules/posixAccount.inc @@ -182,7 +182,7 @@ class posixAccount extends baseModule { // upload $return['upload_preDepends'] = array('inetOrgPerson'); // user specific upload options - if ($this->scope == 'user') { + if (($this->scope == 'user') && $_SESSION['loggedIn']) { $return['upload_columns'] = array( array( 'name' => 'posixAccount_userName', @@ -224,6 +224,13 @@ class posixAccount extends baseModule { 'example' => _('/home/smiller'), 'default' => '/home/<posixAccount_userName>' ), + array( + 'name' => 'posixAccount_createHomeDir', + 'description' => _('Create home directory'), + 'help' => 'createhomedir', + 'example' => 'localhost', + 'values' => $_SESSION['config']->get_scriptServers() + ), array( 'name' => 'posixAccount_shell', 'description' => _('Login shell'), @@ -344,6 +351,10 @@ class posixAccount extends baseModule { "Headline" => _("Home directory"), "Text" => _("Activating this checkbox will remove the user's home directory.") ), + 'createhomedir' => array( + "Headline" => _("Home directory"), + "Text" => _("This will create the user's home directory on the specified server.") + ), 'user' => array( 'uid' => array( "Headline" => _("User name"), @@ -587,10 +598,7 @@ class posixAccount extends baseModule { foreach ($result as $singleresult) { $singleresult = explode(",", $singleresult); if (is_array($singleresult)) { - if (($singleresult[0] == 'ERROR') || ($singleresult[0] == 'WARN')) { - call_user_func_array('StatusMessage', $singleresult); - } - elseif ($singleresult[0] == 'INFO'){ + if (($singleresult[0] == 'ERROR') || ($singleresult[0] == 'WARN') || ($singleresult[0] == 'INFO')) { call_user_func_array('StatusMessage', $singleresult); } } @@ -1467,8 +1475,10 @@ class posixAccount extends baseModule { // on first call generate list of ldap operations if (!isset($temp['counter'])) { $temp['groups'] = array(); + $temp['createHomes'] = array(); $temp['counter'] = 0; $col = $ids['posixAccount_additionalGroups']; + $col_home = $ids['posixAccount_createHomeDir']; for ($i = 0; $i < sizeof($data); $i++) { if (in_array($i, $failed)) continue; // ignore failed accounts if ($data[$i][$col] != "") { @@ -1478,6 +1488,9 @@ class posixAccount extends baseModule { $temp['members'][$groups[$g]][] = $data[$i][$ids['posixAccount_userName']]; } } + if ($data[$i][$col_home] != "") { + $temp['createHomes'][] = $i; + } } return array( 'status' => 'inProgress', @@ -1515,7 +1528,7 @@ class posixAccount extends baseModule { $temp['counter']++; return array ( 'status' => 'inProgress', - 'progress' => ($temp['counter'] * 100) / sizeof($temp['groups']), + 'progress' => ($temp['counter'] * 100) / (sizeof($temp['groups']) + sizeof($temp['createHomes'])), 'errors' => $errors ); } @@ -1523,11 +1536,30 @@ class posixAccount extends baseModule { $temp['counter']++; return array ( 'status' => 'inProgress', - 'progress' => ($temp['counter'] * 100) / sizeof($temp['groups']), + 'progress' => ($temp['counter'] * 100) / (sizeof($temp['groups'] + sizeof($temp['createHomes']))), 'errors' => array(array('ERROR', _('Unable to find group in LDAP.'), $temp['groups'][$temp['counter']])) ); } } + // create home directories + elseif ($temp['counter'] < (sizeof($temp['groups']) + sizeof($temp['createHomes']))) { + $pos = $temp['createHomes'][$temp['counter'] - sizeof($temp['groups'])]; + $result = lamdaemon(array($data[$pos][$ids['posixAccount_userName']] . " home add 0".$_SESSION['config']->scriptRights), + $data[$pos][$ids['posixAccount_createHomeDir']]); + $errors = array(); + if (($result != false) && (sizeof($result) == 1)) { + $parts = explode(",", $result[0]); + if (in_array($parts[0], array('ERROR', 'WARN'))) { + $errors[] = $parts; + } + } + $temp['counter']++; + return array ( + 'status' => 'inProgress', + 'progress' => ($temp['counter'] * 100) / (sizeof($temp['groups']) + sizeof($temp['createHomes'])), + 'errors' => $errors + ); + } // all groups are modified else { return array (