30
30
31
31
#include < iostream>
32
32
33
+ #include < iostream>
34
+ #include < string>
35
+ #include < termios.h>
36
+ #include < unistd.h>
37
+ #include < stdio.h>
38
+
33
39
34
40
namespace cc = console_client;
35
41
namespace clib = cc::clibrary;
@@ -38,11 +44,6 @@ static clib::pclsync_lib g_lib;
38
44
39
45
clib::pclsync_lib& clib::get_lib (){return g_lib;}
40
46
41
- #include < string>
42
- #include < iostream>
43
- #include < cstdio>
44
- #include < memory>
45
-
46
47
static std::string exec (const char * cmd) {
47
48
boost::shared_ptr<FILE> pipe (popen (cmd, " r" ), pclose);
48
49
if (!pipe) return " ERROR" ;
@@ -56,6 +57,22 @@ static std::string exec(const char* cmd) {
56
57
}
57
58
58
59
60
+ void clib::pclsync_lib::get_pass_from_console ()
61
+ {
62
+ if (g_lib.daemon_ ) {
63
+ g_lib.get_out () << " Not able to read password when started as daemon." << std::endl;
64
+ exit (1 );
65
+ }
66
+ termios oldt;
67
+ tcgetattr (STDIN_FILENO, &oldt);
68
+ termios newt = oldt;
69
+ newt.c_lflag &= ~ECHO;
70
+ tcsetattr (STDIN_FILENO, TCSANOW, &newt);
71
+ g_lib.get_out () << " Please, enter password" << std::endl;
72
+ getline (std::cin, password_);
73
+ tcsetattr (STDIN_FILENO, TCSANOW, &oldt);
74
+ }
75
+
59
76
void event_handler (psync_eventtype_t event, psync_eventdata_t eventdata){
60
77
if (event<PEVENT_FIRST_USER_EVENT){
61
78
if (event&PEVENT_TYPE_FOLDER)
@@ -90,24 +107,53 @@ static void lib_setup_cripto(){
90
107
g_lib.crypto_on_ = true ;
91
108
}
92
109
110
+ static char const * status2string (uint32_t status){
111
+ switch (status){
112
+ case PSTATUS_READY: return " READY" ;
113
+ case PSTATUS_DOWNLOADING: return " DOWNLOADING" ;
114
+ case PSTATUS_UPLOADING: return " UPLOADING" ;
115
+ case PSTATUS_DOWNLOADINGANDUPLOADING: return " DOWNLOADINGANDUPLOADING" ;
116
+ case PSTATUS_LOGIN_REQUIRED: return " LOGIN_REQUIRED" ;
117
+ case PSTATUS_BAD_LOGIN_DATA: return " BAD_LOGIN_DATA" ;
118
+ case PSTATUS_BAD_LOGIN_TOKEN : return " BAD_LOGIN_TOKEN" ;
119
+ case PSTATUS_ACCOUNT_FULL: return " ACCOUNT_FULL" ;
120
+ case PSTATUS_DISK_FULL: return " DISK_FULL" ;
121
+ case PSTATUS_PAUSED: return " PAUSED" ;
122
+ case PSTATUS_STOPPED: return " STOPPED" ;
123
+ case PSTATUS_OFFLINE: return " OFFLINE" ;
124
+ case PSTATUS_CONNECTING: return " CONNECTING" ;
125
+ case PSTATUS_SCANNING: return " SCANNING" ;
126
+ case PSTATUS_USER_MISMATCH: return " USER_MISMATCH" ;
127
+ case PSTATUS_ACCOUT_EXPIRED: return " ACCOUT_EXPIRED" ;
128
+ default :return " Unrecognized status" ;
129
+ }
130
+ }
131
+
93
132
static void status_change (pstatus_t * status) {
94
133
static int cryptocheck=0 ;
95
134
static int mount_set=0 ;
96
- g_lib.get_out () << " Down: " << status->downloadstr << " | Up: " << status->uploadstr <<" , status is " << status->status << std::endl;
135
+ g_lib.get_out () << " Down: " << status->downloadstr << " | Up: " << status->uploadstr <<" , status is " << status2string ( status->status ) << std::endl;
97
136
*g_lib.status_ = *status;
98
137
if (status->status ==PSTATUS_LOGIN_REQUIRED){
99
- psync_set_user_pass (g_lib.get_username ().c_str (), g_lib.get_password ().c_str (), 1 );
138
+ psync_set_user_pass (g_lib.get_username ().c_str (), g_lib.get_password ().c_str (), ( int ) g_lib. save_pass_ );
100
139
g_lib.get_out () << " logging in" << std::endl;
101
140
}
102
141
else if (status->status ==PSTATUS_BAD_LOGIN_DATA){
142
+ if (!g_lib.newuser_ ) {
143
+ g_lib.get_pass_from_console ();
144
+ psync_set_user_pass (g_lib.get_username ().c_str (), g_lib.get_password ().c_str (), (int ) g_lib.save_pass_ );
145
+ }
146
+ else {
103
147
g_lib.get_out () << " registering" << std::endl;
104
148
if (psync_register (g_lib.get_username ().c_str (), g_lib.get_password ().c_str (),1 , NULL )){
105
149
g_lib.get_out () << " both login and registration failed" << std::endl;
106
150
exit (1 );
107
151
}
108
152
else {
109
153
g_lib.get_out () << " registered, logging in" << std::endl;
110
- psync_set_user_pass (g_lib.get_username ().c_str (), g_lib.get_password ().c_str (), 1 );
154
+ psync_set_user_pass (g_lib.get_username ().c_str (), g_lib.get_password ().c_str (), (int ) g_lib.save_pass_ );
155
+ }
156
+
111
157
}
112
158
}
113
159
if (status->status ==PSTATUS_READY || status->status ==PSTATUS_UPLOADING || status->status ==PSTATUS_DOWNLOADING || status->status ==PSTATUS_DOWNLOADINGANDUPLOADING){
@@ -158,7 +204,7 @@ int clib::init()//std::string& username, std::string& password, std::string* cry
158
204
159
205
if (username_old){
160
206
if (g_lib.username_ .compare (username_old) != 0 ){
161
- g_lib.get_out () << " logged in with user " << username_old <<" , not " << g_lib.username_ <<" , unlinking and exiting " <<std::endl;
207
+ g_lib.get_out () << " logged in with user " << username_old <<" , not " << g_lib.username_ <<" , unlinking" <<std::endl;
162
208
psync_unlink ();
163
209
psync_free (username_old);
164
210
return 2 ;
0 commit comments