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
|
|
|
|
2011-02-19 03:32:26 +00:00
|
|
|
#ifndef _GUI_RPC_SERVER_
|
|
|
|
#define _GUI_RPC_SERVER_
|
|
|
|
|
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
|
|
|
|
|
|
|
#define GUI_RPC_REQ_MSG_SIZE 4096
|
2011-02-19 03:32:26 +00:00
|
|
|
|
2004-01-21 07:07:16 +00:00
|
|
|
class GUI_RPC_CONN {
|
|
|
|
public:
|
|
|
|
int sock;
|
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
|
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() {
|
|
|
|
if (!notice_refresh) return;
|
|
|
|
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&);
|
2007-09-27 21:03:15 +00:00
|
|
|
void handle_get_project_config(char* buf, MIOFILE& fout);
|
|
|
|
void handle_get_project_config_poll(char*, MIOFILE& fout);
|
2007-09-27 21:28:32 +00:00
|
|
|
void handle_lookup_account(char* buf, MIOFILE& fout);
|
|
|
|
void handle_lookup_account_poll(char*, MIOFILE& fout);
|
|
|
|
void handle_create_account(char* buf, MIOFILE& fout);
|
|
|
|
void handle_create_account_poll(char*, MIOFILE& fout);
|
2004-01-21 07:07:16 +00:00
|
|
|
};
|
|
|
|
|
2005-03-07 06:09:04 +00:00
|
|
|
// authentication for GUI RPCs:
|
|
|
|
// 1) if a IPaddr-list file is found, accept only from those addrs
|
|
|
|
// 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();
|
2005-03-07 06:09:04 +00:00
|
|
|
int 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);
|
2007-04-23 20:35:55 +00:00
|
|
|
bool remote_hosts_file_exists;
|
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&);
|
2007-04-05 18:17:15 +00:00
|
|
|
int init(bool last_time);
|
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
|