2002-04-30 22:22:54 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once("db.inc");
|
2003-02-12 23:06:49 +00:00
|
|
|
require_once("project.inc");
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-08-13 00:08:08 +00:00
|
|
|
define("EMAIL_EXISTS", -1);
|
|
|
|
define("EMAIL_UPDATED", 1);
|
|
|
|
define("EMAIL_FAIL", -2);
|
|
|
|
|
2002-08-12 22:16:34 +00:00
|
|
|
define("LG_FONT", "<font size=+1>");
|
|
|
|
define("SM_FONT", "<font size=-1>");
|
2002-08-13 00:08:08 +00:00
|
|
|
|
2002-09-27 06:12:50 +00:00
|
|
|
define("TD", "<td bgcolor=cccccc>");
|
|
|
|
define("TD2", "<td colspan=2 bgcolor=cccccc>");
|
|
|
|
define("TD3", "<td colspan=3 bgcolor=cccccc>");
|
2002-08-13 00:08:08 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
define("TABLE", "<table cellpadding=10 cellspacing=4 border=0 width=100%>");
|
2002-12-06 21:37:30 +00:00
|
|
|
define("VISTABLE", "<table cellpadding=2 cellspacing=0 border=1 width=100%>");
|
2003-02-08 02:06:35 +00:00
|
|
|
define("TABLE2", "<table width=580 cellpadding=3>");
|
2002-08-13 00:08:08 +00:00
|
|
|
|
2002-09-27 06:12:50 +00:00
|
|
|
define("BG_COLOR", " bgcolor=ffffff ");
|
2002-04-30 22:22:54 +00:00
|
|
|
define("TITLE_COLOR", " bgcolor=000000 ");
|
2002-08-05 23:20:57 +00:00
|
|
|
define("TITLE_FONT", " <font color=ffffff> ");
|
2002-04-30 22:22:54 +00:00
|
|
|
define("BODY_COLOR", " bgcolor=ffffff ");
|
2002-08-13 23:59:34 +00:00
|
|
|
|
2002-12-06 21:37:30 +00:00
|
|
|
// Sends the authenticator to the given email address
|
2002-12-19 18:08:43 +00:00
|
|
|
//
|
2002-12-06 21:37:30 +00:00
|
|
|
function send_auth_email($email_addr, $auth) {
|
2002-12-19 18:08:43 +00:00
|
|
|
mail($email_addr, PROJECT." new account confirmation",
|
2003-02-07 09:00:35 +00:00
|
|
|
"This email confirms the creation of your ".PROJECT." account.
|
|
|
|
".PROJECT." URL: ".MASTER_URL."
|
2002-12-19 18:08:43 +00:00
|
|
|
Your account key: $auth\n
|
|
|
|
Please save this email, as you will need the account key
|
|
|
|
to access your account on the ".PROJECT." web site."
|
|
|
|
);
|
2002-12-06 21:37:30 +00:00
|
|
|
}
|
|
|
|
|
2002-12-04 19:22:58 +00:00
|
|
|
// Initializes the session and returns the authenticator
|
|
|
|
// for the session (if any)
|
2002-12-19 18:08:43 +00:00
|
|
|
//
|
2002-12-04 19:22:58 +00:00
|
|
|
function init_session() {
|
|
|
|
session_start();
|
2002-12-11 23:09:22 +00:00
|
|
|
if (!isset($_SESSION["authenticator"])) {
|
2002-12-16 21:41:41 +00:00
|
|
|
$_SESSION["authenticator"] = $authenticator;
|
2002-12-04 19:22:58 +00:00
|
|
|
}
|
|
|
|
return $_SESSION["authenticator"];
|
|
|
|
}
|
|
|
|
|
2002-12-19 18:08:43 +00:00
|
|
|
// if not logged in, put up login form and exit
|
|
|
|
//
|
2002-12-16 21:41:41 +00:00
|
|
|
function require_login($user) {
|
|
|
|
if (!$user) {
|
|
|
|
print_login_form();
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-04 19:22:58 +00:00
|
|
|
function get_user_from_auth($auth) {
|
|
|
|
if ($auth) return lookup_user_auth($auth);
|
|
|
|
return NULL;
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
function get_user_from_cookie() {
|
|
|
|
$auth = "";
|
|
|
|
$c = getenv("HTTP_COOKIE");
|
|
|
|
$d = str_replace("; ", "&", $c);
|
|
|
|
parse_str($d);
|
|
|
|
if ($auth) return lookup_user_auth($auth);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
function show_login($user) {
|
2002-08-07 18:56:55 +00:00
|
|
|
if ($user) {
|
2002-11-12 17:01:16 +00:00
|
|
|
echo "Logged in as %s.\n", $user->name;
|
2002-12-19 18:08:43 +00:00
|
|
|
echo "<br><a href=login_form.php>Log in as someone else.</a>\n";
|
2002-08-07 18:56:55 +00:00
|
|
|
} else {
|
2002-11-12 17:01:16 +00:00
|
|
|
echo "Not logged in";
|
2002-08-07 18:56:55 +00:00
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
2003-02-08 02:06:35 +00:00
|
|
|
function page_head($title, $user=null) {
|
2002-11-08 17:21:45 +00:00
|
|
|
echo "<head><title>$title</title><body ".BG_COLOR.">\n";
|
|
|
|
|
2003-02-12 23:06:49 +00:00
|
|
|
project_banner($user);
|
2002-11-08 17:21:45 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
2002-12-11 00:12:42 +00:00
|
|
|
function page_tail() {
|
2002-12-11 23:09:22 +00:00
|
|
|
|
2003-02-07 09:00:35 +00:00
|
|
|
echo "<br><hr><center><a href=index.php>Return to ".PROJECT." main page</a><br>\n";
|
2002-11-25 22:14:05 +00:00
|
|
|
|
2002-11-08 17:21:45 +00:00
|
|
|
// put your copyright notice etc. here
|
|
|
|
|
2003-02-07 09:00:35 +00:00
|
|
|
echo "<br><br>Copyright (c) 2003 ".PROJECT."</center>\n";
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function date_str($when) {
|
|
|
|
return date("g:i A, l M j", $when);
|
|
|
|
}
|
|
|
|
|
|
|
|
function time_str($x) {
|
|
|
|
if ($x == 0) return "---";
|
|
|
|
return strftime("%T %b %e, %Y", $x);
|
|
|
|
}
|
|
|
|
|
|
|
|
function start_table() {
|
|
|
|
echo "<table width=600 border=2 cellpadding=4>";
|
|
|
|
}
|
|
|
|
|
|
|
|
function row($x, $y) {
|
|
|
|
echo "<tr><td width=30% valign=top align=right>$x</td><td>$y</td></tr>\n";
|
|
|
|
}
|
|
|
|
|
2002-08-12 22:16:34 +00:00
|
|
|
function row2($x, $y) {
|
|
|
|
echo "<tr><td>$x</td><td>$y</td></tr>\n";
|
|
|
|
}
|
|
|
|
|
2002-09-05 22:19:23 +00:00
|
|
|
function row2a($x, $y) {
|
|
|
|
echo "<tr><td>$x</td><td width=50%>$y</td></tr>\n";
|
|
|
|
}
|
|
|
|
|
2002-08-12 22:16:34 +00:00
|
|
|
function row3($x, $y, $z) {
|
2002-08-12 23:31:43 +00:00
|
|
|
echo "<tr><td width=30% valign=top align=right>$x</td><td>$y</td><td>$z</td></tr>\n";
|
2002-08-12 22:16:34 +00:00
|
|
|
}
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
function random_string() {
|
|
|
|
return md5(uniqid(rand()));
|
|
|
|
}
|
|
|
|
|
2002-12-19 18:08:43 +00:00
|
|
|
function print_country_select($country) {
|
2002-11-09 20:26:50 +00:00
|
|
|
$x = posix_getcwd();
|
2002-12-19 18:08:43 +00:00
|
|
|
PassThru("$x/country_select '$country'");
|
2002-11-09 20:26:50 +00:00
|
|
|
}
|
|
|
|
|
2003-02-14 00:05:56 +00:00
|
|
|
function print_login_form_aux($next_url) {
|
|
|
|
echo "<form method=post action=login_action.php>
|
|
|
|
<input type=hidden name=next_url value='$next_url'>
|
|
|
|
<table cellpadding=8>
|
|
|
|
<tr><td align=right>
|
|
|
|
Your account key:
|
|
|
|
</td><td>
|
|
|
|
<input name=authenticator size=40>
|
|
|
|
</td></tr>
|
|
|
|
|
|
|
|
<tr><td align=right>
|
|
|
|
<br>
|
|
|
|
</td><td>
|
|
|
|
<input type=submit value='Log in'>
|
|
|
|
</td></tr>
|
|
|
|
</table>
|
|
|
|
";
|
|
|
|
echo "<font size=1>
|
|
|
|
If you don't know your account key,
|
|
|
|
<a href=get_passwd.php>click here</a>.
|
|
|
|
</font>
|
|
|
|
";
|
|
|
|
}
|
|
|
|
|
|
|
|
function print_login_form($next_url) {
|
2002-11-11 19:40:22 +00:00
|
|
|
page_head("Please log in");
|
2003-02-14 00:05:56 +00:00
|
|
|
parse_str(getenv("QUERY_STRING"));
|
|
|
|
echo "
|
|
|
|
<h3>Please log in</h3>
|
|
|
|
This function requires that you log in.
|
|
|
|
";
|
|
|
|
print_login_form_aux($next_url);
|
2002-11-11 19:40:22 +00:00
|
|
|
page_tail();
|
|
|
|
}
|
|
|
|
|
2002-11-09 20:26:50 +00:00
|
|
|
// look for an element in some XML text
|
|
|
|
//
|
|
|
|
function parse_element($xml, $tag) {
|
|
|
|
$element = null;
|
|
|
|
$x = strstr($xml, $tag);
|
|
|
|
if ($x) {
|
|
|
|
$y = substr($x, strlen($tag));
|
|
|
|
$n = strpos($y, "<");
|
|
|
|
if ($n) {
|
|
|
|
$element = substr($y, 0, $n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $element;
|
|
|
|
}
|
|
|
|
|
|
|
|
// look for a particular element in the config.xml file
|
|
|
|
//
|
|
|
|
function parse_config($tag) {
|
|
|
|
$element = null;
|
|
|
|
$fp = fopen("config.xml", "r");
|
|
|
|
while (1) {
|
|
|
|
$buf = fgets($fp, 1024);
|
|
|
|
if ($buf == null) break;
|
|
|
|
$element = parse_element($buf, $tag);
|
|
|
|
if ($element) break;
|
|
|
|
}
|
|
|
|
fclose($fp);
|
|
|
|
return $element;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
2002-12-19 05:11:25 +00:00
|
|
|
// Call this if for dynamic pages
|
|
|
|
//
|
|
|
|
function no_cache() {
|
|
|
|
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
|
|
|
|
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
|
|
|
|
header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
|
|
|
|
header ("Pragma: no-cache"); // HTTP/1.0
|
|
|
|
}
|
|
|
|
|
2002-08-13 00:08:08 +00:00
|
|
|
?>
|