2002-04-30 22:22:54 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once("db.inc");
|
|
|
|
|
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%>");
|
2002-08-12 22:16:34 +00:00
|
|
|
define("TABLE2", "<table width=580>");
|
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-11-11 10:26:40 +00:00
|
|
|
define("PROJECT", "Astropulse");
|
2002-11-25 19:44:40 +00:00
|
|
|
define("MASTER_URL", "http://maggie.ssl.berkeley.edu/ap/");
|
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",
|
|
|
|
"This email confirms the creation of your account with ".PROJECT.",
|
|
|
|
a distributed computing project based on BOINC.\n
|
|
|
|
The URL for this project: ".MASTER_URL."
|
|
|
|
Your account key: $auth\n
|
|
|
|
Copy and paste these into the BOINC client when prompted.\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
|
|
|
}
|
|
|
|
|
|
|
|
function page_head($title) {
|
2002-11-08 17:21:45 +00:00
|
|
|
echo "<head><title>$title</title><body ".BG_COLOR.">\n";
|
|
|
|
|
|
|
|
// Put your project title and logo here
|
|
|
|
|
2002-11-11 10:26:40 +00:00
|
|
|
echo "<h2>".PROJECT."</h2><hr>\n";
|
2002-11-08 17:21:45 +00:00
|
|
|
echo "<h3>$title</h3>\n";
|
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
|
|
|
|
2002-12-19 05:11:25 +00:00
|
|
|
echo "<br><hr><center><a href=index.php>Return to main ".PROJECT." 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
|
|
|
|
|
2002-12-19 05:11:25 +00:00
|
|
|
echo "<br><br>Copyright (c) 2002 ".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
|
|
|
}
|
|
|
|
|
2002-11-11 19:40:22 +00:00
|
|
|
function print_login_form() {
|
|
|
|
page_head("Please log in");
|
|
|
|
echo "This function requires that you be logged in.\n";
|
2002-11-26 00:39:58 +00:00
|
|
|
echo "Please <a href=login_form.php>log in</a>.\n<p>\n";
|
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
|
|
|
?>
|