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);
@ -138,23 +149,6 @@
. "'",__LINE__,__FILE__); . "'",__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) function create($login,$passwd)
{ {
@ -186,8 +180,7 @@
} }
$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));
$phpgw->common->key = $phpgw_info["server"]["encryptkey"]; $phpgw->common->key = $phpgw_info["server"]["encryptkey"];
@ -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;
$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 $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; $this->user["domain"] = $this->account_domain;
$phpgw_info["user"]["userid"] = $this->account_lid; $this->user["sessionid"] = $this->sessionid;
$phpgw_info["user"]["passwd"] = $this->passwd; $this->user["kp3"] = $this->kp3;
$this->user["session_ip"] = $this->getuser_ip();
$this->data["user"] = $phpgw_info["user"]; $this->user["session_lid"] = $this->account_lid."@".$this->account_domain;
$this->data["apps"] = $phpgw_info["apps"]; $this->user["account_id"] = $this->account_id;
$this->data["server"] = $phpgw_info["server"]; $this->user["account_lid"] = $this->account_lid;
$this->data["hooks"] = $phpgw->hooks->read(); $this->user["userid"] = $this->account_lid;
$this->data["user"]["preferences"] = $phpgw_info["user"]["preferences"]; $this->user["passwd"] = $this->passwd;
$this->data["user"]["kp3"] = ""; $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,7 +78,8 @@
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 *
\****************************************************************************/ \****************************************************************************/
@ -96,7 +97,7 @@ print_debug('core functions are done');
} }
magic_quotes_runtime(false); magic_quotes_runtime(false);
print_debug('sane environment'); print_debug('sane environment');
/****************************************************************************\ /****************************************************************************\
* Multi-Domain support * * Multi-Domain support *
@ -150,9 +151,10 @@ print_debug('sane environment');
} }
unset ($domain); // we kill this to save memory 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. */ /* 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,
@ -184,7 +186,7 @@ print_debug('domain: '.$phpgw_info["user"]["domain"]);
/* Load main class */ /* Load main class */
$phpgw = CreateObject("phpgwapi.phpgw"); $phpgw = CreateObject("phpgwapi.phpgw");
$phpgw->phpgw_(); $phpgw->phpgw_();
print_debug('main class loaded'); print_debug('main class loaded');
/* Fill phpgw_info["server"] array */ /* Fill phpgw_info["server"] array */
$phpgw->db->query("select * from config",__LINE__,__FILE__); $phpgw->db->query("select * from config",__LINE__,__FILE__);
@ -194,34 +196,26 @@ 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 *
\****************************************************************************/
/* 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 * * Stuff to use if logging in or logging out *
* the currentapp is not login or logout *
\****************************************************************************/ \****************************************************************************/
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 { } else {
if (! $phpgw->session->verify()) { if (! $phpgw->session->verify()) {
Header("Location: " . $phpgw->redirect($phpgw->session->link($phpgw_info["server"]["webserver_url"]."/login.php","cd=10"))); Header("Location: " . $phpgw->redirect($phpgw->session->link($phpgw_info["server"]["webserver_url"]."/login.php","cd=10")));
exit; exit;
} }
/* A few hacker resistant constants that will be used throught the program */ /* 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); define("PHPGW_ACL_DELETE",8);
/********* Load up additional phpgw_info["server"] values *********/ /********* Load up additional phpgw_info["server"] values *********/
/* LEGACY SUPPORT!!! WILL BE DELETED AFTER 0.9.11 IS RELEASED !!! */ /* LEGACY SUPPORT!!! WILL BE DELETED AFTER 0.9.11 IS RELEASED !!! */
$phpgw_info["server"]["template_dir"] = PHPGW_TEMPLATE_DIR; $phpgw_info["server"]["template_dir"] = PHPGW_TEMPLATE_DIR;
$phpgw_info["server"]["images_dir"] = PHPGW_IMAGES_DIR; $phpgw_info["server"]["images_dir"] = PHPGW_IMAGES_DIR;
$phpgw_info["server"]["images_filedir"] = PHPGW_IMAGES_FILEDIR; $phpgw_info["server"]["images_filedir"] = PHPGW_IMAGES_FILEDIR;
$phpgw_info["server"]["app_root"] = PHPGW_APP_ROOT; $phpgw_info["server"]["app_root"] = PHPGW_APP_ROOT;
$phpgw_info["server"]["app_inc"] = PHPGW_APP_INC; $phpgw_info["server"]["app_inc"] = PHPGW_APP_INC;
$phpgw_info["server"]["app_tpl"] = PHPGW_APP_TPL; $phpgw_info["server"]["app_tpl"] = PHPGW_APP_TPL;
$phpgw_info["server"]["app_images"] = PHPGW_IMAGES; $phpgw_info["server"]["app_images"] = PHPGW_IMAGES;
$phpgw_info["server"]["app_images_dir"] = PHPGW_IMAGES_DIR; $phpgw_info["server"]["app_images_dir"] = PHPGW_IMAGES_DIR;
/* END LEGACY SUPPORT!!!*/ /* END LEGACY SUPPORT!!!*/
/********* This sets the user variables *********/ /********* This sets the user variables *********/
$phpgw_info["user"]["private_dir"] = $phpgw_info["server"]["files_dir"] $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 */ /* This will make sure that a user has the basic default prefs. If not it will add them */
$phpgw->preferences->verify_basic_settings(); $phpgw->preferences->verify_basic_settings();

View File

@ -82,10 +82,11 @@
$phpgw_setup->db->query($sql); $phpgw_setup->db->query($sql);
$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),
app varchar(20), location varchar(255),
content text app varchar(20),
content text
)"; )";
$phpgw_setup->db->query($sql); $phpgw_setup->db->query($sql);

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

@ -74,12 +74,13 @@
$phpgw_setup->db->query($sql); $phpgw_setup->db->query($sql);
$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),
app varchar(20), location varchar(255),
content text app varchar(20),
content text
)"; )";
$phpgw_setup->db->query($sql); $phpgw_setup->db->query($sql);
$sql = "create table phpgw_access_log ( $sql = "create table phpgw_access_log (
sessionid varchar(255), sessionid varchar(255),

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";