2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2005-08-05 22:00:19 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2005-08-05 22:00:19 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// 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.
|
2005-08-05 22:00:19 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2005-08-05 22:00:19 +00:00
|
|
|
// 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.
|
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2005-08-05 22:00:19 +00:00
|
|
|
|
2010-05-11 19:10:29 +00:00
|
|
|
#include "cpp.h"
|
|
|
|
|
2005-11-22 02:11:35 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include "boinc_win.h"
|
2010-05-11 19:10:29 +00:00
|
|
|
#else
|
2005-11-21 18:34:44 +00:00
|
|
|
#include "config.h"
|
2010-05-11 19:10:29 +00:00
|
|
|
#include <cstring>
|
2005-11-22 02:11:35 +00:00
|
|
|
#endif
|
|
|
|
|
2005-08-05 22:00:19 +00:00
|
|
|
#include "client_state.h"
|
|
|
|
#include "file_names.h"
|
|
|
|
#include "parse.h"
|
2005-09-22 08:46:51 +00:00
|
|
|
#include "filesys.h"
|
2007-02-21 16:26:51 +00:00
|
|
|
#include "str_util.h"
|
2009-11-05 18:02:51 +00:00
|
|
|
#include "url.h"
|
2007-06-22 20:17:08 +00:00
|
|
|
#include "util.h"
|
2005-10-26 05:43:36 +00:00
|
|
|
#include "client_msgs.h"
|
2008-10-14 23:07:40 +00:00
|
|
|
#include "log_flags.h"
|
2005-08-05 22:00:19 +00:00
|
|
|
|
|
|
|
#include "acct_setup.h"
|
|
|
|
|
2011-08-21 11:18:08 +00:00
|
|
|
void ACCOUNT_IN::parse(XML_PARSER& xp) {
|
2005-08-05 22:00:19 +00:00
|
|
|
url = "";
|
|
|
|
email_addr = "";
|
|
|
|
passwd_hash = "";
|
|
|
|
user_name = "";
|
2011-08-21 11:18:08 +00:00
|
|
|
team_name = "";
|
2016-02-19 15:40:49 +00:00
|
|
|
server_cookie = "";
|
2014-11-19 07:11:27 +00:00
|
|
|
ldap_auth = false;
|
2016-02-19 15:40:49 +00:00
|
|
|
server_assigned_cookie = false;
|
2005-08-05 22:00:19 +00:00
|
|
|
|
2011-08-27 18:32:47 +00:00
|
|
|
while (!xp.get_tag()) {
|
|
|
|
if (xp.parse_string("url", url)) continue;
|
|
|
|
if (xp.parse_string("email_addr", email_addr)) continue;
|
|
|
|
if (xp.parse_string("passwd_hash", passwd_hash)) continue;
|
|
|
|
if (xp.parse_string("user_name", user_name)) continue;
|
|
|
|
if (xp.parse_string("team_name", team_name)) continue;
|
2016-02-19 15:40:49 +00:00
|
|
|
if (xp.parse_string("server_cookie", server_cookie)) continue;
|
2014-11-19 07:11:27 +00:00
|
|
|
if (xp.parse_bool("ldap_auth", ldap_auth)) continue;
|
2016-02-19 15:40:49 +00:00
|
|
|
if (xp.parse_bool("server_assigned_cookie", server_assigned_cookie)) continue;
|
2011-08-21 11:18:08 +00:00
|
|
|
}
|
2005-08-11 06:52:19 +00:00
|
|
|
canonicalize_master_url(url);
|
2005-08-05 22:00:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int GET_PROJECT_CONFIG_OP::do_rpc(string master_url) {
|
|
|
|
int retval;
|
2006-03-01 10:10:22 +00:00
|
|
|
string url;
|
|
|
|
|
|
|
|
url = master_url;
|
|
|
|
canonicalize_master_url(url);
|
|
|
|
|
|
|
|
url += "get_project_config.php";
|
|
|
|
|
2005-10-26 05:43:36 +00:00
|
|
|
msg_printf(NULL, MSG_INFO,
|
2006-01-17 22:48:09 +00:00
|
|
|
"Fetching configuration file from %s", url.c_str()
|
2005-10-26 05:43:36 +00:00
|
|
|
);
|
2006-03-01 10:10:22 +00:00
|
|
|
|
2010-07-22 19:13:36 +00:00
|
|
|
retval = gui_http->do_rpc(
|
2011-06-12 20:58:43 +00:00
|
|
|
this, url.c_str(), GET_PROJECT_CONFIG_FILENAME, false
|
2010-07-22 19:13:36 +00:00
|
|
|
);
|
2005-08-05 22:00:19 +00:00
|
|
|
if (retval) {
|
2005-08-06 19:20:26 +00:00
|
|
|
error_num = retval;
|
2005-08-05 22:00:19 +00:00
|
|
|
} else {
|
2005-08-06 19:20:26 +00:00
|
|
|
error_num = ERR_IN_PROGRESS;
|
2005-08-05 22:00:19 +00:00
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2006-02-14 21:20:43 +00:00
|
|
|
void GET_PROJECT_CONFIG_OP::handle_reply(int http_op_retval) {
|
2005-08-05 22:00:19 +00:00
|
|
|
if (http_op_retval) {
|
2005-08-06 19:20:26 +00:00
|
|
|
error_num = http_op_retval;
|
2005-08-05 22:00:19 +00:00
|
|
|
} else {
|
2007-06-22 18:53:55 +00:00
|
|
|
error_num = read_file_string(GET_PROJECT_CONFIG_FILENAME, reply);
|
2005-08-05 22:00:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int LOOKUP_ACCOUNT_OP::do_rpc(ACCOUNT_IN& ai) {
|
|
|
|
int retval;
|
|
|
|
string url;
|
2006-03-01 10:49:11 +00:00
|
|
|
string parameter;
|
2005-08-05 22:00:19 +00:00
|
|
|
|
2006-03-01 10:10:22 +00:00
|
|
|
url = ai.url;
|
|
|
|
canonicalize_master_url(url);
|
2014-10-19 06:53:27 +00:00
|
|
|
url += "lookup_account.php";
|
|
|
|
|
2014-11-19 07:11:27 +00:00
|
|
|
if (ai.ldap_auth && !strchr(ai.email_addr.c_str(), '@')) {
|
2014-11-19 05:58:38 +00:00
|
|
|
// LDAP case
|
|
|
|
//
|
|
|
|
if (!is_https(ai.url.c_str())) return ERR_NEED_HTTPS;
|
|
|
|
url += "?ldap_auth=1&ldap_uid=";
|
2014-10-19 06:53:27 +00:00
|
|
|
parameter = ai.email_addr;
|
|
|
|
escape_url(parameter);
|
|
|
|
url += parameter;
|
|
|
|
|
2014-11-19 05:58:38 +00:00
|
|
|
url += "&passwd=";
|
2014-10-19 06:53:27 +00:00
|
|
|
parameter = ai.passwd_hash;
|
|
|
|
escape_url(parameter);
|
|
|
|
url += parameter;
|
2016-02-19 15:40:49 +00:00
|
|
|
} else if (ai.server_assigned_cookie) {
|
2016-02-08 20:21:11 +00:00
|
|
|
// Project assigned cookie
|
|
|
|
//
|
2016-02-19 15:40:49 +00:00
|
|
|
url += "?server_assigned_cookie=1&server_cookie=";
|
|
|
|
parameter = ai.server_cookie;
|
2016-02-08 20:21:11 +00:00
|
|
|
escape_url(parameter);
|
|
|
|
url += parameter;
|
2014-10-19 06:53:27 +00:00
|
|
|
} else {
|
2014-11-19 05:58:38 +00:00
|
|
|
url += "?email_addr=";
|
2014-10-19 06:53:27 +00:00
|
|
|
parameter = ai.email_addr;
|
|
|
|
escape_url(parameter);
|
|
|
|
url += parameter;
|
|
|
|
|
2014-11-19 05:58:38 +00:00
|
|
|
url += "&passwd_hash=";
|
2014-10-19 06:53:27 +00:00
|
|
|
parameter = ai.passwd_hash;
|
|
|
|
escape_url(parameter);
|
|
|
|
url += parameter;
|
|
|
|
}
|
2006-03-01 10:10:22 +00:00
|
|
|
|
2010-07-22 19:13:36 +00:00
|
|
|
retval = gui_http->do_rpc(
|
2011-06-12 20:58:43 +00:00
|
|
|
this, url.c_str(), LOOKUP_ACCOUNT_FILENAME, false
|
2010-07-22 19:13:36 +00:00
|
|
|
);
|
2005-08-05 22:00:19 +00:00
|
|
|
if (retval) {
|
2005-08-06 19:20:26 +00:00
|
|
|
error_num = retval;
|
2005-08-05 22:00:19 +00:00
|
|
|
} else {
|
2005-08-06 19:20:26 +00:00
|
|
|
error_num = ERR_IN_PROGRESS;
|
2005-08-05 22:00:19 +00:00
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2006-02-14 21:20:43 +00:00
|
|
|
void LOOKUP_ACCOUNT_OP::handle_reply(int http_op_retval) {
|
2005-08-05 22:00:19 +00:00
|
|
|
if (http_op_retval) {
|
2005-08-06 19:20:26 +00:00
|
|
|
error_num = http_op_retval;
|
2005-08-05 22:00:19 +00:00
|
|
|
} else {
|
2007-06-22 18:53:55 +00:00
|
|
|
error_num = read_file_string(LOOKUP_ACCOUNT_FILENAME, reply);
|
2005-08-05 22:00:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int CREATE_ACCOUNT_OP::do_rpc(ACCOUNT_IN& ai) {
|
|
|
|
int retval;
|
|
|
|
string url;
|
2006-03-01 10:49:11 +00:00
|
|
|
string parameter;
|
2005-08-05 22:00:19 +00:00
|
|
|
|
2006-03-01 10:10:22 +00:00
|
|
|
url = ai.url;
|
|
|
|
canonicalize_master_url(url);
|
|
|
|
|
2006-03-01 10:49:11 +00:00
|
|
|
url += "create_account.php?email_addr=";
|
|
|
|
parameter = ai.email_addr;
|
|
|
|
escape_url(parameter);
|
|
|
|
url += parameter;
|
|
|
|
|
|
|
|
url += "&passwd_hash=";
|
|
|
|
parameter = ai.passwd_hash;
|
|
|
|
escape_url(parameter);
|
|
|
|
url += parameter;
|
|
|
|
|
|
|
|
url += "&user_name=";
|
|
|
|
parameter = ai.user_name;
|
|
|
|
escape_url(parameter);
|
|
|
|
url += parameter;
|
2006-03-01 10:10:22 +00:00
|
|
|
|
2010-03-30 17:46:09 +00:00
|
|
|
if (!ai.team_name.empty()) {
|
|
|
|
url += "&team_name=";
|
|
|
|
parameter = ai.team_name;
|
|
|
|
escape_url(parameter);
|
|
|
|
url += parameter;
|
|
|
|
}
|
2010-07-22 19:13:36 +00:00
|
|
|
retval = gui_http->do_rpc(
|
2011-06-12 20:58:43 +00:00
|
|
|
this, url.c_str(), CREATE_ACCOUNT_FILENAME, false
|
2010-07-22 19:13:36 +00:00
|
|
|
);
|
2005-08-05 22:00:19 +00:00
|
|
|
if (retval) {
|
2005-08-06 19:20:26 +00:00
|
|
|
error_num = retval;
|
2005-08-05 22:00:19 +00:00
|
|
|
} else {
|
2005-08-06 19:20:26 +00:00
|
|
|
error_num = ERR_IN_PROGRESS;
|
2005-08-05 22:00:19 +00:00
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2006-02-14 21:20:43 +00:00
|
|
|
void CREATE_ACCOUNT_OP::handle_reply(int http_op_retval) {
|
2005-08-05 22:00:19 +00:00
|
|
|
if (http_op_retval) {
|
2005-08-06 19:20:26 +00:00
|
|
|
error_num = http_op_retval;
|
2005-08-05 22:00:19 +00:00
|
|
|
} else {
|
2007-06-22 18:53:55 +00:00
|
|
|
error_num = read_file_string(CREATE_ACCOUNT_FILENAME, reply);
|
2005-08-05 22:00:19 +00:00
|
|
|
}
|
2005-08-06 19:20:26 +00:00
|
|
|
}
|
|
|
|
|
2007-03-04 02:30:48 +00:00
|
|
|
int GET_PROJECT_LIST_OP::do_rpc() {
|
|
|
|
int retval;
|
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
sprintf(buf, "http://boinc.berkeley.edu/project_list.php");
|
2007-09-27 21:28:32 +00:00
|
|
|
retval = gui_http->do_rpc(
|
2010-07-22 19:13:36 +00:00
|
|
|
this, buf, ALL_PROJECTS_LIST_FILENAME_TEMP, true
|
2007-03-04 02:30:48 +00:00
|
|
|
);
|
|
|
|
if (retval) {
|
|
|
|
error_num = retval;
|
|
|
|
} else {
|
|
|
|
error_num = ERR_IN_PROGRESS;
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2007-10-02 18:43:12 +00:00
|
|
|
#define ALL_PROJECTS_LIST_CHECK_PERIOD (14*86400)
|
|
|
|
|
2007-03-04 02:58:22 +00:00
|
|
|
void GET_PROJECT_LIST_OP::handle_reply(int http_op_retval) {
|
2009-09-30 17:13:45 +00:00
|
|
|
bool error = false;
|
2007-03-04 02:58:22 +00:00
|
|
|
if (http_op_retval) {
|
|
|
|
error_num = http_op_retval;
|
2009-09-30 17:13:45 +00:00
|
|
|
error = true;
|
|
|
|
} else {
|
|
|
|
string s;
|
|
|
|
read_file_string(ALL_PROJECTS_LIST_FILENAME_TEMP, s);
|
|
|
|
if (strstr(s.c_str(), "</projects>")) {
|
|
|
|
boinc_rename(
|
|
|
|
ALL_PROJECTS_LIST_FILENAME_TEMP, ALL_PROJECTS_LIST_FILENAME
|
|
|
|
);
|
|
|
|
gstate.all_projects_list_check_time = gstate.now;
|
|
|
|
} else {
|
|
|
|
error = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// if error, try again in a day
|
|
|
|
//
|
|
|
|
if (error) {
|
2007-10-02 18:43:12 +00:00
|
|
|
gstate.all_projects_list_check_time =
|
|
|
|
gstate.now - ALL_PROJECTS_LIST_CHECK_PERIOD + SECONDS_PER_DAY;
|
2007-03-04 02:58:22 +00:00
|
|
|
}
|
2007-03-04 02:30:48 +00:00
|
|
|
}
|
|
|
|
|
2007-03-19 19:13:40 +00:00
|
|
|
void CLIENT_STATE::all_projects_list_check() {
|
2014-05-08 07:51:18 +00:00
|
|
|
if (cc_config.dont_contact_ref_site) return;
|
2007-03-19 19:13:40 +00:00
|
|
|
if (all_projects_list_check_time) {
|
|
|
|
if (now - all_projects_list_check_time < ALL_PROJECTS_LIST_CHECK_PERIOD) {
|
2007-03-04 02:58:22 +00:00
|
|
|
return;
|
2007-03-04 02:30:48 +00:00
|
|
|
}
|
|
|
|
}
|
2007-03-04 02:58:22 +00:00
|
|
|
get_project_list_op.do_rpc();
|
2007-03-04 02:30:48 +00:00
|
|
|
}
|
|
|
|
|