2004-02-02 23:34:39 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once("../project/project.inc");
|
|
|
|
require_once("../inc/countries.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."
|
|
|
|
|
2004-03-03 22:45:06 +00:00
|
|
|
Your account ID: $auth\n
|
2004-02-02 23:34:39 +00:00
|
|
|
|
|
|
|
Please save this email.
|
2004-03-03 22:45:06 +00:00
|
|
|
You will need your account ID to log in to the ".PROJECT." web site."
|
2004-02-02 23:34:39 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initializes the session and returns the authenticator
|
|
|
|
// for the session (if any)
|
|
|
|
//
|
|
|
|
function init_session() {
|
2004-03-26 18:37:46 +00:00
|
|
|
$url = parse_url(MASTER_URL);
|
|
|
|
$path = $url['path'];
|
|
|
|
if (strlen($path)) {
|
|
|
|
session_set_cookie_params(0, $path);
|
|
|
|
}
|
2004-02-02 23:34:39 +00:00
|
|
|
session_start();
|
|
|
|
// NOTE: in PHP 4.1+, s/key_exists/array_key_exists/
|
|
|
|
if (key_exists('authenticator', $_SESSION)) {
|
|
|
|
return $_SESSION["authenticator"];
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if not logged in, put up login form and exit
|
|
|
|
//
|
2004-02-03 21:48:49 +00:00
|
|
|
function require_login($user) {
|
2004-02-02 23:34:39 +00:00
|
|
|
if (!$user) {
|
2004-02-03 21:48:49 +00:00
|
|
|
print_login_form();
|
2004-02-02 23:34:39 +00:00
|
|
|
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_profile_from_userid($userid) {
|
|
|
|
if ($userid) {
|
|
|
|
$result = mysql_query("SELECT * FROM profile WHERE userid = $userid");
|
|
|
|
if ($result) {
|
|
|
|
return mysql_fetch_assoc($result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2004-02-03 21:48:49 +00:00
|
|
|
function get_logged_in_user($must_be_logged_in=true) {
|
2004-02-02 23:34:39 +00:00
|
|
|
$authenticator = init_session();
|
|
|
|
if (!$authenticator) {
|
|
|
|
$authenticator = $_COOKIE['auth'];
|
|
|
|
}
|
|
|
|
$user = get_user_from_auth($authenticator);
|
|
|
|
if ($must_be_logged_in) {
|
2004-02-03 21:48:49 +00:00
|
|
|
require_login($user);
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
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 {
|
2004-03-24 23:33:46 +00:00
|
|
|
echo "Not logged in";
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// output a select form item with the given name,
|
|
|
|
// from a list of newline-delineated items from the text file.
|
|
|
|
// If $selection is provided, and if it matches one of the entries in the file,
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
// write to the given fd if non-null; else echo
|
|
|
|
//
|
|
|
|
function write_fd($fd, $str) {
|
|
|
|
if ($fd) {
|
|
|
|
fwrite($fd, $str);
|
|
|
|
} else {
|
|
|
|
echo $str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-11 22:49:23 +00:00
|
|
|
function page_head($title, $fd=null) {
|
2004-02-28 19:05:35 +00:00
|
|
|
$styleSheet = URL_BASE . STYLESHEET;
|
2004-02-02 23:34:39 +00:00
|
|
|
|
2004-05-07 22:17:34 +00:00
|
|
|
write_fd($fd,
|
2004-05-14 22:57:59 +00:00
|
|
|
"<html><head><title>".strip_tags($title)."</title>
|
2004-05-07 22:17:34 +00:00
|
|
|
<link rel=stylesheet type=text/css href=\"$styleSheet\">
|
|
|
|
</head>
|
|
|
|
<body bgcolor=ffffff>
|
|
|
|
"
|
|
|
|
);
|
2004-05-12 17:54:23 +00:00
|
|
|
project_banner($title, $fd);
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
2004-02-10 07:02:38 +00:00
|
|
|
function page_tail($is_main=false, $fd=null) {
|
|
|
|
write_fd($fd, "<br><hr noshade size=1><center>");
|
2004-02-02 23:34:39 +00:00
|
|
|
if (!$is_main) {
|
2004-02-10 07:02:38 +00:00
|
|
|
write_fd($fd, "<a href=".MASTER_URL.">Return to ".PROJECT." main page</a><br>\n");
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// put your copyright notice etc. here
|
|
|
|
|
2004-02-10 07:02:38 +00:00
|
|
|
write_fd($fd, "<br><br>Copyright © 2004 ".COPYRIGHT_HOLDER."</center>\n</body>\n</html>");
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function db_error_page() {
|
|
|
|
page_head("Database error");
|
2004-05-12 17:54:23 +00:00
|
|
|
echo "A database error occurred while handling your request.
|
2004-02-02 23:34:39 +00:00
|
|
|
<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) {
|
2004-03-24 23:33:46 +00:00
|
|
|
page_head("Profile error");
|
|
|
|
echo "$str<br>\n";
|
|
|
|
echo "<p>Click your browser's <b>Back</b> button to try again.\n<p>\n";
|
2004-03-26 18:45:49 +00:00
|
|
|
page_tail();
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function date_str($x) {
|
|
|
|
if ($x == 0) return "---";
|
|
|
|
// return date("g:i A, l M j", $when);
|
|
|
|
return strftime("%Y-%m-%d", $x);
|
|
|
|
}
|
|
|
|
|
|
|
|
function time_str($x) {
|
|
|
|
if ($x == 0) return "---";
|
2004-03-23 01:44:13 +00:00
|
|
|
//return strftime("%j %m-%d %H:%M:%S", $x)";
|
|
|
|
return gmdate('j M Y G:i:s', $x) . " UTC";
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function pretty_time_str($x) {
|
2004-03-23 01:44:13 +00:00
|
|
|
return time_str($x);
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
2004-05-14 22:57:59 +00:00
|
|
|
function start_table($extra="width=100%") {
|
2004-02-02 23:34:39 +00:00
|
|
|
echo "<table border=1 cellpadding=5 $extra>";
|
|
|
|
}
|
|
|
|
|
|
|
|
function start_table_noborder($width="100%") {
|
|
|
|
echo "<table border=0 cellpadding=5 width=$width>";
|
|
|
|
}
|
|
|
|
|
|
|
|
function end_table() {
|
|
|
|
echo "</table>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
function row1($x, $ncols=2) {
|
|
|
|
echo "<tr><td class=heading 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 class=fieldname bgcolor=eeeeee align=right valign=top>$x</td><td valign=top><b>$y</b></td></tr>\n";
|
|
|
|
}
|
|
|
|
function row2_init($x, $y) {
|
|
|
|
echo "<tr><td class=fieldname bgcolor=eeeeee width=40% 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() {
|
2004-04-20 05:05:52 +00:00
|
|
|
return md5(uniqid(rand(), true));
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
2004-02-03 21:48:49 +00:00
|
|
|
function print_login_form_aux($next_url, $user) {
|
2004-02-02 23:34:39 +00:00
|
|
|
echo "
|
2004-02-03 21:48:49 +00:00
|
|
|
<form name=f method=post action=login_action.php>
|
2004-02-02 23:34:39 +00:00
|
|
|
<input type=hidden name=next_url value='$next_url'>
|
|
|
|
";
|
|
|
|
start_table();
|
|
|
|
row1("Log in");
|
2004-03-03 22:45:06 +00:00
|
|
|
row2("Your account ID:
|
2004-02-02 23:34:39 +00:00
|
|
|
<br><font size=-2>
|
2004-03-03 22:45:06 +00:00
|
|
|
If you don't know your account ID,
|
2004-02-02 23:34:39 +00:00
|
|
|
<a href=get_passwd.php>click here</a>.
|
|
|
|
</font>",
|
|
|
|
"<input name=authenticator size=40>"
|
|
|
|
);
|
2004-03-03 22:45:06 +00:00
|
|
|
row2("Remember account ID on this computer",
|
2004-02-02 23:34:39 +00:00
|
|
|
"<input type=checkbox name=send_cookie>"
|
|
|
|
);
|
|
|
|
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();
|
|
|
|
echo "
|
|
|
|
</form>
|
|
|
|
<script>
|
|
|
|
document.f.authenticator.focus();
|
|
|
|
</script>
|
|
|
|
";
|
|
|
|
}
|
|
|
|
|
2004-02-03 21:48:49 +00:00
|
|
|
function print_login_form() {
|
2004-02-02 23:34:39 +00:00
|
|
|
page_head("Please log in");
|
|
|
|
echo "
|
|
|
|
This function requires that you log in.
|
|
|
|
";
|
|
|
|
$next_url = $_SERVER['REQUEST_URI'];
|
2004-02-03 21:48:49 +00:00
|
|
|
print_login_form_aux($next_url, null);
|
2004-02-02 23:34:39 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!function_exists("file_get_contents")) {
|
|
|
|
function file_get_contents($path) {
|
|
|
|
$x = "";
|
|
|
|
$f = fopen($path, "r");
|
|
|
|
if ($f) {
|
|
|
|
while (!feof($f)) $x .= fread($f, 4096);
|
|
|
|
fclose($f);
|
|
|
|
}
|
|
|
|
return $x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-03 21:48:49 +00:00
|
|
|
// look for a particular element in the ../../config.xml file
|
2004-02-02 23:34:39 +00:00
|
|
|
//
|
2004-02-03 21:48:49 +00:00
|
|
|
function parse_config($tag) {
|
2004-02-02 23:34:39 +00:00
|
|
|
$element = null;
|
2004-02-03 21:48:49 +00:00
|
|
|
$buf = file_get_contents("../../config.xml");
|
2004-02-02 23:34:39 +00:00
|
|
|
$element = parse_element($buf, $tag);
|
|
|
|
return trim($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 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 not containing _.
|
|
|
|
// When an email address hasn't been validated yet, it's munged.
|
|
|
|
// (Used during account creation and email address changes)
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generates a standard set of links between associated multi-page documents.
|
|
|
|
// All linked files must be of the form "$filename_<page number>.html".
|
|
|
|
|
|
|
|
function write_page_links($filename, $currPageNum, $numPages, $descriptor) {
|
2004-03-24 23:33:46 +00:00
|
|
|
fwrite($descriptor, "<p>Page $currPageNum of $numPages</p>");
|
2004-02-02 23:34:39 +00:00
|
|
|
|
2004-03-24 23:33:46 +00:00
|
|
|
$nextPageNum = $currPageNum + 1;
|
|
|
|
$prevPageNum = $currPageNum - 1;
|
2004-02-02 23:34:39 +00:00
|
|
|
|
2004-03-24 23:33:46 +00:00
|
|
|
// Make the 'previous' and 'next' page links as appropriate.
|
|
|
|
if ($currPageNum > 1) {
|
|
|
|
fwrite($descriptor, "<a href=$filename" . "_" . $prevPageNum . ".html>Previous Page</a>");
|
2004-02-02 23:34:39 +00:00
|
|
|
|
2004-03-24 23:33:46 +00:00
|
|
|
if ($currPageNum != $numPages) {
|
|
|
|
fwrite($descriptor, " | ");
|
|
|
|
}
|
|
|
|
}
|
2004-02-02 23:34:39 +00:00
|
|
|
if ($currPageNum != $numPages) {
|
2004-03-24 23:33:46 +00:00
|
|
|
fwrite($descriptor, "<a href=$filename" . "_" . $nextPageNum . ".html>Next Page</a>");
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
2004-04-07 23:58:02 +00:00
|
|
|
fwrite($descriptor, "<p>Jump to Page:\n");
|
2004-02-02 23:34:39 +00:00
|
|
|
|
2004-03-24 23:33:46 +00:00
|
|
|
// Make the individual page links (or a bold non-link for the current page).
|
2004-04-07 23:58:02 +00:00
|
|
|
//
|
2004-03-24 23:33:46 +00:00
|
|
|
for ($i = 1; $i <= $numPages; $i++) {
|
|
|
|
if ($i != $currPageNum) {
|
2004-04-07 23:58:02 +00:00
|
|
|
fwrite($descriptor, "<a href=$filename" . "_" . $i . ".html>$i</a>\n");
|
2004-03-24 23:33:46 +00:00
|
|
|
} else {
|
2004-04-07 23:58:02 +00:00
|
|
|
fwrite($descriptor, "<b>$i</b>\n");
|
2004-03-24 23:33:46 +00:00
|
|
|
}
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generates a legal filename from a parameter string.
|
|
|
|
|
|
|
|
function get_legal_filename($name) {
|
2004-03-24 23:33:46 +00:00
|
|
|
$name = ereg_replace(',', '', $name);
|
|
|
|
return ereg_replace(' ', '_', $name);
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns a string containing as many words
|
|
|
|
// (being collections of characters separated by the character $delimiter)
|
|
|
|
// as possible such that the total string length is <= $chars characters long.
|
|
|
|
// If $ellipsis is true, then an ellipsis is added to any sentence which
|
|
|
|
// is cut short.
|
|
|
|
|
|
|
|
function sub_sentence($sentence, $delimiter, $max_chars, $ellipsis=false) {
|
|
|
|
$words = explode($delimiter, $sentence);
|
|
|
|
$total_chars = 0;
|
|
|
|
$count = 0;
|
|
|
|
$result = '';
|
|
|
|
|
|
|
|
do {
|
|
|
|
if ($count > 0) {
|
|
|
|
$result = $result . ' ' . $words[$count];
|
|
|
|
} else {
|
|
|
|
$result = $result . $words[$count];
|
|
|
|
}
|
|
|
|
$total_chars += strlen($words[$count]) + 1;
|
|
|
|
$count++;
|
|
|
|
} while ($count < count($words) && ($total_chars + strlen($words[$count])) <= $max_chars);
|
|
|
|
|
|
|
|
if ($ellipsis && ($count < count($words))) {
|
|
|
|
$result = $result . '...';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function format_credit($cobblestones) {
|
|
|
|
return sprintf("%.2f", $cobblestones);
|
|
|
|
}
|
|
|
|
|
|
|
|
function project_is_stopped() {
|
2004-06-07 03:34:07 +00:00
|
|
|
return file_exists("../../stop_servers");
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
2004-06-01 18:55:59 +00:00
|
|
|
function user_links($user) {
|
|
|
|
$x = "<a href=show_user.php?userid=$user->id>$user->name</a>";
|
2004-02-02 23:34:39 +00:00
|
|
|
if ($user->has_profile) {
|
2004-06-01 18:55:59 +00:00
|
|
|
$x .= " <a href=view_profile?userid=$user->id><img border=0 src=head_20.png></a>";
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
return $x;
|
|
|
|
}
|
2004-02-05 21:35:48 +00:00
|
|
|
|
|
|
|
function host_link($hostid) {
|
|
|
|
if ($hostid) {
|
|
|
|
return "<a href=show_host_detail.php?hostid=$hostid>$hostid</a>";
|
|
|
|
} else {
|
|
|
|
return "---";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-02 23:34:39 +00:00
|
|
|
?>
|