2005-02-10 22:26:31 +00:00
|
|
|
// Berkeley Open Infrastructure for Network Computing
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2005 University of California
|
|
|
|
//
|
|
|
|
// This 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 2.1 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This software 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.
|
|
|
|
//
|
|
|
|
// To view the GNU Lesser General Public License visit
|
|
|
|
// http://www.gnu.org/copyleft/lesser.html
|
|
|
|
// or write to the Free Software Foundation, Inc.,
|
|
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
|
|
|
// boinc_cmd: command-line interface to a BOINC core client,
|
|
|
|
// using GUI RPCs.
|
|
|
|
//
|
2005-03-07 06:09:04 +00:00
|
|
|
// usage: boinc_cmd [--host hostname] [--passwd passwd] command
|
2005-02-10 22:26:31 +00:00
|
|
|
//
|
|
|
|
// commands:
|
|
|
|
// --get_state show entire state
|
|
|
|
// --get_results show results
|
|
|
|
// --get_file_transfers show file transfers
|
|
|
|
// --get_project_status show status of all projects
|
|
|
|
// --get_disk_usage
|
|
|
|
// --result
|
|
|
|
// {suspend | resume | abort | graphics_window | graphics_fullscreen}
|
|
|
|
// url result_name
|
|
|
|
// --project
|
|
|
|
// {reset | detach | update | suspend | resume | nomorework | allowmorework}
|
|
|
|
// url
|
|
|
|
// --project_attach url auth
|
|
|
|
// --file_transfer {retry | abort} url filename
|
|
|
|
// --get_run_mode
|
|
|
|
// --set_run_mode {always | auto | never}
|
|
|
|
// --get_network_mode
|
|
|
|
// --set_network_mode {always | auto | never}
|
|
|
|
// --get_proxy_settings
|
|
|
|
// --set_proxy_settings
|
|
|
|
// --get_messages seqno show messages > seqno
|
|
|
|
// --get_host_info
|
|
|
|
// --acct_mgr_rpc url name password
|
|
|
|
// --run_benchmarks
|
|
|
|
// --get_screensaver_mode
|
|
|
|
// --set_screensaver_mode on|off blank_time {desktop window_station}
|
|
|
|
// --quit
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#include "boinc_win.h"
|
|
|
|
#include "win_net.h"
|
|
|
|
#endif
|
|
|
|
#include <vector>
|
|
|
|
using std::vector;
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
#include <cstdio>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "gui_rpc_client.h"
|
|
|
|
#include "error_numbers.h"
|
|
|
|
|
|
|
|
void usage() {
|
|
|
|
fprintf(stderr, "bad usage\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2005-04-04 21:14:49 +00:00
|
|
|
void parse_display_args(char** argv, int& i, DISPLAY_INFO& di) {
|
2005-02-15 06:32:43 +00:00
|
|
|
strcpy(di.window_station, "winsta0");
|
|
|
|
strcpy(di.desktop, "default");
|
|
|
|
strcpy(di.display, "");
|
|
|
|
while (argv[i]) {
|
|
|
|
if (!strcmp(argv[i], "--window_station")) {
|
|
|
|
strcpy(di.window_station, argv[++i]);
|
|
|
|
} else if (!strcpy(argv[i], "--desktop")) {
|
|
|
|
strcpy(di.desktop, argv[++i]);
|
|
|
|
} else if (!strcpy(argv[i], "--display")) {
|
|
|
|
strcpy(di.display, argv[++i]);
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-07 21:47:28 +00:00
|
|
|
void show_error(int retval) {
|
|
|
|
switch(retval) {
|
|
|
|
case ERR_AUTHENTICATOR:
|
|
|
|
fprintf(stderr, "Authentication failure\n");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "Error %d\n", retval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-03 22:01:18 +00:00
|
|
|
char* next_arg(int argc, char** argv, int& i) {
|
|
|
|
if (i >= argc) {
|
|
|
|
fprintf(stderr, "Missing command-line argument\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
return argv[i++];
|
|
|
|
}
|
|
|
|
|
2005-02-10 22:26:31 +00:00
|
|
|
int main(int argc, char** argv) {
|
|
|
|
RPC_CLIENT rpc;
|
2005-03-15 20:23:24 +00:00
|
|
|
int i;
|
2005-02-10 22:26:31 +00:00
|
|
|
MESSAGES messages;
|
|
|
|
int retval;
|
2005-03-07 06:09:04 +00:00
|
|
|
char* hostname = NULL;
|
|
|
|
char* passwd = NULL;
|
2005-02-10 22:26:31 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
WSADATA wsdata;
|
|
|
|
retval = WSAStartup( MAKEWORD( 1, 1 ), &wsdata);
|
|
|
|
if (retval) {
|
|
|
|
fprintf(stderr, "WinsockInitialize: %d\n", retval);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (argc < 2) usage();
|
|
|
|
i = 1;
|
2005-03-07 06:09:04 +00:00
|
|
|
if (!strcmp(argv[i], "--host")) {
|
|
|
|
hostname = argv[i+1];
|
|
|
|
i += 2;
|
|
|
|
}
|
|
|
|
if (!strcmp(argv[i], "--passwd")) {
|
|
|
|
passwd = argv[i+1];
|
|
|
|
i += 2;
|
2005-02-10 22:26:31 +00:00
|
|
|
}
|
|
|
|
retval = rpc.init(hostname);
|
|
|
|
if (retval) {
|
|
|
|
fprintf(stderr, "can't connect\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2005-03-07 06:09:04 +00:00
|
|
|
if (passwd) {
|
|
|
|
retval = rpc.authorize(passwd);
|
|
|
|
if (retval) {
|
2005-03-07 21:47:28 +00:00
|
|
|
fprintf(stderr, "Authorization failure: %d\n", retval);
|
2005-03-07 06:09:04 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2005-02-10 22:26:31 +00:00
|
|
|
|
2005-04-03 22:01:18 +00:00
|
|
|
char* cmd = next_arg(argc, argv, i);
|
|
|
|
if (!strcmp(cmd, "--get_state")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
CC_STATE state;
|
|
|
|
retval = rpc.get_state(state);
|
|
|
|
if (!retval) state.print();
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(cmd, "--get_results")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
RESULTS results;
|
|
|
|
retval = rpc.get_results(results);
|
|
|
|
if (!retval) results.print();
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(cmd, "--get_file_transfers")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
FILE_TRANSFERS ft;
|
|
|
|
retval = rpc.get_file_transfers(ft);
|
|
|
|
if (!retval) ft.print();
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(cmd, "--get_project_status")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
PROJECTS ps;
|
|
|
|
retval = rpc.get_project_status(ps);
|
|
|
|
if (!retval) ps.print();
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(cmd, "--get_disk_usage")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
PROJECTS ps;
|
|
|
|
retval = rpc.get_disk_usage(ps);
|
|
|
|
if (!retval) ps.print();
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(cmd, "--result")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
RESULT result;
|
2005-04-03 22:01:18 +00:00
|
|
|
char* project_url = next_arg(argc, argv, i);
|
|
|
|
char* name = next_arg(argc, argv, i);
|
|
|
|
result.project_url = project_url;
|
|
|
|
result.name = name;
|
|
|
|
char* op = next_arg(argc, argv, i);
|
|
|
|
if (!strcmp(op, "suspend")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
retval = rpc.result_op(result, "suspend");
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(op, "resume")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
retval = rpc.result_op(result, "resume");
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(op, "abort")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
retval = rpc.result_op(result, "abort");
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(op, "graphics_window")) {
|
2005-02-15 06:32:43 +00:00
|
|
|
DISPLAY_INFO di;
|
2005-04-04 21:14:49 +00:00
|
|
|
parse_display_args(argv, i, di);
|
2005-04-03 22:01:18 +00:00
|
|
|
retval = rpc.show_graphics(project_url, name, false, di);
|
|
|
|
} else if (!strcmp(op, "graphics_fullscreen")) {
|
2005-02-15 06:32:43 +00:00
|
|
|
DISPLAY_INFO di;
|
2005-04-04 21:14:49 +00:00
|
|
|
parse_display_args(argv, i, di);
|
2005-04-03 22:01:18 +00:00
|
|
|
retval = rpc.show_graphics(project_url, name, true, di);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Unknown op %s\n", op);
|
2005-02-10 22:26:31 +00:00
|
|
|
}
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(cmd, "--project")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
PROJECT project;
|
2005-04-03 22:01:18 +00:00
|
|
|
project.master_url = next_arg(argc, argv, i);
|
|
|
|
char* op = next_arg(argc, argv, i);
|
|
|
|
if (!strcmp(op, "reset")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
retval = rpc.project_op(project, "reset");
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(op, "detach")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
retval = rpc.project_op(project, "detach");
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(op, "update")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
retval = rpc.project_op(project, "update");
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(op, "nomorework")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
retval = rpc.project_op(project, "nomorework");
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(op, "allowmorework")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
retval = rpc.project_op(project, "allowmorework");
|
2005-04-03 22:01:18 +00:00
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Unknown op %s\n", op);
|
2005-02-10 22:26:31 +00:00
|
|
|
}
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(cmd, "--project_attach")) {
|
|
|
|
char* url = next_arg(argc, argv, i);
|
|
|
|
char* auth = next_arg(argc, argv, i);
|
|
|
|
retval = rpc.project_attach(url, auth);
|
|
|
|
} else if (!strcmp(cmd, "--file_transfer")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
FILE_TRANSFER ft;
|
|
|
|
|
2005-04-03 22:01:18 +00:00
|
|
|
ft.project_url = next_arg(argc, argv, i);
|
|
|
|
ft.name = next_arg(argc, argv, i);
|
|
|
|
char* op = next_arg(argc, argv, i);
|
|
|
|
if (!strcmp(op, "retry")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
retval = rpc.file_transfer_op(ft, "retry");
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(op, "abort")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
retval = rpc.file_transfer_op(ft, "abort");
|
2005-04-03 22:01:18 +00:00
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Unknown op %s\n", op);
|
2005-02-10 22:26:31 +00:00
|
|
|
}
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(cmd, "--get_run_mode")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
int mode;
|
|
|
|
retval = rpc.get_run_mode(mode);
|
|
|
|
if (!retval) {
|
|
|
|
printf("run mode: %s\n", rpc.mode_name(mode));
|
|
|
|
}
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(cmd, "--set_run_mode")) {
|
|
|
|
char* op = next_arg(argc, argv, i);
|
|
|
|
if (!strcmp(op, "always")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
retval = rpc.set_run_mode(RUN_MODE_ALWAYS);
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(op, "auto")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
retval = rpc.set_run_mode(RUN_MODE_AUTO);
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(op, "never")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
retval = rpc.set_run_mode(RUN_MODE_NEVER);
|
2005-04-03 22:01:18 +00:00
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Unknown op %s\n", op);
|
2005-02-10 22:26:31 +00:00
|
|
|
}
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(cmd, "--get_network_mode")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
int mode;
|
|
|
|
retval = rpc.get_network_mode(mode);
|
|
|
|
if (!retval) {
|
|
|
|
printf("network mode: %s\n", rpc.mode_name(mode));
|
|
|
|
}
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(cmd, "--set_network_mode")) {
|
|
|
|
char* op = next_arg(argc, argv, i);
|
|
|
|
if (!strcmp(op, "always")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
retval = rpc.set_run_mode(RUN_MODE_ALWAYS);
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(op, "auto")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
retval = rpc.set_run_mode(RUN_MODE_AUTO);
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(op, "never")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
retval = rpc.set_run_mode(RUN_MODE_NEVER);
|
2005-04-03 22:01:18 +00:00
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Unknown op %s\n", op);
|
2005-02-10 22:26:31 +00:00
|
|
|
}
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(cmd, "--get_proxy_settings")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
PROXY_INFO pi;
|
|
|
|
retval = rpc.get_proxy_settings(pi);
|
|
|
|
if (!retval) pi.print();
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(cmd, "--set_proxy_settings")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
PROXY_INFO pi;
|
2005-04-03 22:01:18 +00:00
|
|
|
pi.http_server_name = next_arg(argc, argv, i);
|
|
|
|
pi.http_server_port = atoi(next_arg(argc, argv, i));
|
|
|
|
pi.http_user_name = next_arg(argc, argv, i);
|
|
|
|
pi.http_user_passwd = next_arg(argc, argv, i);
|
|
|
|
pi.socks_server_name = next_arg(argc, argv, i);
|
|
|
|
pi.socks_server_port = atoi(next_arg(argc, argv, i));
|
|
|
|
pi.socks_version = atoi(next_arg(argc, argv, i));
|
|
|
|
pi.socks5_user_name = next_arg(argc, argv, i);
|
|
|
|
pi.socks5_user_passwd = next_arg(argc, argv, i);
|
2005-02-10 22:26:31 +00:00
|
|
|
retval = rpc.set_proxy_settings(pi);
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(cmd, "--get_messages")) {
|
|
|
|
int seqno = atoi(next_arg(argc, argv, i));
|
2005-02-10 22:26:31 +00:00
|
|
|
retval = rpc.get_messages(seqno, messages);
|
|
|
|
if (!retval) {
|
2005-03-15 20:23:24 +00:00
|
|
|
unsigned int j;
|
|
|
|
for (j=0; j<messages.messages.size(); j++) {
|
|
|
|
MESSAGE& md = *messages.messages[j];
|
2005-02-10 22:26:31 +00:00
|
|
|
printf("%s %d %d %s\n",
|
|
|
|
md.project.c_str(), md.priority,
|
|
|
|
md.timestamp, md.body.c_str()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(cmd, "--get_host_info")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
HOST_INFO hi;
|
|
|
|
retval = rpc.get_host_info(hi);
|
|
|
|
if (!retval) hi.print();
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(cmd, "--acct_mgr_rpc")) {
|
2005-04-04 21:14:49 +00:00
|
|
|
char* am_url = next_arg(argc, argv, i);
|
|
|
|
char* am_name = next_arg(argc, argv, i);
|
|
|
|
char* am_passwd = next_arg(argc, argv, i);
|
|
|
|
retval = rpc.acct_mgr_rpc(am_url, am_name, am_passwd);
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(cmd, "--run_benchmarks")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
retval = rpc.run_benchmarks();
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(cmd, "--get_screensaver_mode")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
int status;
|
|
|
|
retval = rpc.get_screensaver_mode(status);
|
|
|
|
if (!retval) printf("screensaver mode: %d\n", status);
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(cmd, "--set_screensaver_mode")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
double blank_time;
|
|
|
|
bool enabled = false;
|
2005-02-15 06:32:43 +00:00
|
|
|
DISPLAY_INFO di;
|
2005-02-10 22:26:31 +00:00
|
|
|
|
2005-04-03 22:01:18 +00:00
|
|
|
char* op = next_arg(argc, argv, i);
|
|
|
|
if (!strcmp(op, "on")) enabled = true;
|
|
|
|
blank_time = atof(next_arg(argc, argv, i));
|
2005-04-04 21:14:49 +00:00
|
|
|
parse_display_args(argv, i, di);
|
2005-04-03 22:01:18 +00:00
|
|
|
retval = rpc.set_screensaver_mode(enabled, blank_time, di);
|
|
|
|
} else if (!strcmp(cmd, "--quit")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
retval = rpc.quit();
|
|
|
|
} else {
|
2005-04-03 22:01:18 +00:00
|
|
|
fprintf(stderr, "unrecognized command %s\n", cmd);
|
2005-02-10 22:26:31 +00:00
|
|
|
}
|
|
|
|
if (retval) {
|
2005-03-07 21:47:28 +00:00
|
|
|
show_error(retval);
|
2005-02-10 22:26:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
WSACleanup();
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *BOINC_RCSID_77f00010ab = "$Id$";
|