Started moving the cache for the phpgw_info array over to appsessions() .... some things aren't working correclty yet. mainly preferences

This commit is contained in:
jengo 2001-02-08 04:42:44 +00:00
parent 5b6ff99f40
commit 2ebd03ec7d
8 changed files with 166 additions and 146 deletions

View File

@ -884,29 +884,27 @@
// This will return the full phpgw_info array, used for debugging // 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($array)) {
while (list($key, $val) = each($phpgw_info)) {
if (is_array($val)) { if (is_array($val)) {
while (list($key2, $val2) = each($val)) { while (list($key2, $val2) = each($val)) {
if (is_array($val2)) { if (is_array($val2)) {
while (list($key3, $val3) = each ($val2)) { while (list($key3, $val3) = each ($val2)) {
if (is_array($val3)) { if (is_array($val3)) {
while (list($key4, $val4) = each ($val3)) { while (list($key4, $val4) = each ($val3)) {
echo "phpgw_info[$key][$key2][$key3][$key4]=$val4<br>"; echo $$array . "[$key][$key2][$key3][$key4]=$val4<br>";
} }
} else { } else {
echo "phpgw_info[$key][$key2][$key3]=$val3<br>"; echo $$array . "[$key][$key2][$key3]=$val3<br>";
} }
} }
} else { } else {
echo "phpgw_info[$key][$key2]=$val2<br>"; echo $$array . "[$key][$key2]=$val2<br>";
} }
} }
} else { } else {
echo "phpgw_info[$key]=$val<br>"; echo $$array . "[$key]=$val<br>";
} }
} }
} }

View File

