diff --git a/lam/lib/profiles.inc b/lam/lib/profiles.inc index 71781b5d..dc239254 100644 --- a/lam/lib/profiles.inc +++ b/lam/lib/profiles.inc @@ -30,15 +30,17 @@ include_once("ldap.inc"); // returns an array of String with all available user profiles (without .pru) function getUserProfiles() { - $dir = dir(substr(__FILE__, 0, strlen(__FILE__) - 17) . "/config/profiles/users"); + $dir = @dir(substr(__FILE__, 0, strlen(__FILE__) - 17) . "/config/profiles/users"); $ret = array(); $pos = 0; - while ($entry = $dir->read()){ - $ext = substr($entry, strlen($entry)-4, 4); - $name = substr($entry, 0, strlen($entry)-4); - if ($ext == ".pru") { - $ret[$pos] = $name; - $pos ++; + if ($dir) { + while ($entry = $dir->read()){ + $ext = substr($entry, strlen($entry)-4, 4); + $name = substr($entry, 0, strlen($entry)-4); + if ($ext == ".pru") { + $ret[$pos] = $name; + $pos ++; + } } } return $ret; @@ -47,32 +49,35 @@ function getUserProfiles() { // returns an array of String with all available group profiles (without .prg) function getGroupProfiles() { // group profiles are not supported at this time -/* $dir = dir(substr(__FILE__, 0, strlen(__FILE__) - 17) . "/config/profiles/groups"); + $dir = @dir(substr(__FILE__, 0, strlen(__FILE__) - 17) . "/config/profiles/groups"); $ret = array(); $pos = 0; - while ($entry = $dir->read()){ - $ext = substr($entry, strlen($entry)-4, 4); - $name = substr($entry, 0, strlen($entry)-4); - if ($ext == ".prg") { - $ret[$pos] = $name; - $pos ++; + if ($dir) { + while ($entry = $dir->read()){ + $ext = substr($entry, strlen($entry)-4, 4); + $name = substr($entry, 0, strlen($entry)-4); + if ($ext == ".prg") { + $ret[$pos] = $name; + $pos ++; + } } } - return $ret; */ - return array(); + return $ret; } // returns an array of String with all available host profiles (without .prh) function getHostProfiles() { - $dir = dir(substr(__FILE__, 0, strlen(__FILE__) - 17) . "/config/profiles/hosts"); + $dir = @dir(substr(__FILE__, 0, strlen(__FILE__) - 17) . "/config/profiles/hosts"); $ret = array(); $pos = 0; - while ($entry = $dir->read()){ - $ext = substr($entry, strlen($entry)-4, 4); - $name = substr($entry, 0, strlen($entry)-4); - if ($ext == ".prh") { - $ret[$pos] = $name; - $pos ++; + if ($dir) { + while ($entry = $dir->read()){ + $ext = substr($entry, strlen($entry)-4, 4); + $name = substr($entry, 0, strlen($entry)-4); + if ($ext == ".prh") { + $ret[$pos] = $name; + $pos ++; + } } } return $ret; @@ -228,7 +233,67 @@ function loadUserProfile($profile) { // loads an group profile with name $profile (without .prg) // the return value is an account object function loadGroupProfile($profile) { - // no group profiles yet + if (!eregi("^([0-9]|[a-z]|-|_)*$", $profile)) exit; + $acc = new account(); + $file = substr(__FILE__, 0, strlen(__FILE__) - 17) . "/config/profiles/groups/" . $profile . ".prg"; + if (is_file($file) == True) { + $file = @fopen($file, "r"); + if ($file) { + while (!feof($file)) { + $line = fgets($file, 1024); + if (($line == "\n")||($line[0] == "#")) continue; // ignore comments + // search keywords + if (substr($line, 0, 12) == "smb_domain: ") { + if ($_SESSION['config']->is_samba3()) { + $dn = chop(substr($line, 12, strlen($line)-12)); + // load domain object + $dom = new samba3domain(); + $sr = @ldap_search($_SESSION['ldap']->server, $dn, "objectClass=sambaDomain"); + if ($sr) { + $info = @ldap_get_entries($_SESSION['ldap']->server, $sr); + if ($info) { + // get domain attributes + @array_shift($info); + $dom->dn = $dn; + $dom->name = $info[0]['sambadomainname'][0]; + $dom->SID = $info[0]['sambaSID'][0]; + $dom->nextRID = $info[0]['sambanextrid'][0]; + $dom->nextUserRID = $info[0]['sambanextuserrid'][0]; + $dom->nextGroupRID = $info[0]['sambanextgrouprid'][0]; + if (isset($dom->RIDbase)) $dom->RIDbase = $info[0]['sambaalgorithmicridbase'][0]; + } + } + $acc->smb_domain = $dom; + } + } + if (substr($line, 0, 7) == "quota: ") { + if ($_SESSION['config']->get_scriptPath()) { + $acc->quota = chop(substr($line, 7, strlen($line)-7)); + // split mountpoints + $acc->quota = explode(";", $acc->quota); + // split attributes + for ($i = 0; $i < sizeof($acc->quota); $i++) { + $temp = explode(",", $acc->quota[$i]); + $acc->quota[$i] = array(); + $acc->quota[$i][0] = $temp[0]; + $acc->quota[$i][2] = $temp[1]; + $acc->quota[$i][3] = $temp[2]; + $acc->quota[$i][6] = $temp[3]; + $acc->quota[$i][7] = $temp[4]; + } + } + } + } + fclose($file); + } + else { + StatusMessage("ERROR", "", _("Unable to load profile!") . " " . $file); + } + } + else { + StatusMessage("ERROR", "", _("Unable to load profile!") . " " . $file); + } + return $acc; } // loads an host profile with name $profile (without .prh) @@ -357,7 +422,32 @@ function saveUserProfile($account, $profile) { // saves an account object to an group profile with name $profile (without .prg) // file is created, if needed function saveGroupProfile($account, $profile) { - // no group profiles yet + if (!eregi("^([0-9]|[a-z]|-|_)*$", $profile)) exit; + if (!is_object($account)) { + StatusMessage("ERROR", "", _("saveGroupProfile: account has wrong type!")); + exit; + } + $path = substr(__FILE__, 0, strlen(__FILE__) - 17) . "/config/profiles/groups/" . $profile . ".prg"; + $file = @fopen($path, "w"); + if ($file) { + // write attributes + if (isset($account->smb_domain)) fputs($file, "smb_domain: " . $account->smb_domain . "\n"); + if (isset($account->quota)) { + // convert array to string + for ($i = 0; $i < sizeof($account->quota); $i++) { + $account->quota[$i] = implode(",", $account->quota[$i]); + } + $temp = implode(";", $account->quota); + fputs($file, "quota: " . $temp . "\n"); + } + // close file + fclose($file); + } + else { + StatusMessage("ERROR", _("Unable to save profile!"), $path); + return false; + } + return true; } // saves an account object to an host profile with name $profile (without .prh) @@ -393,6 +483,15 @@ function delUserProfile($file) { } } +// deletes a group profile +function delGroupProfile($file) { + if (!eregi("^([0-9]|[a-z]|-|_)*$", $profile)) exit; + $prof = substr(__FILE__, 0, strlen(__FILE__) - 16) . "config/profiles/groups/".$file.".prg"; + if (is_file($prof)) { + return @unlink($prof); + } +} + // deletes a host profile function delHostProfile($file) { if (!eregi("^([0-9]|[a-z]|-|_)*$", $profile)) exit; diff --git a/lam/templates/profedit/profilecreate.php b/lam/templates/profedit/profilecreate.php index ba166dcf..65094fcd 100644 --- a/lam/templates/profedit/profilecreate.php +++ b/lam/templates/profedit/profilecreate.php @@ -279,6 +279,71 @@ if ($_GET['type'] == "user") { } +// save group profile +elseif ($_GET['type'] == "group") { + $acct = new account(); + // check input + if ($_POST['smb_domain'] && is_string($_POST['smb_domain'])) { + $acct->smb_domain = $_POST['smb_domain']; + } + elseif ($_POST['smb_domain']) { + StatusMessage("ERROR", _("Domain name is invalid!"), $_POST['smb_domain']); + echo ("

