2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2005-01-20 23:22:22 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2004-01-30 22:19: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-01-20 23:22:22 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2005-01-20 23:22:22 +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/>.
|
2004-01-30 22:19:19 +00:00
|
|
|
|
2017-04-08 06:54:49 +00:00
|
|
|
#ifndef BOINC_GUI_RPC_SERVER_H
|
|
|
|
#define BOINC_GUI_RPC_SERVER_H
|
2011-02-19 03:32:26 +00:00
|
|
|
|
2005-08-16 20:48:21 +00:00
|
|
|
#include "network.h"
|
2007-09-27 21:03:15 +00:00
|
|
|
#include "acct_setup.h"
|
2005-08-16 20:48:21 +00:00
|
|
|
|
2006-12-14 20:44:39 +00:00
|
|
|
// FSM states for auto-update
|
|
|
|
|
|
|
|
#define AU_SS_INIT 0
|
|
|
|
// no get_screensaver_mode() yet
|
|
|
|
#define AU_SS_GOT 1
|
|
|
|
// got a get_screensaver_mode()
|
|
|
|
#define AU_SS_QUIT_REQ 2
|
|
|
|
// send a QUIT next time
|
|
|
|
#define AU_SS_QUIT_SENT 3
|
|
|
|
// QUIT sent
|
|
|
|
|
|
|
|
#define AU_MGR_INIT 0
|
|
|
|
#define AU_MGR_GOT 1
|
|
|
|
#define AU_MGR_QUIT_REQ 2
|
|
|
|
#define AU_MGR_QUIT_SENT 3
|
2010-03-02 22:52:22 +00:00
|
|
|
|
2011-04-30 04:57:59 +00:00
|
|
|
#define GUI_RPC_REQ_MSG_SIZE 100000
|
2011-02-19 03:32:26 +00:00
|
|
|
|
2004-01-21 07:07:16 +00:00
|
|
|
class GUI_RPC_CONN {
|
|
|
|
public:
|
|
|
|
int sock;
|
2011-09-18 21:06:49 +00:00
|
|
|
MIOFILE mfout;
|
|
|
|
MFILE mout;
|
|
|
|
MIOFILE mfin;
|
|
|
|
XML_PARSER xp;
|
2010-03-02 22:52:22 +00:00
|
|
|
char request_msg[GUI_RPC_REQ_MSG_SIZE+1];
|
|
|
|
int request_nbytes;
|
2005-03-07 06:09:04 +00:00
|
|
|
char nonce[256];
|
|
|
|
bool auth_needed;
|
2010-04-01 05:54:29 +00:00
|
|
|
// if true, don't allow operations other than authentication
|
2008-05-23 19:24:20 +00:00
|
|
|
bool got_auth1;
|
|
|
|
bool got_auth2;
|
2010-04-01 05:54:29 +00:00
|
|
|
// keep track of whether we've got the 2 authentication msgs;
|
|
|
|
// don't accept more than one of each (to prevent DoS)
|
2008-08-26 20:49:54 +00:00
|
|
|
bool sent_unauthorized;
|
2010-04-01 05:54:29 +00:00
|
|
|
// we've send one <unauthorized>.
|
|
|
|
// On next auth failure, disconnect
|
2005-04-09 23:19:38 +00:00
|
|
|
bool is_local;
|
2010-04-01 05:54:29 +00:00
|
|
|
// connection is from local host
|
2018-10-25 20:24:09 +00:00
|
|
|
VERSION_INFO client_api;
|
|
|
|
std::string client_name;
|
2011-09-20 18:49:38 +00:00
|
|
|
bool quit_flag;
|
2006-12-14 20:44:39 +00:00
|
|
|
int au_ss_state;
|
|
|
|
int au_mgr_state;
|
2007-09-27 21:03:15 +00:00
|
|
|
GUI_HTTP gui_http;
|
|
|
|
GET_PROJECT_CONFIG_OP get_project_config_op;
|
2007-09-27 21:28:32 +00:00
|
|
|
LOOKUP_ACCOUNT_OP lookup_account_op;
|
|
|
|
CREATE_ACCOUNT_OP create_account_op;
|
2011-02-19 03:32:26 +00:00
|
|
|
private:
|
2010-01-27 03:55:46 +00:00
|
|
|
bool notice_refresh;
|
|
|
|
// next time we get a get_notices RPC,
|
|
|
|
// send a -1 seqno, then the whole list
|
2011-02-19 03:32:26 +00:00
|
|
|
public:
|
|
|
|
void set_notice_refresh() {
|
|
|
|
notice_refresh = true;
|
|
|
|
}
|
|
|
|
void clear_notice_refresh() {
|
|
|
|
notice_refresh = false;
|
|
|
|
}
|
|
|
|
bool get_notice_refresh() {
|
|
|
|
return notice_refresh;
|
|
|
|
}
|
2004-01-21 07:07:16 +00:00
|
|
|
GUI_RPC_CONN(int);
|
|
|
|
~GUI_RPC_CONN();
|
|
|
|
int handle_rpc();
|
2005-03-07 06:09:04 +00:00
|
|
|
void handle_auth1(MIOFILE&);
|
2008-05-23 19:24:20 +00:00
|
|
|
int handle_auth2(char*, MIOFILE&);
|
2019-07-17 06:52:34 +00:00
|
|
|
void http_error(const char* msg);
|
2019-07-11 04:58:03 +00:00
|
|
|
void handle_get();
|
2004-01-21 07:07:16 +00:00
|
|
|
};
|
|
|
|
|
2005-03-07 06:09:04 +00:00
|
|
|
// authentication for GUI RPCs:
|
2013-01-03 06:51:56 +00:00
|
|
|
// 1) if a host-list file is found, accept only from those hosts
|
2005-03-07 06:09:04 +00:00
|
|
|
// 2) if a password file file is found, ALSO demand password auth
|
|
|
|
|
2004-01-21 07:07:16 +00:00
|
|
|
class GUI_RPC_CONN_SET {
|
2004-07-10 07:27:00 +00:00
|
|
|
std::vector<GUI_RPC_CONN*> gui_rpcs;
|
2010-09-15 17:41:25 +00:00
|
|
|
std::vector<sockaddr_storage> allowed_remote_ip_addresses;
|
2007-04-23 20:35:55 +00:00
|
|
|
int get_allowed_hosts();
|
2013-01-03 06:51:56 +00:00
|
|
|
void get_password();
|
2004-07-10 07:27:00 +00:00
|
|
|
int insert(GUI_RPC_CONN*);
|
2010-09-15 17:41:25 +00:00
|
|
|
bool check_allowed_list(sockaddr_storage& ip_addr);
|
2020-07-16 07:33:03 +00:00
|
|
|
bool remote_hosts_configured;
|
2004-01-21 07:07:16 +00:00
|
|
|
public:
|
2005-12-02 22:29:35 +00:00
|
|
|
int lsock;
|
2006-09-08 22:28:10 +00:00
|
|
|
double time_of_last_rpc_needing_network;
|
2010-04-01 05:54:29 +00:00
|
|
|
// time of the last RPC that needs network access to handle
|
2005-12-25 04:53:24 +00:00
|
|
|
|
2005-07-23 08:10:39 +00:00
|
|
|
GUI_RPC_CONN_SET();
|
2005-03-07 06:09:04 +00:00
|
|
|
char password[256];
|
2005-08-16 21:31:27 +00:00
|
|
|
void get_fdset(FDSET_GROUP&, FDSET_GROUP&);
|
2005-08-16 20:48:21 +00:00
|
|
|
void got_select(FDSET_GROUP&);
|
2014-01-31 06:57:44 +00:00
|
|
|
int init_tcp(bool last_time);
|
|
|
|
int init_unix_domain();
|
2006-07-17 16:38:53 +00:00
|
|
|
void close();
|
2006-09-08 22:28:10 +00:00
|
|
|
bool recent_rpc_needs_network(double interval);
|
2006-12-14 20:44:39 +00:00
|
|
|
void send_quits();
|
|
|
|
bool quits_sent();
|
2007-09-27 21:03:15 +00:00
|
|
|
bool poll();
|
2010-01-27 03:55:46 +00:00
|
|
|
void set_notice_refresh() {
|
|
|
|
for (unsigned int i=0; i<gui_rpcs.size(); i++) {
|
2011-02-19 03:32:26 +00:00
|
|
|
gui_rpcs[i]->set_notice_refresh();
|
2010-01-27 03:55:46 +00:00
|
|
|
}
|
|
|
|
}
|
2004-01-21 07:07:16 +00:00
|
|
|
};
|
2011-02-19 03:32:26 +00:00
|
|
|
|
2011-04-06 17:57:52 +00:00
|
|
|
#endif
|