From d3ed4a59ae2d7a8b84ff628a209b7ae7bb61656f Mon Sep 17 00:00:00 2001 From: seek3r Date: Sun, 28 Jan 2001 12:07:20 +0000 Subject: [PATCH] Working on load order simplification. It still needs ALOT of work --- login.php | 7 +- phpgwapi/inc/class.accounts_shared.inc.php | 16 +- phpgwapi/inc/class.accounts_sql.inc.php | 69 +++++- phpgwapi/inc/class.acl.inc.php | 58 +++-- phpgwapi/inc/class.applications.inc.php | 250 ++++++++------------ phpgwapi/inc/class.common.inc.php | 61 +---- phpgwapi/inc/class.phpgw.inc.php | 34 +-- phpgwapi/inc/class.phpgw.inc.php-bak | 258 --------------------- phpgwapi/inc/class.preferences.inc.php | 82 ++++--- phpgwapi/inc/class.sessions.inc.php | 3 +- phpgwapi/inc/functions.inc.php | 27 ++- 11 files changed, 303 insertions(+), 562 deletions(-) delete mode 100644 phpgwapi/inc/class.phpgw.inc.php-bak diff --git a/login.php b/login.php index f807052b0a..71f257debb 100755 --- a/login.php +++ b/login.php @@ -115,8 +115,11 @@ // If there is something wrong with this code TELL ME! // Commenting out the code will not fix it. (jengo) if (isset($last_loginid)) { - $pref = new preferences($last_loginid); - $phpgw_info["user"]["preferences"] = $pref; +//echo "check point 1 - $last_loginid
\n"; + $prefs = CreateObject("phpgwapi.preferences", $last_loginid); +//echo "check point 2
\n"; + $phpgw_info["user"]["preferences"] = $prefs->get_saved_preferences(); +//echo "check point 3
\n"; #print "LANG:".$phpgw_info["user"]["preferences"]["common"]["lang"]."
"; $phpgw->translation->add_app("login"); $phpgw->translation->add_app("loginscreen"); diff --git a/phpgwapi/inc/class.accounts_shared.inc.php b/phpgwapi/inc/class.accounts_shared.inc.php index 52219a132e..933dee5af5 100644 --- a/phpgwapi/inc/class.accounts_shared.inc.php +++ b/phpgwapi/inc/class.accounts_shared.inc.php @@ -26,20 +26,12 @@ class accounts extends accounts_ { - function accounts_const($line,$file) + function accounts_const() { global $phpgw, $phpgw_info; - - //echo "accounts_const called
line: $line
$file"; - - $phpgw->accounts->phpgw_fillarray(); - if(!$phpgw->preferences->account_id) { - $phpgw->preferences = CreateObject('phpgwapi.preferences',$phpgw_info["user"]["account_id"]); - } - $phpgw_info["user"]["preferences"] = $phpgw->preferences->get_preferences(); + + $phpgw->accounts->fill_user_array(); $this->groups = $this->read_groups($phpgw_info["user"]["userid"]); - $apps = CreateObject('phpgwapi.applications'); - $phpgw_info["user"]["apps"] = $apps->users_enabled_apps(); } // use this if you make any changes to phpgw_info, including preferences, config table changes, etc @@ -55,7 +47,7 @@ while($db->next_record()) { $phpgw_info["server"][$db->f("config_name")] = $db->f("config_value"); } - $phpgw->accounts->accounts_const(__LINE__,__FILE__); + $phpgw->accounts->accounts_const(); $phpgw_info_temp["user"] = $phpgw_info["user"]; $phpgw_info_temp["apps"] = $phpgw_info["apps"]; diff --git a/phpgwapi/inc/class.accounts_sql.inc.php b/phpgwapi/inc/class.accounts_sql.inc.php index 5a0c3579e1..7cdc8bc67b 100644 --- a/phpgwapi/inc/class.accounts_sql.inc.php +++ b/phpgwapi/inc/class.accounts_sql.inc.php @@ -30,7 +30,7 @@ var $group_names; var $apps; - function phpgw_fillarray() + function fill_user_array() { global $phpgw_info, $phpgw; @@ -46,8 +46,13 @@ $phpgw_info["user"]["fullname"] = $db2->f("account_firstname") . " " . $db2->f("account_lastname"); $phpgw_info["user"]["groups"] = explode (",", $db2->f("account_groups")); + $apps = CreateObject('phpgwapi.applications',intval($phpgw_info["user"]["account_id"])); - $phpgw_info["user"]["app_perms"] = $apps->app_perms; + $prefs = CreateObject('phpgwapi.preferences',intval($phpgw_info["user"]["account_id"])); + $phpgw_info["user"]["preferences"] = $prefs->get_saved_preferences(); + $phpgw_info["user"]["app_perms"] = $apps->app_perms(); + $phpgw_info["user"]["apps"] = $apps->enabled_apps(); + $phpgw_info["user"]["lastlogin"] = $db2->f("account_lastlogin"); $phpgw_info["user"]["lastloginfrom"] = $db2->f("account_lastloginfrom"); $phpgw_info["user"]["lastpasswd_change"] = $db2->f("account_lastpwd_change"); @@ -72,7 +77,11 @@ . $db2->f("account_lastname"); $userData["groups"] = explode(",", $db2->f("account_groups")); $apps = CreateObject('phpgwapi.applications',intval($phpgw_info["user"]["account_id"])); - $userData["app_perms"] = $apps->app_perms; + $prefs = CreateObject('phpgwapi.preferences',intval($phpgw_info["user"]["account_id"])); + $userData["preferences"] = $prefs->get_saved_preferences(); + $userData["app_perms"] = $apps->app_perms(); + $userData["apps"] = $apps->enabled_apps(); + $userData["lastlogin"] = $db2->f("account_lastlogin"); $userData["lastloginfrom"] = $db2->f("account_lastloginfrom"); $userData["lastpasswd_change"] = $db2->f("account_lastpwd_change"); @@ -235,4 +244,56 @@ return $accounts; } - } + function username2userid($user_name) + { + global $phpgw, $phpgw_info; + $db2 = $phpgw->db; + $db2->query("SELECT account_id FROM accounts WHERE account_lid='".$user_name."'",__LINE__,__FILE__); + if($db2->num_rows()) { + $db2->next_record(); + return $db2->f("account_id"); + }else{ + return False; + } + } + + function userid2username($user_id) + { + global $phpgw, $phpgw_info; + $db2 = $phpgw->db; + $db2->query("SELECT account_lid FROM accounts WHERE account_id='".$user_id."'",__LINE__,__FILE__); + if($db2->num_rows()) { + $db2->next_record(); + return $db2->f("account_lid"); + }else{ + return False; + } + } + + function groupname2groupid($group_name) + { + global $phpgw, $phpgw_info; + $db2 = $phpgw->db; + $db2->query("SELECT group_id FROM groups WHERE group_name='".$group_name."'",__LINE__,__FILE__); + if($db2->num_rows()) { + $db2->next_record(); + return $db2->f("group_id"); + }else{ + return False; + } + } + + function groupid2groupname($group_id) + { + global $phpgw, $phpgw_info; + $db2 = $phpgw->db; + $db2->query("SELECT group_name FROM groups WHERE group_id='".$group_id."'",__LINE__,__FILE__); + if($db2->num_rows()) { + $db2->next_record(); + return $db2->f("group_name"); + }else{ + return False; + } + } + }//end of class +?> \ No newline at end of file diff --git a/phpgwapi/inc/class.acl.inc.php b/phpgwapi/inc/class.acl.inc.php index 6e2e73efb0..d9941930a5 100644 --- a/phpgwapi/inc/class.acl.inc.php +++ b/phpgwapi/inc/class.acl.inc.php @@ -25,13 +25,13 @@ class acl { - var $db; + var $db; - function acl() - { - global $phpgw; - $this->db = $phpgw->db; - } + function acl() + { + global $phpgw; + $this->db = $phpgw->db; + } /* This is a new class. These are sample table entries insert into phpgw_acl (acl_appname, acl_location, acl_account, acl_account_type, acl_rights) @@ -43,17 +43,19 @@ insert into phpgw_acl (acl_appname, acl_location, acl_account, acl_account_type, acl_rights) values('filemanager', 'create', 2, 'g', 2); */ - - function get_rights($location,$appname = False){ - global $phpgw, $phpgw_info; + function get_rights($location,$appname = False, $user_id = ""){ + global $phpgw, $phpgw_info; if ($appname == False){ $appname = $phpgw_info["flags"]["currentapp"]; } + if($user_id == "") { + $user_id = $phpgw_info["user"]["account_id"]; + } // User piece $sql = "select acl_rights from phpgw_acl where acl_appname='$appname'"; $sql .= " and (acl_location in ('$location','everywhere')) and "; - $sql .= "((acl_account_type = 'u' and acl_account = ".$phpgw_info["user"]["account_id"].")"; + $sql .= "((acl_account_type = 'u' and acl_account = ".$user_id.")"; // Group piece $sql .= " or (acl_account_type='g' and acl_account in (0"; // group 0 covers all users @@ -74,13 +76,42 @@ return $rights; } - function check($location, $required, $appname = False){ + function check($location, $required, $appname = False, $user_id = ""){ global $phpgw, $phpgw_info; - $rights = $this->get_rights($location,$appname); + $rights = $this->get_rights($location,$appname, $user_id); return !!($rights & $required); } + function get_specific_rights($location, $appname = False, $id = "", $id_type = "u"){ + global $phpgw, $phpgw_info; + + if ($appname == False){ + $appname = $phpgw_info["flags"]["currentapp"]; + } + if($id == "") { + $id = $phpgw_info["user"]["account_id"]; + } + // User piece + $sql = "select acl_rights from phpgw_acl where acl_appname='$appname'"; + $sql .= " and acl_location = '$location' and "; + $sql .= "acl_account_type = ".$id_type." and acl_account = ".$id; + $this->db->query($sql ,__LINE__,__FILE__); + $rights = 0; + if ($this->db->num_rows() == 0 && $phpgw_info["server"]["acl_default"] != "deny"){ return True; } + while ($this->db->next_record()) { + if ($this->db->f("acl_rights") == 0){ return False; } + $rights |= $this->db->f("acl_rights"); + } + return $rights; + } + + function check_specific($location, $required, $appname = False, $id = "", $id_type = "u"){ + global $phpgw, $phpgw_info; + $rights = $this->get_specific_rights($location,$appname, $id, $id_type); + return !!($rights & $required); + } + function add($app, $location, $id, $id_type, $rights){ $sql = "insert into phpgw_acl (acl_appname, acl_location, acl_account, acl_account_type, acl_rights)"; $sql .= " values('".$app."', '".$location."', ".$id.", '".$id_type."', ".$rights.")"; @@ -102,10 +133,9 @@ return True; } - function get_app_list_for_id($location, $required, $id_type = "", $id = ""){ + function get_app_list_for_id($location, $required, $id = "", $id_type = "u"){ global $phpgw, $phpgw_info; if ($id == ""){ $id = $phpgw_info["user"]["account_id"]; } - if ($id_type == ""){ $id_type = "u"; } $sql = "select acl_appname, acl_rights from phpgw_acl where acl_location = '$location' and "; $sql .= "acl_account_type = '".$id_type."' and acl_account = ".$id; $this->db->query($sql ,__LINE__,__FILE__); diff --git a/phpgwapi/inc/class.applications.inc.php b/phpgwapi/inc/class.applications.inc.php index ad58013348..e2c7b2d970 100755 --- a/phpgwapi/inc/class.applications.inc.php +++ b/phpgwapi/inc/class.applications.inc.php @@ -25,121 +25,113 @@ class applications { var $account_id; - var $user_apps = Array(); - var $group_apps = Array(); + var $account_type; + var $account_apps = Array(); + var $db; - function applications($var="") + function applications($account_id = "", $account_type = "u") { + global $phpgw, $phpgw_info; + $this->db = $phpgw->db; + if ($account_id == ""){ + $this->account_id = $phpgw_info["user"]["account_id"]; + }elseif (is_long($account_id)) { + $this->account_id = $account_id; + } elseif(is_string($account_id)) { + $this->account_id = $phpgw->accounts->username2userid($account_id); + } + $this->account_type = $account_type; +//echo "Account ID (Initializing applications) = ".$this->account_id."
\n"; } - function users_enabled_apps() + function enabled_apps() { - global $phpgw, $phpgw_info; + global $phpgw, $phpgw_info; + if (gettype($phpgw_info["apps"]) != "array") { + $this->read_installed_apps(); + } + while (list($app) = each($phpgw_info["apps"])) { + if ($this->account_type == "g") { + $check = $phpgw->acl->check_specific("run",1,$app, $this->account_id, "g"); + }else{ + $check = $phpgw->acl->check("run",1,$app, $this->account_id); + } + if ($check) { + $this->account_apps[$app] = array("title" => $phpgw_info["apps"][$app]["title"], "name" => $app, "enabled" => True, "status" => $phpgw_info["apps"][$app]["status"]); + } + return $this->account_apps; + } + return False; + } - if (gettype($phpgw_info["apps"]) != "array") { - $this->read_installed_apps(); - } - while (list($app) = each($phpgw_info["apps"])) { - if ($phpgw->acl->check("run",1,$app)) { - $phpgw_info["user"]["apps"][$app] = array("title" => $phpgw_info["apps"][$app]["title"], "name" => $app, "enabled" => True, "status" => $phpgw_info["apps"][$app]["status"]); - } - } + function app_perms() + { + global $phpgw, $phpgw_info; + if (count($this->account_apps) == 0) { + $this->enabled_apps(); + } + while (list ($key) = each ($this->account_apps)) { + $app[] = $this->account_apps[$key]["name"]; + } + return $app; + } + + function read_account_specific() { + global $phpgw, $phpgw_info; + if (gettype($phpgw_info["apps"]) != "array") { + $this->read_installed_apps(); + } + while (list($app) = each($phpgw_info["apps"])) { + if ($phpgw->acl->check_specific("run",1,$app, $this->account_id, $this->account_type)) { + $this->account_apps[$app] = array("title" => $phpgw_info["apps"][$app]["title"], "name" => $app, "enabled" => True, "status" => $phpgw_info["apps"][$app]["status"]); + } + return $this->account_apps; + } + return False; + } + + function add_app($apps) { + if(gettype($appname) == "array") { + while($app = each($appname)) { + $this->account_apps[] = $app[0]; + } + } elseif(gettype($appname) == "string") { + $this->account_apps[] = $appname; + } + reset($this->account_apps); + return $this->account_apps; + } + + function delete_app($appname) { + unset($this->account_apps[$appname]); + reset($this->account_apps); + return $this->account_apps; + } + + function save_apps(){ + global $phpgw, $phpgw_info; + $phpgw->acl->delete("%", "run", $this->account_id, $this->account_type); + reset($this->account_apps[$group_id]); + while($app = each($this->account_apps)) { + $phpgw->acl->add($app["name"],'run',$this->account_id,$this->account_type,1); + } + reset($this->account_apps); + return $this->account_apps; } function read_installed_apps(){ global $phpgw, $phpgw_info; - $phpgw->db->query("select * from applications where app_enabled != '0' order by app_order asc",__LINE__,__FILE__); - if($phpgw->db->num_rows()) { - while ($phpgw->db->next_record()) { -// echo "
TEST: " . $phpgw->db->f("app_order") . " - " . $phpgw->db->f("app_name"); - $name = $phpgw->db->f("app_name"); - $title = $phpgw->db->f("app_title"); - $status = $phpgw->db->f("app_enabled"); + $this->db->query("select * from applications where app_enabled != '0' order by app_order asc",__LINE__,__FILE__); + if($this->db->num_rows()) { + while ($this->db->next_record()) { + $name = $this->db->f("app_name"); + $title = $this->db->f("app_title"); + $status = $this->db->f("app_enabled"); $phpgw_info["apps"][$name] = array("title" => $title, "enabled" => True, "status" => $status); } } } - function read_user_apps($lid ="") { - global $phpgw, $phpgw_info; - if ($lid == ""){$lid = $phpgw_info["user"]["account_id"];} - $owner_found = False; - if(gettype($lid) == "string" && $lid == $phpgw_info["user"]["user_id"]) { - $owner_id = $phpgw_info["user"]["account_id"]; - $owner_found = True; - } - if($owner_found == False && gettype($lid) == "integer") { - $owner_id = $lid; - $owner_found = True; - } elseif($owner_found == False && gettype($lid) == "string") { - $phpgw->db->query("SELECT account_id FROM accounts WHERE account_lid='".$lid."'",__LINE__,__FILE__); - if($phpgw->db->num_rows()) { - $phpgw->db->next_record(); - $owner_id = $phpgw->db->f("account_id"); - $owner_found = True; - } - } - if($owner_found) { - $acl_apps = $phpgw->acl->get_app_list_for_id('run', 1, 'u', $owner_id); - if ($acl_apps != False){ - reset ($acl_apps); - while (list(,$value) = each($acl_apps)){ - $apps[] = $value; - } - } - if(gettype($phpgw_info["apps"]) != "array") { - $this->read_installed_apps(); - } - if(count($apps)) { - for ($i=0; $iuser_apps[$owner_id][] = $apps[$i]; - } - } - } - return $this->user_apps[$owner_id]; - } - return False; - } - - function read_group_apps($group_id) { - global $phpgw, $phpgw_info; - $group_found = False; - if(gettype($group_id) == "integer") { - $group_found = True; - } elseif(gettype($group_id) == "string") { - $phpgw->db->query("SELECT group_id FROM groups WHERE group_name='".$group_id."'",__LINE__,__FILE__); - if($phpgw->db->num_rows()) { - settype($group_id,"integer"); - $phpgw->db->next_record(); - $group_id = $phpgw->db->f("group_id"); - $group_found = True; - } - } - - if($group_found) { - $acl_apps = $phpgw->acl->get_app_list_for_id('run', 1, 'g', $group_id); - if ($acl_apps != False){ - reset ($acl_apps); - while (list(,$value) = each($acl_apps)){ - $apps[] = $value; - } - } - if(gettype($phpgw_info["apps"]) != "array") { - $this->read_installed_apps(); - } - if(count($apps)) { - for ($i=0;$igroup_apps[$group_id][] = $apps[$i]; - } - } - } - return $this->group_apps[$group_id]; - } - return False; - } - function is_system_enabled($appname){ if(gettype($phpgw_info["apps"]) != "array") { $this->read_installed_apps(); @@ -150,61 +142,5 @@ return False; } } - - function add_group_app($apps, $group_id) { - if(gettype($appname) == "array") { - while($app = each($appname)) { - $this->group_apps[$group_id][] = $app[0]; - } - } elseif(gettype($appname) == "string") { - $this->group_apps[$group_id][] = $appname; - } - } - - function add_user_app($appname, $user_id = "") { - global $phpgw, $phpgw_info; - if ($user_id == ""){$user_id = $phpgw_info["user"]["account_id"];} - if(gettype($appname) == "array") { - while($app = each($appname)) { - $this->user_apps[$user_id][] = $app[0]; - } - } elseif(gettype($appname) == "string") { - $this->user_apps[$user_id][] = $appname; - } - } - - function delete_group_app($appname, $group_id) { - unset($this->group_apps[$group_id][$appname]); - } - - function delete_user_app($appname, $user_id = ""){ - global $phpgw, $phpgw_info; - if ($user_id == ""){$user_id = $phpgw_info["user"]["account_id"];} - unset($this->group_apps[$user_id][$appname]); - } - - function save_group_apps($group_id){ - global $phpgw, $phpgw_info; - - if($group_id) { - $phpgw->acl->delete("%", "run", "g", $group_id); - reset($this->group_apps[$group_id]); - while($app = each($this->group_apps[$group_id])) { - $phpgw->acl->add($app[1],'run',$group_id,'g',1); - } - } - } - - function save_user_apps($user_id = ""){ - global $phpgw, $phpgw_info; - if ($user_id == ""){$user_id = $phpgw_info["user"]["account_id"];} - if($user_id) { - $phpgw->acl->delete("%", "run", "u", $user_id); - reset($this->user_apps); - while($app = each($this->user_apps[$user_id])) { - $phpgw->acl->add($app[1],'run',$user_id,'u',1); - } - } - } } -?> +?> \ No newline at end of file diff --git a/phpgwapi/inc/class.common.inc.php b/phpgwapi/inc/class.common.inc.php index c6f2bd8f36..bcfc7c216d 100644 --- a/phpgwapi/inc/class.common.inc.php +++ b/phpgwapi/inc/class.common.inc.php @@ -32,45 +32,6 @@ echo "Failed attempt to break in via an old Security Hole!
\n"; exit; } unset($d1);unset($d2);unset($d3); - //incase we are dealing with a fresh login - if (!isset($phpgw_info["user"]["preferences"]["common"]["template_set"])){ - $phpgw_info["user"]["preferences"]["common"]["template_set"] = "default"; - } - // Since LDAP will return system accounts, there are a few we don't want to login. - $phpgw_info["server"]["global_denied_users"] = array('root' => True, - 'bin' => True, - 'daemon' => True, - 'adm' => True, - 'lp' => True, - 'sync' => True, - 'shutdown' => True, - 'halt' => True, - 'mail' => True, - 'news' => True, - 'uucp' => True, - 'operator' => True, - 'games' => True, - 'gopher' => True, - 'nobody' => True, - 'xfs' => True, - 'pgsql' => True, - 'mysql' => True, - 'postgres' => True, - 'ftp' => True, - 'gdm' => True, - 'named' => True); - - - // I had to create this has a wrapper, becuase the phpgw.inc.php files needs it before the classes - // are finished loading (jengo) - function filesystem_separator() - { - if (PHP_OS == "Windows" || PHP_OS == "OS/2") { - return "\\"; - } else { - return "/"; - } - } class common { @@ -455,6 +416,7 @@ $phpgw_info["navbar"]["home"]["url"] = $phpgw->link($phpgw_info["server"]["webserver_url"] . "/index.php"); $phpgw_info["navbar"]["home"]["icon"] = $phpgw_info["server"]["webserver_url"] . "/phpgwapi/templates/" . $phpgw_info["server"]["template_set"] . "/images/home.gif"; + while ($permission = each($phpgw_info["user"]["apps"])) { if ($phpgw_info["apps"][$permission[0]]["status"] != 2) { $phpgw_info["navbar"][$permission[0]]["title"] = $phpgw_info["apps"][$permission[0]]["title"]; @@ -601,10 +563,9 @@ } /* Then add the rest */ reset ($phpgw_info["user"]["apps"]); - asort ($phpgw_info["user"]["apps"]); - while (list (, $appname) = each ($phpgw_info["user"]["apps"])){ - if (gettype($appname) != "array" && $appname != "" && $completed_hooks[$appname] != True){ - $f = $phpgw_info["server"]["server_root"] . "/" . $appname . "/inc/hook_".$phpgw_info["flags"]["currentapp"]; + while ($permission = each($phpgw_info["user"]["apps"])) { + if ($completed_hooks[$permission[0]] != True){ + $f = $phpgw_info["server"]["server_root"] . "/" . $permission[0] . "/inc/hook_".$phpgw_info["flags"]["currentapp"]; if ($location != ""){$f .= "_".$location.".inc.php";}else{$f .= ".inc.php"; } if (file_exists($f)) {include($f);} } @@ -635,10 +596,9 @@ function hook_count($location = ""){ global $phpgw, $phpgw_info; - reset ($phpgw_info["user"]["app_perms"]); $count = 0; - while (list (, $appname) = each ($phpgw_info["user"]["app_perms"])){ - $f = $phpgw_info["server"]["server_root"] . "/" . $appname . "/inc/hook_".$phpgw_info["flags"]["currentapp"]; + while ($permission = each($phpgw_info["user"]["apps"])) { + $f = $phpgw_info["server"]["server_root"] . "/" . $permission[0] . "/inc/hook_".$phpgw_info["flags"]["currentapp"]; if ($location != ""){$f .= "_".$location.".inc.php";}else{$f .= ".inc.php"; } if (file_exists($f)) {++$count;} } @@ -912,11 +872,4 @@ system("grep -r '^[ \t]*function' *"); echo ""; } - - function common_() - { - global $phpgw, $phpgw_info; - $phpgw_info["server"]["dir_separator"] = $this->filesystem_separator(); - } - - } + }//end common class diff --git a/phpgwapi/inc/class.phpgw.inc.php b/phpgwapi/inc/class.phpgw.inc.php index c572e1d128..f84ca525bb 100644 --- a/phpgwapi/inc/class.phpgw.inc.php +++ b/phpgwapi/inc/class.phpgw.inc.php @@ -111,30 +111,35 @@ /* Load selected accounts class */ if (empty($phpgw_info["server"]["account_repository"])){$phpgw_info["server"]["account_repository"] = $phpgw_info["server"]["auth_type"];} - $this->accounts = CreateObject("phpgwapi.accounts"); - $this->preferences = CreateObject("phpgwapi.preferences"); - $this->session = CreateObject("phpgwapi.sessions"); $this->acl = CreateObject("phpgwapi.acl"); - $this->applications = CreateObject("phpgwapi.applications"); + $this->accounts = CreateObject("phpgwapi.accounts"); + $this->session = CreateObject("phpgwapi.sessions"); +// $this->applications = CreateObject("phpgwapi.applications"); +// $this->preferences = CreateObject("phpgwapi.preferences"); +//echo "check point 1
\n"; if ($phpgw_info["flags"]["currentapp"] == "login") { - $log = explode("@",$login); - $this->preferences = CreateObject("phpgwapi.preferences", $log[0]); - $this->applications = CreateObject("phpgwapi.applications"); +//echo "check point 2
\n"; + if ($login != ""){ + $log = explode("@",$login); + $this->preferences = CreateObject("phpgwapi.preferences", $log[0]); +// $this->applications = CreateObject("phpgwapi.applications", $log[0]); + } }else{ +//echo "check point 3
\n"; if (! $this->session->verify()) { +//echo "check point 4
\n"; $this->db->query("select config_value from config where config_name='webserver_url'",__LINE__,__FILE__); $this->db->next_record(); Header("Location: " . $this->redirect($this->link($this->db->f("config_value")."/login.php","cd=10"))); exit; } +//echo "check point 5
\n"; $this->preferences = CreateObject("phpgwapi.preferences", intval($phpgw_info["user"]["account_id"])); - $this->applications = CreateObject("phpgwapi.applications"); - $this->applications->users_enabled_apps(); + $this->applications = CreateObject("phpgwapi.applications", intval($phpgw_info["user"]["account_id"])); } - $this->translation = CreateObject("phpgwapi.translation"); - $sep = filesystem_separator(); + $sep = $phpgw_info["server"]["dir_separator"]; $template_root = $this->common->get_tpl_dir(); if (is_dir($template_root)) { @@ -157,11 +162,11 @@ // please let us know if this doesn't work for you! if (! $url && (PHP_OS == "Windows" || PHP_OS == "OS/2" || PHP_OS == "WIN32" || PHP_OS == "WIN16")) { $exe = strpos($PHP_SELF,"php.exe"); - if ($exe != false) { + if ($exe != false) { $exe += 7; // strlen("php.exe") $url_root = split ("/", $phpgw_info["server"]["webserver_url"]); $url = (strlen($url_root[0])? $url_root[0].'//':'') . $url_root[2]; - $url .= substr($PHP_SELF,$exe,strlen($PHP_SELF)-$exe); + $url .= substr($PHP_SELF,$exe,strlen($PHP_SELF)-$exe); } } if (! $url) { @@ -251,5 +256,4 @@ return $phpgw->translation->translate($key); } - } - + }//end phpgw class diff --git a/phpgwapi/inc/class.phpgw.inc.php-bak b/phpgwapi/inc/class.phpgw.inc.php-bak deleted file mode 100644 index 34470e718c..0000000000 --- a/phpgwapi/inc/class.phpgw.inc.php-bak +++ /dev/null @@ -1,258 +0,0 @@ - * - * -------------------------------------------- * - * 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. * - \**************************************************************************/ - - /* $Id$ */ - - /****************************************************************************\ - * Required classes * - \****************************************************************************/ - /* Load selected database class */ - if (empty($phpgw_info["server"]["db_type"])){$phpgw_info["server"]["db_type"] = "mysql";} - include($phpgw_info["server"]["api_inc"] . "/phpgw_db_".$phpgw_info["server"]["db_type"].".inc.php"); - - include($phpgw_info["server"]["api_inc"] . "/phpgw_session.inc.php"); - - /* Load selected translation class */ - if (empty($phpgw_info["server"]["translation_system"])){$phpgw_info["server"]["translation_system"] = "sql";} - include($phpgw_info["server"]["api_inc"] . "/phpgw_lang_".$phpgw_info["server"]["translation_system"].".inc.php"); - - include($phpgw_info["server"]["api_inc"] . "/phpgw_crypto.inc.php"); - include($phpgw_info["server"]["api_inc"] . "/phpgw_template.inc.php"); - include($phpgw_info["server"]["api_inc"] . "/phpgw_common.inc.php"); - - /****************************************************************************\ - * Our API class starts here * - \****************************************************************************/ - class phpgw - { - var $accounts; - var $acl; - var $auth; - var $db; - var $debug = 0; // This will turn on debugging information. - // (Not fully working) - var $crypto; - var $categories; - var $common; - var $hooks; - var $network; - var $nextmatchs; - var $preferences; - var $session; - var $send; - var $template; - var $translation; - var $utilities; - var $vfs; - - var $calendar; - var $msg; - - var $addressbook; - var $todo; - - // This is here so you can decied what the best way to handle bad sessions - // You could redirect them to login.php with code 2 or use the default - // I recommend using the default until all of the bugs are worked out. - - function phpgw_() - { - global $phpgw_info, $sessionid, $login; - /************************************************************************\ - * Required classes * - \************************************************************************/ - $this->db = new db; - $this->db->Host = $phpgw_info["server"]["db_host"]; - $this->db->Type = $phpgw_info["server"]["db_type"]; - $this->db->Database = $phpgw_info["server"]["db_name"]; - $this->db->User = $phpgw_info["server"]["db_user"]; - $this->db->Password = $phpgw_info["server"]["db_pass"]; - - if ($this->debug) { - $this->db->Debug = 1; - } - - if ($phpgw_info["flags"]["currentapp"] == "login") { - $this->db->query("select * from config",__LINE__,__FILE__); - while($this->db->next_record()) { - $phpgw_info["server"][$this->db->f("config_name")] = $this->db->f("config_value"); - } - } else { - $config_var = array("encryptkey","auth_type","account_repository"); - $c= ""; - for ($i=0;$idb->query("select * from config where $c",__LINE__,__FILE__); - while($this->db->next_record()) { - $phpgw_info["server"][$this->db->f("config_name")] = $this->db->f("config_value"); - } - } - - /************************************************************************\ - * Continue adding the classes * - \************************************************************************/ - $this->common = new common; - $this->hooks = new hooks; - - /* Load selected authentication class */ - if (empty($phpgw_info["server"]["auth_type"])){$phpgw_info["server"]["auth_type"] = "sql";} - include($phpgw_info["server"]["api_inc"] . "/phpgw_auth_".$phpgw_info["server"]["auth_type"].".inc.php"); - - $this->auth = new auth; - - /* Load selected accounts class */ - if (empty($phpgw_info["server"]["account_repository"])){$phpgw_info["server"]["account_repository"] = $phpgw_info["server"]["auth_type"];} - include($phpgw_info["server"]["api_inc"] . "/phpgw_accounts_".$phpgw_info["server"]["account_repository"].".inc.php"); - include($phpgw_info["server"]["api_inc"] . "/phpgw_accounts_shared.inc.php"); - - $this->accounts = new accounts; - $this->preferences = new preferences(0); - - $this->session = new sessions; - - if ($phpgw_info["flags"]["currentapp"] == "login") { - $log = explode("@",$login); - $this->preferences = new preferences($log[0]); - }else{ - if (! $this->session->verify()) { - $this->db->query("select config_value from config where config_name='webserver_url'",__LINE__,__FILE__); - $this->db->next_record(); - Header("Location: " . $this->redirect($this->link($this->db->f("config_value")."/login.php","cd=10"))); - exit; - } - $this->preferences = new preferences(intval($phpgw_info["user"]["account_id"])); - } - - $this->translation = new translation; - $this->acl = new acl; - - $sep = filesystem_separator(); - $template_root = $this->common->get_tpl_dir(); - - if (is_dir($template_root)) { - $this->template = new Template($template_root); - } - } - - - /**************************************************************************\ - * Core functions * - \**************************************************************************/ - - /* A function to handle session support via url session id, or cookies */ - function link($url = "", $extravars = "") - { - global $phpgw, $phpgw_info, $usercookie, $kp3, $PHP_SELF; - if (! $kp3) - $kp3 = $phpgw_info["user"]["kp3"]; - - // PHP won't allow you to set a var to a var - // or function for default values - if (! $url) { - $url_root = split ("/", $phpgw_info["server"]["webserver_url"]); - $url = $url_root[0]."//".$url_root[2].$PHP_SELF; - /* Some hosting providers have their paths screwy. - If the value from $PHP_SELF is not what you expect, you can use this to patch it - It will need to be adjusted to your specific problem tho. - */ - //$patched_php_self = str_replace("/php4/php/phpgroupware", "/phpgroupware", $PHP_SELF); - $patched_php_self = $PHP_SELF; - $url = $url_root[0]."//".$url_root[2].$patched_php_self; - } - - if (isset($phpgw_info["server"]["usecookies"]) && - $phpgw_info["server"]["usecookies"]) { - if ($extravars) { - $url .= "?$extravars"; - } - } else { - $url .= "?sessionid=" . $phpgw_info["user"]["sessionid"]; - $url .= "&kp3=" . $kp3; - $url .= "&domain=" . $phpgw_info["user"]["domain"]; - // This doesn't belong in the API. - // Its up to the app to pass this value. (jengo) - // Putting it into the app requires a massive number of updates in email app. - // Until that happens this needs to stay here (seek3r) - if ($phpgw_info["flags"]["newsmode"]) { - $url .= "&newsmode=on"; - } - - if ($extravars) { - $url .= "&$extravars"; - } - } - - $url = str_replace("/?", "/index.php?", $url); - $webserver_url_count = strlen($phpgw_info["server"]["webserver_url"]); - $slash_check = strtolower(substr($url ,0,1)); - if(substr($url ,0,$webserver_url_count) != $phpgw_info["server"]["webserver_url"]) { - $app = $phpgw_info["flags"]["currentapp"]; - if($slash_check == "/") { - $url = $phpgw_info["server"]["webserver_url"].$url; - } elseif ($app == "home" || $app == "logout" || $app == "login"){ - $url = $phpgw_info["server"]["webserver_url"]."/".$url; - }else{ - $url = $phpgw_info["server"]["webserver_url"]."/".$app."/".$url; - } - } - return $url; - } - - function strip_html($s) - { - return htmlspecialchars(stripslashes($s)); - } - - function redirect($url = "") - { - // This function handles redirects under iis and apache - // it assumes that $phpgw->link() has already been called - - global $HTTP_ENV_VARS; - - $iis = strpos($HTTP_ENV_VARS["SERVER_SOFTWARE"], "IIS", 0); - - if ( !$url ) { - $url = $PHP_SELF; - } - if ( $iis ) { - echo "\n\n\nRedirecting to $url"; - echo "\n"; - echo "\n"; - echo "

Please continue to this page

"; - echo "\n"; - exit; - } else { - Header("Location: $url"); - print("\n\n"); - exit; - } - } - - function lang($key, $m1 = "", $m2 = "", $m3 = "", $m4 = "") - { - global $phpgw; - - return $phpgw->translation->translate($key); - } - - // Some people might prefear to use this one - function _L($key, $m1 = "", $m2 = "", $m3 = "", $m4 = "") - { - global $phpgw; - - return $phpgw->translation->translate($key); - } - } - diff --git a/phpgwapi/inc/class.preferences.inc.php b/phpgwapi/inc/class.preferences.inc.php index 90ac0dd4d1..b37714e4aa 100644 --- a/phpgwapi/inc/class.preferences.inc.php +++ b/phpgwapi/inc/class.preferences.inc.php @@ -27,42 +27,46 @@ class preferences { var $account_id; - var $preference; + var $preference = Array(); + var $db; - function preferences($account_id = 0) + function preferences($account_id = "") { - global $phpgw; -// echo "Account ID (Initializing) = ".$account_id."
\n"; - - - $db2 = $phpgw->db; - $load_pref = True; - if (is_long($account_id) && $account_id) { +//echo "Account_id = ".$account_id."
\n"; + global $phpgw, $phpgw_info; + $this->db = $phpgw->db; + if ($account_id == ""){ + $this->account_id = $phpgw_info["user"]["account_id"]; + }elseif (is_long($account_id)) { $this->account_id = $account_id; } elseif(is_string($account_id)) { - $db2->query("SELECT account_id FROM accounts WHERE account_lid='".$account_id."'",__LINE__,__FILE__); - if($db2->num_rows()) { - $db2->next_record(); - $this->account_id = $db2->f("account_id"); - } else { - $load_pref = False; - } - } else { - $load_pref = False; + $this->account_id = $phpgw->accounts->username2userid($account_id); } +//echo "Account ID (Initializing prefs) = ".$this->account_id."
\n"; + } + + function get_saved_preferences() + { + global $phpgw; + $this->db->lock("preferences"); + $this->db->query("SELECT preference_value FROM preferences WHERE preference_owner=".$this->account_id,__LINE__,__FILE__); + $this->db->next_record(); + $pref_info = $this->db->f("preference_value"); + $this->preference = Array(); + $this->preference = unserialize($pref_info); + $this->db->unlock(); +//echo "Account ID (get_saved_pref) = ".$this->account_id."
\n"; +//echo "Preferences = ".$this->preference."
\n"; + return $this->preference; + } -//echo "Load Pref = $load_pref
\n"; -//echo "Account ID (After Initializing) = ".$this->account_id."
\n"; - if ($load_pref) { - $db2->lock("preferences"); - $db2->query("SELECT preference_value FROM preferences WHERE preference_owner=".$this->account_id,__LINE__,__FILE__); - $db2->next_record(); - $pref_info = $db2->f("preference_value"); - $this->preference = unserialize($pref_info); -// echo "Preferences = ".$this->get_preferences()."
\n"; - $db2->unlock(); - } + function get_preferences() + { + global $phpgw; +//echo "Account ID (get_pref) = ".$this->account_id."
\n"; +//echo "Preferences = ".$this->preference."
\n"; + return $this->preference; } // This should be called when you are done makeing changes to the preferences @@ -72,11 +76,8 @@ //echo "
commit called
Line: $line
File: $file".$phpgw_info["user"]["account_id"]."
"; if ($this->account_id) { - $db = $phpgw->db; - - $db->lock("preferences"); - - $db->query("delete from preferences where preference_owner=" . $this->account_id,__LINE__,__FILE__); + $this->db->lock("preferences"); + $this->db->query("delete from preferences where preference_owner=" . $this->account_id,__LINE__,__FILE__); if ($PHP_VERSION < "4.0.0") { $pref_info = addslashes(serialize($this->preference)); @@ -84,14 +85,13 @@ $pref_info = serialize($this->preference); } - $db->query("insert into preferences (preference_owner,preference_value) values (" + $this->db->query("insert into preferences (preference_owner,preference_value) values (" . $this->account_id . ",'" . $pref_info . "')",__LINE__,__FILE__); - $db->unlock(); - + $this->db->unlock(); if ($phpgw_info["user"]["account_id"] == $this->account_id) { - $phpgw->preferences->preference = $this->get_preferences(); + $this->get_saved_preferences(); $phpgw->accounts->sync(__LINE__,__FILE__); } } @@ -125,9 +125,5 @@ $this->preference["$app_name"] = array(); } - function get_preferences() - { - return $this->preference; - } } //end of preferences class -?> +?> \ No newline at end of file diff --git a/phpgwapi/inc/class.sessions.inc.php b/phpgwapi/inc/class.sessions.inc.php index b192fd2e74..aaac559f8e 100644 --- a/phpgwapi/inc/class.sessions.inc.php +++ b/phpgwapi/inc/class.sessions.inc.php @@ -74,7 +74,6 @@ $phpgw_info_flags = $phpgw_info["flags"]; $phpgw_info = $phpgw->crypto->decrypt($db->f("session_info")); - $phpgw_info["flags"] = $phpgw_info_flags; $userid_array = explode("@",$db->f("session_lid")); @@ -155,7 +154,7 @@ unset ($phpgw_info["server"]["default_domain"]); // we kill this for security reasons } - //$phpgw->accounts->accounts_const(); + $phpgw->accounts->accounts_const(); $phpgw_info["user"]["session_ip"] = $this->getuser_ip(); diff --git a/phpgwapi/inc/functions.inc.php b/phpgwapi/inc/functions.inc.php index 73729040f5..4da5d92d0e 100644 --- a/phpgwapi/inc/functions.inc.php +++ b/phpgwapi/inc/functions.inc.php @@ -67,6 +67,16 @@ return $phpgw->common->check_code($code); } + function filesystem_separator() + { + if (PHP_OS == "Windows" || PHP_OS == "OS/2") { + return "\\"; + } else { + return "/"; + } + } + + /****************************************************************************\ * Optional classes, which can be disabled for performance increases * * - they are loaded after pulling in the config from the DB * @@ -167,12 +177,28 @@ } unset ($domain); // we kill this to save memory + $phpgw_info["server"]["dir_separator"] = filesystem_separator(); + $phpgw_info["server"]["sep"] = $phpgw_info["server"]["dir_separator"]; + // some constants which can be used in setting user acl rights. define("PHPGW_ACL_READ",1); define("PHPGW_ACL_ADD",2); define("PHPGW_ACL_EDIT",4); define("PHPGW_ACL_DELETE",8); + //incase we are dealing with a fresh login + if (!isset($phpgw_info["user"]["preferences"]["common"]["template_set"])){ + $phpgw_info["user"]["preferences"]["common"]["template_set"] = "default"; + } + + // Since LDAP will return system accounts, there are a few we don't want to login. + $phpgw_info["server"]["global_denied_users"] = array( + 'root'=>True,'bin'=>True,'daemon'=>True,'adm'=>True,'lp'=>True,'sync'=>True, + 'shutdown' => True,'halt'=>True,'mail'=>True,'news'=>True,'uucp'=>True, + 'operator' => True,'games'=>True,'gopher'=>True,'nobody'=>True,'xfs'=>True, + 'pgsql'=>True,'mysql'=>True,'postgres'=>True,'ftp'=>True,'gdm'=>True,'named'=>True + ); + // This function needs to be optimized, its reading duplicate information. function phpgw_fillarray() { @@ -210,7 +236,6 @@ load_optional(); phpgw_fillarray(); - $phpgw->common->common_(); if ($phpgw_info["flags"]["enable_utilities_class"]){ $phpgw->utilities->utilities_();