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-08-07 12:22:46 +00:00
|
|
|
include_once("ldap.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-09-20 17:02:21 +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;
|
2003-09-20 17:02:21 +00:00
|
|
|
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 ++;
|
|
|
|
}
|
2003-04-28 18:06:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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-09-20 17:02:21 +00:00
|
|
|
$dir = @dir(substr(__FILE__, 0, strlen(__FILE__) - 17) . "/config/profiles/groups");
|
2003-04-28 18:06:18 +00:00
|
|
|
$ret = array();
|
|
|
|
$pos = 0;
|
2003-09-20 17:02:21 +00:00
|
|
|
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 ++;
|
|
|
|
}
|
2003-04-28 18:06:18 +00:00
|
|
|
}
|
|
|
|
}
|
2003-09-20 17:02:21 +00:00
|
|
|
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 host profiles (without .prh)
|
2003-04-26 20:01:49 +00:00
|
|
|
function getHostProfiles() {
|
2003-09-20 17:02:21 +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;
|
2003-09-20 17:02:21 +00:00
|
|
|
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 ++;
|
|
|
|
}
|
2003-04-28 18:06:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $ret;
|
2003-04-26 20:01:49 +00:00
|
|
|
}
|
|
|
|
|
2003-10-11 17:20:00 +00:00
|
|
|
// loads an user profile
|
|
|
|
// $profile: name of the profile (without .pru)
|
2004-01-26 15:29:56 +00:00
|
|
|
// the return value is an hash array (attribute => value)
|
2003-07-20 18:01:01 +00:00
|
|
|
function loadUserProfile($profile) {
|
2003-10-23 19:31:17 +00:00
|
|
|
if (!eregi("^[0-9a-z_\\-]+$", $profile)) return false;
|
2004-01-26 15:29:56 +00:00
|
|
|
$settings = array();
|
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
|
2004-01-26 15:29:56 +00:00
|
|
|
$parts = array();
|
|
|
|
$parts = split(": ", $line);
|
2004-03-06 19:59:32 +00:00
|
|
|
if (sizeof($parts) != 2) continue; // ignore malformed settings
|
2004-02-12 15:58:04 +00:00
|
|
|
else {
|
2004-03-06 19:59:32 +00:00
|
|
|
$option = $parts[0];
|
|
|
|
$value = $parts[1];
|
2004-02-12 15:58:04 +00:00
|
|
|
// remove line ends
|
2004-03-06 19:59:32 +00:00
|
|
|
$value = chop($value);
|
|
|
|
$settings[$option] = explode("+::+", $value);
|
2004-02-12 15:58:04 +00:00
|
|
|
}
|
2003-06-24 15:50:38 +00:00
|
|
|
}
|
|
|
|
fclose($file);
|
|
|
|
}
|
|
|
|
else {
|
2003-07-30 14:34:33 +00:00
|
|
|
StatusMessage("ERROR", "", _("Unable to load profile!") . " " . $file);
|
2003-04-30 15:20:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2003-07-30 14:34:33 +00:00
|
|
|
StatusMessage("ERROR", "", _("Unable to load profile!") . " " . $file);
|
2003-04-30 15:20:40 +00:00
|
|
|
}
|
2004-01-26 15:29:56 +00:00
|
|
|
return $settings;
|
2003-04-26 20:01:49 +00:00
|
|
|
}
|
|
|
|
|
2003-10-11 17:20:00 +00:00
|
|
|
// loads an group profile
|
|
|
|
// $profile: name of the group profile (without .prg)
|
2004-01-26 15:29:56 +00:00
|
|
|
// the return value is an hash array (attribute => value)
|
2003-04-26 20:01:49 +00:00
|
|
|
function loadGroupProfile($profile) {
|
2003-10-23 19:31:17 +00:00
|
|
|
if (!eregi("^[0-9a-z_\\-]+$", $profile)) return false;
|
2004-01-26 15:29:56 +00:00
|
|
|
$settings = array();
|
2003-09-20 17:02:21 +00:00
|
|
|
$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
|
2004-01-26 15:29:56 +00:00
|
|
|
$parts = array();
|
|
|
|
$parts = split(": ", $line);
|
2004-03-06 19:59:32 +00:00
|
|
|
if (sizeof($parts) != 2) continue; // ignore malformed settings
|
2004-02-12 15:58:04 +00:00
|
|
|
else {
|
2004-03-06 19:59:32 +00:00
|
|
|
$option = $parts[0];
|
|
|
|
$value = $parts[1];
|
2004-02-12 15:58:04 +00:00
|
|
|
// remove line ends
|
2004-03-06 19:59:32 +00:00
|
|
|
$value = chop($value);
|
|
|
|
$settings[$option] = explode("+::+", $value);
|
2004-02-12 15:58:04 +00:00
|
|
|
}
|
2003-09-20 17:02:21 +00:00
|
|
|
}
|
|
|
|
fclose($file);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
StatusMessage("ERROR", "", _("Unable to load profile!") . " " . $file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
StatusMessage("ERROR", "", _("Unable to load profile!") . " " . $file);
|
|
|
|
}
|
2004-01-26 15:29:56 +00:00
|
|
|
return $settings;
|
2003-04-26 20:01:49 +00:00
|
|
|
}
|
|
|
|
|
2003-10-11 17:20:00 +00:00
|
|
|
// loads an host profile
|
|
|
|
// $profile: name of the host profile (without .prh)
|
2004-01-26 15:29:56 +00:00
|
|
|
// the return value is an hash array (attribute => value)
|
2003-04-26 20:01:49 +00:00
|
|
|
function loadHostProfile($profile) {
|
2003-10-23 19:31:17 +00:00
|
|
|
if (!eregi("^[0-9a-z_\\-]+$", $profile)) return false;
|
2004-01-26 15:29:56 +00:00
|
|
|
$settings = array();
|
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
|
2004-01-26 15:29:56 +00:00
|
|
|
$parts = array();
|
|
|
|
$parts = split(": ", $line);
|
2004-03-06 19:59:32 +00:00
|
|
|
if (sizeof($parts) != 2) continue; // ignore malformed settings
|
2004-02-12 15:58:04 +00:00
|
|
|
else {
|
2004-03-06 19:59:32 +00:00
|
|
|
$option = $parts[0];
|
|
|
|
$value = $parts[1];
|
2004-02-12 15:58:04 +00:00
|
|
|
// remove line ends
|
2004-03-06 19:59:32 +00:00
|
|
|
$value = chop($value);
|
|
|
|
$settings[$option] = explode("+::+", $value);
|
2004-02-12 15:58:04 +00:00
|
|
|
}
|
2003-06-24 15:50:38 +00:00
|
|
|
}
|
|
|
|
fclose($file);
|
|
|
|
}
|
|
|
|
else {
|
2003-07-30 14:34:33 +00:00
|
|
|
StatusMessage("ERROR", "", _("Unable to load profile!") . " " . $file);
|
2003-04-30 16:50:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2003-07-30 14:34:33 +00:00
|
|
|
StatusMessage("ERROR", "", _("Unable to load profile!") . " " . $file);
|
2003-04-30 16:50:48 +00:00
|
|
|
}
|
2004-01-26 15:29:56 +00:00
|
|
|
return $settings;
|
2003-04-26 20:01:49 +00:00
|
|
|
}
|
|
|
|
|
2004-01-26 15:29:56 +00:00
|
|
|
// saves an hash array (attribute => value) to an user profile
|
2003-04-26 20:01:49 +00:00
|
|
|
// file is created, if needed
|
2003-10-11 17:20:00 +00:00
|
|
|
// $profile: name of the user profile (without .pru)
|
2004-03-06 19:59:32 +00:00
|
|
|
// $attributes: hash array(attribute => value)
|
2004-01-26 15:29:56 +00:00
|
|
|
function saveUserProfile($attributes, $profile) {
|
2003-11-05 19:53:51 +00:00
|
|
|
if (!$_SESSION['loggedIn'] == true) return false;
|
2003-10-23 19:31:17 +00:00
|
|
|
// check profile name
|
2004-01-26 15:29:56 +00:00
|
|
|
if (!eregi("^[0-9a-z_-]+$", $profile)) return false;
|
|
|
|
if (!is_array($attributes)) {
|
2003-11-05 19:53:51 +00:00
|
|
|
return false;
|
2003-06-24 15:50:38 +00:00
|
|
|
}
|
2003-05-01 11:37:46 +00:00
|
|
|
$path = substr(__FILE__, 0, strlen(__FILE__) - 17) . "/config/profiles/users/" . $profile . ".pru";
|
2003-08-03 11:05:40 +00:00
|
|
|
$file = @fopen($path, "w");
|
|
|
|
if ($file) {
|
2004-03-06 19:59:32 +00:00
|
|
|
// write attributes
|
|
|
|
$keys = array_keys($attributes);
|
|
|
|
for ($i = 0; $i < sizeof($keys); $i++) {
|
|
|
|
$line = $keys[$i] . ": " . implode("+::+", $attributes[$keys[$i]]) . "\n";
|
|
|
|
fputs($file, $line);
|
2003-09-20 08:04:38 +00:00
|
|
|
}
|
2003-08-03 11:05:40 +00:00
|
|
|
// close file
|
|
|
|
fclose($file);
|
2003-05-01 20:30:43 +00:00
|
|
|
}
|
2003-08-03 11:05:40 +00:00
|
|
|
else {
|
|
|
|
StatusMessage("ERROR", _("Unable to save profile!"), $path);
|
|
|
|
return false;
|
2003-05-01 20:30:43 +00:00
|
|
|
}
|
2003-08-03 11:05:40 +00:00
|
|
|
return true;
|
2003-04-26 20:01:49 +00:00
|
|
|
}
|
|
|
|
|
2004-01-26 15:29:56 +00:00
|
|
|
// saves an hash array (attribute => value) to an group profile
|
2003-04-26 20:01:49 +00:00
|
|
|
// file is created, if needed
|
2003-10-11 17:20:00 +00:00
|
|
|
// $profile: name of the group profile (without .prg)
|
2004-03-06 19:59:32 +00:00
|
|
|
// $attributes: hash array(attribute => value)
|
2004-01-26 15:29:56 +00:00
|
|
|
function saveGroupProfile($attributes, $profile) {
|
2003-11-05 19:53:51 +00:00
|
|
|
if (!$_SESSION['loggedIn'] == true) return false;
|
2003-10-23 19:31:17 +00:00
|
|
|
// check profile name
|
2004-01-26 15:29:56 +00:00
|
|
|
if (!eregi("^[0-9a-z_-]+$", $profile)) return false;
|
|
|
|
if (!is_array($attributes)) {
|
2003-11-05 19:53:51 +00:00
|
|
|
return false;
|
2003-09-20 17:02:21 +00:00
|
|
|
}
|
|
|
|
$path = substr(__FILE__, 0, strlen(__FILE__) - 17) . "/config/profiles/groups/" . $profile . ".prg";
|
|
|
|
$file = @fopen($path, "w");
|
|
|
|
if ($file) {
|
|
|
|
// write attributes
|
2004-03-06 19:59:32 +00:00
|
|
|
$keys = array_keys($attributes);
|
|
|
|
for ($i = 0; $i < sizeof($keys); $i++) {
|
|
|
|
$line = $keys[$i] . ": " . implode("+::+", $attributes[$keys[$i]]) . "\n";
|
|
|
|
fputs($file, $line);
|
2003-09-20 17:02:21 +00:00
|
|
|
}
|
|
|
|
// close file
|
|
|
|
fclose($file);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
StatusMessage("ERROR", _("Unable to save profile!"), $path);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2003-04-26 20:01:49 +00:00
|
|
|
}
|
|
|
|
|
2004-01-26 15:29:56 +00:00
|
|
|
// saves an hash array (attribute => value) to an host profile
|
2003-04-26 20:01:49 +00:00
|
|
|
// file is created, if needed
|
2003-10-11 17:20:00 +00:00
|
|
|
// $profile: name of the host profile (without .prh)
|
2004-03-06 19:59:32 +00:00
|
|
|
// $attributes: hash array(attribute => value)
|
2004-01-26 15:29:56 +00:00
|
|
|
function saveHostProfile($attributes, $profile) {
|
2003-11-05 19:53:51 +00:00
|
|
|
if (!$_SESSION['loggedIn'] == true) return false;
|
2003-10-23 19:31:17 +00:00
|
|
|
// check profile name
|
2004-01-26 15:29:56 +00:00
|
|
|
if (!eregi("^[0-9a-z_-]+$", $profile)) return false;
|
|
|
|
if (!is_array($attributes)) {
|
2003-11-05 19:53:51 +00:00
|
|
|
return false;
|
2003-06-24 15:50:38 +00:00
|
|
|
}
|
2003-05-01 11:37:46 +00:00
|
|
|
$path = substr(__FILE__, 0, strlen(__FILE__) - 17) . "/config/profiles/hosts/" . $profile . ".prh";
|
2003-08-03 11:05:40 +00:00
|
|
|
$file = @fopen($path, "w");
|
|
|
|
if ($file) {
|
|
|
|
// write attributes
|
2004-03-06 19:59:32 +00:00
|
|
|
$keys = array_keys($attributes);
|
|
|
|
for ($i = 0; $i < sizeof($keys); $i++) {
|
|
|
|
$line = $keys[$i] . ": " . implode("+::+", $attributes[$keys[$i]]) . "\n";
|
|
|
|
fputs($file, $line);
|
2004-01-26 15:29:56 +00:00
|
|
|
}
|
2003-08-03 11:05:40 +00:00
|
|
|
// close file
|
|
|
|
fclose($file);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
StatusMessage("ERROR", _("Unable to save profile!"), $path);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2003-04-26 20:01:49 +00:00
|
|
|
}
|
|
|
|
|
2003-05-25 10:51:10 +00:00
|
|
|
// deletes a user profile
|
|
|
|
function delUserProfile($file) {
|
2003-11-05 19:53:51 +00:00
|
|
|
if (!$_SESSION['loggedIn'] == true) return false;
|
|
|
|
if (!eregi("^[0-9a-z\\-_]+$", $file)) return false;
|
2003-05-25 10:51:10 +00:00
|
|
|
$prof = substr(__FILE__, 0, strlen(__FILE__) - 16) . "config/profiles/users/".$file.".pru";
|
|
|
|
if (is_file($prof)) {
|
|
|
|
return @unlink($prof);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-20 17:02:21 +00:00
|
|
|
// deletes a group profile
|
|
|
|
function delGroupProfile($file) {
|
2003-11-05 19:53:51 +00:00
|
|
|
if (!$_SESSION['loggedIn'] == true) return false;
|
|
|
|
if (!eregi("^[0-9a-z\\-_]+$", $file)) return false;
|
2003-09-20 17:02:21 +00:00
|
|
|
$prof = substr(__FILE__, 0, strlen(__FILE__) - 16) . "config/profiles/groups/".$file.".prg";
|
|
|
|
if (is_file($prof)) {
|
|
|
|
return @unlink($prof);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-25 10:51:10 +00:00
|
|
|
// deletes a host profile
|
|
|
|
function delHostProfile($file) {
|
2003-11-05 19:53:51 +00:00
|
|
|
if (!$_SESSION['loggedIn'] == true) return false;
|
|
|
|
if (!eregi("^[0-9a-z\\-_]+$", $file)) return false;
|
2003-05-25 10:51:10 +00:00
|
|
|
$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
|
|
|
?>
|