2004-02-02 23:34:39 +00:00
|
|
|
<?php
|
2008-08-05 22:43:14 +00:00
|
|
|
// This file is part of BOINC.
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2008 University of California
|
|
|
|
//
|
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2004-02-02 23:34:39 +00:00
|
|
|
|
|
|
|
require_once('../inc/util.inc');
|
2007-10-27 20:38:12 +00:00
|
|
|
require_once('../inc/boinc_db.inc');
|
2004-02-02 23:34:39 +00:00
|
|
|
|
|
|
|
// database-related functions.
|
|
|
|
// Presentation code (HTML) shouldn't be here
|
|
|
|
|
2007-03-14 18:05:30 +00:00
|
|
|
function db_init_aux($try_replica=false) {
|
2004-06-30 18:53:35 +00:00
|
|
|
$config = get_config();
|
2010-11-04 18:20:57 +00:00
|
|
|
$user = parse_config($config, "<db_user>");
|
|
|
|
$pass = parse_config($config, "<db_passwd>");
|
2011-01-28 22:03:46 +00:00
|
|
|
$db_name = parse_config($config, "<db_name>");
|
2007-03-14 18:05:30 +00:00
|
|
|
$host = null;
|
2011-01-28 22:03:46 +00:00
|
|
|
if ($try_replica) {
|
|
|
|
$x = parse_config($config, "<replica_db_host>");
|
|
|
|
if ($x) {
|
|
|
|
$host = $x;
|
|
|
|
$x = parse_config($config, "<replica_db_user>");
|
|
|
|
if ($x) $user = $x;
|
|
|
|
$x = parse_config($config, "<replica_db_passwd>");
|
|
|
|
if ($x) $pass = $x;
|
|
|
|
$x = parse_config($config, "<replica_db_name>");
|
|
|
|
if ($x) $db_name = $x;
|
|
|
|
}
|
2007-03-14 18:05:30 +00:00
|
|
|
}
|
|
|
|
if ($host == null) {
|
2010-11-04 18:20:57 +00:00
|
|
|
$host = parse_config($config, "<db_host>");
|
2007-03-14 18:05:30 +00:00
|
|
|
}
|
2004-06-30 18:53:35 +00:00
|
|
|
if ($host == null) {
|
|
|
|
$host = "localhost";
|
|
|
|
}
|
2007-10-25 21:34:13 +00:00
|
|
|
$link = mysql_pconnect($host, $user, $pass);
|
|
|
|
if (!$link) {
|
2004-09-14 20:45:17 +00:00
|
|
|
return 1;
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
2007-10-25 21:34:13 +00:00
|
|
|
if (!mysql_select_db($db_name, $link)) {
|
|
|
|
echo "selecting $db_name\n";
|
2004-09-14 20:45:17 +00:00
|
|
|
return 2;
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-09-21 21:56:10 +00:00
|
|
|
function lookup_user_auth($auth) {
|
2007-11-12 22:28:17 +00:00
|
|
|
$auth = BoincDb::escape_string($auth);
|
2007-10-29 16:38:25 +00:00
|
|
|
return BoincUser::lookup("authenticator='$auth'");
|
2004-09-21 21:56:10 +00:00
|
|
|
}
|
|
|
|
|
2004-02-02 23:34:39 +00:00
|
|
|
function lookup_user_id($id) {
|
2007-10-29 16:38:25 +00:00
|
|
|
return BoincUser::lookup_id($id);
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
2005-02-25 00:41:22 +00:00
|
|
|
function lookup_user_email_addr($email_addr) {
|
2007-11-12 22:28:17 +00:00
|
|
|
$e = BoincDb::escape_string($email_addr);
|
|
|
|
return BoincUser::lookup("email_addr='$e'");
|
2005-02-25 00:41:22 +00:00
|
|
|
}
|
|
|
|
|
2007-04-29 14:22:28 +00:00
|
|
|
function lookup_user_name($name) {
|
2011-08-26 18:30:13 +00:00
|
|
|
// TODO: is the following double escaped? Why?
|
2007-11-12 22:28:17 +00:00
|
|
|
$name = BoincDb::escape_string($name);
|
2007-10-31 23:50:21 +00:00
|
|
|
$users = BoincUser::enum("name='".boinc_real_escape_string($name)."'");
|
|
|
|
if (sizeof($users)==1) {
|
|
|
|
return $users[0];
|
2007-04-29 14:22:28 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2004-02-02 23:34:39 +00:00
|
|
|
function lookup_host($id) {
|
2007-10-29 16:38:25 +00:00
|
|
|
return BoincHost::lookup_id($id);
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function lookup_team($id) {
|
2007-10-29 16:38:25 +00:00
|
|
|
return BoincTeam::lookup_id($id);
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
2006-10-30 09:03:52 +00:00
|
|
|
function lookup_team_founder($id) {
|
2007-10-29 16:38:25 +00:00
|
|
|
return BoincTeam::lookup("userid=$id");
|
2006-10-30 09:03:52 +00:00
|
|
|
}
|
|
|
|
|
2007-07-25 03:17:31 +00:00
|
|
|
function lookup_team_name($name) {
|
2007-11-12 22:28:17 +00:00
|
|
|
$name = BoincDb::escape_string($name);
|
2007-10-29 16:38:25 +00:00
|
|
|
return BoincTeam::lookup("name='$name'");
|
2007-07-25 03:17:31 +00:00
|
|
|
}
|
|
|
|
|
2004-02-02 23:34:39 +00:00
|
|
|
function lookup_wu($id) {
|
2007-11-12 22:39:56 +00:00
|
|
|
return BoincWorkunit::lookup_id($id);
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
2005-02-15 22:29:32 +00:00
|
|
|
function lookup_result($id) {
|
2007-11-12 22:39:56 +00:00
|
|
|
return BoincResult::lookup_id($id);
|
2005-02-15 22:29:32 +00:00
|
|
|
}
|
|
|
|
|
2004-02-02 23:34:39 +00:00
|
|
|
function lookup_app($id) {
|
2007-11-12 22:39:56 +00:00
|
|
|
return BoincApp::lookup_id($id);
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
2011-08-26 18:30:13 +00:00
|
|
|
// DEPRECATED: use BoincDb::escape_string where possible
|
|
|
|
//
|
2004-12-27 03:42:11 +00:00
|
|
|
// apply this to any user-supplied strings used in queries
|
2011-08-26 18:30:13 +00:00
|
|
|
//
|
2004-12-27 03:42:11 +00:00
|
|
|
function boinc_real_escape_string($x) {
|
2005-02-23 00:42:14 +00:00
|
|
|
if (version_compare(phpversion(),"4.3.0")>=0) {
|
2007-10-27 20:38:12 +00:00
|
|
|
return BoincDb::escape_string($x);
|
2005-02-23 00:42:14 +00:00
|
|
|
} else {
|
|
|
|
$x = str_replace("'", "\'", $x);
|
|
|
|
$x = str_replace("\"", "\\\"", $x);
|
|
|
|
return $x;
|
|
|
|
}
|
2004-12-27 03:42:11 +00:00
|
|
|
}
|
|
|
|
|
2004-08-06 12:12:26 +00:00
|
|
|
// escape a string for MySQL "like"
|
|
|
|
//
|
|
|
|
function escape_pattern($str) {
|
|
|
|
$str = str_replace('_', '\\\\_', $str);
|
|
|
|
$str = str_replace('%', '\\\\%', $str);
|
|
|
|
return $str;
|
|
|
|
}
|
|
|
|
|
2004-02-02 23:34:39 +00:00
|
|
|
?>
|