added lots of comments

This commit is contained in:
Roland Gruber 2003-03-15 11:42:08 +00:00
parent ef13f1f067
commit 2cf741cc13
1 changed files with 41 additions and 2 deletions

View File

@ -19,10 +19,12 @@ $Id$
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Config supplies access to the configuration data.
*/ */
// Config supplies access to the configuration data.
class Config { class Config {
@ -79,6 +81,7 @@ class Config {
while (!feof($file)) { while (!feof($file)) {
$line = fgets($file, 1024); $line = fgets($file, 1024);
if (($line == "\n")||($line[0] == "#")) continue; // ignore comments if (($line == "\n")||($line[0] == "#")) continue; // ignore comments
// search keywords
if (substr($line, 0, 5) == "ssl: ") { if (substr($line, 0, 5) == "ssl: ") {
$this->SSL = chop(substr($line, 5, strlen($line)-5)); $this->SSL = chop(substr($line, 5, strlen($line)-5));
continue; continue;
@ -157,6 +160,7 @@ class Config {
function save() { function save() {
$conffile = "../lam.conf"; $conffile = "../lam.conf";
if (is_file($conffile) == True) { if (is_file($conffile) == True) {
// booleans to check if value was already saved
$save_ssl = $save_host = $save_port = $save_passwd = $save_admins = $save_suffusr = $save_suffgrp = $save_suffhst = $save_ssl = $save_host = $save_port = $save_passwd = $save_admins = $save_suffusr = $save_suffgrp = $save_suffhst =
$save_minUID = $save_maxUID = $save_minGID = $save_maxGID = $save_minMach = $save_maxMach = $save_defShell = $save_shellList = False; $save_minUID = $save_maxUID = $save_minGID = $save_maxGID = $save_minMach = $save_maxMach = $save_defShell = $save_shellList = False;
$file = fopen($conffile, "r"); $file = fopen($conffile, "r");
@ -167,6 +171,7 @@ class Config {
fclose($file); fclose($file);
for ($i = 0; $i < sizeof($file_array); $i++) { for ($i = 0; $i < sizeof($file_array); $i++) {
if (($file_array[$i] == "\n")||($file_array[$i][0] == "#")) continue; // ignore comments if (($file_array[$i] == "\n")||($file_array[$i][0] == "#")) continue; // ignore comments
// search for keywords
if (substr($file_array[$i], 0, 5) == "ssl: ") { if (substr($file_array[$i], 0, 5) == "ssl: ") {
$file_array[$i] = "ssl: " . $this->SSL . "\n"; $file_array[$i] = "ssl: " . $this->SSL . "\n";
$save_ssl = True; $save_ssl = True;
@ -248,7 +253,7 @@ class Config {
continue; continue;
} }
} }
// check if we have to add new entries (e.g. if user upgraded LAM) // check if we have to add new entries (e.g. if user upgraded LAM and has an old lam.conf)
if (!$save_ssl == True) array_push($file_array, "\n\n# use SSL to connect, can be True or False\n" . "ssl: " . $this->SSL); if (!$save_ssl == True) array_push($file_array, "\n\n# use SSL to connect, can be True or False\n" . "ssl: " . $this->SSL);
if (!$save_host == True) array_push($file_array, "\n\n# hostname of LDAP server (e.g localhost)\n" . "host: " . $this->Host); if (!$save_host == True) array_push($file_array, "\n\n# hostname of LDAP server (e.g localhost)\n" . "host: " . $this->Host);
if (!$save_port == True) array_push($file_array, "\n\n# portnumber of LDAP server (default 389)\n" . "port: " . $this->Port); if (!$save_port == True) array_push($file_array, "\n\n# portnumber of LDAP server (default 389)\n" . "port: " . $this->Port);
@ -297,37 +302,45 @@ class Config {
// functions to read/write preferences // functions to read/write preferences
// returns a string that can be "True" or "False"
function get_SSL() { function get_SSL() {
return $this->SSL; return $this->SSL;
} }
// accepts only strings that are either "True" or "False"
function set_SSL($value) { function set_SSL($value) {
if (($value == "True") || ($value == "False")) $this->SSL = $value; if (($value == "True") || ($value == "False")) $this->SSL = $value;
else echo _("Config->set_SSL failed!"); else echo _("Config->set_SSL failed!");
} }
// returns the hostname
function get_Host() { function get_Host() {
return $this->Host; return $this->Host;
} }
// sets the hostname
function set_Host($value) { function set_Host($value) {
if (is_string($value)) $this->Host = $value; if (is_string($value)) $this->Host = $value;
else echo _("Config->set_Host failed!"); else echo _("Config->set_Host failed!");
} }
// returns the port number as string
function get_Port() { function get_Port() {
return $this->Port; return $this->Port;
} }
// sets the portnumber
function set_Port($value) { function set_Port($value) {
if (is_numeric($value)) $this->Port = $value; if (is_numeric($value)) $this->Port = $value;
else echo _("Config->set_Port failed!"); else echo _("Config->set_Port failed!");
} }
// returns an array of string with all admin names
function get_Admins() { function get_Admins() {
return $this->Admins; return $this->Admins;
} }
// needs an array of string containing all admin users
function set_Admins($value) { function set_Admins($value) {
if (is_array($value)) { // check if $value is array of strings if (is_array($value)) { // check if $value is array of strings
$b = true; $b = true;
@ -342,10 +355,12 @@ class Config {
else echo _("Config->set_Admins failed!"); else echo _("Config->set_Admins failed!");
} }
// returns all admin users seperated by semicolons
function get_Adminstring() { function get_Adminstring() {
return $this->Adminstring; return $this->Adminstring;
} }
// needs a string that contains all admin users seperated by semicolons
function set_Adminstring($value) { function set_Adminstring($value) {
if (is_string($value)) { if (is_string($value)) {
$this->Adminstring = $value; $this->Adminstring = $value;
@ -354,109 +369,133 @@ class Config {
else echo _("Config->set_Adminstring failed!"); else echo _("Config->set_Adminstring failed!");
} }
// returns the password to access the preferences wizard
function get_Passwd() { function get_Passwd() {
return $this->Passwd; return $this->Passwd;
} }
// sets the preferences wizard password
function set_Passwd($value) { function set_Passwd($value) {
if (is_string($value)) $this->Passwd = $value; if (is_string($value)) $this->Passwd = $value;
else echo _("Config->set_Passwd failed!"); else echo _("Config->set_Passwd failed!");
} }
// returns the LDAP suffix where users are saved
function get_UserSuffix() { function get_UserSuffix() {
return $this->Suff_users; return $this->Suff_users;
} }
// sets the LDAP suffix where users are saved
function set_UserSuffix($value) { function set_UserSuffix($value) {
if (is_string($value)) $this->Suff_users = $value; if (is_string($value)) $this->Suff_users = $value;
else echo _("Config->set_UserSuffix failed!"); else echo _("Config->set_UserSuffix failed!");
} }
// returns the LDAP suffix where groups are saved
function get_GroupSuffix() { function get_GroupSuffix() {
return $this->Suff_groups; return $this->Suff_groups;
} }
// sets the LDAP suffix where groups are saved
function set_GroupSuffix($value) { function set_GroupSuffix($value) {
if (is_string($value)) $this->Suff_groups = $value; if (is_string($value)) $this->Suff_groups = $value;
else echo _("Config->set_GroupSuffix failed!"); else echo _("Config->set_GroupSuffix failed!");
} }
// returns the LDAP suffix where hosts are saved
function get_HostSuffix() { function get_HostSuffix() {
return $this->Suff_hosts; return $this->Suff_hosts;
} }
// sets the LDAP suffix where hosts are saved
function set_HostSuffix($value) { function set_HostSuffix($value) {
if (is_string($value)) $this->Suff_hosts = $value; if (is_string($value)) $this->Suff_hosts = $value;
else echo _("Config->set_HostSuffix failed!"); else echo _("Config->set_HostSuffix failed!");
} }
// returns the minimum UID to use when creating new users
function get_minUID() { function get_minUID() {
return $this->MinUID; return $this->MinUID;
} }
// sets the minimum UID to use when creating new users
function set_minUID($value) { function set_minUID($value) {
if (is_numeric($value)) $this->MinUID = $value; if (is_numeric($value)) $this->MinUID = $value;
else echo _("Config->set_minUID failed!"); else echo _("Config->set_minUID failed!");
} }
// returns the maximum UID to use when creating new users
function get_maxUID() { function get_maxUID() {
return $this->MaxUID; return $this->MaxUID;
} }
// sets the maximum UID to use when creating new users
function set_maxUID($value) { function set_maxUID($value) {
if (is_numeric($value)) $this->MaxUID = $value; if (is_numeric($value)) $this->MaxUID = $value;
else echo _("Config->set_maxUID failed!"); else echo _("Config->set_maxUID failed!");
} }
// returns the minimum GID to use when creating new groups
function get_minGID() { function get_minGID() {
return $this->MinGID; return $this->MinGID;
} }
// sets the minimum GID to use when creating new groups
function set_minGID($value) { function set_minGID($value) {
if (is_numeric($value)) $this->MinGID = $value; if (is_numeric($value)) $this->MinGID = $value;
else echo _("Config->set_minGID failed!"); else echo _("Config->set_minGID failed!");
} }
// returns the maximum GID to use when creating new groups
function get_maxGID() { function get_maxGID() {
return $this->MaxGID; return $this->MaxGID;
} }
// sets the maximum GID to use when creating new groups
function set_maxGID($value) { function set_maxGID($value) {
if (is_numeric($value)) $this->MaxGID = $value; if (is_numeric($value)) $this->MaxGID = $value;
else echo _("Config->set_maxGID failed!"); else echo _("Config->set_maxGID failed!");
} }
// returns the minimum UID to use when creating new Samba hosts
function get_minMachine() { function get_minMachine() {
return $this->MinMachine; return $this->MinMachine;
} }
// sets the minimum UID to use when creating new Samba hosts
function set_minMachine($value) { function set_minMachine($value) {
if (is_numeric($value)) $this->MinMachine = $value; if (is_numeric($value)) $this->MinMachine = $value;
else echo _("Config->set_minMachine failed!"); else echo _("Config->set_minMachine failed!");
} }
// returns the maximum UID to use when creating new Samba hosts
function get_maxMachine() { function get_maxMachine() {
return $this->MaxMachine; return $this->MaxMachine;
} }
// sets the maximum UID to use when creating new Samba hosts
function set_maxMachine($value) { function set_maxMachine($value) {
if (is_numeric($value)) $this->MaxMachine = $value; if (is_numeric($value)) $this->MaxMachine = $value;
else echo _("Config->set_maxMachine failed!"); else echo _("Config->set_maxMachine failed!");
} }
// returns the default shell to use when creating new users
function get_defaultShell() { function get_defaultShell() {
return $this->DefaultShell; return $this->DefaultShell;
} }
// sets the default shell to use when creating new users
function set_defaultShell($value) { function set_defaultShell($value) {
if (is_string($value)) $this->DefaultShell = $value; if (is_string($value)) $this->DefaultShell = $value;
else echo _("Config->set_shellList failed!"); else echo _("Config->set_shellList failed!");
} }
// returns a list of possible shells when creating new users
function get_shellList() { function get_shellList() {
return $this->ShellList; return $this->ShellList;
} }
// sets the list of possible shells when creating new users
function set_shellList($value) { function set_shellList($value) {
if (is_string($value)) $this->ShellList = $value; if (is_string($value)) $this->ShellList = $value;
else echo _("Config->set_shellList failed!"); else echo _("Config->set_shellList failed!");