2003-04-26 20:01:49 +00:00
|
|
|
<?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
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
// profiles.inc provides functions to load and save profiles for users/groups/hosts
|
|
|
|
|
2003-04-28 18:06:18 +00:00
|
|
|
include_once("config.inc");
|
2003-04-30 15:20:40 +00:00
|
|
|
include_once("account.inc");
|
2003-04-28 18:06:18 +00:00
|
|
|
|
|
|
|
|
2003-04-30 15:20:40 +00:00
|
|
|
// returns an array of String with all available user profiles (without .pru)
|
2003-04-26 20:01:49 +00:00
|
|
|
function getUserProfiles() {
|
2003-05-01 11:37:46 +00:00
|
|
|
$dir = dir(substr(__FILE__, 0, strlen(__FILE__) - 17) . "/config/profiles/users");
|
2003-04-28 18:06:18 +00:00
|
|
|
$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 ++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $ret;
|
2003-04-26 20:01:49 +00:00
|
|
|
}
|
|
|
|
|
2003-04-30 15:20:40 +00:00
|
|
|
// returns an array of String with all available group profiles (without .prg)
|
2003-04-26 20:01:49 +00:00
|
|
|
function getGroupProfiles() {
|
2003-06-04 16:52:37 +00:00
|
|
|
// group profiles are not supported at this time
|
|
|
|
/* $dir = dir(substr(__FILE__, 0, strlen(__FILE__) - 17) . "/config/profiles/groups");
|
2003-04-28 18:06:18 +00:00
|
|
|
$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 ++;
|
|
|
|
}
|
|
|
|
}
|
2003-06-04 16:52:37 +00:00
|
|
|
return $ret; */
|
|
|
|
return array();
|
2003-04-26 20:01:49 +00:00
|
|
|
}
|
|
|
|
|
2003-04-30 15:20:40 +00:00
|
|
|
// returns an array of String with all available host profiles (without .prh)
|
2003-04-26 20:01:49 +00:00
|
|
|
function getHostProfiles() {
|
2003-05-01 11:37:46 +00:00
|
|
|
$dir = dir(substr(__FILE__, 0, strlen(__FILE__) - 17) . "/config/profiles/hosts");
|
2003-04-28 18:06:18 +00:00
|
|
|
$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 ++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $ret;
|
2003-04-26 20:01:49 +00:00
|
|
|
}
|
|
|
|
|
2003-04-30 15:20:40 +00:00
|
|
|
// loads an user profile with name $profile (without .pru)
|
2003-04-26 20:01:49 +00:00
|
|
|
// the return value is an account object
|
2003-07-13 10:40:40 +00:00
|
|
|
// if $timestamps is true, smb_pwdcanchange and smb_pwdmustchange are returned as timestamp
|
2003-07-20 18:01:01 +00:00
|
|
|
function loadUserProfile($profile) {
|
2003-05-01 12:00:18 +00:00
|
|
|
if (!eregi("^([0-9]|[a-z]|-|_)*$", $profile)) exit;
|
2003-04-30 15:20:40 +00:00
|
|
|
$acc = new account();
|
2003-05-01 11:37:46 +00:00
|
|
|
$file = substr(__FILE__, 0, strlen(__FILE__) - 17) . "/config/profiles/users/" . $profile . ".pru";
|
2003-04-30 15:20:40 +00:00
|
|
|
if (is_file($file) == True) {
|
2003-06-24 15:50:38 +00:00
|
|
|
$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, 15) == "general_group: ") {
|
|
|
|
$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, 17) == "general_homedir: ") {
|
|
|
|
$acc->general_homedir = chop(substr($line, 17, strlen($line)-17));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (substr($line, 0, 15) == "general_shell: ") {
|
|
|
|
$acc->general_shell = chop(substr($line, 15, strlen($line)-15));
|
|
|
|
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;
|
|
|
|
}
|
2003-07-13 10:40:40 +00:00
|
|
|
if (substr($line, 0, 16) == "unix_pwdexpire: ") {
|
|
|
|
$acc->unix_pwdexpire = chop(substr($line, 16, strlen($line)-16));
|
2003-06-24 15:50:38 +00:00
|
|
|
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;
|
|
|
|
}
|
2003-07-13 10:40:40 +00:00
|
|
|
if (substr($line, 0, 12) == "smb_flagsD: ") {
|
|
|
|
$acc->smb_flagsD = chop(substr($line, 12, strlen($line)-12));
|
|
|
|
continue;
|
|
|
|
}
|
2003-06-24 15:50:38 +00:00
|
|
|
if (substr($line, 0, 15) == "smb_homedrive: ") {
|
|
|
|
$acc->smb_homedrive = chop(substr($line, 15, strlen($line)-15));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (substr($line, 0, 16) == "smb_scriptPath: ") {
|
|
|
|
$acc->smb_scriptPath = chop(substr($line, 16, strlen($line)-16));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (substr($line, 0, 17) == "smb_profilePath: ") {
|
|
|
|
$acc->smb_profilePath = chop(substr($line, 17, strlen($line)-17));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (substr($line, 0, 25) == "smb_smbuserworkstations: ") {
|
|
|
|
$acc->smb_smbuserworkstations = chop(substr($line, 25, strlen($line)-25));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (substr($line, 0, 13) == "smb_smbhome: ") {
|
|
|
|
$acc->smb_smbhome = chop(substr($line, 13, strlen($line)-13));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (substr($line, 0, 12) == "smb_domain: ") {
|
|
|
|
$acc->smb_domain = chop(substr($line, 12, strlen($line)-12));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose($file);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
StatusMessage("ERROR", "", _("Unable to load profile! ") . $file);
|
2003-04-30 15:20:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2003-06-24 15:50:38 +00:00
|
|
|
StatusMessage("ERROR", "", _("Unable to load profile! ") . $file);
|
2003-04-30 15:20:40 +00:00
|
|
|
}
|
|
|
|
return $acc;
|
2003-04-26 20:01:49 +00:00
|
|
|
}
|
|
|
|
|
2003-04-30 15:20:40 +00:00
|
|
|
// loads an group profile with name $profile (without .prg)
|
2003-04-26 20:01:49 +00:00
|
|
|
// the return value is an account object
|
|
|
|
function loadGroupProfile($profile) {
|
2003-04-30 16:50:48 +00:00
|
|
|
// no group profiles yet
|
2003-04-26 20:01:49 +00:00
|
|
|
}
|
|
|
|
|
2003-04-30 15:20:40 +00:00
|
|
|
// loads an host profile with name $profile (without .prh)
|
2003-04-26 20:01:49 +00:00
|
|
|
// the return value is an account object
|
|
|
|
function loadHostProfile($profile) {
|
2003-05-01 12:00:18 +00:00
|
|
|
if (!eregi("^([0-9]|[a-z]|-|_)*$", $profile)) exit;
|
2003-04-30 16:50:48 +00:00
|
|
|
$acc = new account();
|
2003-05-01 11:37:46 +00:00
|
|
|
$file = substr(__FILE__, 0, strlen(__FILE__) - 17) . "/config/profiles/hosts/" . $profile . ".prh";
|
2003-04-30 16:50:48 +00:00
|
|
|
if (is_file($file) == True) {
|
2003-06-24 15:50:38 +00:00
|
|
|
$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, 15) == "general_group: ") {
|
|
|
|
$acc->general_group = chop(substr($line, 15, strlen($line)-15));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (substr($line, 0, 12) == "smb_domain: ") {
|
|
|
|
$acc->smb_domain = chop(substr($line, 12, strlen($line)-12));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose($file);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
StatusMessage("ERROR", "", _("Unable to load profile! ") . $file);
|
2003-04-30 16:50:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2003-06-24 15:50:38 +00:00
|
|
|
StatusMessage("ERROR", "", _("Unable to load profile! ") . $file);
|
2003-04-30 16:50:48 +00:00
|
|
|
}
|
|
|
|
return $acc;
|
2003-04-26 20:01:49 +00:00
|
|
|
}
|
|
|
|
|
2003-04-30 15:20:40 +00:00
|
|
|
// saves an account object to an user profile with name $profile (without .pru)
|
2003-04-26 20:01:49 +00:00
|
|
|
// file is created, if needed
|
|
|
|
function saveUserProfile($account, $profile) {
|
2003-05-01 12:00:18 +00:00
|
|
|
if (!eregi("^([0-9]|[a-z]|-|_)*$", $profile)) exit;
|
2003-06-24 15:50:38 +00:00
|
|
|
if (!is_object($account)) {
|
2003-07-04 16:25:05 +00:00
|
|
|
StatusMessage("ERROR", "", _("saveUserProfile: account has wrong type!"));
|
2003-06-24 15:50:38 +00:00
|
|
|
exit;
|
|
|
|
}
|
2003-05-01 11:37:46 +00:00
|
|
|
$path = substr(__FILE__, 0, strlen(__FILE__) - 17) . "/config/profiles/users/" . $profile . ".pru";
|
2003-04-30 15:20:40 +00:00
|
|
|
$file = fopen($path, "w");
|
2003-05-01 20:30:43 +00:00
|
|
|
// replace user and group names
|
|
|
|
$homedir = $account->general_homedir;
|
2003-05-02 16:27:30 +00:00
|
|
|
$profpath = $account->smb_profilePath;
|
2003-06-01 12:25:23 +00:00
|
|
|
$scriptPath = $account->smb_scriptPath;
|
2003-05-01 20:30:43 +00:00
|
|
|
$smbhome = $account->smb_smbhome;
|
|
|
|
if ($account->general_username) {
|
|
|
|
$homedir = str_replace($account->general_username, "\$user", $homedir);
|
2003-05-02 16:27:30 +00:00
|
|
|
$profpath = str_replace($account->general_username, "\$user", $profpath);
|
2003-06-01 12:25:23 +00:00
|
|
|
$scriptPath = str_replace($account->general_username, "\$user", $scriptPath);
|
2003-05-01 20:30:43 +00:00
|
|
|
$smbhome = str_replace($account->general_username, "\$user", $smbhome);
|
|
|
|
}
|
|
|
|
if ($account->general_group) {
|
|
|
|
$homedir = str_replace($account->general_group, "\$group", $homedir);
|
2003-05-02 16:27:30 +00:00
|
|
|
$profpath = str_replace($account->general_group, "\$group", $profpath);
|
2003-06-01 12:25:23 +00:00
|
|
|
$scriptPath = str_replace($account->general_group, "\$group", $scriptPath);
|
2003-05-01 20:30:43 +00:00
|
|
|
$smbhome = str_replace($account->general_group, "\$group", $smbhome);
|
|
|
|
}
|
2003-04-30 15:20:40 +00:00
|
|
|
// write attributes
|
2003-05-31 23:17:16 +00:00
|
|
|
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->general_homedir)) fputs($file, "general_homedir: " . $homedir . "\n");
|
|
|
|
if (isset($account->general_shell)) fputs($file, "general_shell: " . $account->general_shell . "\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");
|
2003-07-13 10:40:40 +00:00
|
|
|
if (isset($account->unix_pwdexpire)) fputs($file, "unix_pwdexpire: " . $account->unix_pwdexpire . "\n");
|
2003-05-31 23:17:16 +00:00
|
|
|
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");
|
2003-07-13 10:40:40 +00:00
|
|
|
if (isset($account->smb_flagsD)) fputs($file, "smb_flagsD: " . $account->smb_flagsD . "\n");
|
2003-05-31 23:17:16 +00:00
|
|
|
if (isset($account->smb_homedrive)) fputs($file, "smb_homedrive: " . $account->smb_homedrive . "\n");
|
2003-06-01 12:25:23 +00:00
|
|
|
if (isset($account->smb_scriptPath)) fputs($file, "smb_scriptPath: " . $scriptPath . "\n");
|
2003-05-31 23:17:16 +00:00
|
|
|
if (isset($account->smb_profilePath)) fputs($file, "smb_profilePath: " . $profpath . "\n");
|
|
|
|
if (isset($account->smb_smbuserworkstations)) fputs($file, "smb_smbuserworkstations: " . $account->smb_smbuserworkstations . "\n");
|
|
|
|
if (isset($account->smb_smbhome)) fputs($file, "smb_smbhome: " . $smbhome . "\n");
|
|
|
|
if (isset($account->smb_domain)) fputs($file, "smb_domain: " . $account->smb_domain . "\n");
|
2003-04-30 15:20:40 +00:00
|
|
|
// close file
|
|
|
|
fclose($file);
|
2003-04-26 20:01:49 +00:00
|
|
|
}
|
|
|
|
|
2003-04-30 15:20:40 +00:00
|
|
|
// saves an account object to an group profile with name $profile (without .prg)
|
2003-04-26 20:01:49 +00:00
|
|
|
// file is created, if needed
|
|
|
|
function saveGroupProfile($account, $profile) {
|
2003-04-30 16:50:48 +00:00
|
|
|
// no group profiles yet
|
2003-04-26 20:01:49 +00:00
|
|
|
}
|
|
|
|
|
2003-04-30 15:20:40 +00:00
|
|
|
// saves an account object to an host profile with name $profile (without .prh)
|
2003-04-26 20:01:49 +00:00
|
|
|
// file is created, if needed
|
|
|
|
function saveHostProfile($account, $profile) {
|
2003-05-31 23:17:16 +00:00
|
|
|
if (!eregi("^[0-9a-z\\-_]+$", $profile)) exit;
|
2003-06-24 15:50:38 +00:00
|
|
|
if (!is_object($account)) {
|
2003-07-04 16:25:05 +00:00
|
|
|
StatusMessage ("ERROR", "", _("saveHostProfile: account has wrong type!"));
|
2003-06-24 15:50:38 +00:00
|
|
|
exit;
|
|
|
|
}
|
2003-05-01 11:37:46 +00:00
|
|
|
$path = substr(__FILE__, 0, strlen(__FILE__) - 17) . "/config/profiles/hosts/" . $profile . ".prh";
|
2003-04-30 16:50:48 +00:00
|
|
|
$file = fopen($path, "w");
|
|
|
|
// write attributes
|
2003-05-31 23:17:16 +00:00
|
|
|
if (isset($account->general_group)) fputs($file, "general_group: " . $account->general_group . "\n");
|
|
|
|
if (isset($account->smb_domain)) fputs($file, "smb_domain: " . $account->smb_domain . "\n");
|
2003-04-30 16:50:48 +00:00
|
|
|
// close file
|
|
|
|
fclose($file);
|
2003-04-26 20:01:49 +00:00
|
|
|
}
|
|
|
|
|
2003-05-25 10:51:10 +00:00
|
|
|
// deletes a user profile
|
|
|
|
function delUserProfile($file) {
|
|
|
|
if (!eregi("^([0-9]|[a-z]|-|_)*$", $profile)) exit;
|
|
|
|
$prof = substr(__FILE__, 0, strlen(__FILE__) - 16) . "config/profiles/users/".$file.".pru";
|
|
|
|
if (is_file($prof)) {
|
|
|
|
return @unlink($prof);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// deletes a host profile
|
|
|
|
function delHostProfile($file) {
|
|
|
|
if (!eregi("^([0-9]|[a-z]|-|_)*$", $profile)) exit;
|
|
|
|
$prof = substr(__FILE__, 0, strlen(__FILE__) - 16) . "config/profiles/hosts/".$file.".prh";
|
|
|
|
if (is_file($prof)) {
|
|
|
|
return @unlink($prof);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-28 18:06:18 +00:00
|
|
|
?>
|