updated to new account class

This commit is contained in:
Roland Gruber 2003-07-13 10:40:40 +00:00
parent 29653b4ba3
commit 568080aae6
3 changed files with 59 additions and 119 deletions

View File

@ -79,7 +79,8 @@ function getHostProfiles() {
// loads an user profile with name $profile (without .pru)
// the return value is an account object
function loadUserProfile($profile) {
// if $timestamps is true, smb_pwdcanchange and smb_pwdmustchange are returned as timestamp
function loadUserProfile($profile, $timestamps=True) {
if (!eregi("^([0-9]|[a-z]|-|_)*$", $profile)) exit;
$acc = new account();
$file = substr(__FILE__, 0, strlen(__FILE__) - 17) . "/config/profiles/users/" . $profile . ".pru";
@ -126,16 +127,8 @@ function loadUserProfile($profile) {
$acc->unix_pwdmaxage = chop(substr($line, 16, strlen($line)-16));
continue;
}
if (substr($line, 0, 20) == "unix_pwdexpire_day: ") {
$acc->unix_pwdexpire_day = chop(substr($line, 20, strlen($line)-20));
continue;
}
if (substr($line, 0, 20) == "unix_pwdexpire_mon: ") {
$acc->unix_pwdexpire_mon = chop(substr($line, 20, strlen($line)-20));
continue;
}
if (substr($line, 0, 20) == "unix_pwdexpire_yea: ") {
$acc->unix_pwdexpire_yea = chop(substr($line, 20, strlen($line)-20));
if (substr($line, 0, 16) == "unix_pwdexpire: ") {
$acc->unix_pwdexpire = chop(substr($line, 16, strlen($line)-16));
continue;
}
if (substr($line, 0, 18) == "unix_deactivated: ") {
@ -150,6 +143,10 @@ function loadUserProfile($profile) {
$acc->smb_useunixpwd = chop(substr($line, 16, strlen($line)-16));
continue;
}
if (substr($line, 0, 12) == "smb_flagsD: ") {
$acc->smb_flagsD = chop(substr($line, 12, strlen($line)-12));
continue;
}
if (substr($line, 0, 18) == "smb_pwdcanchange: ") {
$acc->smb_pwdcanchange = chop(substr($line, 18, strlen($line)-18));
continue;
@ -184,6 +181,11 @@ function loadUserProfile($profile) {
}
}
fclose($file);
// set timestamps if needed
if ($timestamps) {
$acct->smb_pwdcanchange = ($acct->smb_pwdcanchange * 86400) + time();
$acct->smb_pwdmustchange = ($acct->smb_pwdmustchange * 86400) + time();
}
}
else {
StatusMessage("ERROR", "", _("Unable to load profile! ") . $file);
@ -218,62 +220,6 @@ function loadHostProfile($profile) {
$acc->general_group = chop(substr($line, 15, strlen($line)-15));
continue;
}
if (substr($line, 0, 18) == "general_groupadd: ") {
$acc->general_groupadd = explode(";", chop(substr($line, 18, strlen($line)-18)));
continue;
}
if (substr($line, 0, 18) == "unix_password_no: ") {
$acc->unix_password_no = chop(substr($line, 18, strlen($line)-18));
continue;
}
if (substr($line, 0, 14) == "unix_pwdwarn: ") {
$acc->unix_pwdwarn = chop(substr($line, 14, strlen($line)-14));
continue;
}
if (substr($line, 0, 20) == "unix_pwdallowlogin: ") {
$acc->unix_pwdallowlogin = chop(substr($line, 20, strlen($line)-20));
continue;
}
if (substr($line, 0, 16) == "unix_pwdminage: ") {
$acc->unix_pwdminage = chop(substr($line, 16, strlen($line)-16));
continue;
}
if (substr($line, 0, 16) == "unix_pwdmaxage: ") {
$acc->unix_pwdmaxage = chop(substr($line, 16, strlen($line)-16));
continue;
}
if (substr($line, 0, 20) == "unix_pwdexpire_day: ") {
$acc->unix_pwdexpire_day = chop(substr($line, 20, strlen($line)-20));
continue;
}
if (substr($line, 0, 20) == "unix_pwdexpire_mon: ") {
$acc->unix_pwdexpire_mon = chop(substr($line, 20, strlen($line)-20));
continue;
}
if (substr($line, 0, 20) == "unix_pwdexpire_yea: ") {
$acc->unix_pwdexpire_yea = chop(substr($line, 20, strlen($line)-20));
continue;
}
if (substr($line, 0, 18) == "unix_deactivated: ") {
$acc->unix_deactivated = chop(substr($line, 18, strlen($line)-18));
continue;
}
if (substr($line, 0, 17) == "smb_password_no: ") {
$acc->smb_password_no = chop(substr($line, 17, strlen($line)-17));
continue;
}
if (substr($line, 0, 16) == "smb_useunixpwd: ") {
$acc->smb_useunixpwd = chop(substr($line, 16, strlen($line)-16));
continue;
}
if (substr($line, 0, 18) == "smb_pwdcanchange: ") {
$acc->smb_pwdcanchange = chop(substr($line, 18, strlen($line)-18));
continue;
}
if (substr($line, 0, 19) == "smb_pwdmustchange: ") {
$acc->smb_pwdmustchange = chop(substr($line, 19, strlen($line)-19));
continue;
}
if (substr($line, 0, 12) == "smb_domain: ") {
$acc->smb_domain = chop(substr($line, 12, strlen($line)-12));
continue;
@ -328,12 +274,11 @@ function saveUserProfile($account, $profile) {
if (isset($account->unix_pwdallowlogin)) fputs($file, "unix_pwdallowlogin: " . $account->unix_pwdallowlogin . "\n");
if (isset($account->unix_pwdminage)) fputs($file, "unix_pwdminage: " . $account->unix_pwdminage . "\n");
if (isset($account->unix_pwdmaxage)) fputs($file, "unix_pwdmaxage: " . $account->unix_pwdmaxage . "\n");
if (isset($account->unix_pwdexpire_day)) fputs($file, "unix_pwdexpire_day: " . $account->unix_pwdexpire_day . "\n");
if (isset($account->unix_pwdexpire_mon)) fputs($file, "unix_pwdexpire_mon: " . $account->unix_pwdexpire_mon . "\n");
if (isset($account->unix_pwdexpire_yea)) fputs($file, "unix_pwdexpire_yea: " . $account->unix_pwdexpire_yea . "\n");
if (isset($account->unix_pwdexpire)) fputs($file, "unix_pwdexpire: " . $account->unix_pwdexpire . "\n");
if (isset($account->unix_deactivated)) fputs($file, "unix_deactivated: " . $account->unix_deactivated . "\n");
if (isset($account->smb_password_no)) fputs($file, "smb_password_no: " . $account->smb_password_no . "\n");
if (isset($account->smb_useunixpwd)) fputs($file, "smb_useunixpwd: " . $account->smb_useunixpwd . "\n");
if (isset($account->smb_flagsD)) fputs($file, "smb_flagsD: " . $account->smb_flagsD . "\n");
if (isset($account->smb_pwdcanchange)) fputs($file, "smb_pwdcanchange: " . $account->smb_pwdcanchange . "\n");
if (isset($account->smb_pwdmustchange)) fputs($file, "smb_pwdmustchange: " . $account->smb_pwdmustchange . "\n");
if (isset($account->smb_homedrive)) fputs($file, "smb_homedrive: " . $account->smb_homedrive . "\n");
@ -364,20 +309,6 @@ function saveHostProfile($account, $profile) {
$file = fopen($path, "w");
// write attributes
if (isset($account->general_group)) fputs($file, "general_group: " . $account->general_group . "\n");
if (isset($account->general_groupadd)) fputs($file, "general_groupadd: " . implode(";", $account->general_groupadd) . "\n");
if (isset($account->unix_password_no)) fputs($file, "unix_password_no: " . $account->unix_password_no . "\n");
if (isset($account->unix_pwdwarn)) fputs($file, "unix_pwdwarn: " . $account->unix_pwdwarn . "\n");
if (isset($account->unix_pwdallowlogin)) fputs($file, "unix_pwdallowlogin: " . $account->unix_pwdallowlogin . "\n");
if (isset($account->unix_pwdminage)) fputs($file, "unix_pwdminage: " . $account->unix_pwdminage . "\n");
if (isset($account->unix_pwdmaxage)) fputs($file, "unix_pwdmaxage: " . $account->unix_pwdmaxage . "\n");
if (isset($account->unix_pwdexpire_day)) fputs($file, "unix_pwdexpire_day: " . $account->unix_pwdexpire_day . "\n");
if (isset($account->unix_pwdexpire_mon)) fputs($file, "unix_pwdexpire_mon: " . $account->unix_pwdexpire_mon . "\n");
if (isset($account->unix_pwdexpire_yea)) fputs($file, "unix_pwdexpire_yea: " . $account->unix_pwdexpire_yea . "\n");
if (isset($account->unix_deactivated)) fputs($file, "unix_deactivated: " . $account->unix_deactivated . "\n");
if (isset($account->smb_password_no)) fputs($file, "smb_password_no: " . $account->smb_password_no . "\n");
if (isset($account->smb_useunixpwd)) fputs($file, "smb_useunixpwd: " . $account->smb_useunixpwd . "\n");
if (isset($account->smb_pwdcanchange)) fputs($file, "smb_pwdcanchange: " . $account->smb_pwdcanchange . "\n");
if (isset($account->smb_pwdmustchange)) fputs($file, "smb_pwdmustchange: " . $account->smb_pwdmustchange . "\n");
if (isset($account->smb_domain)) fputs($file, "smb_domain: " . $account->smb_domain . "\n");
// close file
fclose($file);

View File

@ -113,27 +113,11 @@ if ($_GET['type'] == "user") {
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
if ($_POST['unix_pwdexpire_day'] && is_numeric($_POST['unix_pwdexpire_day'])) {
$acct->unix_pwdexpire_day = $_POST['unix_pwdexpire_day'];
if (is_numeric($_POST['unix_pwdexpire_day']) && is_numeric($_POST['unix_pwdexpire_mon']) && is_numeric($_POST['unix_pwdexpire_yea'])) {
$acct->unix_pwdexpire = mktime(0, 0, 0, $_POST['unix_pwdexpire_mon'], $_POST['unix_pwdexpire_day'], $_POST['unix_pwdexpire_yea']);
}
else {
StatusMessage("ERROR", "", _("Wrong parameter for password expiry day!") . " " . $_POST['unix_pwdexpire_day']);
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
if ($_POST['unix_pwdexpire_mon'] && is_numeric($_POST['unix_pwdexpire_mon'])) {
$acct->unix_pwdexpire_mon = $_POST['unix_pwdexpire_mon'];
}
else {
StatusMessage("ERROR", "", _("Wrong parameter for password expiry month!") . " " . $_POST['unix_pwdexpire_mon']);
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
if ($_POST['unix_pwdexpire_yea'] && is_numeric($_POST['unix_pwdexpire_yea'])) {
$acct->unix_pwdexpire_yea = $_POST['unix_pwdexpire_yea'];
}
else {
StatusMessage("ERROR", "", _("Wrong parameter for password expiry year!") . " " . $_POST['unix_pwdexpire_yea']);
StatusMessage("ERROR", "", _("Wrong parameter for Unix password expiry!"));
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
@ -157,7 +141,7 @@ if ($_GET['type'] == "user") {
$acct->smb_password_no = $_POST['smb_password_no'];
}
else {
StatusMessage("ERROR", "", _("Wrong parameter for Samba option: no password!") . " " . $_POST['smb_password_no']);
StatusMessage("ERROR", "", _("Wrong parameter for Samba option: Set Samba Password!") . " " . $_POST['smb_password_no']);
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
@ -165,11 +149,19 @@ if ($_GET['type'] == "user") {
$acct->smb_useunixpwd = $_POST['smb_useunixpwd'];
}
else {
StatusMessage("ERROR", "", _("Wrong parameter for Samba option: use Unix password!") . " " . $_POST['smb_useunixpwd']);
StatusMessage("ERROR", "", _("Wrong parameter for Samba option: Set Unix Password for Samba!") . " " . $_POST['smb_useunixpwd']);
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
if (($_POST['smb_pwdcanchange'] == "1") || ($_POST['smb_pwdcanchange'] == "0")) {
if (($_POST['smb_flagsD'] == "1") || ($_POST['smb_flagsD'] == "0")) {
$acct->smb_flagsD = $_POST['smb_flagsD'];
}
else {
StatusMessage("ERROR", "", _("Wrong parameter for Samba option: Account does not expire!") . " " . $_POST['smb_flagsD']);
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
if (!$_POST['smb_pwdcanchange'] || is_numeric($_POST['smb_pwdcanchange'])) {
$acct->smb_pwdcanchange = $_POST['smb_pwdcanchange'];
}
else {
@ -177,7 +169,7 @@ if ($_GET['type'] == "user") {
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
if (($_POST['smb_pwdmustchange'] == "1") || ($_POST['smb_pwdmustchange'] == "0")) {
if (!$_POST['smb_pwdmustchange'] || is_numeric($_POST['smb_pwdmustchange'])) {
$acct->smb_pwdmustchange = $_POST['smb_pwdmustchange'];
}
else {

View File

@ -55,12 +55,21 @@ for ($i = 0; $i < sizeof($shelllist); $i++) {
// check if profile should be edited
if ($_GET['edit']) {
$acct = loadUserProfile($_GET['edit']);
$acct = loadUserProfile($_GET['edit'], False);
}
// search available groups
$groups = findgroups();
// calculate date for unix password expiry
if ($acct->unix_pwdexpire) {
$tstamp = $acct->unix_pwdexpire;
$tdate = date(dmY, $acct->unix_pwdexpire);
$unix_pwdexpire_day = substr($tdate, 0, 2);
$unix_pwdexpire_mon = substr($tdate, 2, 2);
$unix_pwdexpire_yea = substr($tdate, 4, 4);
}
// display formular
echo ("<form action=\"profilecreate.php?type=user\" method=\"post\">\n");
@ -162,19 +171,19 @@ echo ("<td align=\"right\"><b>" . _("Account expires on") . ": </b></td>\n");
echo ("<td>\n");
echo ("<select name=\"unix_pwdexpire_day\">\n");
for ( $i=1; $i<=31; $i++ ) {
if ($acct->unix_pwdexpire_day == $i) echo "<option selected>$i</option>\n";
if ($unix_pwdexpire_day == $i) echo "<option selected>$i</option>\n";
else echo "<option>$i</option>\n";
}
echo ("</select>\n");
echo ("<select name=\"unix_pwdexpire_mon\">\n");
for ( $i=1; $i<=12; $i++ ) {
if ($acct->unix_pwdexpire_mon == $i) echo "<option selected>$i</option>\n";
if ($unix_pwdexpire_mon == $i) echo "<option selected>$i</option>\n";
else echo "<option>$i</option>\n";
}
echo ("</select>\n");
echo ("<select name=\"unix_pwdexpire_yea\">");
for ( $i=2003; $i<=2030; $i++ ) {
if ($acct->unix_pwdexpire_yea == $i) echo "<option selected>$i</option>\n";
if ($unix_pwdexpire_yea == $i) echo "<option selected>$i</option>\n";
else echo "<option>$i</option>\n";
}
echo ("</select></td>");
@ -225,23 +234,31 @@ echo ("</select></td>\n");
echo ("<td><a href=\"../help.php?HelpNumber=301\" target=\"lamhelp\">" . _("Help") . "</a></td>\n");
echo ("</tr>\n");
// password expires
echo ("<tr>\n");
echo ("<td align=\"right\"><b>" . _("Password does not expire") . ": </b></td>\n");
echo ("<td><select name=\"smb_flagsD\">\n");
if ($acct->smb_flagsD == "0") echo ("<option selected value=0>"._("no")."</option><option value=1>"._("yes")."</option>\n");
else echo ("<option selected value=1>"._("yes")."</option><option value=0>"._("no")."</option>\n");
echo ("</select></td>\n");
echo ("<td><a href=\"../help.php?HelpNumber=302\" target=\"lamhelp\">" . _("Help") . "</a></td>\n");
echo ("</tr>\n");
// user can change his password
echo ("<tr>\n");
echo ("<td align=\"right\"><b>" . _("User can change password") . ": </b></td>\n");
echo ("<td><select name=\"smb_pwdcanchange\">\n");
if ($acct->smb_pwdcanchange == "0") echo ("<option selected value=0>"._("no")."</option><option value=1>"._("yes")."</option>\n");
else echo ("<option selected value=1>"._("yes")."</option><option value=0>"._("no")."</option>\n");
echo ("</select></td>\n");
echo ("<td>\n");
echo ("<input type=\"text\" name=\"smb_pwdcanchange\" value=\"" . $acct->smb_pwdcanchange . "\">\n");
echo ("</td>\n");
echo ("<td><a href=\"../help.php?HelpNumber=302\" target=\"lamhelp\">" . _("Help") . "</a></td>\n");
echo ("</tr>\n");
// user must change his password
echo ("<tr>\n");
echo ("<td align=\"right\"><b>" . _("User must change password") . ": </b></td>\n");
echo ("<td><select name=\"smb_pwdmustchange\">\n");
if ($acct->smb_pwdmustchange == "1") echo ("<option selected value=1>"._("yes")."</option><option value=0>"._("no")."</option>\n");
else echo ("<option selected value=0>"._("no")."</option><option value=1>"._("yes")."</option>\n");
echo ("</select></td>\n");
echo ("<td>\n");
echo ("<input type=\"text\" name=\"smb_pwdmustchange\" value=\"" . $acct->smb_pwdmustchange . "\">\n");
echo ("</td>\n");
echo ("<td><a href=\"../help.php?HelpNumber=303\" target=\"lamhelp\">" . _("Help") . "</a></td>\n");
echo ("</tr>\n");