diff --git a/pCloudCC/main.cpp b/pCloudCC/main.cpp index d2f6a8ff..43ff67a7 100644 --- a/pCloudCC/main.cpp +++ b/pCloudCC/main.cpp @@ -12,6 +12,7 @@ int main(int argc, char **argv) { std::cout << "pCloud console client v."<< version << std::endl; std::string username; std::string password; + std::string tfa_code; bool daemon = false; bool commands = false; bool commands_only = false; @@ -19,13 +20,16 @@ int main(int argc, char **argv) { bool passwordsw = false; bool save_pass = false; bool crypto = false; - + bool trusted_device = false; + try { po::options_description desc("Allowed options"); desc.add_options() ("help,h", "produce help message") ("username,u", po::value(&username), "pCloud account name") ("password,p", po::bool_switch(&passwordsw), "Ask pCloud account password") + ("tfa_code,t", po::value(&tfa_code), "pCloud tfa code") + ("trusted_device,r", po::bool_switch(&trusted_device), "Trust this device.") ("crypto,c", po::bool_switch(&crypto), "Ask crypto password") ("passascrypto,y", po::value(), "Use user password as crypto password also.") ("daemonize,d", po::bool_switch(&daemon), "Daemonize the process.") @@ -63,7 +67,8 @@ int main(int argc, char **argv) { return 1; } console_client::clibrary::pclsync_lib::get_lib().set_username(username); - + console_client::clibrary::pclsync_lib::get_lib().set_tfa_code(tfa_code); + console_client::clibrary::pclsync_lib::get_lib().set_trusted_device(trusted_device); if (passwordsw) { console_client::clibrary::pclsync_lib::get_lib().get_pass_from_console(); } diff --git a/pCloudCC/pclsync_lib.cpp b/pCloudCC/pclsync_lib.cpp index 4f49a59e..0afabbe6 100644 --- a/pCloudCC/pclsync_lib.cpp +++ b/pCloudCC/pclsync_lib.cpp @@ -68,6 +68,16 @@ void clib::pclsync_lib::get_pass_from_console() do_get_pass_from_console(password_); } +void clib::pclsync_lib::get_tfa_code_from_console() +{ + if (daemon_) { + std::cout << "Not able to read 2fa code when started as daemon." << std::endl; + exit(1); + } + std::cout << "Please enter 2fa code" << std::endl; + getline(std::cin, tfa_code_); +} + void clib::pclsync_lib::get_cryptopass_from_console() { do_get_pass_from_console(crypto_pass_); @@ -163,6 +173,8 @@ static char const * status2string (uint32_t status){ case PSTATUS_SCANNING: return "SCANNING"; case PSTATUS_USER_MISMATCH: return "USER_MISMATCH"; case PSTATUS_ACCOUT_EXPIRED: return "ACCOUT_EXPIRED"; + case PSTATUS_TFA_REQUIRED: return "TFA_REQUIRED"; + case PSTATUS_BAD_TFA_CODE: return "BAD_TFA_CODE"; default :return "Unrecognized status"; } } @@ -183,6 +195,12 @@ static void status_change(pstatus_t* status) { psync_set_user_pass(clib::pclsync_lib::get_lib().get_username().c_str(), clib::pclsync_lib::get_lib().get_password().c_str(), (int) clib::pclsync_lib::get_lib().save_pass_); std::cout << "logging in" << std::endl; } + else if (status->status == PSTATUS_TFA_REQUIRED) + { + if (clib::pclsync_lib::get_lib().get_tfa_code().empty()) + clib::pclsync_lib::get_lib().get_tfa_code_from_console(); + psync_tfa_set_code(clib::pclsync_lib::get_lib().get_tfa_code().c_str(), clib::pclsync_lib::get_lib().get_trusted_device(), 0); + } else if (status->status==PSTATUS_BAD_LOGIN_DATA){ if (!clib::pclsync_lib::get_lib().newuser_) { clib::pclsync_lib::get_lib().get_pass_from_console(); diff --git a/pCloudCC/pclsync_lib.h b/pCloudCC/pclsync_lib.h index 17d8b417..04b0e095 100644 --- a/pCloudCC/pclsync_lib.h +++ b/pCloudCC/pclsync_lib.h @@ -46,9 +46,13 @@ namespace console_client { //Getters const std::string& get_username() {return username_;} const std::string& get_password() {return password_;} + const std::string& get_tfa_code() {return tfa_code_;} const std::string& get_crypto_pass() {return crypto_pass_;}; const std::string& get_mount() {return mount_;} + const bool get_trusted_device() {return trusted_device_;}; //Setters + void set_trusted_device(bool arg) { trusted_device_ = arg;} + void set_tfa_code(const std::string& arg) { tfa_code_ = arg;} void set_username(const std::string& arg) { username_ = arg;} void set_password(const std::string& arg) { password_ = arg;} void set_crypto_pass(const std::string& arg) { crypto_pass_ = arg;}; @@ -59,6 +63,7 @@ namespace console_client { void set_daemon(bool p) {daemon_ = p;} void set_status_callback(status_callback_t p) {status_callback_ = p;} //Console + void get_tfa_code_from_console(); void get_pass_from_console(); void get_cryptopass_from_console(); //API calls @@ -74,6 +79,7 @@ namespace console_client { int unlink(); int login(const char* user, const char* pass, int save); + bool trusted_device_; bool crypto_on_; bool save_pass_; bool setup_crypto_; @@ -85,6 +91,7 @@ namespace console_client { private: std::string username_; std::string password_; + std::string tfa_code_; std::string crypto_pass_; std::string mount_;