2018-04-18 22:18:23 +00:00
|
|
|
<?php
|
|
|
|
// This file is part of BOINC.
|
|
|
|
// https://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2018 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 <https://www.gnu.org/licenses/>.
|
|
|
|
|
2018-05-08 22:15:05 +00:00
|
|
|
require_once("../inc/common_defs.inc");
|
2018-04-30 22:10:12 +00:00
|
|
|
require_once("../inc/util.inc");
|
|
|
|
require_once("../inc/user.inc");
|
2018-06-08 09:07:18 +00:00
|
|
|
require_once("../inc/user_util.inc");
|
2018-04-30 22:10:12 +00:00
|
|
|
require_once("../inc/host.inc");
|
|
|
|
require_once("../inc/friend.inc");
|
2018-05-01 22:08:29 +00:00
|
|
|
require_once("../inc/boinc_db.inc");
|
2018-05-04 22:36:09 +00:00
|
|
|
require_once("../inc/submit_util.inc");
|
2018-05-02 20:36:57 +00:00
|
|
|
require_once("../project/project.inc");
|
2018-04-30 22:10:12 +00:00
|
|
|
|
2018-05-02 20:36:57 +00:00
|
|
|
// Constants for different methods of deleting accounts
|
|
|
|
// These correspond to the value used in the config.xml
|
|
|
|
// field of <enable_delete_account/>
|
2018-07-15 03:14:14 +00:00
|
|
|
//
|
2018-04-30 20:08:58 +00:00
|
|
|
define("DELETE_ACCOUNT_METHOD_OBFUSCATE", 1);
|
|
|
|
define("DELETE_ACCOUNT_METHOD_WIPE", 2);
|
2018-05-02 20:36:57 +00:00
|
|
|
define("DELETE_ACCOUNT_METHOD_PROJECT_DEFINED", 3);
|
2018-04-30 20:08:58 +00:00
|
|
|
|
2018-07-15 03:14:14 +00:00
|
|
|
// Constant for how long to sleep after invalidating authenticator
|
|
|
|
// before proceeding with rest of delete
|
|
|
|
// This is done on the chance that there is an active scheduler request
|
|
|
|
// in progress
|
|
|
|
//
|
2018-05-17 14:15:27 +00:00
|
|
|
if (!defined("DELETE_DELAY")) define("DELETE_DELAY", 2);
|
2018-05-16 20:43:49 +00:00
|
|
|
|
2018-07-15 03:14:14 +00:00
|
|
|
function is_delete_account_token_valid($userid, $token) {
|
|
|
|
if (!is_valid_token($userid, $token, TOKEN_TYPE_DELETE_ACCOUNT) ) {
|
2018-04-18 22:18:23 +00:00
|
|
|
sleep(LOGIN_FAIL_SLEEP_SEC);
|
2018-05-16 21:08:19 +00:00
|
|
|
return false;
|
2018-04-18 22:18:23 +00:00
|
|
|
}
|
2018-05-16 21:08:19 +00:00
|
|
|
return true;
|
2018-04-30 20:08:58 +00:00
|
|
|
}
|
|
|
|
|
2018-07-15 03:14:14 +00:00
|
|
|
// Save the minimal information from the user and their hosts
|
|
|
|
// so that db_dump can provide the information necessary
|
|
|
|
// to export the deleted_user and deleted_host files.
|
|
|
|
// These records are deleted after 60 days by the
|
|
|
|
// daily ops task "delete_expired_users_and_hosts.php"
|
|
|
|
//
|
2018-05-04 22:36:09 +00:00
|
|
|
function insert_deleted_records($user) {
|
|
|
|
BoincUserDeleted::insert_user($user);
|
|
|
|
BoincHostDeleted::insert_hosts_for_user($user);
|
|
|
|
}
|
|
|
|
|
2018-07-15 03:14:14 +00:00
|
|
|
// This method selects which delete method to utilize.
|
|
|
|
// Projects can implement their own method
|
|
|
|
// and make that a third mechanism if they have a need to
|
|
|
|
//
|
2018-04-30 22:10:12 +00:00
|
|
|
function delete_account($user) {
|
|
|
|
$config = get_config();
|
|
|
|
$enable_delete_account = parse_config($config, "<enable_delete_account>");
|
2018-07-15 03:14:14 +00:00
|
|
|
if ($enable_delete_account == DELETE_ACCOUNT_METHOD_OBFUSCATE) {
|
2018-04-30 22:10:12 +00:00
|
|
|
return obfuscate_account($user);
|
2018-07-15 03:14:14 +00:00
|
|
|
} else if ($enable_delete_account == DELETE_ACCOUNT_METHOD_WIPE) {
|
2018-04-30 22:10:12 +00:00
|
|
|
return wipe_account($user);
|
2018-07-15 03:14:14 +00:00
|
|
|
} else if ($enable_delete_account == DELETE_ACCOUNT_METHOD_PROJECT_DEFINED) {
|
2018-05-02 20:36:57 +00:00
|
|
|
return project_delete_account($user);
|
2018-05-16 21:08:19 +00:00
|
|
|
}
|
2018-07-15 03:14:14 +00:00
|
|
|
return ERR_NO_OPTION;
|
2018-04-30 20:08:58 +00:00
|
|
|
}
|
|
|
|
|
2018-07-15 03:14:14 +00:00
|
|
|
// invalidate the authenticator and then sleep for DELETE_DELAY seconds
|
|
|
|
// in order to let any active scheduler requests complete.
|
|
|
|
//
|
2018-05-16 20:43:49 +00:00
|
|
|
function invalidate_authenticator($user) {
|
|
|
|
$x = "deleted_".time()."_".random_string();
|
|
|
|
$retval = $user->update("authenticator='$x'");
|
2018-07-15 03:14:14 +00:00
|
|
|
if (!$retval) return ERR_DB_NOT_FOUND;
|
2018-05-16 20:43:49 +00:00
|
|
|
sleep(DELETE_DELAY);
|
2018-07-15 03:14:14 +00:00
|
|
|
return 0;
|
2018-05-16 20:43:49 +00:00
|
|
|
}
|
|
|
|
|
2018-04-30 22:10:12 +00:00
|
|
|
// "obfuscate" an account: leave user record (for DB consistency) but:
|
2018-05-16 20:43:49 +00:00
|
|
|
// - set email address and authenticator to "deleted_time_randomstring"
|
2018-04-30 22:10:12 +00:00
|
|
|
// - clear name, country, postal_code
|
|
|
|
// - remove from team
|
|
|
|
// - delete posts, subscriptions, and forum prefs
|
|
|
|
// - delete private messages (sent and received)
|
|
|
|
// - delete profile and associated image
|
|
|
|
// for each host:
|
|
|
|
// - clear domain_name, last_ip_addr
|
|
|
|
//
|
|
|
|
function obfuscate_account($user) {
|
2018-05-16 20:43:49 +00:00
|
|
|
$retval = invalidate_authenticator($user);
|
2018-07-15 03:14:14 +00:00
|
|
|
if ($retval) return $retval;
|
2018-05-04 22:36:09 +00:00
|
|
|
insert_deleted_records($user);
|
2018-04-30 22:10:12 +00:00
|
|
|
$x = "deleted_".time()."_".random_string();
|
|
|
|
$retval = $user->update("email_addr='$x', authenticator='$x', name='deleted', country='', postal_code='', has_profile=0");
|
2018-07-15 03:14:14 +00:00
|
|
|
if (!$retval) return ERR_DB_NOT_FOUND;
|
2018-04-30 22:10:12 +00:00
|
|
|
user_quit_team($user);
|
|
|
|
forum_delete_user($user);
|
|
|
|
pm_delete_user($user);
|
|
|
|
anonymize_hosts($user);
|
|
|
|
delete_profile($user);
|
2018-05-02 20:36:57 +00:00
|
|
|
delete_friends($user);
|
2018-07-15 03:14:14 +00:00
|
|
|
return 0;
|
2018-04-30 20:08:58 +00:00
|
|
|
}
|
|
|
|
|
2018-05-08 22:15:05 +00:00
|
|
|
|
|
|
|
// return true if the result is in progress
|
2018-07-15 03:14:14 +00:00
|
|
|
//
|
2018-05-08 22:15:05 +00:00
|
|
|
function is_in_progress($res) {
|
2018-07-15 03:14:14 +00:00
|
|
|
return ($res->server_state == RESULT_SERVER_STATE_IN_PROGRESS);
|
2018-05-08 22:15:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// returns true if the result finished successfully but is either
|
|
|
|
// pending validation or inconclusive
|
2018-07-15 03:14:14 +00:00
|
|
|
//
|
2018-05-08 22:15:05 +00:00
|
|
|
function is_over_but_not_validated($res) {
|
|
|
|
if ($res->server_state == RESULT_SERVER_STATE_OVER && $res->outcome == RESULT_OUTCOME_SUCCESS &&
|
|
|
|
($res->validate_state == VALIDATE_STATE_INIT || $res->validate_state == VALIDATE_STATE_INCONCLUSIVE) ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function transition_workunit($res) {
|
|
|
|
$now = time();
|
|
|
|
BoincWorkunit::update_aux("transition_time=$now where id=$res->workunitid");
|
|
|
|
}
|
|
|
|
|
|
|
|
// This method handles dissassociating the user from their results.
|
|
|
|
// It will cancel all in progress or returned, but not yet validated
|
|
|
|
// results for a user. For other results, it will set the userid and
|
|
|
|
// hostid fields to 0
|
2018-07-15 03:14:14 +00:00
|
|
|
//
|
2018-05-08 22:15:05 +00:00
|
|
|
function cancel_results_for_user($user) {
|
|
|
|
$ress = BoincResult::enum("userid = $user->id");
|
|
|
|
$cancel_clause="server_state=".RESULT_SERVER_STATE_OVER.", outcome=".RESULT_OUTCOME_CLIENT_DETACHED.", validate_state=".VALIDATE_STATE_INVALID;
|
|
|
|
$set_id_clause="hostid=0, userid=0";
|
2018-07-15 03:14:14 +00:00
|
|
|
foreach ($ress as $res) {
|
2018-05-16 20:43:49 +00:00
|
|
|
if (is_in_progress($res) || is_over_but_not_validated($res)) {
|
2018-05-08 22:15:05 +00:00
|
|
|
$res->update($cancel_clause.", ".$set_id_clause);
|
|
|
|
transition_workunit($res);
|
|
|
|
} else {
|
|
|
|
$res->update($set_id_clause);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-30 20:08:58 +00:00
|
|
|
// This method deletes all rows from the database associated with the user
|
2018-07-15 03:14:14 +00:00
|
|
|
//
|
2018-04-30 22:10:12 +00:00
|
|
|
function wipe_account($user) {
|
2018-05-16 20:43:49 +00:00
|
|
|
$retval = invalidate_authenticator($user);
|
2018-07-15 03:14:14 +00:00
|
|
|
if ($retval) return $retval;
|
2018-05-04 22:36:09 +00:00
|
|
|
|
2018-05-16 20:43:49 +00:00
|
|
|
//insert records into tables for db_dump to announce deletion of user
|
2018-07-15 03:14:14 +00:00
|
|
|
//
|
2018-05-04 22:36:09 +00:00
|
|
|
insert_deleted_records($user);
|
|
|
|
|
|
|
|
// delete remote submit user
|
2018-07-15 03:14:14 +00:00
|
|
|
//
|
2018-05-04 22:36:09 +00:00
|
|
|
delete_remote_submit_user($user); // from submit_util.inc
|
|
|
|
|
|
|
|
// remove user's team records
|
2018-07-15 03:14:14 +00:00
|
|
|
//
|
2018-05-04 22:36:09 +00:00
|
|
|
user_erase_team_owner($user); // from team.inc
|
|
|
|
user_quit_team($user); // from team.inc
|
|
|
|
user_erase_team_delta($user); // from team.inc
|
|
|
|
|
|
|
|
// Items that do not have logic elsewhere
|
|
|
|
// and do not have objects in boinc_db.inc
|
2018-07-15 03:14:14 +00:00
|
|
|
//
|
2018-05-16 20:43:49 +00:00
|
|
|
$db = BoincDb::get();
|
2018-05-04 22:36:09 +00:00
|
|
|
if (!$db) die("no DB connection");
|
|
|
|
$db->do_query("delete from credited_job where userid = $user->id");
|
|
|
|
$db->do_query("delete from donation_paypal where userid = $user->id");
|
|
|
|
$db->do_query("delete from banishment_vote where userid = $user->id");
|
|
|
|
$db->do_query("delete from post_ratings where post in ( select id from post where user = $user->id )");
|
|
|
|
$db->do_query("delete from post_ratings where user = $user->id");
|
|
|
|
$db->do_query("delete from msg_from_host where hostid in (select id from host where userid = $user->id )");
|
|
|
|
$db->do_query("delete from msg_to_host where hostid in (select id from host where userid = $user->id )");
|
|
|
|
$db->do_query("delete from sent_email where userid = $user->id");
|
|
|
|
|
|
|
|
//It is much faster to update results with single query
|
2018-07-15 03:14:14 +00:00
|
|
|
//
|
2018-05-08 22:15:05 +00:00
|
|
|
cancel_results_for_user($user);
|
2018-05-04 22:36:09 +00:00
|
|
|
|
|
|
|
BoincHostAppVersion::delete_for_user($user->id);
|
|
|
|
BoincHost::delete_for_user($user->id);
|
2018-05-24 17:02:43 +00:00
|
|
|
BoincConsent::delete_for_user($user->id);
|
2018-05-04 22:36:09 +00:00
|
|
|
|
|
|
|
// final action
|
|
|
|
delete_user($user); //from user_util.inc
|
2018-07-15 03:14:14 +00:00
|
|
|
return 0;
|
2018-05-17 14:15:27 +00:00
|
|
|
}
|