#!/usr/local/bin/php new userID if ($team_field_map[$i] == 'userid') { $result = mysql_query("SELECT * FROM user WHERE seti_id = " . $team_data[$i]); if ($result) { $row = mysql_fetch_assoc($result); } else { print "DB error.\n"; exit(); } $team_data[$i] = $row['id']; } print $team_field_map[$i] . ": " . addslashes(clean_newlines(trim($team_data[$i]))) . "\n"; if (!$first_field) { $query = $query . ", "; } else { $first_field = false; } $query = $query . $team_field_map[$i] . " = '" . addslashes(clean_newlines(trim($team_data[$i]))) . "'"; } } echo "QUERY: $query\n"; mysql_query($query); $num++; } fclose($fd); // Wrapping up. print "Re-linking team IDs and sending notification emails...\n"; $result = mysql_query("SELECT * FROM user WHERE seti_id IS NOT NULL"); while ($user = mysql_fetch_assoc($result)) { // Relink team ID. if (!is_null($user['teamid'])) { $result2 = mysql_query("SELECT * FROM team WHERE seti_id = " . $user['teamid']); $team = mysql_fetch_assoc($result2); $result2 = mysql_query("UPDATE user SET teamid = " . $team['id'] . " WHERE id = " . $user['id']); } // Send out email. split_munged_email_addr($user['email_addr'], $user['authenticator'], $address); $body = "Your SETI@Home account has been transferred to BOINC. Your authenticator is\n\n" . $user['authenticator']; //mail($address, "Your SETI@Home BOINC account is ready!", $body); } print "Migration Complete.\n"; } function clean_newlines($string) { return ereg_replace('\\\0d\\\0a', "\n", $string); } /** Flat file traversal functions */ function get_row($descriptor, $keys, $delim) { $data = NULL; $empty = true; for ($i=0; $i < count($keys); $i++) { $field = get_next_field($descriptor, $delim); if (!is_null($keys[$i])) { $data[$i] = $field; if (!empty($field)) $empty = false; } } if ($empty) { return NULL; } return $data; } function get_next_field($descriptor, $delim) { $data = NULL; $pos = 0; while (($char = fgetc($descriptor)) !== FALSE) { if ($char == $delim) { if (!($pos > 0 && $data[($pos-1)] == '\\')) { return $data; } } $data = $data . $char; $pos++; } return NULL; } /** Functions copied over from util.inc */ function random_string() { return md5(uniqid(rand())); } 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; } function jd_to_unix($raw_jd) { $jd = floor($raw_jd); $jtime = $raw_jd - $jd; $total_secs = 86400 * ($raw_jd - $jd); $hours = floor($total_secs / 3600); $minutes = floor(($total_secs - (3600 * $hours)) / 60); $seconds = floor(($total_secs - (3600 * $hours) - (60 * $minutes))); // Calculate Gregorian date $l = $jd + 68569; $n = floor(( 4 * $l ) / 146097); $l = $l - floor((146097 * $n + 3 ) / 4); $i = floor(( 4000 * ( $l + 1 ) ) / 1461001); $l = floor($l - ( 1461 * $i ) / 4 + 31); $j = floor(( 80 * $l ) / 2447); $d = floor($l - ( 2447 * $j ) / 80); $l = floor($j / 11); $m = $j + 2 - ( 12 * $l ); $y = 100 * ( $n - 49 ) + $i + $l; return mktime($hours, $minutes, $seconds, $m, $d, $y); } function move_user_pic($img_name, $userid) { $img_name = trim($img_name); $filename = SETI_IMAGE_PATH . $img_name; $filename_sm = SETI_IMAGE_PATH . 'sm_' . $img_name; if (file_exists($filename)) { $dotpos = strrpos($img_name, "."); $name = substr($img_name, 0, $dotpos); $ext = strrchr($img_name, "."); if ($ext == '.jpg' || $ext == '.jpeg') { shell_exec("mv $filename " . BOINC_IMAGE_PATH . $userid . ".jpg"); shell_exec("mv $filename_sm " . BOINC_IMAGE_PATH . "$userid . "_sm.jpg"); return true; } else if ($ext == '.png' || $ext == '.gif') { shell_exec("convert $filename jpg:" . BOINC_IMAGE_PATH . $userid . ".jpg"); shell_exec("convert $filename_sm jpg:" . BOINC_IMAGE_PATH . $userid . "_sm.jpg"); return true; } else { print "Failed to move image $filename"; return false; } } print "Image $filename does not exist!\n"; return false; }