// This file is part of BOINC. // http://boinc.berkeley.edu // Copyright (C) 2008 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 . // boinccmd: command-line interface to a BOINC core client, // using GUI RPCs. // // usage: boinccmd [--host hostname] [--passwd passwd] command #if defined(_WIN32) && !defined(__STDWX_H__) && !defined(_BOINC_WIN_) && !defined(_AFX_STDAFX_H_) #include "boinc_win.h" #endif #ifdef _WIN32 #include "win_util.h" #else #include "config.h" #include #include #include #endif #include #include using std::vector; using std::string; #include "gui_rpc_client.h" #include "error_numbers.h" #include "util.h" #include "str_util.h" #include "str_replace.h" #include "url.h" #include "version.h" #include "common_defs.h" void version(){ printf("boinccmd, built from %s \n", PACKAGE_STRING ); exit(0); } void usage() { fprintf(stderr, "\n\ usage: boinccmd [--host hostname] [--passwd passwd] command\n\n\ Commands:\n\ --lookup_account URL email passwd\n\ --create_account URL email passwd name\n\ --project_attach URL auth attach to project\n\ --join_acct_mgr URL name passwd attach account manager\n\ --quit_acct_mgr quit current account manager\n\ --get_state show entire state\n\ --get_tasks show tasks\n\ --get_simple_gui_info show status of projects and active tasks\n\ --get_file_transfers show file transfers\n\ --get_project_status show status of all attached projects\n\ --get_disk_usage show disk usage\n\ --get_proxy_settings\n\ --get_messages [ seqno ] show messages > seqno\n\ --get_message_count show largest message seqno\n\ --get_notices [ seqno ] show notices > seqno\n\ --get_host_info\n\ --version, -V show core client version\n\ --task url task_name op task operation\n\ op = suspend | resume | abort | graphics_window | graphics_fullscreen\n\ --project URL op project operation\n\ op = reset | detach | update | suspend | resume | nomorework | allowmorework\n\ --file_transfer URL filename op file transfer operation\n\ op = retry | abort\n\ --set_run_mode mode duration set run mode for given duration\n\ mode = always | auto | never\n\ --set_gpu_mode mode duration set GPU run mode for given duration\n\ mode = always | auto | never\n\ --set_network_mode mode duration\n\ --set_proxy_settings\n\ --run_benchmarks\n\ --read_global_prefs_override\n\ --quit\n\ --read_cc_config\n\ --set_debts URL1 std1 ltd1 [URL2 std2 ltd2 ...]\n\ --get_project_config URL\n\ --get_project_config_poll\n\ --network_available\n\ --get_cc_status\n\ " ); exit(1); } void parse_display_args(char** argv, int& i, DISPLAY_INFO& di) { strcpy(di.window_station, "winsta0"); strcpy(di.desktop, "default"); strcpy(di.display, ""); while (argv[i]) { if (!strcmp(argv[i], "--window_station")) { strlcpy(di.window_station, argv[++i], sizeof(di.window_station)); } else if (!strcpy(argv[i], "--desktop")) { strlcpy(di.desktop, argv[++i], sizeof(di.desktop)); } else if (!strcpy(argv[i], "--display")) { strlcpy(di.display, argv[++i], sizeof(di.display)); } i++; } } void show_error(int retval) { fprintf(stderr, "Error %d: %s\n", retval, boincerror(retval)); } char* next_arg(int argc, char** argv, int& i) { if (i >= argc) { fprintf(stderr, "Missing command-line argument\n"); usage(); exit(1); } return argv[i++]; } const char* prio_name(int prio) { switch (prio) { case MSG_INFO: return "low"; case MSG_USER_ALERT: return "medium"; case MSG_INTERNAL_ERROR: return "high"; } return "unknown"; } int main(int argc, char** argv) { RPC_CLIENT rpc; int i, retval, port=0; MESSAGES messages; NOTICES notices; char passwd_buf[256], hostname_buf[256], *hostname=0; char* passwd = passwd_buf, *p; #ifdef _WIN32 chdir_to_data_dir(); #endif strcpy(passwd_buf, ""); read_gui_rpc_password(passwd_buf); #if defined(_WIN32) && defined(USE_WINSOCK) 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; if (!strcmp(argv[i], "--help")) usage(); if (!strcmp(argv[i], "-h")) usage(); if (!strcmp(argv[i], "--version")) version(); if (!strcmp(argv[i], "-V")) version(); if (!strcmp(argv[i], "--host")) { if (++i == argc) usage(); strlcpy(hostname_buf, argv[i], sizeof(hostname_buf)); hostname = hostname_buf; p = strchr(hostname, ':'); if (p) { port = atoi(p+1); *p=0; } i++; } if ((i= argc || (argv[i][0] == '-')) { duration = 0; } else { duration = atof(next_arg(argc, argv, i)); } if (!strcmp(op, "always")) { retval = rpc.set_run_mode(RUN_MODE_ALWAYS, duration); } else if (!strcmp(op, "auto")) { retval = rpc.set_run_mode(RUN_MODE_AUTO, duration); } else if (!strcmp(op, "never")) { retval = rpc.set_run_mode(RUN_MODE_NEVER, duration); } else { fprintf(stderr, "Unknown op %s\n", op); } } else if (!strcmp(cmd, "--set_gpu_mode")) { char* op = next_arg(argc, argv, i); double duration; if (i >= argc || (argv[i][0] == '-')) { duration = 0; } else { duration = atof(next_arg(argc, argv, i)); } if (!strcmp(op, "always")) { retval = rpc.set_gpu_mode(RUN_MODE_ALWAYS, duration); } else if (!strcmp(op, "auto")) { retval = rpc.set_gpu_mode(RUN_MODE_AUTO, duration); } else if (!strcmp(op, "never")) { retval = rpc.set_gpu_mode(RUN_MODE_NEVER, duration); } else { fprintf(stderr, "Unknown op %s\n", op); } } else if (!strcmp(cmd, "--set_network_mode")) { char* op = next_arg(argc, argv, i); double duration; if (i >= argc || (argv[i][0] == '-')) { duration = 0; } else { duration = atof(next_arg(argc, argv, i)); } if (!strcmp(op, "always")) { retval = rpc.set_network_mode(RUN_MODE_ALWAYS, duration); } else if (!strcmp(op, "auto")) { retval = rpc.set_network_mode(RUN_MODE_AUTO, duration); } else if (!strcmp(op, "never")) { retval = rpc.set_network_mode(RUN_MODE_NEVER, duration); } else { fprintf(stderr, "Unknown op %s\n", op); } } else if (!strcmp(cmd, "--get_proxy_settings")) { GR_PROXY_INFO pi; retval = rpc.get_proxy_settings(pi); if (!retval) pi.print(); } else if (!strcmp(cmd, "--set_proxy_settings")) { GR_PROXY_INFO pi; 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); pi.noproxy_hosts = next_arg(argc, argv, i); if (pi.http_server_name.size()) pi.use_http_proxy = true; if (pi.http_user_name.size()) pi.use_http_authentication = true; if (pi.socks_server_name.size()) pi.use_socks_proxy = true; retval = rpc.set_proxy_settings(pi); } else if (!strcmp(cmd, "--get_message_count")) { int seqno; retval = rpc.get_message_count(seqno); if (!retval) { printf("Greatest message sequence number: %d\n", seqno); } } else if (!strcmp(cmd, "--get_messages")) { int seqno; if (i == argc) { seqno = 0; } else { seqno = atoi(next_arg(argc, argv, i)); } retval = rpc.get_messages(seqno, messages); if (!retval) { unsigned int j; for (j=0; jprojects; while (i < argc) { PROJECT proj; strcpy(proj.master_url, next_arg(argc, argv, i)); int std = atoi(next_arg(argc, argv, i)); proj.cpu_short_term_debt = std; proj.cuda_short_term_debt = std; proj.ati_short_term_debt = std; int ltd = atoi(next_arg(argc, argv, i)); proj.cpu_long_term_debt = ltd; proj.cuda_debt = ltd; proj.ati_debt = ltd; projects.push_back(proj); } retval = rpc.set_debts(projects); } else if (!strcmp(cmd, "--quit")) { retval = rpc.quit(); } else { fprintf(stderr, "unrecognized command %s\n", cmd); } if (retval < 0) { show_error(retval); } #if defined(_WIN32) && defined(USE_WINSOCK) WSACleanup(); #endif exit(retval); }