mirror of https://github.com/BOINC/boinc.git
327 lines
8.4 KiB
PHP
327 lines
8.4 KiB
PHP
<?php
|
|
|
|
require_once("db.inc");
|
|
require_once("project.inc");
|
|
|
|
// Sends the authenticator to the given email address
|
|
//
|
|
function send_auth_email($email_addr, $auth) {
|
|
mail($email_addr, PROJECT." new account confirmation",
|
|
"This email confirms the creation of your ".PROJECT." account.
|
|
|
|
".PROJECT." URL: ".MASTER_URL."
|
|
|
|
Your account key: $auth\n
|
|
|
|
Please save this email.
|
|
You will need your account key to log in to the ".PROJECT." web site."
|
|
);
|
|
}
|
|
|
|
// Initializes the session and returns the authenticator
|
|
// for the session (if any)
|
|
//
|
|
function init_session() {
|
|
session_start();
|
|
return $_SESSION["authenticator"];
|
|
}
|
|
|
|
// if not logged in, put up login form and exit
|
|
//
|
|
function require_login($user) {
|
|
if (!$user) {
|
|
print_login_form();
|
|
exit();
|
|
}
|
|
}
|
|
|
|
function get_user_from_auth($auth) {
|
|
if ($auth) return lookup_user_auth($auth);
|
|
return NULL;
|
|
}
|
|
|
|
function get_user_from_id($id) {
|
|
if ($id) return lookup_user_id($id);
|
|
return NULL;
|
|
}
|
|
|
|
function get_logged_in_user($must_be_logged_in=true) {
|
|
$authenticator = init_session();
|
|
$user = get_user_from_auth($authenticator);
|
|
if ($must_be_logged_in) {
|
|
require_login($user);
|
|
}
|
|
return $user;
|
|
}
|
|
|
|
function show_login($user) {
|
|
if ($user) {
|
|
echo "Logged in as %s.\n", $user->name;
|
|
echo "<br><a href=login_form.php>Log in as someone else.</a>\n";
|
|
} else {
|
|
echo "Not logged in";
|
|
}
|
|
}
|
|
|
|
// Constructs a combo box with name attribute = $name, from a list of newline-
|
|
// delineated items from the regular text file $filename. If $selection is
|
|
// provided, and if it matches one of the entries in $filename, it will be
|
|
// selected by default.
|
|
function show_combo_box($name, $filename, $selection=null) {
|
|
if (!file_exists($filename)) {
|
|
echo "ERROR: $filename does not exist! Cannot create combo box.<br>";
|
|
exit();
|
|
}
|
|
echo "<select name=\"$name\">\n";
|
|
|
|
$file = fopen($filename, "r");
|
|
|
|
while ($line = trim(fgets($file, 1024))) {
|
|
if ($line == $selection) {
|
|
echo "<option SELECTED value=\"$line\">$line\n";
|
|
} else {
|
|
echo "<option value=\"$line\">$line\n";
|
|
}
|
|
}
|
|
|
|
echo "</select>\n";
|
|
fclose($file);
|
|
}
|
|
|
|
function page_head($title, $user=null, $fileDescriptor=null) {
|
|
if ($fileDescriptor) {
|
|
fwrite($fileDescriptor, "<head><title>$title</title><body bgcolor=ffffff>\n");
|
|
} else {
|
|
echo "<head><title>$title</title><body bgcolor=ffffff>\n";
|
|
}
|
|
project_banner($user, $fileDescriptor);
|
|
|
|
}
|
|
|
|
function page_tail($fileDescriptor=null) {
|
|
if ($fileDescriptor) {
|
|
|
|
fwrite($fileDescriptor, "<br><hr><center><a href=". MASTER_URL . "index.php>Return to ".PROJECT." main page</a><br>\n");
|
|
|
|
// put your copyright notice etc. here
|
|
|
|
fwrite($fileDescriptor, "<br><br>Copyright (c) 2003 ".PROJECT."</center>\n");
|
|
|
|
} else {
|
|
|
|
echo "<br><hr><center><a href=" . MASTER_URL . "index.php>Return to ".PROJECT." main page</a><br>\n";
|
|
|
|
// put your copyright notice etc. here
|
|
|
|
echo "<br><br>Copyright (c) 2003 ".PROJECT."</center>\n";
|
|
}
|
|
}
|
|
|
|
function db_error_page() {
|
|
page_head("Database error");
|
|
echo "<h2>Database error</h2>
|
|
A database error occurred while handling your request.
|
|
<br>Please try again later.
|
|
<br>If the error persists, please submit a
|
|
<a href=bug_report_form.php>problem report</a>.
|
|
";
|
|
page_tail();
|
|
}
|
|
|
|
function profile_error_page($str) {
|
|
page_head("Profile error");
|
|
echo "$str<br>\n";
|
|
echo "<p>Click your browser's <b>Back</b> button to try again.\n<p>\n";
|
|
page_tail();
|
|
}
|
|
|
|
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 border=1 cellpadding=5>";
|
|
}
|
|
|
|
function start_table_noborder() {
|
|
echo "<table border=0 cellpadding=0 width=640>";
|
|
}
|
|
|
|
function end_table() {
|
|
echo "</table>\n";
|
|
}
|
|
|
|
function row1($x, $ncols=2) {
|
|
echo "<tr><td bgcolor=cccccc colspan=$ncols><b>$x</b></td></tr>\n";
|
|
}
|
|
|
|
function row2($x, $y) {
|
|
if ($x=="") $x="<br>";
|
|
if ($y=="") $y="<br>";
|
|
echo "<tr><td bgcolor=eeeeee width=50% align=right valign=top>$x</td><td valign=top><b>$y</b></td></tr>\n";
|
|
}
|
|
function row2_init($x, $y) {
|
|
echo "<tr><td bgcolor=eeeeee width=50% align=right valign=top>$x</td><td valign=top><b>$y\n";
|
|
}
|
|
|
|
function row2_plain($x, $y) {
|
|
echo "<tr><td>$x</td><td>$y</td></tr>\n";
|
|
}
|
|
|
|
function row3($x, $y, $z) {
|
|
echo "<tr><td width=30% valign=top align=right>$x</td><td>$y</td><td>$z</td></tr>\n";
|
|
}
|
|
|
|
function rowify($string) {
|
|
echo "<tr><td>$string</td></tr>";
|
|
}
|
|
|
|
function random_string() {
|
|
return md5(uniqid(rand()));
|
|
}
|
|
|
|
function print_country_select($country="None") {
|
|
$x = posix_getcwd();
|
|
PassThru("$x/country_select '$country'");
|
|
}
|
|
|
|
function print_login_form_aux($next_url, $user) {
|
|
echo "<form method=post action=login_action.php>
|
|
<input type=hidden name=next_url value='$next_url'>
|
|
";
|
|
start_table();
|
|
row1("Log in");
|
|
row2("Your account key:
|
|
<br><font size=-1>
|
|
If you don't know your account key,
|
|
<a href=get_passwd.php>click here</a>.
|
|
</font>",
|
|
"<input name=authenticator size=40>"
|
|
);
|
|
row2("",
|
|
"<input type=submit value='Log in'>"
|
|
);
|
|
if ($user) {
|
|
row1("Log out");
|
|
row2("You are logged in as $user->name",
|
|
"<a href=logout.php>Log out</a>"
|
|
);
|
|
}
|
|
end_table();
|
|
}
|
|
|
|
function print_login_form() {
|
|
page_head("Please log in");
|
|
echo "
|
|
<h3>Please log in</h3>
|
|
This function requires that you log in.
|
|
";
|
|
$next_url = $_SERVER[REQUEST_URI];
|
|
print_login_form_aux($next_url, null);
|
|
page_tail();
|
|
}
|
|
|
|
// Look for an element in a line of XML text
|
|
// If it's a single-tag element, and it's present, just return the tag
|
|
//
|
|
function parse_element($xml, $tag) {
|
|
$element = null;
|
|
$x = strstr($xml, $tag);
|
|
if ($x) {
|
|
if (strstr($tag, "/>")) return $tag;
|
|
$y = substr($x, strlen($tag));
|
|
$n = strpos($y, "<");
|
|
if ($n) {
|
|
$element = substr($y, 0, $n);
|
|
}
|
|
}
|
|
return $element;
|
|
}
|
|
|
|
// look for a particular element in the .htconfig.xml file
|
|
//
|
|
function parse_config($tag) {
|
|
$element = null;
|
|
$fp = fopen(".htconfig.xml", "r");
|
|
while (1) {
|
|
$buf = fgets($fp, 1024);
|
|
if ($buf == null) break;
|
|
$element = parse_element($buf, $tag);
|
|
if ($element) break;
|
|
}
|
|
fclose($fp);
|
|
return $element;
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
// A few functions relating to email-address munging
|
|
// A "munged" email address is of the form @X_Y,
|
|
// where X is a valid email address and Y is a random string.
|
|
// When an email address hasn't been validated yet, it's munged.
|
|
// (Used during account creation and email address changes)
|
|
|
|
// a valid email address is of the form A@B.C
|
|
// where A, B, C are nonempty,
|
|
// A and B don't contain @ or .,
|
|
// and C doesn't contain @
|
|
//
|
|
function is_valid_email_addr($addr) {
|
|
$x = strstr($addr, "@");
|
|
if (!$x) return false;
|
|
if (strlen($x) == strlen($addr)) return false;
|
|
$x = substr($x, 1);
|
|
if (strstr($x, "@")) return false;
|
|
$y = strstr($x, ".");
|
|
if (!$y) return false;
|
|
if (strlen($y) == strlen($x)) return false;
|
|
if (strlen($y) == 1) return false;
|
|
return true;
|
|
}
|
|
|
|
function munge_email_addr($email, $string) {
|
|
return "@".$email."_".$string;
|
|
}
|
|
|
|
// if email_addr is of the form @X_Y, split out the X and return true.
|
|
// otherwise return false
|
|
//
|
|
function split_munged_email_addr($addr, $string, &$email) {
|
|
if (substr($addr, 0, 1) != "@") return false;
|
|
$x = strrchr($addr, "_");
|
|
if (!$x) return false;
|
|
$y = substr($x, 1);
|
|
if ($y != $string) return false;
|
|
$email = substr($addr, 1, strlen($addr)-strlen($x)-1);
|
|
return true;
|
|
}
|
|
|
|
// If the user with id = $userid has uploaded a picture his/herself,
|
|
// delete it and its thumbnail.
|
|
|
|
function delete_user_pictures($userid) {
|
|
$filename1 = IMAGE_PATH . $userid . '.jpg';
|
|
$filename2 = IMAGE_PATH . $userid . '_sm.jpg';
|
|
|
|
if (file_exists($filename1)) {
|
|
unlink($filename1);
|
|
}
|
|
if (file_exists($filename2)) {
|
|
unlink($filename2);
|
|
}
|
|
}
|
|
|
|
?>
|