From 0fa6016fa49ef798c11598534ebb96bfaa86a64d Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 27 Dec 2023 12:07:48 -0800 Subject: [PATCH] Fix some PHP8 warnings am_set_info.php: some bad code here. --- html/inc/util.inc | 27 ++++++++++++++------------- html/user/am_set_info.php | 17 +++++++++++++++-- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/html/inc/util.inc b/html/inc/util.inc index cbfef28bc0c..cef3311a0b4 100644 --- a/html/inc/util.inc +++ b/html/inc/util.inc @@ -414,30 +414,30 @@ function error_page($msg) { exit(); } -// takes argument in second and returns a human formatted time string -// in the form D days + h Hours + m Min + s sec. +// convert time interval in seconds to a string of the form +// 'D days h hours m min s sec'. function time_diff($x, $res=3) { + $x = (int)$x; $days = (int)($x/86400); $hours = (int)(($x-$days*86400)/3600); $minutes = (int)(($x-$days*86400-$hours*3600)/60); - $seconds = (int)($x % 60); + $seconds = $x % 60; - $datestring = ""; + $s = ""; if ($days) { - $datestring .= "$days ".tra("days")." "; + $s .= "$days ".tra("days")." "; } - if ($res>0 && ($hours || strlen($datestring))) { - $datestring .= "$hours ".tra("hours")." "; + if ($res>0 && ($hours || strlen($s))) { + $s .= "$hours ".tra("hours")." "; } - if ($res>1 && ($minutes || strlen($datestring))) { - $datestring .= "$minutes ".tra("min")." "; + if ($res>1 && ($minutes || strlen($s))) { + $s .= "$minutes ".tra("min")." "; } - if ($res>2 && ($seconds)) { - $datestring .= "$seconds ".tra("sec")." "; + if ($res>2) { + $s .= "$seconds ".tra("sec")." "; } - - return $datestring; + return $s; } @@ -1019,6 +1019,7 @@ function get_app_types() { // "next_url" arguments (must be local, not full URLs) // function sanitize_local_url($x) { + if (!$x) return $x; $x = trim($x, "/"); if (strstr($x, "/")) return ""; if (strstr($x, "<")) return ""; diff --git a/html/user/am_set_info.php b/html/user/am_set_info.php index 18cc9f29fa8..538941ca09e 100644 --- a/html/user/am_set_info.php +++ b/html/user/am_set_info.php @@ -16,6 +16,10 @@ // You should have received a copy of the GNU Lesser General Public License // along with BOINC. If not, see . +// Handler for an RPC (used by account managers) +// to change attributes of an account. +// This probably shouldn't exist. + require_once("../inc/boinc_db.inc"); require_once("../inc/xml.inc"); require_once("../inc/team.inc"); @@ -27,6 +31,7 @@ // for now, just make sure it has the given start and end tags, // and at least one \n in the middle. // Ideally, we'd like to check that it's valid XML +// WHY NOT USE simplexml_load_string()?? // function bad_xml($text, $start, $end) { $text = trim($text); @@ -129,19 +134,27 @@ function success($x) { $show_hosts = BoincDb::escape_string($show_hosts); $venue = BoincDb::escape_string($venue); $send_changed_email_to_user = false; -$email_addr = strtolower($email_addr); +if ($email_addr) { + $email_addr = strtolower($email_addr); +} if ($email_addr && $email_addr != $user->email_addr) { + // is addr already in use? + // $tmpuser = BoincUser::lookup_email_addr($email_addr); if ($tmpuser) { xml_error(ERR_DB_NOT_UNIQUE, "There's already an account with that email address."); } - //check if the email address is included in previous_email_addr window. + // did another account use this addr previously? + // WHY CHECK THIS??? // $tmpuser = BoincUser::lookup_prev_email_addr($email_addr); if ($tmpuser) { xml_error(ERR_DB_NOT_UNIQUE, "Email address is already in use"); } + + // see if email addr was changed too recently + // if ($user->email_addr_change_time + 604800 > time()) { xml_error(ERR_BAD_EMAIL_ADDR, "Email address was changed within the past 7 days, please look for an email to $user->previous_email_addr if this email change is incorrect."); }