cacert-webdb/includes/loggedin.php

155 lines
4.8 KiB
PHP
Raw Normal View History

2004-11-10 06:12:43 +00:00
<? /*
Copyright (C) 2004 by Duane Groth <duane_at_CAcert_dot_org>
This file is part of CAcert.
CAcert has been released under a CAcert Source license
which can be found included with these source files or can
be downloaded from the internet from the following address:
http://www.cacert.org/src-lic.php
CAcert is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the License for more details.
*/
2005-07-14 19:56:28 +00:00
if($_SERVER['HTTP_HOST'] == $_SESSION['_config']['securehostname'] && $_SESSION['profile']['id'] > 0 && $_SESSION['profile']['loggedin'] != 0)
2004-12-06 14:02:02 +00:00
{
2006-08-03 13:20:55 +00:00
$uid = $_SESSION['profile']['id'];
$_SESSION['profile']['loggedin'] = 0;
$_SESSION['profile'] = "";
foreach($_SESSION as $key)
{
2006-08-04 22:05:11 +00:00
if($key == '_config')
continue;
if(is_int($key) || is_string($key))
unset($_SESSION[$key]);
2006-08-03 13:20:55 +00:00
unset($$key);
session_unregister($key);
}
$_SESSION['profile'] = mysql_fetch_assoc(mysql_query("select * from `users` where `id`='$uid'"));
2006-08-16 05:56:39 +00:00
if($_SESSION['profile']['locked'] == 0)
$_SESSION['profile']['loggedin'] = 1;
else
unset($_SESSION['profile']);
2004-12-06 14:02:02 +00:00
}
2005-07-14 19:56:28 +00:00
if($_SERVER['HTTP_HOST'] == $_SESSION['_config']['securehostname'] && ($_SESSION['profile']['id'] == 0 || $_SESSION['profile']['loggedin'] == 0))
2004-11-10 06:12:43 +00:00
{
2006-08-16 05:56:39 +00:00
$query = "select * from `emailcerts` where `serial`='${_SERVER['SSL_CLIENT_M_SERIAL']}' and `revoked`=0 and
2004-11-10 06:12:43 +00:00
UNIX_TIMESTAMP(`expire`) - UNIX_TIMESTAMP() > 0";
$res = mysql_query($query);
if(mysql_num_rows($res) > 0)
{
$row = mysql_fetch_assoc($res);
2006-08-03 13:20:55 +00:00
$_SESSION['profile']['loggedin'] = 0;
$_SESSION['profile'] = "";
foreach($_SESSION as $key)
{
2006-08-04 22:05:11 +00:00
if($key == '_config')
continue;
if(is_int($key) || is_string($key))
unset($_SESSION[$key]);
unset($$key);
session_unregister($key);
2006-08-03 13:20:55 +00:00
}
2004-11-10 06:12:43 +00:00
$_SESSION['profile'] = mysql_fetch_assoc(mysql_query("select * from `users` where `id`='".$row['memid']."'"));
2006-08-16 05:56:39 +00:00
if($_SESSION['profile']['locked'] == 0)
$_SESSION['profile']['loggedin'] = 1;
else
unset($_SESSION['profile']);
2004-11-10 06:12:43 +00:00
} else {
$_SESSION['profile']['loggedin'] = 0;
2006-08-03 13:20:55 +00:00
$_SESSION['profile'] = "";
foreach($_SESSION as $key)
{
2006-08-04 22:05:11 +00:00
if($key == '_config')
continue;
2006-08-03 13:20:55 +00:00
unset($_SESSION[$key]);
unset($$key);
session_unregister($key);
}
2004-11-10 06:12:43 +00:00
unset($_SESSION['_config']['oldlocation']);
foreach($_GET as $key => $val)
{
if($_SESSION['_config']['oldlocation'])
$_SESSION['_config']['oldlocation'] .= "&";
$_SESSION['_config']['oldlocation'] .= "$key=$val";
}
2005-12-04 21:04:05 +00:00
$_SESSION['_config']['oldlocation'] = substr($_SERVER['SCRIPT_NAME'], 1)."?".$_SESSION['_config']['oldlocation'];
2004-11-10 06:12:43 +00:00
header("location: https://".$_SERVER['HTTP_HOST']."/index.php?id=4");
exit;
}
}
2004-12-06 21:53:35 +00:00
if($_SERVER['HTTP_HOST'] == $_SESSION['_config']['securehostname'] && ($_SESSION['profile']['id'] <= 0 || $_SESSION['profile']['loggedin'] == 0))
2004-11-10 06:12:43 +00:00
{
2004-12-06 21:53:35 +00:00
header("location: https://".$_SESSION['_config']['normalhostname']);
2004-11-10 06:12:43 +00:00
exit;
}
2005-07-14 19:56:28 +00:00
if($_SERVER['HTTP_HOST'] == $_SESSION['_config']['securehostname'] && $_SESSION['profile']['id'] > 0 && $_SESSION['profile']['loggedin'] > 0)
2004-11-10 06:12:43 +00:00
{
$query = "select sum(`points`) as `total` from `notary` where `to`='".$_SESSION['profile']['id']."' group by `to`";
$res = mysql_query($query);
$row = mysql_fetch_assoc($res);
$_SESSION['profile']['points'] = $row['total'];
if($_SESSION['profile']['language'] == "")
{
$query = "update `users` set `language`='".$_SESSION['_config']['language']."'
where `id`='".$_SESSION['profile']['id']."'";
mysql_query($query);
} else {
$_SESSION['_config']['language'] = $_SESSION['profile']['language'];
putenv("LANG=".$_SESSION['_config']['language']);
setlocale(LC_ALL, $_SESSION['_config']['language']);
$domain = 'messages';
2004-12-06 21:53:35 +00:00
bindtextdomain("$domain", $_SESSION['_config']['filepath']."/locale");
2004-11-10 06:12:43 +00:00
textdomain("$domain");
}
}
2006-02-03 18:45:23 +00:00
if($_REQUEST['id'] == "logout")
2004-11-10 06:12:43 +00:00
{
$_SESSION['profile']['loggedin'] = 0;
2006-02-03 18:45:23 +00:00
$_SESSION['profile'] = "";
foreach($_SESSION as $key)
{
unset($_SESSION[$key]);
unset($$key);
session_unregister($key);
}
unset($_SESSION);
2005-03-12 19:40:24 +00:00
2004-11-10 06:12:43 +00:00
header("location: https://".$_SERVER['HTTP_HOST']."/index.php");
exit;
}
if($_SESSION['profile']['loggedin'] < 1)
{
unset($_SESSION['_config']['oldlocation']);
2006-02-03 18:45:23 +00:00
foreach($_REQUEST as $key => $val)
2004-11-10 06:12:43 +00:00
{
if($_SESSION['_config']['oldlocation'])
$_SESSION['_config']['oldlocation'] .= "&";
$_SESSION['_config']['oldlocation'] .= "$key=$val";
}
2005-12-04 21:04:05 +00:00
$_SESSION['_config']['oldlocation'] = substr($_SERVER['SCRIPT_NAME'], 1)."?".$_SESSION['_config']['oldlocation'];
2004-11-10 06:12:43 +00:00
header("location: https://".$_SERVER['HTTP_HOST']."/index.php?id=4");
exit;
}
?>