@ -25,6 +25,7 @@
class sessions class sessions
{ {
var $use_cache = True; // If you want to cache the phpgw_info array
var $login; var $login;
var $passwd; var $passwd;
var $account_id; var $account_id;
@ -100,11 +101,23 @@
$phpgw_info["user"]["kp3"] = $this->kp3; $phpgw_info["user"]["kp3"] = $this->kp3;
$phpgw_info_flags = $phpgw_info["flags"]; $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; $phpgw_info["flags"] = $phpgw_info_flags;
$userid_array = explode("@",$db->f("session_lid")); $userid_array = explode("@",$db->f("session_lid"));
$this->account_lid = $userid_array[0]; $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"]) { if ($userid_array[1] != $phpgw_info["user"]["domain"]) {
return False; return False;
@ -114,8 +127,6 @@
return False; return False;
} }
$this->update_dla();
$this->account_id = $phpgw->accounts->name2id($this->account_lid);
$phpgw->acl->acl($this->account_id); $phpgw->acl->acl($this->account_id);
$phpgw->accounts->accounts($this->account_id); $phpgw->accounts->accounts($this->account_id);
$phpgw->preferences->preferences($this->account_id); $phpgw->preferences->preferences($this->account_id);
@ -139,23 +150,6 @@
} }
} }
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) function create($login,$passwd)
{ {
global $phpgw_info, $phpgw; global $phpgw_info, $phpgw;
@ -186,7 +180,6 @@
} }
$phpgw->accounts->account_id = $this->account_id; $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)); $this->kp3 = md5($phpgw->common->randomstring(15));
@ -212,16 +205,16 @@
unset ($phpgw_info["server"]["default_domain"]); // we kill this for security reasons 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(); $this->read_repositories();
$phpgw_info["user"] = $this->user;
if ($PHP_VERSION < "4.0.0") { $phpgw_info["hooks"] = $this->hooks;
$info_string = addslashes($phpgw->crypto->encrypt($this->data)); if ($this->use_cache) {
} else { $this->appsession('phpgw_info_cache','phpgwapi',$phpgw_info);
$info_string = $phpgw->crypto->encrypt($this->data);
} }
// This is going to be stored by appsessions in its own record
// $this->passwd = $phpgw->common->encrypt($passwd);
$phpgw->db->query("insert into phpgw_sessions values ('" . $this->sessionid $phpgw->db->query("insert into phpgw_sessions values ('" . $this->sessionid
. "','".$login."','" . $this->getuser_ip() . "','" . "','".$login."','" . $this->getuser_ip() . "','"
. time() . "','" . time() . "','".$info_string."')",__LINE__,__FILE__); . time() . "','" . time() . "','".$info_string."')",__LINE__,__FILE__);
@ -270,84 +263,78 @@
/*************************************************************************\ /*************************************************************************\
* Functions for appsession data and session cache * * Functions for appsession data and session cache *
\*************************************************************************/ \*************************************************************************/
function read_repositories() function read_repositories()
{ {
global $phpgw_info, $phpgw; global $phpgw;
$phpgw->acl->acl($this->account_id); $phpgw->acl->acl($this->account_id);
$phpgw->accounts->accounts($this->account_id); $phpgw->accounts->accounts($this->account_id);
$phpgw->preferences->preferences($this->account_id); $phpgw->preferences->preferences($this->account_id);
$phpgw->applications->applications($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; $this->user = $phpgw->accounts->read_repository();
$phpgw_info["user"]["sessionid"] = $this->sessionid; $this->user["acl"] = $phpgw->acl->read_repository();
$phpgw_info["user"]["kp3"] = $this->kp3; $this->user["preferences"] = $phpgw->preferences->read_repository();
$phpgw_info["user"]["session_ip"] = $this->getuser_ip(); $this->user["apps"] = $phpgw->applications->read_repository();
$phpgw_info["user"]["session_lid"] = $this->account_lid."@".$this->account_domain; //@reset($this->data["user"]["apps"]);
$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->user["domain"] = $this->account_domain;
$this->data["apps"] = $phpgw_info["apps"]; $this->user["sessionid"] = $this->sessionid;
$this->data["server"] = $phpgw_info["server"]; $this->user["kp3"] = $this->kp3;
$this->data["hooks"] = $phpgw->hooks->read(); $this->user["session_ip"] = $this->getuser_ip();
$this->data["user"]["preferences"] = $phpgw_info["user"]["preferences"]; $this->user["session_lid"] = $this->account_lid."@".$this->account_domain;
$this->data["user"]["kp3"] = ""; $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; global $phpgw_info, $phpgw;
if ($data == "##NOTHING##") { /* This allows the user to put "" as the value. */ if (! $appname) {
$sql = 'select content from phpgw_app_sessions where' $appname = $phpgw_info['flags']['currentapp'];
.' sessionid = "'.$this->sessionid.'"' }
.' and loginid = "'.$this->account_id.'"'
.' and app = "'.$phpgw_info["user"]["currentapp"].'"'
.' and location = "'.$location.'"';
$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(); $phpgw->db->next_record();
$data = $phpgw->db->f("content"); $data = $phpgw->db->f("content");
// $data = $phpgw->common->decrypt($data); $data = $phpgw->common->decrypt($data);
return $data; return $data;
}
} else { } else {
// $data = $phpgw->common->encrypt($data); $phpgw->db->query('select content from phpgw_app_sessions where '
$sql = 'select content from phpgw_app_sessions where' . 'sessionid = "'.$this->sessionid.'" and loginid = "'.$this->account_id.'" '
.' sessionid = "'.$this->sessionid.'"' . 'and app = "'.$appname.'" and location = "'.$location.'"',__LINE__,__FILE__);
.' and loginid = "'.$this->account_id.'"'
.' and app = "'.$phpgw_info["user"]["currentapp"].'"'
.' and location = "'.$location.'"';
$phpgw->db->query($sql,__LINE__,__FILE__);
if ($phpgw->db->num_rows()==0) { if ($phpgw->db->num_rows()==0) {
$sql = 'INSERT INTO phpgw_app_sessions (sessionid,loginid,app,location,content)' $data = addslashes($phpgw->crypto->encrypt(serialize($data)));
.' VALUES ("'.$this->sessionid.'"' $phpgw->db->query('INSERT INTO phpgw_app_sessions (sessionid,loginid,app,location,content) '
.' ","'.$this->account_id.'"' . 'VALUES ("'.$this->sessionid.'","'.$this->account_id.'","'.$appname
.' ","'.$phpgw_info["flags"]["currentapp"].'"' . '","'.$location.'","'.$data.'")',__LINE__,__FILE__);
.' ","'.$location.'"'
.' ","'.$data.'")'
;
$phpgw->db->query($sql,__LINE__,__FILE__);
} else { } else {
$sql = 'update phpgw_app_sessions set content = "'.$data.'"' $phpgw->db->query('update phpgw_app_sessions set content = "'.$data.'" '
. 'where sessionid = "'.$this->sessionid.'" ' . 'where sessionid = "'.$this->sessionid.'" '
.' and loginid = "'.$this->account_id.'"' . 'and loginid = "'.$this->account_id.'" and app = "'.$appname.'" '
.' and app = "'.$phpgw_info["user"]["currentapp"].'"' . 'and location = "'.$location.'"',__LINE__,__FILE__);
.' and location = "'.$location.'"';
$phpgw->db->query($sql,__LINE__,__FILE__);
} }
//$data = $phpgw->common->decrypt($data);
return $data; return $data;
} }
} }

