2003-02-17 18:21:44 +00:00
|
|
|
<?php
|
2003-02-21 22:01:01 +00:00
|
|
|
/*
|
|
|
|
$Id$
|
|
|
|
|
2003-02-21 22:09:59 +00:00
|
|
|
This code is part of LDAP Account Manager (http://www.sourceforge.net/projects/lam)
|
2003-02-21 22:01:01 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2003-02-17 18:21:44 +00:00
|
|
|
// Config supplies access to the configuration data.
|
|
|
|
|
|
|
|
class Config {
|
2003-02-25 21:28:17 +00:00
|
|
|
// string: can be "True" or "False"
|
|
|
|
// use SSL-connection?
|
2003-02-17 18:21:44 +00:00
|
|
|
var $SSL;
|
|
|
|
// string: hostname
|
|
|
|
var $Host;
|
2003-02-25 21:28:17 +00:00
|
|
|
// string: port number
|
2003-02-17 18:21:44 +00:00
|
|
|
var $Port;
|
|
|
|
// array of strings: users with admin rights
|
|
|
|
var $Admins;
|
|
|
|
// string: password to edit preferences
|
|
|
|
var $Passwd;
|
|
|
|
|
2003-02-25 21:28:17 +00:00
|
|
|
// single line with the names of all admin users
|
|
|
|
var $Adminstring;
|
2003-02-17 21:38:54 +00:00
|
|
|
|
|
|
|
// constructor, loads preferences from ../lam.conf
|
2003-02-17 18:21:44 +00:00
|
|
|
function Config() {
|
|
|
|
$this->reload();
|
|
|
|
}
|
|
|
|
|
|
|
|
// reloads preferences from ../lam.conf
|
|
|
|
function reload() {
|
|
|
|
$conffile = "../lam.conf";
|
|
|
|
if (is_file($conffile) == True) {
|
|
|
|
$file = fopen($conffile, "r");
|
|
|
|
while (!feof($file)) {
|
2003-02-17 21:38:54 +00:00
|
|
|
$line = fgets($file, 1024);
|
|
|
|
if (($line == "\n")||($line[0] == "#")) continue;
|
|
|
|
if (substr($line, 0, 5) == "ssl: ") {
|
2003-02-25 21:28:17 +00:00
|
|
|
$this->SSL = chop(substr($line, 5, strlen($line)-5));
|
2003-02-17 21:38:54 +00:00
|
|
|
continue;
|
2003-02-17 18:21:44 +00:00
|
|
|
}
|
2003-02-17 21:38:54 +00:00
|
|
|
if (substr($line, 0, 6) == "host: ") {
|
2003-02-25 21:28:17 +00:00
|
|
|
$this->Host = chop(substr($line, 6, strlen($line)-6));
|
2003-02-17 21:38:54 +00:00
|
|
|
continue;
|
2003-02-17 18:21:44 +00:00
|
|
|
}
|
2003-02-17 21:38:54 +00:00
|
|
|
if (substr($line, 0, 6) == "port: ") {
|
2003-02-25 21:28:17 +00:00
|
|
|
$this->Port = chop(substr($line, 6, strlen($line)-6));
|
2003-02-17 21:38:54 +00:00
|
|
|
continue;
|
2003-02-17 18:21:44 +00:00
|
|
|
}
|
2003-02-17 21:38:54 +00:00
|
|
|
if (substr($line, 0, 8) == "passwd: ") {
|
2003-02-25 21:28:17 +00:00
|
|
|
$this->Passwd = chop(substr($line, 8, strlen($line)-8));
|
2003-02-17 21:38:54 +00:00
|
|
|
continue;
|
2003-02-17 18:21:44 +00:00
|
|
|
}
|
2003-02-17 21:38:54 +00:00
|
|
|
if (substr($line, 0, 8) == "admins: ") {
|
2003-02-25 21:28:17 +00:00
|
|
|
$adminstr = chop(substr($line, 8, strlen($line)-8));
|
|
|
|
$this->Adminstring = $adminstr;
|
2003-02-17 21:38:54 +00:00
|
|
|
$this->Admins = explode(";", $adminstr);
|
|
|
|
continue;
|
2003-02-17 18:21:44 +00:00
|
|
|
}
|
|
|
|
}
|
2003-02-17 21:38:54 +00:00
|
|
|
fclose($file);
|
2003-02-17 18:21:44 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
echo _("Unable to load lam.conf!"); echo "</br>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// saves preferences to ../lam.conf
|
|
|
|
function save() {
|
2003-02-17 21:38:54 +00:00
|
|
|
$conffile = "../lam.conf";
|
|
|
|
if (is_file($conffile) == True) {
|
|
|
|
$save_ssl = $save_host = $save_port = $save_passwd = $save_admins = False;
|
|
|
|
$file = fopen($conffile, "r");
|
|
|
|
$file_array = array();
|
|
|
|
while (!feof($file)) {
|
|
|
|
array_push($file_array, fgets($file, 1024));
|
|
|
|
}
|
|
|
|
fclose($file);
|
|
|
|
for ($i = 0; $i < sizeof($file_array); $i++) {
|
|
|
|
if (($file_array[$i] == "\n")||($file_array[$i][0] == "#")) continue;
|
|
|
|
if (substr($file_array[$i], 0, 5) == "ssl: ") {
|
2003-02-25 21:28:17 +00:00
|
|
|
$file_array[$i] = "ssl: " . $this->SSL . "\n";
|
2003-02-17 21:38:54 +00:00
|
|
|
$save_ssl = True;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (substr($file_array[$i], 0, 6) == "host: ") {
|
2003-02-25 21:28:17 +00:00
|
|
|
$file_array[$i] = "host: " . $this->Host . "\n";
|
2003-02-17 21:38:54 +00:00
|
|
|
$save_host = True;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (substr($file_array[$i], 0, 6) == "port: ") {
|
2003-02-25 21:28:17 +00:00
|
|
|
$file_array[$i] = "port: " . $this->Port . "\n";
|
2003-02-17 21:38:54 +00:00
|
|
|
$save_port = True;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (substr($file_array[$i], 0, 8) == "passwd: ") {
|
2003-02-25 21:28:17 +00:00
|
|
|
$file_array[$i] = "passwd: " . $this->Passwd . "\n";
|
2003-02-17 21:38:54 +00:00
|
|
|
$save_passwd = True;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (substr($file_array[$i], 0, 8) == "admins: ") {
|
2003-02-25 21:28:17 +00:00
|
|
|
$file_array[$i] = "admins: " . implode(";", $this->Admins) . "\n";
|
2003-02-17 21:38:54 +00:00
|
|
|
$save_admins = True;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// check if we have to add new entries
|
|
|
|
if (!$save_ssl == True) array_push($file_array, "# use SSL to connect, can be True or False\n" . "ssl: " . $this->SSL);
|
|
|
|
if (!$save_host == True) array_push($file_array, "# hostname of LDAP server (e.g localhost)\n" . "ssl: " . $this->Host);
|
|
|
|
if (!$save_port == True) array_push($file_array, "# portnumber of LDAP server (default 389)\n" . "ssl: " . $this->Port);
|
|
|
|
if (!$save_passwd == True) array_push($file_array, "# password to change these preferences via webfrontend\n" . "ssl: " . $this->Passwd);
|
|
|
|
if (!$save_admins == True) array_push($file_array, "# list of users who are allowed to use LDAP Account Manager\n
|
|
|
|
# names have to be seperated by semicolons\n
|
|
|
|
# e.g. admins: cn=admin,dc=yourdomain,dc=org;cn=root,dc=yourdomain,dc=org\n" . "ssl: " . $this->Admins);
|
|
|
|
$file = fopen($conffile, "w");
|
|
|
|
for ($i = 0; $i < sizeof($file_array); $i++) fputs($file, $file_array[$i]);
|
|
|
|
fclose($file);
|
|
|
|
}
|
2003-02-17 18:21:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// prints current preferences
|
|
|
|
function printconf() {
|
2003-03-01 12:22:35 +00:00
|
|
|
echo _("<b>SSL: </b>" ) . $this->SSL . "</br>";
|
|
|
|
echo _("<b>Host: </b>") . $this->Host . "</br>";
|
|
|
|
echo _("<b>Port: </b>") . $this->Port . "</br>";
|
|
|
|
echo _("<b>Admins: </b>") . $this->Adminstring;
|
2003-02-17 18:21:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_SSL() {
|
|
|
|
return $this->SSL;
|
|
|
|
}
|
|
|
|
|
|
|
|
function set_SSL($value) {
|
2003-02-25 21:28:17 +00:00
|
|
|
if (($value == "True") || ($value == "False")) $this->SSL = $value;
|
|
|
|
else echo _("Config->set_SSL failed!");
|
2003-02-17 18:21:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_Host() {
|
|
|
|
return $this->Host;
|
|
|
|
}
|
|
|
|
|
|
|
|
function set_Host($value) {
|
|
|
|
if (is_string($value)) $this->Host = $value;
|
2003-02-25 21:28:17 +00:00
|
|
|
else echo _("Config->set_Host failed!");
|
2003-02-17 18:21:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_Port() {
|
|
|
|
return $this->Port;
|
|
|
|
}
|
|
|
|
|
|
|
|
function set_Port($value) {
|
|
|
|
if (is_numeric($value)) $this->Port = $value;
|
2003-02-25 21:28:17 +00:00
|
|
|
else echo _("Config->set_Port failed!");
|
2003-02-17 18:21:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_Admins() {
|
|
|
|
return $this->Admins;
|
|
|
|
}
|
|
|
|
|
|
|
|
function set_Admins($value) {
|
|
|
|
if (is_array($value)) {
|
|
|
|
$b = true;
|
|
|
|
for($i = 0; $i < sizeof($value); $i++){
|
|
|
|
if (is_string($value[$i]) == false) {
|
|
|
|
$b = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($b) $this->Admins = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-25 21:28:17 +00:00
|
|
|
function get_Adminstring() {
|
|
|
|
return $this->Adminstring;
|
|
|
|
}
|
|
|
|
|
|
|
|
function set_Adminstring($value) {
|
|
|
|
if (is_string($value)) {
|
|
|
|
$this->Adminstring = $value;
|
|
|
|
$this->Admins = explode(";", $value);
|
|
|
|
}
|
|
|
|
else echo _("Config->set_Adminstring failed!");
|
|
|
|
}
|
|
|
|
|
2003-02-17 18:21:44 +00:00
|
|
|
function get_Passwd() {
|
|
|
|
return $this->Passwd;
|
|
|
|
}
|
|
|
|
|
|
|
|
function set_Passwd($value) {
|
|
|
|
if (is_string($value)) $this->Passwd = $value;
|
2003-02-25 21:28:17 +00:00
|
|
|
else echo _("Config->set_Passwd failed!");
|
2003-02-17 18:21:44 +00:00
|
|
|
}
|
|
|
|
|
2003-02-17 21:38:54 +00:00
|
|
|
}
|