" . _("Back to Profile Editor") . ""); + exit; + } + // check quota settings if script is given + if ($_SESSION['config']->get_scriptPath()) { + if ($_POST['quotacount'] && ($_POST['quotacount'] > 0)) { + for ($i = 0; $i < $_POST['quotacount']; $i++) { + $acct->quota[$i][0] = $_POST['f_quota_'.$i.'_0']; + $acct->quota[$i][2] = $_POST['f_quota_'.$i.'_2']; + $acct->quota[$i][3] = $_POST['f_quota_'.$i.'_3']; + $acct->quota[$i][6] = $_POST['f_quota_'.$i.'_6']; + $acct->quota[$i][7] = $_POST['f_quota_'.$i.'_7']; + // Check if values are OK + if (!ereg('^([0-9])*$', $acct->quota[$i][2])) { + StatusMessage('ERROR', _('Block soft quota'), _('Block soft quota contains invalid characters. Only natural numbers are allowed')); + echo ("

" . _("Back to Profile Editor") . ""); + exit; + } + if (!ereg('^([0-9])*$', $acct->quota[$i][3])) { + StatusMessage('ERROR', _('Block hard quota'), _('Block hard quota contains invalid characters. Only natural numbers are allowed')); + echo ("

" . _("Back to Profile Editor") . ""); + exit; + } + if (!ereg('^([0-9])*$', $acct->quota[$i][6])) { + StatusMessage('ERROR', _('Inode soft quota'), _('Inode soft quota contains invalid characters. Only natural numbers are allowed')); + echo ("

