Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,30 @@ 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;
bool newuser = false;
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),
Expand Down Expand Up @@ -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")) {
Expand Down
34 changes: 34 additions & 0 deletions pclsync_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_; }
Expand All @@ -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;
}
Expand Down Expand Up @@ -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_);
}
Expand Down Expand Up @@ -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";
}
Expand All @@ -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();
Expand Down
7 changes: 7 additions & 0 deletions pclsync_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class pclsync_lib {
~pclsync_lib();
pclsync_lib();

bool trusted_device_;
bool crypto_on_;
bool save_pass_;
bool setup_crypto_;
Expand All @@ -55,12 +56,16 @@ class pclsync_lib {
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);
Expand All @@ -75,6 +80,7 @@ class pclsync_lib {
static pclsync_lib &get_lib();

// Console
void get_tfa_code_from_console();
void get_pass_from_console();
void get_cryptopass_from_console();

Expand All @@ -97,6 +103,7 @@ class pclsync_lib {
private:
std::string username_;
std::string password_;
std::string tfa_code_;
std::string crypto_pass_;
std::string mount_;

Expand Down
Loading