View File

@ -78,6 +78,7 @@
global $debugme; global $debugme;
if ($debugme == "on") { echo 'debug: '.$text.'<br>'; } if ($debugme == "on") { echo 'debug: '.$text.'<br>'; }
} }
print_debug('core functions are done'); print_debug('core functions are done');
/****************************************************************************\ /****************************************************************************\
* Quick verification of sane environment * * Quick verification of sane environment *
@ -152,7 +153,8 @@ print_debug('sane environment');
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. */ /* 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, $phpgw_info["server"]["global_denied_users"] = array('root' => True,
'bin' => True, 'bin' => True,
@ -194,17 +196,10 @@ print_debug('main class loaded');
// Handy little shortcut // Handy little shortcut
$sep = $phpgw_info["server"]["dir_separator"]; $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 * * Stuff to use if logging in or logging out *
\****************************************************************************/ \****************************************************************************/
if ($phpgw_info["flags"]["currentapp"] == "login" || $phpgw_info["flags"]["currentapp"] == "logout") {
/* 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 ($phpgw_info["flags"]["currentapp"] == "login") {
if ($login != ""){ if ($login != ""){
$login_array = explode("@",$login); $login_array = explode("@",$login);
@ -213,7 +208,6 @@ print_debug('main class loaded');
$phpgw->preferences->preferences($login_id); $phpgw->preferences->preferences($login_id);
} }
} }
/****************************************************************************\ /****************************************************************************\
* Everything from this point on will ONLY happen if * * Everything from this point on will ONLY happen if *
* the currentapp is not login or logout * * the currentapp is not login or logout *

View File

@ -84,6 +84,7 @@
$sql = "CREATE TABLE phpgw_app_sessions ( $sql = "CREATE TABLE phpgw_app_sessions (
sessionid varchar(255) NOT NULL, sessionid varchar(255) NOT NULL,
loginid varchar(20), loginid varchar(20),
location varchar(255),
app varchar(20), app varchar(20),
content text content text
)"; )";

View File

@ -940,6 +940,26 @@
$phpgw_info["setup"]["currentver"]["phpgwapi"] = "0.9.10pre5"; $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); reset ($test);
while (list ($key, $value) = each ($test)){ while (list ($key, $value) = each ($test)){
if ($phpgw_info["setup"]["currentver"]["phpgwapi"] == $value) { if ($phpgw_info["setup"]["currentver"]["phpgwapi"] == $value) {

View File

@ -76,6 +76,7 @@
$sql = "CREATE TABLE phpgw_app_sessions ( $sql = "CREATE TABLE phpgw_app_sessions (
sessionid varchar(255) NOT NULL, sessionid varchar(255) NOT NULL,
loginid varchar(20), loginid varchar(20),
location varchar(255),
app varchar(20), app varchar(20),
content text content text
)"; )";

View File

@ -995,6 +995,25 @@
$phpgw_info["setup"]["currentver"]["phpgwapi"] = "0.9.10pre5"; $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); reset ($test);
while (list ($key, $value) = each ($test)){ while (list ($key, $value) = each ($test)){
if ($phpgw_info["setup"]["currentver"]["phpgwapi"] == $value) { if ($phpgw_info["setup"]["currentver"]["phpgwapi"] == $value) {

View File

@ -11,5 +11,5 @@
/* $Id$ */ /* $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"; $phpgw_info["server"]["versions"]["current_header"] = "1.11";