2004-02-02 23:34:39 +00:00
|
|
|
<?php
|
2005-01-12 13:39:05 +00:00
|
|
|
$cvs_version_tracker[]="\$Id$"; //Generated automatically - do not edit
|
2004-02-02 23:34:39 +00:00
|
|
|
|
|
|
|
require_once("../project/project.inc");
|
|
|
|
require_once("../inc/countries.inc");
|
2004-09-14 20:45:17 +00:00
|
|
|
require_once("../inc/db.inc");
|
2007-10-26 21:14:35 +00:00
|
|
|
require_once("../inc/boinc_db.inc");
|
2005-10-01 16:07:11 +00:00
|
|
|
require_once("../inc/translation.inc");
|
2004-09-14 20:45:17 +00:00
|
|
|
|
2007-11-08 00:13:11 +00:00
|
|
|
ini_set("memory_limit", "64M");
|
|
|
|
|
2006-09-06 20:56:55 +00:00
|
|
|
$generating_xml = false;
|
|
|
|
|
2007-03-14 18:05:30 +00:00
|
|
|
// db_init
|
|
|
|
// Connects to database server and selects database as noted in config.xml
|
|
|
|
// (Or, in some cases, if only read-only access is necessary, tries instead
|
|
|
|
// to connect to replica database server noted in <replica_db_host> tag. If
|
|
|
|
// this tag doesn't exist, db_init will revert to connecting to <db_host>.)
|
|
|
|
//
|
|
|
|
function db_init($try_replica=false) {
|
2006-12-07 23:39:23 +00:00
|
|
|
if (web_stopped()) {
|
2005-02-25 19:35:34 +00:00
|
|
|
page_head("Not available");
|
|
|
|
echo "This page requires database access.
|
|
|
|
Our database server is temporarily shut down for maintenance.
|
|
|
|
Please try again later.
|
|
|
|
";
|
|
|
|
page_tail();
|
2004-09-21 21:56:10 +00:00
|
|
|
exit();
|
|
|
|
}
|
2007-03-14 18:05:30 +00:00
|
|
|
$retval = db_init_aux($try_replica);
|
2004-09-21 21:56:10 +00:00
|
|
|
if ($retval == 1) {
|
|
|
|
echo "Unable to connect to database - please try again later\n";
|
2005-10-29 05:30:57 +00:00
|
|
|
echo "Error: ", mysql_errno(), mysql_error();
|
2004-09-21 21:56:10 +00:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
if ($retval == 2) {
|
|
|
|
echo "Unable to select database - please try again later";
|
2005-10-29 05:30:57 +00:00
|
|
|
echo mysql_error();
|
2004-09-21 21:56:10 +00:00
|
|
|
exit();
|
|
|
|
}
|
2006-09-06 20:56:55 +00:00
|
|
|
return 0;
|
2004-09-21 21:56:10 +00:00
|
|
|
}
|
|
|
|
|
2004-02-02 23:34:39 +00:00
|
|
|
// Initializes the session and returns the authenticator
|
|
|
|
// for the session (if any)
|
|
|
|
//
|
|
|
|
function init_session() {
|
2006-05-09 18:25:15 +00:00
|
|
|
$master_url = parse_config(get_config(), "<master_url>");
|
|
|
|
$url = parse_url($master_url);
|
2004-03-26 18:37:46 +00:00
|
|
|
$path = $url['path'];
|
|
|
|
if (strlen($path)) {
|
|
|
|
session_set_cookie_params(0, $path);
|
|
|
|
}
|
2006-08-13 21:51:15 +00:00
|
|
|
if (session_id() == "") session_start(); // first check if there is a session
|
2004-02-02 23:34:39 +00:00
|
|
|
// NOTE: in PHP 4.1+, s/key_exists/array_key_exists/
|
2004-08-20 18:45:43 +00:00
|
|
|
if (array_key_exists('authenticator', $_SESSION)) {
|
2004-02-02 23:34:39 +00:00
|
|
|
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_id($id) {
|
|
|
|
if ($id) return lookup_user_id($id);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-01-29 18:15:16 +00:00
|
|
|
$g_logged_in_user = null;
|
|
|
|
|
2004-02-03 21:48:49 +00:00
|
|
|
function get_logged_in_user($must_be_logged_in=true) {
|
2007-01-29 18:15:16 +00:00
|
|
|
global $g_logged_in_user;
|
2007-10-26 21:14:35 +00:00
|
|
|
$g_logged_in_user = null;
|
2004-02-02 23:34:39 +00:00
|
|
|
$authenticator = init_session();
|
|
|
|
if (!$authenticator) {
|
2005-05-11 08:44:27 +00:00
|
|
|
if (isset($_COOKIE['auth'])) $authenticator = $_COOKIE['auth'];
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
2005-02-13 06:13:33 +00:00
|
|
|
$authenticator = process_user_text($authenticator);
|
2007-10-26 21:14:35 +00:00
|
|
|
if ($authenticator) {
|
2007-10-29 16:38:25 +00:00
|
|
|
$g_logged_in_user = BoincUser::lookup("authenticator='$authenticator'");
|
2007-10-26 21:14:35 +00:00
|
|
|
}
|
2004-02-02 23:34:39 +00:00
|
|
|
if ($must_be_logged_in) {
|
2007-01-29 18:15:16 +00:00
|
|
|
require_login($g_logged_in_user);
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
2007-01-29 18:15:16 +00:00
|
|
|
return $g_logged_in_user;
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-22 03:46:42 +00:00
|
|
|
// Page_head() is overridable so that projects that want to integrate BOINC
|
|
|
|
// with an existing web framework can more easily do so.
|
|
|
|
// To take advantage of this simply define the function page_head()
|
|
|
|
// somewhere in the project include file.
|
|
|
|
//
|
2006-08-22 08:33:15 +00:00
|
|
|
if (!function_exists("page_head")){
|
2005-10-17 03:03:48 +00:00
|
|
|
function page_head($title, $java_onload=null, $title_plain=null, $prefix="") {
|
2007-07-05 19:37:33 +00:00
|
|
|
$styleSheet = URL_BASE . "/".STYLESHEET;
|
2004-10-20 05:45:43 +00:00
|
|
|
$rssname = PROJECT . " RSS 2.0";
|
2007-07-05 19:37:33 +00:00
|
|
|
$rsslink = URL_BASE . "/rss_main.php";
|
2007-10-22 19:36:01 +00:00
|
|
|
|
2005-03-28 22:26:22 +00:00
|
|
|
if (defined("CHARSET")) {
|
2007-11-02 14:43:02 +00:00
|
|
|
header("Content-type: text/html; charset=".tra(CHARSET));
|
2005-03-28 22:26:22 +00:00
|
|
|
}
|
2007-10-22 19:36:01 +00:00
|
|
|
|
|
|
|
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd\">\n";
|
|
|
|
|
2005-10-29 05:30:57 +00:00
|
|
|
if (!$title_plain) {
|
2007-10-22 19:36:01 +00:00
|
|
|
echo "<html><head><title>".strip_tags($title)."</title>\n";
|
2005-10-29 05:30:57 +00:00
|
|
|
} else {
|
2007-10-22 19:36:01 +00:00
|
|
|
echo "<html><head><title>".strip_tags($title_plain)."</title>\n";
|
2005-10-29 05:30:57 +00:00
|
|
|
}
|
2007-10-22 19:36:01 +00:00
|
|
|
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$styleSheet\">
|
|
|
|
<link rel=\"alternate\" type=\"application/rss+xml\" title=\"$rssname\" href=\"$rsslink\">
|
|
|
|
</head>
|
|
|
|
";
|
2005-10-17 03:03:48 +00:00
|
|
|
if ($java_onload){
|
2007-11-07 17:23:29 +00:00
|
|
|
echo "<body bgcolor=\"#ffffff\" onload=\"".$java_onload."\">";
|
|
|
|
} else {
|
|
|
|
echo "<body bgcolor=\"#ffffff\">";
|
2005-10-17 03:03:48 +00:00
|
|
|
}
|
2005-01-12 13:25:33 +00:00
|
|
|
display_cvs_versions();
|
2005-10-17 03:03:48 +00:00
|
|
|
project_banner($title, $prefix);
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
2006-08-22 08:33:15 +00:00
|
|
|
}
|
2004-02-02 23:34:39 +00:00
|
|
|
|
2005-10-29 05:30:57 +00:00
|
|
|
function page_tail_aux($show_return, $show_date, $prefix="") {
|
|
|
|
project_footer($show_return, $show_date, $prefix);
|
2004-11-18 20:01:12 +00:00
|
|
|
echo "</body>\n</html>";
|
|
|
|
}
|
|
|
|
function page_tail_main($show_date=false) {
|
|
|
|
page_tail_aux(false, $show_date);
|
|
|
|
}
|
2004-02-02 23:34:39 +00:00
|
|
|
|
2007-11-06 18:25:44 +00:00
|
|
|
// See the comments for page_head()
|
|
|
|
//
|
2006-08-22 08:33:15 +00:00
|
|
|
if (!function_exists("page_tail")){
|
2005-10-17 03:03:48 +00:00
|
|
|
function page_tail($show_date=false, $prefix="") {
|
|
|
|
page_tail_aux(true, $show_date, $prefix);
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
2006-08-22 08:33:15 +00:00
|
|
|
}
|
2004-02-02 23:34:39 +00:00
|
|
|
|
2005-01-12 13:25:33 +00:00
|
|
|
function display_cvs_versions(){
|
|
|
|
global $cvs_version_tracker;
|
2007-05-15 10:06:38 +00:00
|
|
|
echo "\n<!-- SVN VERSIONS -->\n";
|
2005-10-29 05:30:57 +00:00
|
|
|
for ($i=0;$i<sizeof($cvs_version_tracker);$i++) {
|
|
|
|
echo "<!-- ".$cvs_version_tracker[$i]." -->\n";
|
2005-01-12 13:25:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2004-11-21 18:56:30 +00:00
|
|
|
function error_page($msg) {
|
2006-09-06 20:56:55 +00:00
|
|
|
global $generating_xml;
|
|
|
|
if ($generating_xml) {
|
|
|
|
xml_error(-1, $msg);
|
|
|
|
}
|
2004-11-21 18:56:30 +00:00
|
|
|
page_head("Unable to handle request");
|
|
|
|
echo $msg;
|
|
|
|
page_tail();
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2004-11-29 11:56:25 +00:00
|
|
|
// takes argument in second and returns a human formatted time string
|
|
|
|
// in the form D days + h Hours + m Min + s sec.
|
|
|
|
|
|
|
|
function time_diff($x) {
|
2005-10-29 05:30:57 +00:00
|
|
|
$days = (int)($x/86400);
|
|
|
|
$hours = (int)(($x-$days*86400)/3600);
|
|
|
|
$minutes = (int)(($x-$days*86400-$hours*3600)/60);
|
|
|
|
$seconds = (int)($x % 60);
|
|
|
|
|
|
|
|
$datestring = "";
|
|
|
|
if ($days) {
|
|
|
|
$datestring .= "$days days ";
|
|
|
|
}
|
|
|
|
if ($hours || strlen($datestring)) {
|
|
|
|
$datestring .= "$hours hours ";
|
|
|
|
}
|
|
|
|
if ($minutes || strlen($datestring)) {
|
|
|
|
$datestring .= "$minutes min ";
|
|
|
|
}
|
|
|
|
if ($seconds) {
|
|
|
|
$datestring .= "$seconds sec";
|
|
|
|
}
|
|
|
|
|
|
|
|
return $datestring;
|
2004-11-29 11:56:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-02 23:34:39 +00:00
|
|
|
function date_str($x) {
|
|
|
|
if ($x == 0) return "---";
|
2005-01-08 19:45:26 +00:00
|
|
|
return gmdate('j M Y', $x);
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function time_str($x) {
|
|
|
|
if ($x == 0) return "---";
|
2004-03-23 01:44:13 +00:00
|
|
|
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
|
|
|
}
|
2007-10-22 19:36:01 +00:00
|
|
|
function start_table($extra="width=\"100%\"") {
|
|
|
|
echo "<table border=\"1\" cellpadding=\"5\" $extra>";
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function start_table_noborder($width="100%") {
|
2007-10-22 19:36:01 +00:00
|
|
|
echo "<table border=\"0\" cellpadding=\"5\" width=\"$width\">";
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function end_table() {
|
|
|
|
echo "</table>\n";
|
|
|
|
}
|
|
|
|
|
2007-11-05 23:55:33 +00:00
|
|
|
// Table header row with unlimited number of columns
|
|
|
|
|
2007-08-26 12:01:41 +00:00
|
|
|
function table_header() {
|
|
|
|
echo "<tr>\n";
|
|
|
|
for ($i = 0; $i < func_num_args(); $i++) {
|
|
|
|
if (is_array(func_get_arg($i))) {
|
|
|
|
$col = func_get_arg($i);
|
|
|
|
echo "<th ".$col[1].">".$col[0]."</th>\n";
|
|
|
|
} else {
|
|
|
|
echo "<th>".func_get_arg($i)."</th>\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
echo "</tr>\n";
|
|
|
|
}
|
|
|
|
|
2007-11-05 23:55:33 +00:00
|
|
|
// Table row with unlimited number of columns
|
|
|
|
|
2007-08-26 12:01:41 +00:00
|
|
|
function table_row() {
|
|
|
|
echo "<tr>\n";
|
|
|
|
for ($i = 0; $i < func_num_args(); $i++) {
|
|
|
|
if (is_array(func_get_arg($i))) {
|
|
|
|
$col = func_get_arg($i);
|
|
|
|
echo "<td ".$col[1].">".$col[0]."</td>\n";
|
|
|
|
} else {
|
|
|
|
echo "<td>".func_get_arg($i)."</td>\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
echo "</tr>\n";
|
|
|
|
}
|
|
|
|
|
2004-12-16 19:37:26 +00:00
|
|
|
function row1($x, $ncols=2, $class="heading") {
|
2007-10-30 19:36:27 +00:00
|
|
|
echo "<tr><td class=\"$class\" colspan=\"$ncols\">$x</td></tr>\n";
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
2006-08-13 21:51:15 +00:00
|
|
|
function row2($x, $y, $show_error=false) {
|
2004-02-02 23:34:39 +00:00
|
|
|
if ($x=="") $x="<br>";
|
|
|
|
if ($y=="") $y="<br>";
|
2006-08-13 21:51:15 +00:00
|
|
|
if ($show_error) {
|
|
|
|
$class1 = 'fieldname_error';
|
|
|
|
$class2 = 'fieldvalue_error';
|
|
|
|
} else {
|
|
|
|
$class1 = 'fieldname';
|
|
|
|
$class2 = 'fieldvalue';
|
|
|
|
}
|
2007-10-30 19:36:27 +00:00
|
|
|
echo "<tr><td width=\"40%\" class=\"$class1\">$x</td><td class=\"$class2\">$y</td></tr>\n";
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
2006-08-13 21:51:15 +00:00
|
|
|
|
2004-02-02 23:34:39 +00:00
|
|
|
function row2_init($x, $y) {
|
2007-10-30 19:36:27 +00:00
|
|
|
echo "<tr><td class=\"fieldname\" width=\"40%\">$x</td><td valign=\"top\"><b>$y\n";
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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";
|
|
|
|
}
|
|
|
|
|
2004-09-23 00:32:10 +00:00
|
|
|
function row4($xx, $xy, $yx, $yy) {
|
2004-11-01 23:42:29 +00:00
|
|
|
echo "<tr><td width=25% valign=top>$xx</td><td width=25%>$xy</td>"
|
2005-04-07 20:46:25 +00:00
|
|
|
. "<td width=25% >$yx</td><td width=%25>$yy</td></tr>
|
|
|
|
";
|
2004-09-23 00:12:19 +00:00
|
|
|
}
|
|
|
|
|
2004-02-02 23:34:39 +00:00
|
|
|
function rowify($string) {
|
|
|
|
echo "<tr><td>$string</td></tr>";
|
|
|
|
}
|
|
|
|
|
2005-04-08 00:06:52 +00:00
|
|
|
function row_array($x) {
|
2005-04-07 20:46:25 +00:00
|
|
|
echo "<tr>";
|
|
|
|
foreach ($x as $h) {
|
2006-01-31 22:21:11 +00:00
|
|
|
echo "<td>$h</td>";
|
2005-04-07 20:46:25 +00:00
|
|
|
}
|
|
|
|
echo "</tr>\n";
|
|
|
|
}
|
|
|
|
|
2005-04-08 00:06:52 +00:00
|
|
|
function row_heading_array($x) {
|
2005-04-07 20:46:25 +00:00
|
|
|
echo "<tr>";
|
|
|
|
foreach ($x as $h) {
|
|
|
|
echo "<th class=heading>$h</th>";
|
|
|
|
}
|
|
|
|
echo "</tr>\n";
|
|
|
|
}
|
|
|
|
|
2004-02-02 23:34:39 +00:00
|
|
|
function random_string() {
|
2004-04-20 05:05:52 +00:00
|
|
|
return md5(uniqid(rand(), true));
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
2007-01-29 18:15:16 +00:00
|
|
|
function url_tokens($auth) {
|
|
|
|
$now = time();
|
|
|
|
$ttok = md5((string)$now.$auth);
|
2007-10-30 19:36:27 +00:00
|
|
|
return "&tnow=$now&ttok=$ttok";
|
2007-01-29 18:15:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function form_tokens($auth) {
|
|
|
|
$now = time();
|
|
|
|
$ttok = md5((string)$now.$auth);
|
2007-10-30 19:36:27 +00:00
|
|
|
return "<input type=\"hidden\" name=\"tnow\" value=\"$now\">
|
|
|
|
<input type=\"hidden\" name=\"ttok\" value=\"$ttok\">
|
2007-01-29 18:15:16 +00:00
|
|
|
";
|
|
|
|
}
|
|
|
|
|
|
|
|
function valid_tokens($auth) {
|
2007-10-29 16:38:25 +00:00
|
|
|
$tnow = get_str('tnow', true);
|
|
|
|
$ttok = get_str('ttok', true);
|
2007-10-28 15:03:14 +00:00
|
|
|
if (!$tnow) {
|
|
|
|
$tnow = $_POST['tnow'];
|
|
|
|
}
|
|
|
|
if (!$ttok) {
|
|
|
|
$ttok = $_POST['ttok'];
|
|
|
|
}
|
2007-01-29 18:15:16 +00:00
|
|
|
if (!$tnow) return false;
|
|
|
|
if (!$ttok) return false;
|
|
|
|
$t = md5((string)$tnow.$auth);
|
|
|
|
if ($t != $ttok) return false;
|
|
|
|
if (time() > $tnow + 86400) return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function check_tokens($auth) {
|
|
|
|
if (valid_tokens($auth)) return;
|
|
|
|
error_page(
|
|
|
|
"Link has timed out. Please click Back, refresh the page,
|
|
|
|
and try again."
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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();
|
2005-08-07 01:33:15 +00:00
|
|
|
row1("Log in with email/password");
|
2006-12-17 16:05:56 +00:00
|
|
|
row2("Email address:", '<input name="email_addr" size="40" tabindex="1">');
|
2006-08-09 21:54:38 +00:00
|
|
|
row2("Password:<br><font size=-2><a href=edit_passwd_form.php>Forgot password?</a>",
|
2006-12-17 16:05:56 +00:00
|
|
|
'<input type="password" name="passwd" size="40" tabindex="2">'
|
2005-08-26 22:26:26 +00:00
|
|
|
);
|
2006-12-17 16:05:56 +00:00
|
|
|
row2("", '<input type="submit" name="mode" value="Log in with email/password" tabindex="3">');
|
2005-08-07 01:33:15 +00:00
|
|
|
row1("Log in with account key");
|
2004-12-06 22:41:19 +00:00
|
|
|
row2("Your account key:
|
2004-02-02 23:34:39 +00:00
|
|
|
<br><font size=-2>
|
2004-12-06 22:41:19 +00:00
|
|
|
If you don't know your account key,
|
2004-02-02 23:34:39 +00:00
|
|
|
<a href=get_passwd.php>click here</a>.
|
|
|
|
</font>",
|
|
|
|
"<input name=authenticator size=40>"
|
|
|
|
);
|
2005-12-23 22:36:37 +00:00
|
|
|
row2("", "<input type=submit name=mode value='Log in with account key'>");
|
|
|
|
row1("Stay logged in");
|
2005-08-07 01:33:15 +00:00
|
|
|
row2("Stay logged in on this computer",
|
2005-08-26 22:26:26 +00:00
|
|
|
"<input type=checkbox name=send_cookie checked>"
|
2004-02-02 23:34:39 +00:00
|
|
|
);
|
|
|
|
if ($user) {
|
|
|
|
row1("Log out");
|
|
|
|
row2("You are logged in as $user->name",
|
2007-01-29 18:15:16 +00:00
|
|
|
"<a href=logout.php?".url_tokens($user->authenticator).">Log out</a>"
|
2004-02-02 23:34:39 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
end_table();
|
|
|
|
echo "
|
|
|
|
</form>
|
|
|
|
<script>
|
2005-08-07 01:33:15 +00:00
|
|
|
document.f.email_addr.focus();
|
2004-02-02 23:34:39 +00:00
|
|
|
</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.
|
2005-08-26 22:26:26 +00:00
|
|
|
<p>
|
2004-02-02 23:34:39 +00:00
|
|
|
";
|
|
|
|
$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;
|
2005-09-20 22:48:35 +00:00
|
|
|
$closetag = "</" . substr($tag,1);
|
2004-02-02 23:34:39 +00:00
|
|
|
$x = strstr($xml, $tag);
|
|
|
|
if ($x) {
|
|
|
|
if (strstr($tag, "/>")) return $tag;
|
|
|
|
$y = substr($x, strlen($tag));
|
2005-09-20 22:48:35 +00:00
|
|
|
$n = strpos($y, $closetag);
|
2004-02-02 23:34:39 +00:00
|
|
|
if ($n) {
|
|
|
|
$element = substr($y, 0, $n);
|
|
|
|
}
|
|
|
|
}
|
2005-09-27 21:40:50 +00:00
|
|
|
return trim($element);
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
2006-12-17 17:19:29 +00:00
|
|
|
function parse_next_element($xml, $tag, &$cursor) {
|
2005-09-20 22:48:35 +00:00
|
|
|
$element = null;
|
|
|
|
$closetag = "</" . substr($tag,1);
|
|
|
|
$pos = substr($xml,$cursor);
|
|
|
|
$x = strstr($pos, $tag);
|
|
|
|
if ($x) {
|
|
|
|
if (strstr($tag, "/>")) return $tag;
|
|
|
|
$y = substr($x, strlen($tag));
|
|
|
|
$n = strpos($y, $closetag);
|
|
|
|
if ($n) {
|
|
|
|
$element = substr($y, 0, $n);
|
|
|
|
}
|
|
|
|
$cursor = (strlen($xml) - strlen($x)) + strlen($tag) + strlen($closetag) + strlen($element);
|
|
|
|
}
|
2005-09-27 21:40:50 +00:00
|
|
|
return trim($element);
|
2005-09-20 22:48:35 +00:00
|
|
|
}
|
|
|
|
|
2004-02-02 23:34:39 +00:00
|
|
|
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-08-25 19:04:47 +00:00
|
|
|
$g_config = null;
|
2004-06-30 18:53:35 +00:00
|
|
|
function get_config() {
|
2004-08-25 19:04:47 +00:00
|
|
|
global $g_config;
|
|
|
|
if ($g_config == null) {
|
|
|
|
$g_config = file_get_contents("../../config.xml");
|
|
|
|
}
|
|
|
|
return $g_config;
|
2004-06-30 18:53:35 +00:00
|
|
|
}
|
|
|
|
|
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-06-30 18:53:35 +00:00
|
|
|
function parse_config($config, $tag) {
|
|
|
|
$element = parse_element($config, $tag);
|
2005-09-27 21:40:50 +00:00
|
|
|
return $element;
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
2004-11-12 22:50:58 +00:00
|
|
|
// return true if XML contains either <tag/> or <tag>1</tag>
|
|
|
|
//
|
|
|
|
function parse_bool($xml, $tag) {
|
|
|
|
$x = "<$tag/>";
|
|
|
|
if (strstr($xml, $x)) return true;
|
|
|
|
$x = "<$tag>";
|
|
|
|
$y = (int)parse_element($xml, $x);
|
|
|
|
if ($y != 0) return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2004-02-02 23:34:39 +00:00
|
|
|
// Call this if for dynamic pages
|
|
|
|
//
|
|
|
|
function no_cache() {
|
2005-05-11 08:44:27 +00:00
|
|
|
header ("Expires: Mon, 26 Jul 1997 05:00:00 UTC"); // Date in the past
|
|
|
|
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " UTC"); // always modified
|
2004-02-02 23:34:39 +00:00
|
|
|
header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
|
|
|
|
header ("Pragma: no-cache"); // HTTP/1.0
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2007-10-07 19:27:59 +00:00
|
|
|
// use this for user RAC and result credit
|
|
|
|
//
|
2004-12-15 23:50:00 +00:00
|
|
|
function format_credit($x) {
|
2007-10-07 19:27:59 +00:00
|
|
|
return number_format($x, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
// use this when credit is likely to be large, e.g. team RAC
|
|
|
|
//
|
|
|
|
function format_credit_large($x) {
|
2007-10-02 15:32:28 +00:00
|
|
|
return number_format($x, 0);
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
2006-12-07 23:39:23 +00:00
|
|
|
function web_stopped() {
|
|
|
|
return file_exists("../../stop_web");
|
|
|
|
}
|
|
|
|
|
|
|
|
function sched_stopped() {
|
|
|
|
return file_exists("../../stop_sched");
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
2004-06-01 18:55:59 +00:00
|
|
|
function user_links($user) {
|
2007-07-05 19:37:33 +00:00
|
|
|
$x = "<a href=\"".URL_BASE."/show_user.php?userid=".$user->id."\">".$user->name."</a>";
|
2004-02-02 23:34:39 +00:00
|
|
|
if ($user->has_profile) {
|
2007-11-01 20:41:24 +00:00
|
|
|
$x .= ' <a href="'.URL_BASE.'/view_profile.php?userid='.$user->id.'"><img title="View the profile of '.$user->name.'" vspace=2 border="0" src="'.URL_BASE.'/img/head_20.png" alt="User profile image"></a>';
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
2007-11-01 20:41:24 +00:00
|
|
|
// Does this project accept donations?
|
|
|
|
// If so, do you want to have a link next to user name as it appears on the web site?
|
|
|
|
//
|
2005-08-31 22:50:53 +00:00
|
|
|
if ($user->donated == 1) {
|
2005-09-15 20:45:11 +00:00
|
|
|
require_once("../project/donations.inc");
|
|
|
|
$x .= DONATION_LINK;
|
|
|
|
}
|
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-06-15 18:50:57 +00:00
|
|
|
function open_output_buffer() {
|
|
|
|
ob_start();
|
|
|
|
ob_implicit_flush(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
function close_output_buffer($filename) {
|
|
|
|
$fh = fopen($filename, "w");
|
|
|
|
$page = ob_get_contents();
|
|
|
|
ob_end_clean();
|
|
|
|
fwrite($fh, $page);
|
|
|
|
fclose($fh);
|
|
|
|
}
|
|
|
|
|
2005-01-30 20:15:18 +00:00
|
|
|
function html_info() {
|
2007-11-02 14:43:02 +00:00
|
|
|
return "<br><a href=\"bbcode.php\" target=\"_new\"><span class=\"smalltext\">".tra("Use BBCode tags to format your text")."</span></a>\n";
|
2005-01-30 20:15:18 +00:00
|
|
|
}
|
|
|
|
|
2005-02-13 06:13:33 +00:00
|
|
|
function get_int($name, $optional=false) {
|
2005-05-11 09:48:07 +00:00
|
|
|
$x=null;
|
|
|
|
if (isset($_GET[$name])) $x = $_GET[$name];
|
2005-02-13 06:13:33 +00:00
|
|
|
if (!is_numeric($x)) {
|
|
|
|
if ($optional) {
|
|
|
|
return null;
|
|
|
|
} else {
|
2007-09-13 09:46:36 +00:00
|
|
|
error_page("missing or bad parameter: $name; supplied: ".htmlspecialchars($x));
|
2005-02-13 06:13:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return (int)$x;
|
|
|
|
}
|
|
|
|
|
|
|
|
function post_int($name, $optional=false) {
|
2005-05-11 10:30:28 +00:00
|
|
|
$x = null;
|
|
|
|
if (isset($_POST[$name])) $x = $_POST[$name];
|
2005-02-13 06:13:33 +00:00
|
|
|
if (!is_numeric($x)) {
|
|
|
|
if ($optional) {
|
|
|
|
return null;
|
|
|
|
} else {
|
2007-09-13 09:46:36 +00:00
|
|
|
error_page("missing or bad parameter: $name; supplied: ".htmlspecialchars($x));
|
2005-02-13 06:13:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return (int)$x;
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_str($name, $optional=false) {
|
2005-05-11 10:11:54 +00:00
|
|
|
$x = null;
|
|
|
|
if (isset($_GET[$name])) $x = $_GET[$name];
|
2005-05-11 09:48:07 +00:00
|
|
|
if (!$x && !$optional) {
|
2005-02-13 06:13:33 +00:00
|
|
|
error_page("missing or bad parameter: $name");
|
|
|
|
}
|
|
|
|
return $x;
|
|
|
|
}
|
|
|
|
|
2005-02-15 22:29:32 +00:00
|
|
|
function get_venue($name) {
|
|
|
|
$x = $_GET[$name];
|
|
|
|
if ($x == "") return $x;
|
|
|
|
if ($x == "home") return $x;
|
|
|
|
if ($x == "work") return $x;
|
|
|
|
if ($x == "school") return $x;
|
|
|
|
error_page("no such venue: $x");
|
|
|
|
}
|
|
|
|
|
2005-02-13 06:13:33 +00:00
|
|
|
function post_str($name, $optional=false) {
|
2006-12-29 20:57:29 +00:00
|
|
|
$x = null;
|
|
|
|
if (isset($_POST[$name])) $x = $_POST[$name];
|
2005-05-11 12:30:39 +00:00
|
|
|
if (!$x && !$optional) {
|
2005-02-13 06:13:33 +00:00
|
|
|
error_page("missing or bad parameter: $name");
|
|
|
|
}
|
|
|
|
return $x;
|
|
|
|
}
|
|
|
|
|
2005-10-12 22:51:55 +00:00
|
|
|
function is_ascii($str) {
|
|
|
|
// the mb_* functions are not included by default
|
|
|
|
// return (mb_detect_encoding($passwd) -= 'ASCII');
|
|
|
|
|
|
|
|
for ($i=0; $i<strlen($str); $i++) {
|
|
|
|
$c = ord(substr($str, $i));
|
|
|
|
if ($c < 32 || $c > 127) return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2006-02-20 19:11:51 +00:00
|
|
|
|
|
|
|
// This function takes as input a GET variable name X and value Y.
|
|
|
|
// It returns the corresponding text GET variable string, appended with
|
|
|
|
// any existing GET variable names and values, with &X=Y.
|
|
|
|
//
|
|
|
|
// This is useful for constructing urls for sorting a table by different
|
|
|
|
// columns.
|
|
|
|
//
|
|
|
|
function make_GET_list($variable_name, $variable_value) {
|
|
|
|
$retval="";
|
|
|
|
$sepchar='?';
|
|
|
|
$modified=false;
|
|
|
|
foreach ($_GET as $key => $value) {
|
|
|
|
$retval .= "$sepchar"."$key=";
|
|
|
|
$sepchar='&';
|
|
|
|
if ($key==$variable_name) {
|
|
|
|
$modified=true;
|
|
|
|
if ($value!=$variable_value) {
|
|
|
|
$retval .= "$variable_value";
|
|
|
|
} else {
|
|
|
|
$retval .= "$variable_value"."_reversed";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$retval .= "$value";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!$modified) $retval .= "$sepchar$variable_name=$variable_value";
|
|
|
|
return $retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
function link_with_GET_variables($text, $baseurl, $variable_name, $variable_value) {
|
|
|
|
$list=make_GET_list($variable_name, $variable_value);
|
|
|
|
return "<a href=\"$baseurl$list\">$text</a>";
|
|
|
|
}
|
|
|
|
|
2006-08-13 21:51:15 +00:00
|
|
|
// This function replaces some often made mistakes while entering numbers
|
|
|
|
// and gives back an error if there are false characters
|
|
|
|
// It will also be checked if the value is within certain borders
|
|
|
|
// @param string &$value reference to the value that should be verified
|
|
|
|
// @param double $low the lowest number of value if verified
|
|
|
|
// @param double $high the highest number of value if verified
|
|
|
|
// @return bool true if $value is numeric and within the defined borders, false if $value is not numeric, no changes were made in this case
|
2006-08-14 17:04:57 +00:00
|
|
|
//
|
2006-08-13 21:51:15 +00:00
|
|
|
function verify_numeric(&$value, $low, $high = false) {
|
|
|
|
$number = trim($value);
|
|
|
|
$number = str_replace('o', '0', $number);
|
|
|
|
$number = str_replace('O', '0', $number);
|
|
|
|
$number = str_replace('x', '', $number); //if someone enters '0x100'
|
|
|
|
$number = str_replace(',', '.', $number); // replace the german decimal separator
|
|
|
|
// if no value was entered and this is ok
|
|
|
|
if ($number=='' && $low=='') return true;
|
2006-10-31 17:14:03 +00:00
|
|
|
|
2006-08-13 21:51:15 +00:00
|
|
|
// the supplied value contains alphabetic characters
|
|
|
|
if (!is_numeric($number)) return false;
|
2006-10-31 17:14:03 +00:00
|
|
|
|
2006-08-13 21:51:15 +00:00
|
|
|
if ($number < $low) $number = $low;
|
|
|
|
if ($high) {
|
|
|
|
if ($number > $high) $number = $high;
|
|
|
|
}
|
|
|
|
$value = (double)$number;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-01-03 18:07:44 +00:00
|
|
|
// Generate a "select" HTML element from an array of values
|
|
|
|
function select_from_array($name, $array, $selection) {
|
|
|
|
$out = "<select name=\"$name\">";
|
|
|
|
|
|
|
|
foreach ($array as $key => $value) {
|
|
|
|
if ($value) {
|
|
|
|
$out .= "<option ";
|
|
|
|
if ($key == $selection) {
|
|
|
|
$out .= "selected ";
|
|
|
|
}
|
|
|
|
$out .= "value=\"".$key."\">".$value."</option>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$out.= "</select>";
|
|
|
|
return $out;
|
|
|
|
}
|
|
|
|
|
2007-05-18 15:02:02 +00:00
|
|
|
// Convert to entities, while preserving already-encoded entities.
|
|
|
|
// Do NOT use if $str contains valid HTML tags.
|
2007-07-25 03:17:31 +00:00
|
|
|
//
|
2007-05-18 15:02:02 +00:00
|
|
|
function boinc_htmlentities($str) {
|
|
|
|
$str = html_entity_decode($str, ENT_COMPAT, "UTF-8");
|
|
|
|
$str = htmlentities($str, ENT_COMPAT, "UTF-8");
|
|
|
|
return $str;
|
|
|
|
}
|
|
|
|
|
2007-06-27 20:44:56 +00:00
|
|
|
function strip_bbcode($string){
|
|
|
|
return preg_replace("/((\[.+\])+?)(.+?)((\[\/.+\])+?)/","",$string);
|
|
|
|
}
|
|
|
|
|
2007-08-18 16:45:54 +00:00
|
|
|
function current_url() {
|
|
|
|
$url = "http";
|
|
|
|
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") {
|
|
|
|
$url .= "s";
|
|
|
|
}
|
|
|
|
$url .= "://";
|
|
|
|
$url .= $_SERVER['SERVER_NAME'];
|
|
|
|
$url .= ":".$_SERVER['SERVER_PORT'];
|
|
|
|
if (isset($_SERVER['REQUEST_URI'])) {
|
|
|
|
$url .= $_SERVER['REQUEST_URI'];
|
|
|
|
} else {
|
|
|
|
if ($_SERVER['QUERY_STRING']) {
|
|
|
|
$url .= "?".$_SERVER['QUERY_STRING'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $url;
|
|
|
|
}
|
|
|
|
|
2007-10-31 23:50:21 +00:00
|
|
|
function show_button($url, $text, $desc) {
|
2007-11-01 20:41:24 +00:00
|
|
|
echo "<a href=$url><input onClick=\"document.location.href='$url'\" class=btn type=button value=\"$text\" title=\"$desc\"></a>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
function show_image($src, $title, $height=null) {
|
|
|
|
$h = "";
|
|
|
|
if ($height) {
|
|
|
|
$h = "height=\"$height\"";
|
|
|
|
}
|
|
|
|
echo "<img border=0 title=\"$title\" alt=\"$title\" src=\"$src\" $h>";
|
2007-10-31 23:50:21 +00:00
|
|
|
}
|
|
|
|
|
2004-02-02 23:34:39 +00:00
|
|
|
?>
|