" . _("Back to Profile Editor") . ""); + exit; + } + if (!ereg('^([0-9])*$', $acct->quota[$i][7])) { + StatusMessage('ERROR', _('Inode hard quota'), _('Inode hard quota contains invalid characters. Only natural numbers are allowed')); + echo ("

" . _("Back to Profile Editor") . ""); + exit; + } + } + } + } + + if ($_POST['profname'] && eregi("^[0-9a-z\\-_]+$", $_POST['profname'])) { + $profname = $_POST['profname']; + } + else { + StatusMessage("ERROR", _("Invalid profile name!"), $_POST['profname']); + echo ("

" . _("Back to Profile Editor") . ""); + exit; + } + + // save profile + if (savegroupProfile($acct, $profname)) { + StatusMessage("INFO", _("Profile was saved."), $profname); + } + else StatusMessage("ERROR", _("Unable to save profile!"), $profname); + + echo ("

" . _("Back to Profile Editor") . "

"); +} + + // save host profile elseif ($_GET['type'] == "host") { $acct = new account(); diff --git a/lam/templates/profedit/profiledelete.php b/lam/templates/profedit/profiledelete.php index 6e6f7fc0..0f493d92 100644 --- a/lam/templates/profedit/profiledelete.php +++ b/lam/templates/profedit/profiledelete.php @@ -55,6 +55,13 @@ if ($_POST['submit']) { } else StatusMessage("INFO", "", _("Deleted profile:") . " " . $_POST['del']); } + // delete group profile + elseif ($_POST['type'] == "group") { + if (!delGroupProfile($_POST['del'])) { + StatusMessage("ERROR", "", _("Unable to delete profile!") . " " . $_POST['del']); + } + else StatusMessage("INFO", "", _("Deleted profile:") . " " . $_POST['del']); + } // delete host profile elseif ($_POST['type'] == "host") { if (!delHostProfile($_POST['del'])) { @@ -81,7 +88,7 @@ if ($_POST['abort']) { // check if right type was given $type = $_GET['type']; -if (($type == "user") || ($type == "host")) { +if (($type == "user") || ($type == "host") || ($type == "group")) { // user profile if ($type == "user") { echo ("

" . _("Do you really want to delete this profile?") . " "); @@ -94,6 +101,18 @@ if (($type == "user") || ($type == "host")) { echo (""); echo ("

\n"); } + // group profile + elseif ($type == "group") { + echo ("

" . _("Do you really want to delete this profile?") . " "); + echo ($_GET['del'] . "

\n"); + echo ("
\n"); + echo ("

\n"); + echo ("\n"); + echo ("\n"); + echo (""); + echo (""); + echo ("

\n"); + } // host profile elseif ($type == "host") { echo ("

" . _("Do you really want to delete this profile?") . " "); diff --git a/lam/templates/profedit/profilegroup.php b/lam/templates/profedit/profilegroup.php new file mode 100644 index 00000000..321f59f2 --- /dev/null +++ b/lam/templates/profedit/profilegroup.php @@ -0,0 +1,155 @@ +server()) { + metaRefresh("../login.php"); + exit; +} + +// load quota list +if ($_SESSION['config']->get_scriptPath()) { + $acct_q = getquotas("group"); +} + +// print header +echo $_SESSION['header']; +echo ("\n\n\n
\n"); + +$acct = new Account(); + +// check if profile should be edited +if ($_GET['edit']) { + $acct = loadGroupProfile($_GET['edit']); +} + +// display formular +echo ("

