added group profiles

This commit is contained in:
Roland Gruber 2003-09-20 17:02:21 +00:00
parent c7830ae357
commit 8675e6a9cb
5 changed files with 436 additions and 27 deletions

View File

@ -30,9 +30,10 @@ 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;
if ($dir) {
while ($entry = $dir->read()){
$ext = substr($entry, strlen($entry)-4, 4);
$name = substr($entry, 0, strlen($entry)-4);
@ -41,15 +42,17 @@ function getUserProfiles() {
$pos ++;
}
}
}
return $ret;
}
// 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;
if ($dir) {
while ($entry = $dir->read()){
$ext = substr($entry, strlen($entry)-4, 4);
$name = substr($entry, 0, strlen($entry)-4);
@ -58,15 +61,16 @@ function getGroupProfiles() {
$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;
if ($dir) {
while ($entry = $dir->read()){
$ext = substr($entry, strlen($entry)-4, 4);
$name = substr($entry, 0, strlen($entry)-4);
@ -75,6 +79,7 @@ function getHostProfiles() {
$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;

View File

@ -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 ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
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 ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
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 ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
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 ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
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 ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
}
}
}
if ($_POST['profname'] && eregi("^[0-9a-z\\-_]+$", $_POST['profname'])) {
$profname = $_POST['profname'];
}
else {
StatusMessage("ERROR", _("Invalid profile name!"), $_POST['profname']);
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
// save profile
if (savegroupProfile($acct, $profname)) {
StatusMessage("INFO", _("Profile was saved."), $profname);
}
else StatusMessage("ERROR", _("Unable to save profile!"), $profname);
echo ("<br><p><a href=\"profilemain.php\">" . _("Back to Profile Editor") . "</a></p>");
}
// save host profile
elseif ($_GET['type'] == "host") {
$acct = new account();

View File

@ -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 ("<p align=\"center\"><big>" . _("Do you really want to delete this profile?") . " <b>");
@ -94,6 +101,18 @@ if (($type == "user") || ($type == "host")) {
echo ("<input type=\"hidden\" name=\"del\" value=\"" . $_GET['del'] . "\">");
echo ("</p></form></body></html>\n");
}
// group profile
elseif ($type == "group") {
echo ("<p align=\"center\"><big>" . _("Do you really want to delete this profile?") . " <b>");
echo ($_GET['del'] . "</b></big><br></p>\n");
echo ("<form action=\"profiledelete.php\" method=\"post\">\n");
echo ("<p align=\"center\">\n");
echo ("<input type=\"submit\" name=\"submit\" value=\"" . _("Submit") . "\">\n");
echo ("<input type=\"submit\" name=\"abort\" value=\"" . _("Abort") . "\">\n");
echo ("<input type=\"hidden\" name=\"type\" value=\"group\">");
echo ("<input type=\"hidden\" name=\"del\" value=\"" . $_GET['del'] . "\">");
echo ("</p></form></body></html>\n");
}
// host profile
elseif ($type == "host") {
echo ("<p align=\"center\"><big>" . _("Do you really want to delete this profile?") . " <b>");

View File

@ -0,0 +1,155 @@
<?php
/*
$Id$
This code is part of LDAP Account Manager (http://www.sourceforge.net/projects/lam)
Copyright (C) 2003 Roland Gruber
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Manages creating/changing of profiles.
*/
include_once("../../lib/profiles.inc");
include_once("../../lib/ldap.inc");
include_once("../../lib/account.inc");
include_once("../../lib/config.inc");
// start session
session_save_path("../../sess");
@session_start();
setlanguage();
// check if user is logged in, if not go to login
if (!$_SESSION['ldap'] || !$_SESSION['ldap']->server()) {
metaRefresh("../login.php");
exit;
}
// load quota list
if ($_SESSION['config']->get_scriptPath()) {
$acct_q = getquotas("group");
}
// print header
echo $_SESSION['header'];
echo ("<html><head>\n<title></title>\n<link rel=\"stylesheet\" type=\"text/css\" href=\"../../style/layout.css\">\n</head><body><br>\n");
$acct = new Account();
// check if profile should be edited
if ($_GET['edit']) {
$acct = loadGroupProfile($_GET['edit']);
}
// display formular
echo ("<form action=\"profilecreate.php?type=group\" method=\"post\">\n");
if ($_SESSION['config']->is_samba3()) {
// Samba part
echo ("<fieldset><legend><b>" . _("Samba") . "</b></legend>\n");
echo ("<table border=0>\n");
// domain
echo ("<tr>\n");
echo ("<td align=\"right\"><b>" . _("Domain") . ": </b></td>\n");
echo "<td><select name=\"smb_domain\">\n";
$doms = $_SESSION['ldap']->search_domains($_SESSION['config']->get_DomainSuffix());
for ($i = 0; $i < sizeof($doms); $i++) {
if (strtolower($acct->smb_domain->name) == strtolower($doms[$i]->name)) {
echo ("<option selected value=\"" . $acct->smb_domain->dn . "\">" . $acct->smb_domain->name . "</option>\n");
}
else {
echo ("<option value=\"" . $doms[$i]->dn . "\">" . $doms[$i]->name . "</option>\n");
}
}
echo "</select></td>\n";
echo ("<td><a href=\"../help.php?HelpNumber=438\" target=\"lamhelp\">" . _("Help") . "</a></td>\n");
echo ("</tr>\n");
echo ("</table>\n");
echo ("</fieldset>\n");
}
// Quota settings if script is given
if ($_SESSION['config']->get_scriptPath()) {
echo ("<br>");
echo "<fieldset><legend><b>"._('Quota properties')."</b></legend>\n";
echo "<table border=0>\n";
// description line
echo "<tr>\n";
echo "<td align=\"center\"><b>" . _('Mountpoint') . "</b>&nbsp;&nbsp;</td>\n";
echo "<td align=\"center\"><b>" . _('Soft block limit') . "</b>&nbsp;&nbsp;</td>\n";
echo "<td align=\"center\"><b>" . _('Hard block limit') . "</b>&nbsp;&nbsp;</td>\n";
echo "<td align=\"center\"><b>" . _('Soft inode limit') . "</b>&nbsp;&nbsp;</td>\n";
echo "<td align=\"center\"><b>" . _('Hard inode limit') . "</b>&nbsp;&nbsp;</td>\n";
echo "</tr>\n";
// help line
echo "<tr><td align=\"center\"><a href=\"../help.php?HelpNumber=439\" target=\"lamhelp\">"._('Help').'</a></td>'."\n".
"<td align=\"center\"><a href=\"../help.php?HelpNumber=441\" target=\"lamhelp\">"._('Help').'</a></td>'."\n".
"<td align=\"center\"><a href=\"../help.php?HelpNumber=442\" target=\"lamhelp\">"._('Help').'</a></td>'."\n".
"<td align=\"center\"><a href=\"../help.php?HelpNumber=445\" target=\"lamhelp\">"._('Help').'</a></td>'."\n".
"<td align=\"center\"><a href=\"../help.php?HelpNumber=446\" target=\"lamhelp\">"._('Help').'</a></td>'."\n".
'</tr>'."\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 "<tr>\n";
echo '<td>' . $acct_q->quota[$i][0] . "<input type=\"hidden\" name=\"f_quota_" . $i . "_0\" value=\"" . $acct_q->quota[$i][0] . "\"></td>\n"; // mountpoint
echo '<td align="center"><input name="f_quota_' . $i . '_2" type="text" size="12" maxlength="20" value="' . $acct_q->quota[$i][2] . "\"></td>\n"; // blocks soft limit
echo '<td align="center"><input name="f_quota_' . $i . '_3" type="text" size="12" maxlength="20" value="' . $acct_q->quota[$i][3] . "\"></td>\n"; // blocks hard limit
echo '<td align="center"><input name="f_quota_' . $i . '_6" type="text" size="12" maxlength="20" value="' . $acct_q->quota[$i][6] . "\"></td>\n"; // inodes soft limit
echo '<td align="center"><input name="f_quota_' . $i . '_7" type="text" size="12" maxlength="20" value="' . $acct_q->quota[$i][7] . "\"></td>\n"; // inodes hard limit
echo "</tr>\n";
}
echo "</table>\n";
// save number of mountpoints
echo "<input type=\"hidden\" name=\"quotacount\" value=\"" . (sizeof($acct_q->quota) - 1) . "\">\n";
echo "</fieldset>\n";
}
echo ("<br><br>\n");
// profile name and submit/abort buttons
echo ("<table border=0>\n");
echo ("<tr>\n");
echo ("<td><b>" . _("Profile name") . ":</b></td>\n");
echo ("<td><input type=\"text\" name=\"profname\" value=\"" . $_GET['edit'] . "\"></td>\n");
echo ("<td><a href=\"../help.php?HelpNumber=360\" target=\"lamhelp\">" . _("Help") . "</a></td>\n");
echo ("</tr>\n");
echo ("<tr>\n");
echo ("<td colspan=2>&nbsp</td>");
echo ("</tr>\n");
echo ("<tr>\n");
echo ("<td><input type=\"submit\" name=\"submit\" value=\"" . _("Save") . "\"></td>\n");
echo ("<td><input type=\"reset\" name=\"reset\" value=\"" . _("Reset") . "\">\n");
echo ("<input type=\"submit\" name=\"abort\" value=\"" . _("Abort") . "\"></td>\n");
echo ("<td>&nbsp</td>");
echo ("</tr>\n");
echo ("</table>\n");
echo ("</form></body></html>\n");

View File

@ -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 . "<option>" . $usrprof[$i] . "</option>\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 . "<option>" . $grpprof[$i] . "</option>\n";
}
}
// get list of host profiles and generate entries for dropdown box
$hstprof = getHostProfiles();
$hostprofiles = "";
@ -143,6 +166,54 @@ echo $_SESSION['header'];
<p></p>
<?php
if ($_SESSION['config']->is_samba3() || $_SESSION['config']->get_scriptPath()) {
echo " <!-- group profile options -->";
echo " <fieldset>";
echo " <legend>";
echo " <b>" . _("Group Profiles") . "</b>";
echo " </legend>";
echo " <table border=0>";
echo " <!-- new group profile -->";
echo " <tr>";
echo " <td>";
echo " <input type=\"radio\" name=\"profile\" value=\"newgroup\">";
echo " </td>";
echo " <td colspan=2>" . _("Create a new Group Profile") . "</td>";
echo " </tr>";
if ($groupprofiles != "") {
echo " <!-- edit group profile -->";
echo " <tr>";
echo " <td>";
echo " <input type=\"radio\" name=\"profile\" value=\"editgroup\">";
echo " </td>";
echo " <td>";
echo " <select name=\"e_group\" size=1>";
echo " " . $groupprofiles;
echo " </select>";
echo " </td>";
echo " <td>" . _("Edit Group Profile") . "</td>";
echo " </tr>";
echo " <!-- delete group profile -->";
echo " <tr>";
echo " <td>";
echo " <input type=\"radio\" name=\"profile\" value=\"delgroup\">";
echo " </td>";
echo " <td>";
echo " <select name=\"d_group\" size=1>";
echo " " . $groupprofiles;
echo " </select>";
echo " </td>";
echo " <td>" . _("Delete Group Profile") . "</td>";
echo " </tr>";
}
echo " </table>";
echo " </fieldset>";
echo " <p></p>";
}
?>
<!-- host profile options -->
<fieldset>
<legend>