// This file is part of BOINC. // http://boinc.berkeley.edu // Copyright (C) 2019 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 client, // using GUI RPCs. // // usage: boinccmd [--host hostname] [--passwd passwd] command #ifdef _WIN32 #include "boinc_win.h" #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] [--unix_domain] command\n\n\ default hostname: localhost\n\ default password: contents of gui_rpc_auth.cfg\n\ Commands:\n\ --acct_mgr attach URL name passwd attach to account manager\n\ --acct_mgr info show current account manager info\n\ --acct_mgr sync synchronize with acct mgr\n\ --acct_mgr detach detach from acct mgr\n\ --client_version show client version\n\ --create_account URL email passwd name\n\ --file_transfer URL filename op file transfer operation\n\ op = retry | abort\n\ --get_app_config URL show app config for given project\n\ --get_cc_status\n\ --get_daily_xfer_history show network traffic history\n\ --get_disk_usage show disk usage\n\ --get_file_transfers show file transfers\n\ --get_host_info\n\ --get_message_count show largest message seqno\n\ --get_messages [ seqno ] show messages > seqno\n\ --get_notices [ seqno ] show notices > seqno\n\ --get_project_config URL\n\ --get_project_status show status of all attached projects\n\ --get_proxy_settings\n\ --get_simple_gui_info show status of projects and active tasks\n\ --get_state show entire state\n\ --get_tasks show tasks (detailed)\n\ --get_task_summary [pcedsrw] show tasks (1 task per line)\n\ p: project name\n\ c: completion %%\n\ e: elapsed time\n\ d: deadline\n\ s: status\n\ r: resource usage\n\ w: WU name\n\ --get_old_tasks show reported tasks from last 1 hour\n\ --join_acct_mgr URL name passwd same as --acct_mgr attach\n\ --lookup_account URL email passwd\n\ --network_available retry deferred network communication\n\ --project URL op project operation\n\ op = reset | detach | update | suspend | resume | nomorework | allowmorework | detach_when_done | dont_detach_when_done\n\ --project_attach URL auth attach to project\n\ --quit tell client to exit\n\ --quit_acct_mgr same as --acct_mgr detach\n\ --read_cc_config\n\ --read_global_prefs_override\n\ --reset_host_info have client get mem size, #CPUs etc. again\n\ --run_benchmarks\n\ --run_graphics_app id op (Macintosh only) run, test or stop graphics app\n\ op = run | runfullscreen | stop | test\n\ id = slot # for run or runfullscreen, process ID for stop or test\n\ id = -1 for default screensaver (boincscr)\n\ --set_gpu_mode mode duration set GPU run mode for given duration\n\ mode = always | auto | never\n\ --set_host_info product_name\n\ --set_network_mode mode duration set network mode for given duration\n\ mode = always | auto | never\n\ --set_proxy_settings\n\ --set_run_mode mode duration set run mode for given duration\n\ mode = always | auto | never\n\ --task url task_name op task operation\n\ op = suspend | resume | abort\n\ " ); exit(1); } char* next_arg(int argc, char** argv, int& i) { if (i >= argc) { fprintf(stderr, "Missing command-line argument\n"); usage(); } return argv[i++]; } const char* prio_name(int prio) { switch (prio) { case MSG_INFO: return "low"; case MSG_USER_ALERT: return "user notification"; case MSG_INTERNAL_ERROR: return "internal error"; } return "unknown"; } void acct_mgr_do_rpc( RPC_CLIENT& rpc, char* am_url, char* am_name, char* am_passwd ) { int retval; if (am_url) { retval = rpc.acct_mgr_rpc(am_url, am_name, am_passwd); } else { retval = rpc.acct_mgr_rpc(0, 0, 0, true); } if (!retval) { while (1) { printf("polling for reply\n"); ACCT_MGR_RPC_REPLY amrr; retval = rpc.acct_mgr_rpc_poll(amrr); if (retval) { printf("poll status: %s\n", boincerror(retval)); } else { if (amrr.error_num) { printf("poll status: %s\n", boincerror(amrr.error_num)); if (amrr.error_num != ERR_IN_PROGRESS) break; boinc_sleep(1); } else { int j, n = (int)amrr.messages.size(); if (n) { printf("Messages from account manager:\n"); for (j=0; j STR_LIST; // given: a list of lines, each consisting of n columns // for each column: find the longest entry. // Then display the lines so the columns line up. // void show_str_lists(vector &lines, size_t ncols) { vector lengths; size_t i; for (i=0; i(max)); } for (const STR_LIST &line : lines) { for (i=0; i lines; STR_LIST title; bool projects = false; for (char opt: options) { switch(opt) { case 'p': title.push_back("Project"); projects = true; break; case 'c': title.push_back("% Done"); break; case 'e': title.push_back("Elapsed"); break; case 'd': title.push_back("Deadline"); break; case 's': title.push_back("Status"); break; case 'r': title.push_back("Procs"); break; case 'w': title.push_back("WU name"); break; } } lines.push_back(title); if (projects) { retval = rpc.get_project_status(ps); if (retval) return retval; } for (RESULT* r: results.results) { RESULT_INFO* ri = new RESULT_INFO; STR_LIST line; for (char opt2: options) { switch(opt2) { case 'p': strcpy(ri->project_name, r->project_url); for (PROJECT* p: ps.projects) { if (!strcmp(p->master_url, r->project_url)) { strcpy(ri->project_name, p->project_name.c_str()); break; } } line.push_back(ri->project_name); break; case 'c': if (r->scheduler_state > CPU_SCHED_UNINITIALIZED) { sprintf(ri->pct_done, "%.2f%%", r->fraction_done*100); } else { strcpy(ri->pct_done, "---"); } line.push_back(ri->pct_done); break; case 'e': if (r->scheduler_state > CPU_SCHED_UNINITIALIZED) { strcpy(ri->elapsed_time, timediff_format(r->elapsed_time).c_str()); } else { strcpy(ri->elapsed_time, "---"); } line.push_back(ri->elapsed_time); break; case 'd': strcpy(ri->deadline, time_to_string(r->report_deadline)); line.push_back(ri->deadline); break; case 's': strcpy(ri->status, active_task_state_string(r->active_task_state)); downcase_string(ri->status); line.push_back(ri->status); break; case 'r': strcpy(ri->resource_usage, strlen(r->resources)?r->resources:"1 CPU"); line.push_back(ri->resource_usage); break; case 'w': strcpy(ri->wu_name, r->wu_name); line.push_back(ri->wu_name); break; } } lines.push_back(line); } show_str_lists(lines, options.length()); return 0; } ////////////// --get_task_summary end //////////////// 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=0, *p, *q; bool unix_domain = false; string msg; #ifdef _WIN32 chdir_to_data_dir(); #elif defined(__APPLE__) chdir("/Library/Application Support/BOINC Data"); #endif #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 // parse command line. // TODO: do this the right way. // shouldn't require args to be in a particular order. 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)); // see if port is specified. // syntax: // [a:b:..]:port for IPv6 // a.b.c.d:port for IPv4 // hostname:port for domain names // p = strchr(hostname_buf, '['); if (p) { q = strchr(p, ']'); if (!q) { fprintf(stderr, "invalid IPv6 syntax: %s\n", hostname_buf); exit(1); } hostname = p+1; *q = 0; port = atoi(q+1); } else { hostname = hostname_buf; p = strchr(hostname, ':'); if (p) { q = strchr(p+1, ':'); if (!q) { port = atoi(p+1); *p=0; } } } i++; } if ((i ors; retval = rpc.get_old_results(ors); if (!retval) { for (unsigned int j=0; j= 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_host_info")) { HOST_INFO h; char* pn = next_arg(argc, argv, i); safe_strcpy(h.product_name, pn); retval = rpc.set_host_info(h); } 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.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; j