\n"); + +if ($_SESSION['config']->is_samba3()) { + // Samba part + echo ("
" . _("Samba") . "\n"); + echo ("\n"); + + // domain + echo ("\n"); + echo ("\n"); + echo "\n"; + echo ("\n"); + echo ("\n"); + + echo ("
" . _("Domain") . ": " . _("Help") . "
\n"); + echo ("
\n"); +} + + +// Quota settings if script is given +if ($_SESSION['config']->get_scriptPath()) { + echo ("
"); + echo "
"._('Quota properties')."\n"; + echo "\n"; + // description line + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + // help line + echo "'."\n". + "'."\n". + "'."\n". + "'."\n". + "'."\n". + ''."\n"; + // quota settings + for ($i = 0; $i < (sizeof($acct_q->quota) - 1); $i++) { + // load values from profile + for ($k = 0; $k < sizeof($acct->quota); $k++) { + // check for equal mountpoints + if ($acct->quota[$k][0] == $acct_q->quota[$i][0]) { + $acct_q->quota[$i][2] = $acct->quota[$i][2]; + $acct_q->quota[$i][3] = $acct->quota[$i][3]; + $acct_q->quota[$i][6] = $acct->quota[$i][6]; + $acct_q->quota[$i][7] = $acct->quota[$i][7]; + } + } + echo "\n"; + echo '\n"; // mountpoint + echo '\n"; // blocks soft limit + echo '\n"; // blocks hard limit + echo '\n"; // inodes soft limit + echo '\n"; // inodes hard limit + echo "\n"; + } + echo "
" . _('Mountpoint') . "  " . _('Soft block limit') . "  " . _('Hard block limit') . "  " . _('Soft inode limit') . "  " . _('Hard inode limit') . "  
"._('Help').'"._('Help').'"._('Help').'"._('Help').'"._('Help').'
' . $acct_q->quota[$i][0] . "quota[$i][0] . "\">
\n"; + // save number of mountpoints + echo "quota) - 1) . "\">\n"; + echo "
\n"; +} + +echo ("

\n"); + +// profile name and submit/abort buttons +echo ("\n"); +echo ("\n"); +echo ("\n"); +echo ("\n"); +echo ("\n"); +echo ("\n"); +echo ("\n"); +echo (""); +echo ("\n"); +echo ("\n"); +echo ("\n"); +echo ("\n"); +echo (""); +echo ("\n"); +echo ("
" . _("Profile name") . ":" . _("Help") . "
 
\n"); +echo (" 
\n"); + +echo ("\n"); diff --git a/lam/templates/profedit/profilemain.php b/lam/templates/profedit/profilemain.php index a539f79a..0a698519 100644 --- a/lam/templates/profedit/profilemain.php +++ b/lam/templates/profedit/profilemain.php @@ -59,8 +59,22 @@ if ($_POST['forward'] == "yes") { elseif($_POST['profile'] == "deluser") { metaRefresh("profiledelete.php?type=user&del=" . $_POST['d_user']); } + if ($_SESSION['config']->is_samba3() || $_SESSION['config']->get_scriptPath()) { + // create new group profile + if ($_POST['profile'] == "newgroup") { + metaRefresh("profilegroup.php"); + } + // edit group profile + elseif($_POST['profile'] == "editgroup") { + metaRefresh("profilegroup.php?edit=" . $_POST['e_group']); + } + // delete group profile + elseif($_POST['profile'] == "delgroup") { + metaRefresh("profiledelete.php?type=group&del=" . $_POST['d_group']); + } + } // create new host profile - elseif ($_POST['profile'] == "newhost") { + if ($_POST['profile'] == "newhost") { metaRefresh("profilehost.php"); } // edit host profile @@ -82,6 +96,15 @@ for ($i = 0; $i < sizeof($usrprof); $i++) { $userprofiles = $userprofiles . "\n"; } +if ($_SESSION['config']->is_samba3() || $_SESSION['config']->get_scriptPath()) { + // get list of group profiles and generate entries for dropdown box + $grpprof = getGroupProfiles(); + $groupprofiles = ""; + for ($i = 0; $i < sizeof($grpprof); $i++) { + $groupprofiles = $groupprofiles . "\n"; + } +} + // get list of host profiles and generate entries for dropdown box $hstprof = getHostProfiles(); $hostprofiles = ""; @@ -143,6 +166,54 @@ echo $_SESSION['header'];

+is_samba3() || $_SESSION['config']->get_scriptPath()) { + echo " "; + echo "
"; + echo " "; + echo " " . _("Group Profiles") . ""; + echo " "; + echo " "; + echo " "; + echo " "; + echo " "; + echo " "; + echo " "; + if ($groupprofiles != "") { + echo " "; + echo " "; + echo " "; + echo " "; + echo " "; + echo " "; + echo " "; + echo " "; + echo " "; + echo " "; + echo " "; + echo " "; + } + echo "
"; + echo " "; + echo " " . _("Create a new Group Profile") . "
"; + echo " "; + echo " "; + echo " "; + echo " " . _("Edit Group Profile") . "
"; + echo " "; + echo " "; + echo " "; + echo " " . _("Delete Group Profile") . "
"; + echo "
"; + + echo "

"; +} +?> +