From 450f6808800bf6b3f1c0b5d8cfcbf84b0650987a Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 24 Apr 2014 09:41:23 -0700 Subject: [PATCH 01/15] client: detect NVIDIA driver version on Linux; from Matt Harvey --- client/gpu_nvidia.cpp | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/client/gpu_nvidia.cpp b/client/gpu_nvidia.cpp index f279f525c5..64a04f1ff6 100644 --- a/client/gpu_nvidia.cpp +++ b/client/gpu_nvidia.cpp @@ -47,6 +47,32 @@ using std::string; static void get_available_nvidia_ram(COPROC_NVIDIA &cc, vector& warnings); +static int nvidia_driver_version() { + int (*nvml_init)() = NULL; + int (*nvml_finish)() = NULL; + int (*nvml_driver)(char *f, unsigned int len) = NULL; + int dri_ver = 0; + void *handle = NULL; + char driver_string[81]; + + handle = dlopen("libnvidia-ml.so", RTLD_NOW); + if (!handle) goto end; + + nvml_driver = (int(*)(char *, unsigned int)) dlsym(handle, "nvmlSystemGetDriverVersion"); + nvml_init = (int(*)(void)) dlsym(handle, "nvmlInit"); + nvml_finish = (int(*)(void)) dlsym(handle, "nvmlShutdown"); + if (!nvml_driver || !nvml_init || !nvml_finish) goto end; + + if (nvml_init()) goto end; + if (nvml_driver(driver_string, 80)) goto end; + dri_ver = (int) (100. * atof(driver_string)); + +end: + if (nvml_finish) nvml_finish(); + if (handle) dlclose(handle); + return dri_ver; +} + // return 1/-1/0 if device 1 is more/less/same capable than device 2. // factors (decreasing priority): // - compute capability @@ -323,7 +349,7 @@ void COPROC_NVIDIA::get( #elif defined(__APPLE__) cc.display_driver_version = NSVersionOfRunTimeLibrary("cuda"); #else - cc.display_driver_version = 0; + cc.display_driver_version = nvidia_driver_version(); #endif have_cuda = true; cc.have_cuda = true; From 278f3fd37056d4d7852b1a4d0782dc6e0646d175 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 24 Apr 2014 09:41:59 -0700 Subject: [PATCH 02/15] web: use new DB API here and there; should be no visible changes --- html/inc/boinc_db.inc | 10 +++++++ html/inc/db.inc | 31 ++------------------- html/inc/forum.inc | 2 +- html/inc/host.inc | 2 +- html/inc/profile.inc | 2 +- html/inc/uotd.inc | 8 +++--- html/inc/util.inc | 5 ---- html/ops/credit_study.php | 2 +- html/ops/manage_user.php | 2 +- html/ops/mass_email_script.php | 2 +- html/ops/remind.php | 2 +- html/user/account_finish.php | 2 +- html/user/am_get_info.php | 6 ++-- html/user/am_set_info.php | 4 +-- html/user/create_account.php | 4 +-- html/user/create_account_action.php | 6 ++-- html/user/create_account_form.php | 8 +++--- html/user/create_team.php | 2 +- html/user/edit_email_action.php | 4 +-- html/user/edit_forum_preferences_action.php | 2 +- html/user/edit_passwd_action.php | 4 +-- html/user/forum_get_data.php | 2 +- html/user/forum_user_posts.php | 2 +- html/user/host_update_credit.php | 5 ++-- html/user/hosts_user.php | 4 +-- html/user/login_action.php | 4 +-- html/user/mail_passwd.php | 4 +-- html/user/openid_login.php | 8 +++--- html/user/opt_out.php | 4 +-- html/user/pm.php | 6 ++-- html/user/profile_menu.php | 2 +- html/user/profile_search_action.php | 4 +-- html/user/show_user.php | 6 ++-- html/user/team_email_list.php | 2 +- html/user/team_founder_transfer_action.php | 2 +- html/user/uotd.php | 4 +-- html/user/validate_email_addr.php | 4 +-- 37 files changed, 76 insertions(+), 97 deletions(-) diff --git a/html/inc/boinc_db.inc b/html/inc/boinc_db.inc index 8beb38d111..4b27165ae3 100644 --- a/html/inc/boinc_db.inc +++ b/html/inc/boinc_db.inc @@ -125,6 +125,16 @@ class BoincUser { } return self::$cache[$id]; } + static function lookup_auth($auth) { + $db = BoincDb::get(); + $auth = BoincDb::escape_string($auth); + return self::lookup("authenticator='$auth'"); + } + static function lookup_email_addr($email_addr) { + $db = BoincDb::get(); + $email_addr = BoincDb::escape_string($email_addr); + return self::lookup("email_addr='$email_addr'"); + } static function count($clause) { $db = BoincDb::get(); return $db->count('user', $clause); diff --git a/html/inc/db.inc b/html/inc/db.inc index b1a138d9de..f7a82fb0bc 100644 --- a/html/inc/db.inc +++ b/html/inc/db.inc @@ -22,6 +22,9 @@ require_once('../inc/boinc_db.inc'); // database-related functions. // Presentation code (HTML) shouldn't be here +// DEPRECATED; use boinc_db.inc instead. +// TODO: replace calls to these functions + function db_init_aux($try_replica=false) { $config = get_config(); $user = parse_config($config, ""); @@ -58,34 +61,6 @@ function db_init_aux($try_replica=false) { return 0; } -function lookup_user_auth($auth) { - $auth = BoincDb::escape_string($auth); - return BoincUser::lookup("authenticator='$auth'"); -} - -function lookup_user_id($id) { - return BoincUser::lookup_id($id); -} - -function lookup_user_email_addr($email_addr) { - $e = BoincDb::escape_string($email_addr); - return BoincUser::lookup("email_addr='$e'"); -} - -function lookup_user_name($name) { - // TODO: is the following double escaped? Why? - $name = BoincDb::escape_string($name); - $users = BoincUser::enum("name='".boinc_real_escape_string($name)."'"); - if (sizeof($users)==1) { - return $users[0]; - } - return null; -} - -function lookup_host($id) { - return BoincHost::lookup_id($id); -} - function lookup_team($id) { return BoincTeam::lookup_id($id); } diff --git a/html/inc/forum.inc b/html/inc/forum.inc index af55f6381c..9c169f2264 100644 --- a/html/inc/forum.inc +++ b/html/inc/forum.inc @@ -704,7 +704,7 @@ function show_post_and_context($post, $thread, $forum, $options, $n) { $content = output_transform($post->content, $options); $when = time_diff_str($post->timestamp, time()); - $user = lookup_user_id($post->user); + $user = BoincUser::lookup_id($post->user); $title = cleanup_title($thread->title); $m = $n%2; if ($post->hidden) { diff --git a/html/inc/host.inc b/html/inc/host.inc index 00e3bc5316..610973bef2 100644 --- a/html/inc/host.inc +++ b/html/inc/host.inc @@ -99,7 +99,7 @@ function show_host($host, $user, $ipprivate) { if ($x >= 0) $x="+$x"; row2(tra("Local Standard Time"), tra("UTC %1 hours", $x)); } else { - $owner = lookup_user_id($host->userid); + $owner = BoincUser::lookup_id($host->userid); if ($owner && $owner->show_hosts) { row2(tra("Owner"), user_links($owner)); } else { diff --git a/html/inc/profile.inc b/html/inc/profile.inc index 0f03765818..9f924e0b6c 100644 --- a/html/inc/profile.inc +++ b/html/inc/profile.inc @@ -166,7 +166,7 @@ function scale_image( // of said user's profile. function get_profile_summary($profile) { - $user = get_user_from_id($profile->userid); + $user = BoincUser::lookup_id($profile->userid); if (!$user || !$profile) { error_page(tra("Database error")); diff --git a/html/inc/uotd.inc b/html/inc/uotd.inc index c81e73c95b..0ab0ec32cb 100644 --- a/html/inc/uotd.inc +++ b/html/inc/uotd.inc @@ -16,7 +16,7 @@ // You should have received a copy of the GNU Lesser General Public License // along with BOINC. If not, see . -require_once('../inc/db.inc'); +require_once('../inc/boinc_db.inc'); require_once('../inc/email.inc'); require_once('../inc/profile.inc'); @@ -34,7 +34,7 @@ function uotd_thumbnail($profile, $user) { // show UOTD in a small box // function show_uotd($profile) { - $user = lookup_user_id($profile->userid); + $user = BoincUser::lookup_id($profile->userid); echo uotd_thumbnail($profile, $user); echo user_links($user, true)."
"; $x = output_transform($profile->response1); @@ -61,7 +61,7 @@ function select_uotd() { $assigned = getdate($current_uotd->uotd_time); $now = getdate(time()); if ($assigned['mday'] == $now['mday']) { - $user = lookup_user_id($current_uotd->userid); + $user = BoincUser::lookup_id($current_uotd->userid); echo "Already have UOTD for today\n"; generate_uotd_gadget($current_uotd, $user); exit(); @@ -107,7 +107,7 @@ function select_uotd() { exit(); } $profile = mysql_fetch_object($result); - $user = lookup_user_id($profile->userid); + $user = BoincUser::lookup_id($profile->userid); // if profile is "orphaned", delete it and try again // diff --git a/html/inc/util.inc b/html/inc/util.inc index 2541359954..6fc1f88482 100644 --- a/html/inc/util.inc +++ b/html/inc/util.inc @@ -96,11 +96,6 @@ function clear_cookie($name, $ops=false) { setcookie($name, '', time()-3600, $path); } -function get_user_from_id($id) { - if ($id) return lookup_user_id($id); - return NULL; -} - $g_logged_in_user = null; $got_logged_in_user = false; diff --git a/html/ops/credit_study.php b/html/ops/credit_study.php index 1103dec3bd..20441ca814 100644 --- a/html/ops/credit_study.php +++ b/html/ops/credit_study.php @@ -97,7 +97,7 @@ function get_data() { $found_zero = false; while ($result = mysql_fetch_object($r2)) { if ($result->granted_credit==0) continue; // skip invalid - $host = lookup_host($result->hostid); + $host = BoincHost::lookup_id($result->hostid); $r = new StdClass; $r->cpu_time = $result->cpu_time; $r->p_fpops = $host->p_fpops; diff --git a/html/ops/manage_user.php b/html/ops/manage_user.php index d291d4ec4e..f3951c348f 100644 --- a/html/ops/manage_user.php +++ b/html/ops/manage_user.php @@ -294,7 +294,7 @@ if (!$id) { $id = post_int("userid", true); } if (!$id) error_page("No ID given"); -$user = lookup_user_id($id); +$user = BoincUser::lookup_id($id); if (!$user) error_page("No such user: $id"); BoincForumPrefs::lookup($user); diff --git a/html/ops/mass_email_script.php b/html/ops/mass_email_script.php index 441e14b1be..4872c697f8 100755 --- a/html/ops/mass_email_script.php +++ b/html/ops/mass_email_script.php @@ -311,7 +311,7 @@ if (!$USE_PHPMAILER) { $email_files = read_email_files(); if ($globals->userid) { - $user = lookup_user_id($globals->userid); + $user = BoincUser::lookup_id($globals->userid); if (!$user) { echo "no such user\n"; } else { diff --git a/html/ops/remind.php b/html/ops/remind.php index e14bf75d57..2313ede4fb 100755 --- a/html/ops/remind.php +++ b/html/ops/remind.php @@ -320,7 +320,7 @@ if (!$USE_PHPMAILER) { $email_files = read_email_files(); if ($globals->userid) { - $user = lookup_user_id($globals->userid); + $user = BoincUser::lookup_id($globals->userid); if (!$user) { echo "No such user: $globals->userid\n"; exit(); diff --git a/html/user/account_finish.php b/html/user/account_finish.php index 12c6b4f369..3a0acd3918 100644 --- a/html/user/account_finish.php +++ b/html/user/account_finish.php @@ -27,7 +27,7 @@ require_once('../inc/countries.inc'); check_get_args(array("auth")); $auth = get_str("auth"); -$user = lookup_user_auth($auth); +$user = BoincUser::lookup_auth($auth); if (!$user) { error_page("no such account"); } diff --git a/html/user/am_get_info.php b/html/user/am_get_info.php index 2a841b85ca..54f5b3056e 100644 --- a/html/user/am_get_info.php +++ b/html/user/am_get_info.php @@ -16,7 +16,7 @@ // You should have received a copy of the GNU Lesser General Public License // along with BOINC. If not, see . -require_once("../inc/db.inc"); +require_once("../inc/boinc_db.inc"); require_once("../inc/xml.inc"); xml_header(); @@ -27,7 +27,7 @@ if ($retval) xml_error($retval); check_get_args(array("account_key")); $auth = get_str("account_key"); -$user = lookup_user_auth($auth); +$user = BoincUser::lookup_auth($auth); if (!$user) { xml_error(ERR_DB_NOT_FOUND); } @@ -60,7 +60,7 @@ $user->project_prefs $user->venue"; if ($user->teamid) { - $team = lookup_team($user->teamid); + $team = BoincTeam::lookup_id_nocache($user->teamid); if ($team->userid == $user->id) { $ret = $ret . "\n"; } diff --git a/html/user/am_set_info.php b/html/user/am_set_info.php index c2e684fdf1..87d1b9f201 100644 --- a/html/user/am_set_info.php +++ b/html/user/am_set_info.php @@ -82,7 +82,7 @@ if ($auth) { $password_hash = get_str("password_hash", true); } -$user = lookup_user_auth($auth); +$user = BoincUser::lookup_auth($auth); if (!$user) { xml_error(ERR_DB_NOT_FOUND); } @@ -161,7 +161,7 @@ if (!is_null($teamid)) { if ($teamid==0) { user_quit_team($user); } else { - $team = lookup_team($teamid); + $team = BoincTeam::lookup_id_nocache($teamid); if ($team && $team->joinable) { user_join_team($team, $user); } diff --git a/html/user/create_account.php b/html/user/create_account.php index cc47d7ff65..cab335f328 100644 --- a/html/user/create_account.php +++ b/html/user/create_account.php @@ -18,7 +18,7 @@ // RPC handler for account creation -require_once("../inc/db.inc"); +require_once("../inc/boinc_db.inc"); require_once("../inc/util.inc"); require_once("../inc/email.inc"); require_once("../inc/xml.inc"); @@ -67,7 +67,7 @@ if (strlen($passwd_hash) != 32) { xml_error(-1, "password hash length not 32"); } -$user = lookup_user_email_addr($email_addr); +$user = BoincUser::lookup_email_addr($email_addr); if ($user) { if ($user->passwd_hash != $passwd_hash) { xml_error(ERR_DB_NOT_UNIQUE); diff --git a/html/user/create_account_action.php b/html/user/create_account_action.php index e0322f5216..86a75f23af 100644 --- a/html/user/create_account_action.php +++ b/html/user/create_account_action.php @@ -53,8 +53,8 @@ if ($privatekey) { // $teamid = post_int("teamid", true); if ($teamid) { - $team = lookup_team($teamid); - $clone_user = lookup_user_id($team->userid); + $team = BoincTeam::lookup_id($teamid); + $clone_user = BoincUser::lookup_id($team->userid); if (!$clone_user) { error_page("User $userid not found"); } @@ -83,7 +83,7 @@ $new_email_addr = strtolower(post_str("new_email_addr")); if (!is_valid_email_addr($new_email_addr)) { show_error(tra("Invalid email address: you must enter a valid address of the form name@domain")); } -$user = lookup_user_email_addr($new_email_addr); +$user = BoincUser::lookup_email_addr($new_email_addr); if ($user) { show_error(tra("There's already an account with that email address.")); } diff --git a/html/user/create_account_form.php b/html/user/create_account_form.php index 355b97769d..c4d0b8cf67 100644 --- a/html/user/create_account_form.php +++ b/html/user/create_account_form.php @@ -1,7 +1,7 @@ . -require_once('../inc/db.inc'); +require_once('../inc/boinc_db.inc'); require_once('../inc/util.inc'); require_once('../inc/countries.inc'); require_once('../inc/translation.inc'); @@ -53,8 +53,8 @@ echo " $teamid = get_int("teamid", true); if ($teamid) { - $team = lookup_team($teamid); - $user = lookup_user_id($team->userid); + $team = BoincTeam::lookup_id($teamid); + $user = BoincUser::lookup_id($team->userid); if (!$user) { echo "No such user"; } else { diff --git a/html/user/create_team.php b/html/user/create_team.php index 86b35bf3ff..99856f3f2a 100644 --- a/html/user/create_team.php +++ b/html/user/create_team.php @@ -28,7 +28,7 @@ $retval = db_init_xml(); if ($retval) xml_error($retval); $auth = get_str("account_key"); -$user = lookup_user_auth($auth); +$user = BoincUser::lookup_auth($auth); if (!$user) { xml_error(ERR_DB_NOT_FOUND); } diff --git a/html/user/edit_email_action.php b/html/user/edit_email_action.php index 784951bb93..26304ba2dd 100644 --- a/html/user/edit_email_action.php +++ b/html/user/edit_email_action.php @@ -1,7 +1,7 @@ email_addr) { echo tra("New email address is same as existing address. Nothing is changed."); } else { - $existing = lookup_user_email_addr($email_addr); + $existing = BoincUser::lookup_email_addr($email_addr); if ($existing) { echo tra("There's already an account with that email address"); } else { diff --git a/html/user/edit_forum_preferences_action.php b/html/user/edit_forum_preferences_action.php index c8f7bbf58f..7b5647b0f8 100644 --- a/html/user/edit_forum_preferences_action.php +++ b/html/user/edit_forum_preferences_action.php @@ -21,7 +21,7 @@ require_once("../inc/forum.inc"); require_once("../inc/image.inc"); // Avatar scaling if (post_str("account_key", true) != null) { - $user = lookup_user_auth(post_str("account_key")); + $user = BoincUser::lookup_auth(post_str("account_key")); $rpc = true; } else { $user = get_logged_in_user(); diff --git a/html/user/edit_passwd_action.php b/html/user/edit_passwd_action.php index 51ec7646d3..79a24a411e 100644 --- a/html/user/edit_passwd_action.php +++ b/html/user/edit_passwd_action.php @@ -45,12 +45,12 @@ if (strlen($passwd)<$min_passwd_length) { error_page(tra("New password is too short: minimum password length is %1 characters.", $min_passwd_length)); } if ($auth) { - $user = lookup_user_auth($auth); + $user = BoincUser::lookup_auth($auth); if (!$user) { error_page(tra("Invalid account key")); } } else { - $user = lookup_user_email_addr($email_addr); + $user = BoincUser::lookup_email_addr($email_addr); if (!$user) { error_page(tra("No account with that email address was found")); } diff --git a/html/user/forum_get_data.php b/html/user/forum_get_data.php index c7025ec784..36e9b7248e 100644 --- a/html/user/forum_get_data.php +++ b/html/user/forum_get_data.php @@ -35,7 +35,7 @@ if ($method != "user_posts" && $method != "user_threads") { } $userid = get_int("userid", true); -$user = lookup_user_id($userid); +$user = BoincUser::lookup_id($userid); if (!$user) { xml_error(ERR_DB_NOT_FOUND); } diff --git a/html/user/forum_user_posts.php b/html/user/forum_user_posts.php index 825052fec0..eb8e9896da 100644 --- a/html/user/forum_user_posts.php +++ b/html/user/forum_user_posts.php @@ -30,7 +30,7 @@ $offset = get_int("offset", true); if (!$offset) $offset=0; $items_per_page = 20; -$user = lookup_user_id($userid); +$user = BoincUser::lookup_id($userid); $logged_in_user = get_logged_in_user(false); // Policy for what to show: diff --git a/html/user/host_update_credit.php b/html/user/host_update_credit.php index 58d799aa2f..4edb2a6245 100644 --- a/html/user/host_update_credit.php +++ b/html/user/host_update_credit.php @@ -16,20 +16,19 @@ // You should have received a copy of the GNU Lesser General Public License // along with BOINC. If not, see . -require_once("../inc/db.inc"); +require_once("../inc/boinc_db.inc"); require_once("../inc/util.inc"); require_once("../inc/host.inc"); check_get_args(array("hostid")); -db_init(); $user = get_logged_in_user(); page_head(tra("Updating computer credit")); $hostid = get_int("hostid"); -$host = lookup_host($hostid); +$host = BoincHost::lookup_id($hostid); if (!$host || $host->userid != $user->id) { error_page(We have no record of that computer"); } diff --git a/html/user/hosts_user.php b/html/user/hosts_user.php index c4c4f70c0c..ecb36e76ce 100644 --- a/html/user/hosts_user.php +++ b/html/user/hosts_user.php @@ -1,7 +1,7 @@ id == $userid) { $userid = 0; } if ($userid) { - $user = lookup_user_id($userid); + $user = BoincUser::lookup_id($userid); if (!$user) { error_page("No such user"); } diff --git a/html/user/login_action.php b/html/user/login_action.php index ee82dd6a2b..b1d0709291 100644 --- a/html/user/login_action.php +++ b/html/user/login_action.php @@ -33,7 +33,7 @@ $email_addr = strtolower(sanitize_tags(post_str("email_addr", true))); $passwd = post_str("passwd", true); if ($email_addr && $passwd) { - $user = lookup_user_email_addr($email_addr); + $user = BoincUser::lookup_email_addr($email_addr); if (!$user) { page_head("No such account"); echo "No account with email address $email_addr exists. @@ -111,7 +111,7 @@ if (substr($user->authenticator, 0, 1) == 'x'){ //User has been bad so we are going to take away ability to post for awhile. error_page("This account has been administratively disabled."); } -$user = lookup_user_auth($authenticator); +$user = BoincUser::lookup_auth($authenticator); if (!$user) { page_head("Login failed"); echo "There is no account with that authenticator. diff --git a/html/user/mail_passwd.php b/html/user/mail_passwd.php index b57b273c14..8ddbf8a47a 100644 --- a/html/user/mail_passwd.php +++ b/html/user/mail_passwd.php @@ -1,7 +1,7 @@ userid); + // $team = BoincTeam::lookup_id($teamid); + // $clone_user = BoincUser::lookup_id($team->userid); // if (!$clone_user) { // echo "User $userid not found"; // exit(); @@ -110,7 +110,7 @@ try { name@domain" ); } - $user = lookup_user_email_addr($new_email_addr); + $user = BoincUser::lookup_email_addr($new_email_addr); if (!$user) { $passwd_hash = random_string(); diff --git a/html/user/opt_out.php b/html/user/opt_out.php index 94a83988ff..a60f2e464e 100644 --- a/html/user/opt_out.php +++ b/html/user/opt_out.php @@ -1,7 +1,7 @@ update("opened=1"); } echo " $checkbox $msg->subject \n"; - echo "".user_links(get_user_from_id($msg->senderid)); + echo "".user_links(BoincUser::lookup_id($msg->senderid)); show_block_link($msg->senderid); echo "
".time_str($msg->date)."\n"; echo "".output_transform($msg->content, $options)."

"; @@ -200,12 +200,12 @@ function do_send($logged_in_user) { $user = explode(" ", $username); if (is_numeric($user[0])) { // user ID is gived $userid = $user[0]; - $user = lookup_user_id($userid); + $user = BoincUser::lookup_id($userid); if ($user == null) { pm_form($replyto, $userid, tra("Could not find user with id %1", $userid)); } } else { - $user = lookup_user_name($username); + $user = BoincUser:lookup_name($username); if ($user == null) { pm_form($replyto, $userid, tra("Could not find user with username %1", $username)); } elseif ($user == -1) { // Non-unique username diff --git a/html/user/profile_menu.php b/html/user/profile_menu.php index 227caba30a..48c930ad4d 100644 --- a/html/user/profile_menu.php +++ b/html/user/profile_menu.php @@ -46,7 +46,7 @@ row1($UOTD_heading); echo ""; $profile = get_current_uotd(); if ($profile) { - $user = lookup_user_id($profile->userid); + $user = BoincUser::lookup_id($profile->userid); echo uotd_thumbnail($profile, $user); echo user_links($user)."
"; $resp = output_transform($profile->response1); diff --git a/html/user/profile_search_action.php b/html/user/profile_search_action.php index 92d5056e71..76c446da8b 100644 --- a/html/user/profile_search_action.php +++ b/html/user/profile_search_action.php @@ -1,7 +1,7 @@ userid); + $user = BoincUser::lookup_id($profile->userid); echo "".user_links($user)."".date_str($user->create_time)."$user->country".(int)$user->total_credit."".(int)$user->expavg_credit."\n"; } diff --git a/html/user/show_user.php b/html/user/show_user.php index 74fbf167d2..494f425f30 100644 --- a/html/user/show_user.php +++ b/html/user/show_user.php @@ -45,10 +45,10 @@ if ($format=="xml"){ $retval = db_init_xml(); if ($retval) xml_error($retval); if ($auth){ - $user = lookup_user_auth($auth); + $user = BoincUser::lookup_auth($auth); $show_hosts = true; } else { - $user = lookup_user_id($id); + $user = BoincUser::lookup_id($id); $show_hosts = false; } if (!$user) xml_error(ERR_DB_NOT_FOUND); @@ -70,7 +70,7 @@ if ($format=="xml"){ $community_links = $data->clo; } else { // No data was found, generate new data for the cache and store it - $user = lookup_user_id($id); + $user = BoincUser::lookup_id($id); if (!$user) { error_page("No such user $id"); } diff --git a/html/user/team_email_list.php b/html/user/team_email_list.php index 9e5fe1e57e..687421d8ec 100644 --- a/html/user/team_email_list.php +++ b/html/user/team_email_list.php @@ -38,7 +38,7 @@ if ($xml) { xml_error(ERR_DB_NOT_FOUND); } $account_key = get_str('account_key', true); - $user = lookup_user_auth($account_key); + $user = Boinc_user::lookup_auth($account_key); $show_email = ($user && is_team_founder($user, $team)); echo "\n"; $users = BoincUser::enum_fields("id, email_addr, send_email, name, total_credit, expavg_credit, expavg_time, has_profile, donated, country, cross_project_id, create_time, url", "teamid=$team->id"); diff --git a/html/user/team_founder_transfer_action.php b/html/user/team_founder_transfer_action.php index 7924f28d63..4f80c86562 100644 --- a/html/user/team_founder_transfer_action.php +++ b/html/user/team_founder_transfer_action.php @@ -39,7 +39,7 @@ if (!$user->teamid) { } function send_founder_transfer_email($team, $user) { - $founder = lookup_user_id($team->userid); + $founder = BoincUser::lookup_id($team->userid); // send founder a private message for good measure diff --git a/html/user/uotd.php b/html/user/uotd.php index 73dc24429c..c793194f58 100644 --- a/html/user/uotd.php +++ b/html/user/uotd.php @@ -1,7 +1,7 @@ userid); + $user = BoincUser::lookup_id($profile->userid); page_head(tra("User of the Day for %1: %2", $d, $user->name)); start_table(); show_profile($user, get_logged_in_user(false)); diff --git a/html/user/validate_email_addr.php b/html/user/validate_email_addr.php index 8195ac21b4..0b80dc98d7 100644 --- a/html/user/validate_email_addr.php +++ b/html/user/validate_email_addr.php @@ -1,7 +1,7 @@ Date: Thu, 24 Apr 2014 09:54:13 -0700 Subject: [PATCH 03/15] web: tweaks to last commit --- html/inc/boinc_db.inc | 11 +++++++++++ html/user/pm.php | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/html/inc/boinc_db.inc b/html/inc/boinc_db.inc index 4b27165ae3..1c471aa109 100644 --- a/html/inc/boinc_db.inc +++ b/html/inc/boinc_db.inc @@ -135,6 +135,17 @@ class BoincUser { $email_addr = BoincDb::escape_string($email_addr); return self::lookup("email_addr='$email_addr'"); } + static function lookup_name($name) { + $name = BoincDb::escape_string($name); + $users = BoincUser::enum("name='$name'"); + switch (sizeof($users)) { + case 1: + return $users[0]; + case 0: + return null; + } + return -1; + } static function count($clause) { $db = BoincDb::get(); return $db->count('user', $clause); diff --git a/html/user/pm.php b/html/user/pm.php index 026dd36adb..092c91e24f 100644 --- a/html/user/pm.php +++ b/html/user/pm.php @@ -205,7 +205,7 @@ function do_send($logged_in_user) { pm_form($replyto, $userid, tra("Could not find user with id %1", $userid)); } } else { - $user = BoincUser:lookup_name($username); + $user = BoincUser::lookup_name($username); if ($user == null) { pm_form($replyto, $userid, tra("Could not find user with username %1", $username)); } elseif ($user == -1) { // Non-unique username From a67819e42aa717072ae0bb3e9f18895367552049 Mon Sep 17 00:00:00 2001 From: Rytis Slatkevicius Date: Fri, 25 Apr 2014 11:16:06 +0300 Subject: [PATCH 04/15] Split select name from file filter regexp in sandbox_file_select; optionally allow selection of an empty value. --- html/inc/sandbox.inc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/html/inc/sandbox.inc b/html/inc/sandbox.inc index 9b67f98aae..21784a8cde 100644 --- a/html/inc/sandbox.inc +++ b/html/inc/sandbox.inc @@ -104,11 +104,17 @@ function sandbox_file_names($user) { // return a \n"; + if ($allow_none) { + $x .= "\n"; + } $files = sandbox_file_names($user); foreach ($files as $f) { - if(preg_match("/$select_name/",$f)){ + if(preg_match("/$regexp/",$f)){ $x .= "\n"; } } From 166d9f46c06e7367ec3665395cf26d3b4bac2c59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rytis=20Slatkevi=C4=8Dius?= Date: Fri, 25 Apr 2014 15:22:46 +0300 Subject: [PATCH 05/15] If sandbox link file does not exist, return an error --- html/inc/sandbox.inc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/html/inc/sandbox.inc b/html/inc/sandbox.inc index 21784a8cde..4b94656816 100644 --- a/html/inc/sandbox.inc +++ b/html/inc/sandbox.inc @@ -65,6 +65,7 @@ function sandbox_lf_exist($user, $md5) { // parse a link file and return (error, size, md5) // function sandbox_parse_link_file($path) { + if (!file_exists($path)) { return array(true, null, null); } $x = file_get_contents($path); $n = sscanf($x, "%s %d %s", $s, $size, $md5); if ($n != 3) return array(true, null, null); @@ -110,7 +111,7 @@ function sandbox_file_select($user, $select_name, $regexp = null, $allow_none = } $x = " From 5b62645853b1ea87393ebfec7fe687f6002f2c62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rytis=20Slatkevi=C4=8Dius?= Date: Tue, 29 Apr 2014 10:23:13 +0300 Subject: [PATCH 14/15] Add missing directory separator to the last commit --- html/inc/sandbox.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html/inc/sandbox.inc b/html/inc/sandbox.inc index 52d024fabc..5a9da3dc76 100644 --- a/html/inc/sandbox.inc +++ b/html/inc/sandbox.inc @@ -32,7 +32,7 @@ function sandbox_dir($user) { if (!is_dir($dir)) { mkdir($dir); } - $d = $dir."$user->id"; + $d = "$dir/$user->id"; if (!is_dir($d)) { mkdir($d); } From e9d5a08edac27860eb88195987701ea3c21ac9a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rytis=20Slatkevi=C4=8Dius?= Date: Tue, 29 Apr 2014 10:43:39 +0300 Subject: [PATCH 15/15] Load job input file information from the database instead of checking download dir (fixes remote files). --- html/inc/sandbox.inc | 2 +- html/user/submit.php | 23 +++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/html/inc/sandbox.inc b/html/inc/sandbox.inc index 5a9da3dc76..b52176755a 100644 --- a/html/inc/sandbox.inc +++ b/html/inc/sandbox.inc @@ -27,7 +27,7 @@ require_once("../inc/dir_hier.inc"); // if (!function_exists("sandbox_dir")){ function sandbox_dir($user) { - $dir = parse_str(get_config(), "sandbox_dir"); + $dir = parse_config(get_config(), ""); if (!$dir) { $dir = "../../sandbox/"; } if (!is_dir($dir)) { mkdir($dir); diff --git a/html/user/submit.php b/html/user/submit.php index 04451fe4ce..7db0b370b3 100644 --- a/html/user/submit.php +++ b/html/user/submit.php @@ -409,21 +409,19 @@ function handle_query_job($user) { table_header("Logical name
(click to view)", "Size (bytes)", "MD5" ); - $fanout = parse_config(get_config(), ""); - $download_dir = parse_config(get_config(), ""); foreach ($x->workunit->file_ref as $fr) { $pname = (string)$fr->file_name; $lname = (string)$fr->open_name; - $dir = filename_hash($pname, $fanout); - $path = $download_dir."/$dir/$pname"; - $md5 = md5_file($path); - $s = stat($path); - $size = $s['size']; - table_row( - "$lname", - $size, - $md5 - ); + foreach ($x->file_info as $fi) { + if ((string)$fi->name == $pname) { + table_row( + "url>$lname", + $fi->nbytes, + $fi->md5_cksum + ); + break; + } + } } end_table(); @@ -435,6 +433,7 @@ function handle_query_job($user) { ); $results = BoincResult::enum("workunitid=$wuid"); $upload_dir = parse_config(get_config(), ""); + $fanout = parse_config(get_config(), ""); foreach($results as $result) { echo " id>$result->id · $result->name