Co-authored-by: Florian Friedrich <friedrich@procster.de>
This commit is contained in:
FloFri 2025-01-12 17:34:39 +01:00 committed by GitHub
parent 8737bec43f
commit 5a5dec975f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 54 additions and 3 deletions

View File

@ -45,6 +45,7 @@ int main(int argc, char **argv) {
std::cout << "pCloud console client (" << version << ")" << std::endl;
std::string username = "";
std::string password = "";
std::string tfa_code = "";
bool daemon = false;
bool commands = false;
bool commands_only = false;
@ -52,15 +53,22 @@ int main(int argc, char **argv) {
bool passwordsw = false;
bool save_pass = false;
bool crypto = false;
bool trusted_device = false;
po::variables_map vm;
try {
po::options_description desc("Allowed options");
desc.add_options()("help,h", "Show this help message.")(
"username,u", po::value<std::string>(&username),
"pCloud account name.")("password,p", po::bool_switch(&passwordsw),
"Ask for pCloud account password.")(
"crypto,c", po::bool_switch(&crypto), "Ask for crypto password.")(
"pCloud account name.")(
"password,p", po::bool_switch(&passwordsw),
"Ask for pCloud account password.")(
"tfa_code,t", po::value<std::string>(&tfa_code),
"pCloud tfa code")(
"trusted_device,r", po::bool_switch(&trusted_device),
"Trust this device.")(
"crypto,c", po::bool_switch(&crypto),
"Ask for crypto password.")(
"passascrypto,y", po::value<std::string>(),
"User password is the same as crypto password.")(
"daemonize,d", po::bool_switch(&daemon),
@ -113,6 +121,8 @@ int main(int argc, char **argv) {
if (passwordsw) {
cc::clibrary::pclsync_lib::get_lib().get_pass_from_console();
}
cc::clibrary::pclsync_lib::get_lib().set_tfa_code(tfa_code);
cc::clibrary::pclsync_lib::get_lib().set_trusted_device(trusted_device);
if (crypto) {
cc::clibrary::pclsync_lib::get_lib().setup_crypto_ = true;
if (vm.count("passascrypto")) {

View File

@ -54,6 +54,10 @@ clib::pclsync_lib::pclsync_lib()
clib::pclsync_lib::~pclsync_lib() {}
const bool clib::pclsync_lib::get_trusted_device() { return trusted_device_; };
const std::string &clib::pclsync_lib::get_tfa_code() { return tfa_code_; }
const std::string &clib::pclsync_lib::get_username() { return username_; }
const std::string &clib::pclsync_lib::get_password() { return password_; }
@ -64,6 +68,12 @@ const std::string &clib::pclsync_lib::get_crypto_pass() {
const std::string &clib::pclsync_lib::get_mount() { return mount_; }
void clib::pclsync_lib::set_trusted_device(bool arg) {
trusted_device_ = arg;
}
void clib::pclsync_lib::set_tfa_code(const std::string &arg) {
tfa_code_ = arg;
}
void clib::pclsync_lib::set_username(const std::string &arg) {
username_ = arg;
}
@ -93,6 +103,18 @@ 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_);
}
@ -233,6 +255,10 @@ static const char *status2string(uint32_t status) {
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";
}
@ -256,6 +282,14 @@ static void status_change(pstatus_t *status) {
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();

View File

@ -46,6 +46,7 @@ public:
~pclsync_lib();
pclsync_lib();
bool trusted_device_;
bool crypto_on_;
bool save_pass_;
bool setup_crypto_;
@ -55,12 +56,16 @@ public:
bool was_init_;
// Getters
const bool get_trusted_device();
const std::string &get_tfa_code();
const std::string &get_username();
const std::string &get_password();
const std::string &get_crypto_pass();
const std::string &get_mount();
// Setters
void set_trusted_device(bool arg);
void set_tfa_code(const std::string& arg);
void set_username(const std::string &arg);
void set_password(const std::string &arg);
void set_crypto_pass(const std::string &arg);
@ -75,6 +80,7 @@ public:
static pclsync_lib &get_lib();
// Console
void get_tfa_code_from_console();
void get_pass_from_console();
void get_cryptopass_from_console();
@ -97,6 +103,7 @@ public:
private:
std::string username_;
std::string password_;
std::string tfa_code_;
std::string crypto_pass_;
std::string mount_;