From 2ebd03ec7da507fc9a0a96af6b19285882a8a613 Mon Sep 17 00:00:00 2001 From: jengo Date: Thu, 8 Feb 2001 04:42:44 +0000 Subject: [PATCH] Started moving the cache for the phpgw_info array over to appsessions() .... some things aren't working correclty yet. mainly preferences --- phpgwapi/inc/class.common.inc.php | 14 +-- phpgwapi/inc/class.sessions.inc.php | 163 ++++++++++++--------------- phpgwapi/inc/functions.inc.php | 74 ++++++------ setup/sql/mysql_newtables.inc.php | 9 +- setup/sql/mysql_upgrade_beta.inc.php | 20 ++++ setup/sql/pgsql_newtables.inc.php | 11 +- setup/sql/pgsql_upgrade_beta.inc.php | 19 ++++ version.inc.php | 2 +- 8 files changed, 166 insertions(+), 146 deletions(-) diff --git a/phpgwapi/inc/class.common.inc.php b/phpgwapi/inc/class.common.inc.php index 60ed359dd9..6765ecbd72 100644 --- a/phpgwapi/inc/class.common.inc.php +++ b/phpgwapi/inc/class.common.inc.php @@ -884,29 +884,27 @@ // This will return the full phpgw_info array, used for debugging - function debug_phpgw_info() + function debug_list_array_contents($array) { - global $phpgw_info; - - while (list($key, $val) = each($phpgw_info)) { + while (list($key, $val) = each($array)) { if (is_array($val)) { while (list($key2, $val2) = each($val)) { if (is_array($val2)) { while (list($key3, $val3) = each ($val2)) { if (is_array($val3)) { while (list($key4, $val4) = each ($val3)) { - echo "phpgw_info[$key][$key2][$key3][$key4]=$val4
"; + echo $$array . "[$key][$key2][$key3][$key4]=$val4
"; } } else { - echo "phpgw_info[$key][$key2][$key3]=$val3
"; + echo $$array . "[$key][$key2][$key3]=$val3
"; } } } else { - echo "phpgw_info[$key][$key2]=$val2
"; + echo $$array . "[$key][$key2]=$val2
"; } } } else { - echo "phpgw_info[$key]=$val
"; + echo $$array . "[$key]=$val
"; } } } diff --git a/phpgwapi/inc/class.sessions.inc.php b/phpgwapi/inc/class.sessions.inc.php index 84becaa866..833d43372d 100644 --- a/phpgwapi/inc/class.sessions.inc.php +++ b/phpgwapi/inc/class.sessions.inc.php @@ -25,6 +25,7 @@ class sessions { + var $use_cache = True; // If you want to cache the phpgw_info array var $login; var $passwd; var $account_id; @@ -100,11 +101,23 @@ $phpgw_info["user"]["kp3"] = $this->kp3; $phpgw_info_flags = $phpgw_info["flags"]; - $phpgw_info = $phpgw->crypto->decrypt($db->f("session_info")); - $this->data = $phpgw_info["user"]; + $phpgw_info["flags"] = $phpgw_info_flags; $userid_array = explode("@",$db->f("session_lid")); $this->account_lid = $userid_array[0]; + $this->update_dla(); + $this->account_id = $phpgw->accounts->name2id($this->account_lid); + + if ($this->use_cache) { + $t = $this->appsession('phpgw_info_cache','phpgwapi'); + } else { + $t = $this->read_repositories(); + } + + $phpgw_info["server"] = $t["server"]; + $phpgw_info["user"] = $t["user"]; + $phpgw_info["hooks"] = $t["hooks"]; + $phpgw_info["user"]["session_ip"] = $db->f("session_ip"); if ($userid_array[1] != $phpgw_info["user"]["domain"]) { return False; @@ -114,8 +127,6 @@ return False; } - $this->update_dla(); - $this->account_id = $phpgw->accounts->name2id($this->account_lid); $phpgw->acl->acl($this->account_id); $phpgw->accounts->accounts($this->account_id); $phpgw->preferences->preferences($this->account_id); @@ -138,23 +149,6 @@ . "'",__LINE__,__FILE__); } } - - function update_session_info() - { - global $phpgw, $phpgw_info; - $phpgw_info_temp = $phpgw_info; - $phpgw_info_temp["user"]["kp3"] = ""; - $phpgw_info_temp["flags"] = array(); - - //$this->read_repositories(); - if ($PHP_VERSION < "4.0.0") { - $info_string = addslashes($phpgw->crypto->encrypt($phpgw_info_temp)); - } else { - $info_string = $phpgw->crypto->encrypt($phpgw_info_temp); - } - $phpgw->db->query("update phpgw_sessions set session_info='$info_string' where session_id='" - . $this->sessionid . "'",__LINE__,__FILE__); - } function create($login,$passwd) { @@ -186,8 +180,7 @@ } $phpgw->accounts->account_id = $this->account_id; - $phpgw_info["user"] = $phpgw->accounts->read_repository(); - $this->sessionid = md5($phpgw->common->randomstring(10)); + $this->sessionid = md5($phpgw->common->randomstring(10)); $this->kp3 = md5($phpgw->common->randomstring(15)); $phpgw->common->key = $phpgw_info["server"]["encryptkey"]; @@ -212,16 +205,16 @@ unset ($phpgw_info["server"]["default_domain"]); // we kill this for security reasons } - // Why are we double encrypting it ? - // If mcrypt is already installed, the entire session_info field is all ready encrypted. (jengo) - $this->passwd = $phpgw->common->encrypt($passwd); $this->read_repositories(); + $phpgw_info["user"] = $this->user; + $phpgw_info["hooks"] = $this->hooks; + if ($this->use_cache) { + $this->appsession('phpgw_info_cache','phpgwapi',$phpgw_info); + } + + // This is going to be stored by appsessions in its own record +// $this->passwd = $phpgw->common->encrypt($passwd); - if ($PHP_VERSION < "4.0.0") { - $info_string = addslashes($phpgw->crypto->encrypt($this->data)); - } else { - $info_string = $phpgw->crypto->encrypt($this->data); - } $phpgw->db->query("insert into phpgw_sessions values ('" . $this->sessionid . "','".$login."','" . $this->getuser_ip() . "','" . time() . "','" . time() . "','".$info_string."')",__LINE__,__FILE__); @@ -270,84 +263,78 @@ /*************************************************************************\ * Functions for appsession data and session cache * \*************************************************************************/ - function read_repositories() { - global $phpgw_info, $phpgw; + global $phpgw; $phpgw->acl->acl($this->account_id); $phpgw->accounts->accounts($this->account_id); $phpgw->preferences->preferences($this->account_id); $phpgw->applications->applications($this->account_id); - $phpgw_info["user"] = $phpgw->accounts->read_repository(); - $phpgw_info["user"]["acl"] = $phpgw->acl->read_repository(); - $phpgw_info["user"]["preferences"] = $phpgw->preferences->read_repository(); - $phpgw_info["user"]["apps"] = $phpgw->applications->read_repository(); - @reset($phpgw_info["user"]["apps"]); - $phpgw_info["user"]["domain"] = $this->account_domain; - $phpgw_info["user"]["sessionid"] = $this->sessionid; - $phpgw_info["user"]["kp3"] = $this->kp3; - $phpgw_info["user"]["session_ip"] = $this->getuser_ip(); - $phpgw_info["user"]["session_lid"] = $this->account_lid."@".$this->account_domain; - $phpgw_info["user"]["account_id"] = $this->account_id; - $phpgw_info["user"]["account_lid"] = $this->account_lid; - $phpgw_info["user"]["userid"] = $this->account_lid; - $phpgw_info["user"]["passwd"] = $this->passwd; - - $this->data["user"] = $phpgw_info["user"]; - $this->data["apps"] = $phpgw_info["apps"]; - $this->data["server"] = $phpgw_info["server"]; - $this->data["hooks"] = $phpgw->hooks->read(); - $this->data["user"]["preferences"] = $phpgw_info["user"]["preferences"]; - $this->data["user"]["kp3"] = ""; + $this->user = $phpgw->accounts->read_repository(); + $this->user["acl"] = $phpgw->acl->read_repository(); + $this->user["preferences"] = $phpgw->preferences->read_repository(); + $this->user["apps"] = $phpgw->applications->read_repository(); + //@reset($this->data["user"]["apps"]); + + $this->user["domain"] = $this->account_domain; + $this->user["sessionid"] = $this->sessionid; + $this->user["kp3"] = $this->kp3; + $this->user["session_ip"] = $this->getuser_ip(); + $this->user["session_lid"] = $this->account_lid."@".$this->account_domain; + $this->user["account_id"] = $this->account_id; + $this->user["account_lid"] = $this->account_lid; + $this->user["userid"] = $this->account_lid; + $this->user["passwd"] = $this->passwd; + $this->hooks = $phpgw->hooks->read(); } - function appsession($data = "##NOTHING##", $location = "default") { + function save_repositories() + { + global $phpgw, $phpgw_info; + $phpgw_info_temp = $phpgw_info; + $phpgw_info_temp["user"]["kp3"] = ""; + $phpgw_info_temp["flags"] = array(); + + if ($this->use_cache) { + $this->appsessions("phpgw_info_cache","phpgwapi",$phpgw_info_temp); + } + } + + function appsession($location = "default", $appname = "", $data = "##NOTHING##") + { global $phpgw_info, $phpgw; - if ($data == "##NOTHING##") { /* This allows the user to put "" as the value. */ - $sql = 'select content from phpgw_app_sessions where' - .' sessionid = "'.$this->sessionid.'"' - .' and loginid = "'.$this->account_id.'"' - .' and app = "'.$phpgw_info["user"]["currentapp"].'"' - .' and location = "'.$location.'"'; + if (! $appname) { + $appname = $phpgw_info['flags']['currentapp']; + } - $phpgw->db->query($sql,__LINE__,__FILE__); + /* This allows the user to put "" as the value. */ + if ($data == "##NOTHING##") { + $phpgw->db->query('select content from phpgw_app_sessions where' + .' sessionid = "'.$this->sessionid.'" and loginid = "'.$this->account_id.'"' + .' and app = "'.$appname.'" and location = "'.$location.'"',__LINE__,__FILE__); - if($phpgw->db->num_rows()) { $phpgw->db->next_record(); $data = $phpgw->db->f("content"); -// $data = $phpgw->common->decrypt($data); + $data = $phpgw->common->decrypt($data); return $data; - } } else { -// $data = $phpgw->common->encrypt($data); - $sql = 'select content from phpgw_app_sessions where' - .' sessionid = "'.$this->sessionid.'"' - .' and loginid = "'.$this->account_id.'"' - .' and app = "'.$phpgw_info["user"]["currentapp"].'"' - .' and location = "'.$location.'"'; - - $phpgw->db->query($sql,__LINE__,__FILE__); + $phpgw->db->query('select content from phpgw_app_sessions where ' + . 'sessionid = "'.$this->sessionid.'" and loginid = "'.$this->account_id.'" ' + . 'and app = "'.$appname.'" and location = "'.$location.'"',__LINE__,__FILE__); if ($phpgw->db->num_rows()==0) { - $sql = 'INSERT INTO phpgw_app_sessions (sessionid,loginid,app,location,content)' - .' VALUES ("'.$this->sessionid.'"' - .' ","'.$this->account_id.'"' - .' ","'.$phpgw_info["flags"]["currentapp"].'"' - .' ","'.$location.'"' - .' ","'.$data.'")' - ; - $phpgw->db->query($sql,__LINE__,__FILE__); + $data = addslashes($phpgw->crypto->encrypt(serialize($data))); + $phpgw->db->query('INSERT INTO phpgw_app_sessions (sessionid,loginid,app,location,content) ' + . 'VALUES ("'.$this->sessionid.'","'.$this->account_id.'","'.$appname + . '","'.$location.'","'.$data.'")',__LINE__,__FILE__); } else { - $sql = 'update phpgw_app_sessions set content = "'.$data.'"' - .' where sessionid = "'.$this->sessionid.'"' - .' and loginid = "'.$this->account_id.'"' - .' and app = "'.$phpgw_info["user"]["currentapp"].'"' - .' and location = "'.$location.'"'; - $phpgw->db->query($sql,__LINE__,__FILE__); + $phpgw->db->query('update phpgw_app_sessions set content = "'.$data.'" ' + . 'where sessionid = "'.$this->sessionid.'" ' + . 'and loginid = "'.$this->account_id.'" and app = "'.$appname.'" ' + . 'and location = "'.$location.'"',__LINE__,__FILE__); } - //$data = $phpgw->common->decrypt($data); return $data; } } diff --git a/phpgwapi/inc/functions.inc.php b/phpgwapi/inc/functions.inc.php index 70ab21d84e..e9ffbbfb0a 100644 --- a/phpgwapi/inc/functions.inc.php +++ b/phpgwapi/inc/functions.inc.php @@ -78,7 +78,8 @@ global $debugme; if ($debugme == "on") { echo 'debug: '.$text.'
'; } } -print_debug('core functions are done'); + + print_debug('core functions are done'); /****************************************************************************\ * Quick verification of sane environment * \****************************************************************************/ @@ -96,7 +97,7 @@ print_debug('core functions are done'); } magic_quotes_runtime(false); -print_debug('sane environment'); + print_debug('sane environment'); /****************************************************************************\ * Multi-Domain support * @@ -150,9 +151,10 @@ print_debug('sane environment'); } unset ($domain); // we kill this to save memory -print_debug('domain: '.$phpgw_info["user"]["domain"]); + print_debug('domain: '.$phpgw_info["user"]["domain"]); -//dont know where to put this (seek3r) + // Dont know where to put this (seek3r) + // This is where it belongs (jengo) /* 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, @@ -184,7 +186,7 @@ print_debug('domain: '.$phpgw_info["user"]["domain"]); /* Load main class */ $phpgw = CreateObject("phpgwapi.phpgw"); $phpgw->phpgw_(); -print_debug('main class loaded'); + print_debug('main class loaded'); /* Fill phpgw_info["server"] array */ $phpgw->db->query("select * from config",__LINE__,__FILE__); @@ -194,34 +196,26 @@ print_debug('main class loaded'); // Handy little shortcut $sep = $phpgw_info["server"]["dir_separator"]; - if ($phpgw_info["flags"]["currentapp"] == "login" || $phpgw_info["flags"]["currentapp"] == "logout") { - /****************************************************************************\ - * Stuff to use if logging in or logging out * - \****************************************************************************/ - - /* incase we are dealing with a fresh login */ -// not sure these lines are needed anymore (seek3r) -// if (! isset($phpgw_info["user"]["preferences"]["common"]["template_set"])) { -// $phpgw_info["user"]["preferences"]["common"]["template_set"] = "default"; -// } - - if ($phpgw_info["flags"]["currentapp"] == "login") { - if ($login != ""){ - $login_array = explode("@",$login); - $login_id = $phpgw->accounts->name2id($login_array[0]); - $phpgw->accounts->accounts($login_id); - $phpgw->preferences->preferences($login_id); - } - } - /****************************************************************************\ - * Everything from this point on will ONLY happen if * - * the currentapp is not login or logout * + * Stuff to use if logging in or logging out * \****************************************************************************/ + if ($phpgw_info["flags"]["currentapp"] == "login" || $phpgw_info["flags"]["currentapp"] == "logout") { + if ($phpgw_info["flags"]["currentapp"] == "login") { + if ($login != ""){ + $login_array = explode("@",$login); + $login_id = $phpgw->accounts->name2id($login_array[0]); + $phpgw->accounts->accounts($login_id); + $phpgw->preferences->preferences($login_id); + } + } + /****************************************************************************\ + * Everything from this point on will ONLY happen if * + * the currentapp is not login or logout * + \****************************************************************************/ } else { if (! $phpgw->session->verify()) { - Header("Location: " . $phpgw->redirect($phpgw->session->link($phpgw_info["server"]["webserver_url"]."/login.php","cd=10"))); - exit; + Header("Location: " . $phpgw->redirect($phpgw->session->link($phpgw_info["server"]["webserver_url"]."/login.php","cd=10"))); + exit; } /* A few hacker resistant constants that will be used throught the program */ @@ -240,20 +234,20 @@ print_debug('main class loaded'); define("PHPGW_ACL_DELETE",8); /********* Load up additional phpgw_info["server"] values *********/ - /* LEGACY SUPPORT!!! WILL BE DELETED AFTER 0.9.11 IS RELEASED !!! */ - $phpgw_info["server"]["template_dir"] = PHPGW_TEMPLATE_DIR; - $phpgw_info["server"]["images_dir"] = PHPGW_IMAGES_DIR; - $phpgw_info["server"]["images_filedir"] = PHPGW_IMAGES_FILEDIR; - $phpgw_info["server"]["app_root"] = PHPGW_APP_ROOT; - $phpgw_info["server"]["app_inc"] = PHPGW_APP_INC; - $phpgw_info["server"]["app_tpl"] = PHPGW_APP_TPL; - $phpgw_info["server"]["app_images"] = PHPGW_IMAGES; - $phpgw_info["server"]["app_images_dir"] = PHPGW_IMAGES_DIR; - /* END LEGACY SUPPORT!!!*/ + /* LEGACY SUPPORT!!! WILL BE DELETED AFTER 0.9.11 IS RELEASED !!! */ + $phpgw_info["server"]["template_dir"] = PHPGW_TEMPLATE_DIR; + $phpgw_info["server"]["images_dir"] = PHPGW_IMAGES_DIR; + $phpgw_info["server"]["images_filedir"] = PHPGW_IMAGES_FILEDIR; + $phpgw_info["server"]["app_root"] = PHPGW_APP_ROOT; + $phpgw_info["server"]["app_inc"] = PHPGW_APP_INC; + $phpgw_info["server"]["app_tpl"] = PHPGW_APP_TPL; + $phpgw_info["server"]["app_images"] = PHPGW_IMAGES; + $phpgw_info["server"]["app_images_dir"] = PHPGW_IMAGES_DIR; + /* END LEGACY SUPPORT!!!*/ /********* This sets the user variables *********/ $phpgw_info["user"]["private_dir"] = $phpgw_info["server"]["files_dir"] - . "/users/".$phpgw_info["user"]["userid"]; + . "/users/".$phpgw_info["user"]["userid"]; /* This will make sure that a user has the basic default prefs. If not it will add them */ $phpgw->preferences->verify_basic_settings(); diff --git a/setup/sql/mysql_newtables.inc.php b/setup/sql/mysql_newtables.inc.php index 4fd95d5a9a..cf63e0ce59 100644 --- a/setup/sql/mysql_newtables.inc.php +++ b/setup/sql/mysql_newtables.inc.php @@ -82,10 +82,11 @@ $phpgw_setup->db->query($sql); $sql = "CREATE TABLE phpgw_app_sessions ( - sessionid varchar(255) NOT NULL, - loginid varchar(20), - app varchar(20), - content text + sessionid varchar(255) NOT NULL, + loginid varchar(20), + location varchar(255), + app varchar(20), + content text )"; $phpgw_setup->db->query($sql); diff --git a/setup/sql/mysql_upgrade_beta.inc.php b/setup/sql/mysql_upgrade_beta.inc.php index cbdfef4335..b8cf9c2e3b 100644 --- a/setup/sql/mysql_upgrade_beta.inc.php +++ b/setup/sql/mysql_upgrade_beta.inc.php @@ -940,6 +940,26 @@ $phpgw_info["setup"]["currentver"]["phpgwapi"] = "0.9.10pre5"; } + + $test[] = "0.9.10pre5"; + function upgrade0_9_10pre5() + { + global $phpgw_info, $phpgw_setup; + + // This is only temp data, so we can kill it. + $phpgw_setup->db->query('drop table phpgw_app_sessions',__LINE__,__FILE__); + $sql = "CREATE TABLE phpgw_app_sessions ( + sessionid varchar(255) NOT NULL, + loginid varchar(20), + location varchar(255), + app varchar(20), + content text + )"; + $phpgw_setup->db->query($sql); + + $phpgw_info["setup"]["currentver"]["phpgwapi"] = "0.9.10pre6"; + } + reset ($test); while (list ($key, $value) = each ($test)){ if ($phpgw_info["setup"]["currentver"]["phpgwapi"] == $value) { diff --git a/setup/sql/pgsql_newtables.inc.php b/setup/sql/pgsql_newtables.inc.php index 2c7f99e7d1..03dea0c90a 100644 --- a/setup/sql/pgsql_newtables.inc.php +++ b/setup/sql/pgsql_newtables.inc.php @@ -74,12 +74,13 @@ $phpgw_setup->db->query($sql); $sql = "CREATE TABLE phpgw_app_sessions ( - sessionid varchar(255) NOT NULL, - loginid varchar(20), - app varchar(20), - content text + sessionid varchar(255) NOT NULL, + loginid varchar(20), + location varchar(255), + app varchar(20), + content text )"; - $phpgw_setup->db->query($sql); + $phpgw_setup->db->query($sql); $sql = "create table phpgw_access_log ( sessionid varchar(255), diff --git a/setup/sql/pgsql_upgrade_beta.inc.php b/setup/sql/pgsql_upgrade_beta.inc.php index c4807edc06..42d26b8ad8 100644 --- a/setup/sql/pgsql_upgrade_beta.inc.php +++ b/setup/sql/pgsql_upgrade_beta.inc.php @@ -995,6 +995,25 @@ $phpgw_info["setup"]["currentver"]["phpgwapi"] = "0.9.10pre5"; } + $test[] = "0.9.10pre5"; + function upgrade0_9_10pre5() + { + global $phpgw_info, $phpgw_setup; + + // This is only temp data, so we can kill it. + $phpgw_setup->db->query('drop table phpgw_app_sessions',__LINE__,__FILE__); + $sql = "CREATE TABLE phpgw_app_sessions ( + sessionid varchar(255) NOT NULL, + loginid varchar(20), + location varchar(255), + app varchar(20), + content text + )"; + $phpgw_setup->db->query($sql); + + $phpgw_info["setup"]["currentver"]["phpgwapi"] = "0.9.10pre6"; + } + reset ($test); while (list ($key, $value) = each ($test)){ if ($phpgw_info["setup"]["currentver"]["phpgwapi"] == $value) { diff --git a/version.inc.php b/version.inc.php index d4156e8f6e..a9cabf3dc7 100644 --- a/version.inc.php +++ b/version.inc.php @@ -11,5 +11,5 @@ /* $Id$ */ - $phpgw_info["server"]["versions"]["phpgwapi"] = "0.9.10pre5"; + $phpgw_info["server"]["versions"]["phpgwapi"] = "0.9.10pre6"; $phpgw_info["server"]["versions"]["current_header"] = "1.11";