correction of password managment
This commit is contained in:
+146
-58
@@ -68,7 +68,8 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
connect(this, &MainWindow::stopDownloading, this, &MainWindow::cancelled);
|
||||
connect(config.buttonBox, SIGNAL(accepted()), this, SLOT(on_buttonBox_accepted()));
|
||||
connect(config.comboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &MainWindow::on_comboBox_currentIndexChanged);
|
||||
connect(loginD.loginBox, SIGNAL(accepted()), this, SLOT(on_loginBox_accepted()));
|
||||
// connect(loginD.loginBox, SIGNAL(accepted()), this, SLOT(on_loginBox_accepted()));
|
||||
// connect(this, SIGNAL(passwordReady()), this, SLOT(waitPasswword()));
|
||||
|
||||
loadSettings();
|
||||
|
||||
@@ -292,7 +293,7 @@ void MainWindow::populateTree()
|
||||
{
|
||||
// server is validated, scanning directory
|
||||
path = this->connexion.service + "/";
|
||||
scanDir(this->connexion.server, this->connexion.port, nullptr, path);
|
||||
scanDir(this->connexion.server, this->connexion.port, nullptr, path);
|
||||
}
|
||||
// Restoring cursor
|
||||
QGuiApplication::restoreOverrideCursor();
|
||||
@@ -303,6 +304,7 @@ void MainWindow::populateTree()
|
||||
void MainWindow::populateList()
|
||||
{
|
||||
QString server;
|
||||
QString service;
|
||||
QStringList hidden;
|
||||
int port;
|
||||
int i;
|
||||
@@ -353,18 +355,70 @@ void MainWindow::populateList()
|
||||
}
|
||||
}
|
||||
this->settings.endGroup();
|
||||
this->settings.beginGroup("Hidden/");
|
||||
this->settings.beginGroup("Hidden/" + server);
|
||||
hidden = this->settings.allKeys();
|
||||
this->settings.endGroup();
|
||||
for (i = 0; i < hidden.size(); i++)
|
||||
{
|
||||
service = hidden.at(i);
|
||||
//TODO detect if service is already present
|
||||
ui->listWidget->addItem(this->settings.value(hidden.at(i)).toString() + "\n\t");
|
||||
if (testServicePresence(service, false))
|
||||
{
|
||||
ui->listWidget->addItem(service + "\n\t");
|
||||
}
|
||||
}
|
||||
QGuiApplication::restoreOverrideCursor(); //setting cursor to default
|
||||
this->settings.endGroup();
|
||||
}
|
||||
}
|
||||
|
||||
// Test if service is already present on the server
|
||||
bool MainWindow::testServicePresence(QString service, bool askPassword)
|
||||
{
|
||||
QString cmd;
|
||||
QStringList param;
|
||||
QString line;
|
||||
QString errorRsync;
|
||||
QStringList v;
|
||||
QProcess *myProcess;
|
||||
bool returnValue = false;
|
||||
QEventLoop loop;
|
||||
|
||||
cmd = "/usr/bin/rsync";
|
||||
param << "--contimeout=10" << "-nq" << "--port=" + QString::number(this->connexion.port) << this->connexion.server + "::" + service;
|
||||
myProcess = new QProcess(this);
|
||||
myProcess->setProcessChannelMode(QProcess::MergedChannels);
|
||||
myProcess->start(cmd, param);
|
||||
myProcess->waitForStarted();
|
||||
myProcess->write("\n");
|
||||
//myProcess->waitForFinished(12000);
|
||||
while(myProcess->waitForReadyRead(10000))
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
// line empty then buffer is empty so returning to wait new datas
|
||||
line = QString::fromUtf8(myProcess->readLine());
|
||||
if (line.isEmpty())
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (line.contains("auth failed"))
|
||||
{
|
||||
if (askPassword)
|
||||
{
|
||||
getUserPassword(&this->connexion);
|
||||
}
|
||||
returnValue = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (myProcess->exitCode() == 0)
|
||||
{
|
||||
returnValue = true;
|
||||
}
|
||||
myProcess->close();
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
//list services of the rsync server
|
||||
void MainWindow::listServices()
|
||||
{
|
||||
@@ -425,13 +479,15 @@ bool MainWindow::scanDir(QString server, int portN, QTreeWidgetItem *parent, QSt
|
||||
QString fileType;
|
||||
QString date;
|
||||
QProcess * myProcess;
|
||||
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
||||
bool isDir = false;
|
||||
bool flag = false;
|
||||
bool readOk = false;
|
||||
bool passwdOk = false;
|
||||
int nChild = 0;
|
||||
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
||||
|
||||
myProcess = new QProcess(this);
|
||||
myProcess->setProcessChannelMode(QProcess::MergedChannels);
|
||||
|
||||
if (parent != nullptr)
|
||||
{
|
||||
@@ -470,12 +526,19 @@ bool MainWindow::scanDir(QString server, int portN, QTreeWidgetItem *parent, QSt
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
if (line.contains("auth failed"))
|
||||
{
|
||||
myProcess->readAllStandardOutput();
|
||||
getUserPassword(&this->connexion);
|
||||
this->rescan = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// extracting name, size and if is dir/file
|
||||
line = line.simplified();
|
||||
filename = line.section(" ", 4);
|
||||
if (filename != '.')
|
||||
{
|
||||
|
||||
size = line.section(" ", 1, 1);
|
||||
fullsize = size;
|
||||
fullsize.remove(",");
|
||||
@@ -484,7 +547,8 @@ bool MainWindow::scanDir(QString server, int portN, QTreeWidgetItem *parent, QSt
|
||||
{
|
||||
size = sizeA.at(0) + " " + UnitText[0] + " ";
|
||||
}else
|
||||
{
|
||||
{ myProcess->setProcessEnvironment(env);
|
||||
|
||||
size = sizeA.at(0) + "," + sizeA.at(1).left(2) + " " + UnitText[sizeA.count()-1] + " ";
|
||||
}
|
||||
|
||||
@@ -498,6 +562,11 @@ bool MainWindow::scanDir(QString server, int portN, QTreeWidgetItem *parent, QSt
|
||||
date = line.section(' ', 2, 2);
|
||||
fileType = getFileType(filename);
|
||||
addTreeItem(filename, size, fullsize, fileType, date, isDir, parent);
|
||||
if (passwdOk == false and !this->connexion.password.isEmpty())
|
||||
{
|
||||
this->settings.setValue("Passwords/" + this->connexion.server + "/" + this->connexion.service + "/" + this->connexion.user, this->connexion.password);
|
||||
this->settings.sync();
|
||||
}
|
||||
}
|
||||
}
|
||||
flag = false;
|
||||
@@ -655,6 +724,7 @@ void MainWindow::addTreeItem(QString name, QString fileSize, QString fullsize, Q
|
||||
void MainWindow::on_listWidget_clicked()
|
||||
{
|
||||
this->connexion.service = ui->listWidget->currentItem()->text().section("\n", 0 ,0);
|
||||
ui->treeWidget->clear();
|
||||
preparePopulateTree();
|
||||
}
|
||||
|
||||
@@ -674,65 +744,72 @@ void MainWindow::preparePopulateTree()
|
||||
this->downloading.savePath = this->settings.value(str).toString();
|
||||
}
|
||||
|
||||
getUserPassword(false);
|
||||
//this->settings.beginGroup("Passwords/" + this->connexion.server + "/" + this->connexion.service);
|
||||
//logins = this->settings.allKeys();
|
||||
//if (logins.count() != 0)
|
||||
//{
|
||||
// this->connexion.user = logins[0];
|
||||
// this->connexion.password = this->settings.value(logins[0]).toString();
|
||||
//}
|
||||
this->settings.endGroup();
|
||||
getUserPassword(&this->connexion);
|
||||
|
||||
populateTree();
|
||||
}
|
||||
|
||||
// get password and user login
|
||||
// if object = false ==> searching from connexion object
|
||||
// else searching from downloading object
|
||||
bool MainWindow::getUserPassword(bool object = false)
|
||||
bool MainWindow::getUserPassword(Connexion * object)
|
||||
{
|
||||
QStringList logins;
|
||||
QString login;
|
||||
bool returnValue;
|
||||
QString password;
|
||||
QString server;
|
||||
QString service;
|
||||
|
||||
bool returnValue = false;
|
||||
bool ok = false;
|
||||
|
||||
if (object == false)
|
||||
{
|
||||
this->settings.beginGroup("Passwords/" + this->connexion.server + "/" + this->connexion.service);
|
||||
}else
|
||||
{
|
||||
this->settings.beginGroup("Passwords/" + this->downloading.server + "/" + this->downloading.service);
|
||||
}
|
||||
logins = this->settings.allKeys();
|
||||
server = object->server;
|
||||
service = object->service;
|
||||
|
||||
//TODO choose login in case of multiples logins
|
||||
if (logins.count() != 0)
|
||||
object->user = "";
|
||||
object->password = "";
|
||||
|
||||
this->settings.beginGroup("Passwords/" + server + "/" + service);
|
||||
logins = this->settings.allKeys();
|
||||
if (logins.count() != 1)
|
||||
{
|
||||
//choose login in case of multiples logins
|
||||
loginD.loginEdit->setHistoryItems(logins);
|
||||
login = QInputDialog::getItem(this,
|
||||
"RsincUI",
|
||||
tr("There is many users for this service.\nSelect user you want to connect with."),
|
||||
logins,
|
||||
0,
|
||||
true,
|
||||
&ok,
|
||||
Qt::Popup,
|
||||
Qt::ImhNoPredictiveText
|
||||
"RsincUI",
|
||||
tr("Select the user you want to connect with or enter a new one"),
|
||||
logins,
|
||||
0,
|
||||
true,
|
||||
&ok,
|
||||
Qt::Popup,
|
||||
Qt::ImhNoPredictiveText
|
||||
);
|
||||
if (object == false)
|
||||
if (ok and !login.isEmpty())
|
||||
{
|
||||
this->connexion.user = logins[0];
|
||||
this->connexion.password = this->settings.value(logins[0]).toString();
|
||||
}else
|
||||
{
|
||||
this->downloading.user = logins[0];
|
||||
this->downloading.password = this->settings.value(logins[0]).toString();
|
||||
if (!logins.contains(login))
|
||||
{
|
||||
password = QInputDialog::getText(this,
|
||||
tr("RsyncUI Request"),
|
||||
tr("Enter password"), QLineEdit::Password,
|
||||
"", &ok, Qt::Popup,
|
||||
Qt::ImhNoPredictiveText);
|
||||
if (!ok or password.isEmpty())
|
||||
{
|
||||
password = "";
|
||||
}
|
||||
}else
|
||||
{
|
||||
password = this->settings.value(login).toString();
|
||||
}
|
||||
object->user = login;
|
||||
object->password = password;
|
||||
}
|
||||
returnValue = true;
|
||||
}else
|
||||
{
|
||||
this->downloading.user = nullptr;
|
||||
this->downloading.password = nullptr;
|
||||
returnValue = false;
|
||||
object->user = logins.at(0);
|
||||
object->password = this->settings.value(object->user).toString();
|
||||
returnValue = true;
|
||||
}
|
||||
this->settings.endGroup();
|
||||
return returnValue;
|
||||
@@ -866,7 +943,7 @@ void MainWindow::startDownloading()
|
||||
|
||||
ui->progressBar->setValue(0);
|
||||
ui->progressBar->show();
|
||||
getUserPassword(false);
|
||||
//getUserPassword();
|
||||
|
||||
//QtConcurrent::run(&this->downloadO, &downloadFile::download, this);
|
||||
this->download();
|
||||
@@ -905,7 +982,7 @@ void MainWindow::downloadFinished(int exitCode, QProcess::ExitStatus exitStatus)
|
||||
aborted = tr("stopped by user");
|
||||
}else if (exitCode == 5) // password asked
|
||||
{
|
||||
loginDialog.show();
|
||||
getUserPassword(&this->downloading);
|
||||
retry = true;
|
||||
}
|
||||
|
||||
@@ -927,7 +1004,7 @@ void MainWindow::downloadFinished(int exitCode, QProcess::ExitStatus exitStatus)
|
||||
// disconnecting signals to slots
|
||||
disconnect(this->downloading.process, 0, 0, 0);
|
||||
|
||||
// reset variables and window
|
||||
// reset variables and window, close process
|
||||
this->downloading.process->close();
|
||||
ui->progressBar->hide();
|
||||
|
||||
@@ -949,7 +1026,9 @@ void MainWindow::downloadFinished(int exitCode, QProcess::ExitStatus exitStatus)
|
||||
this->downloading.server = path.midRef(pos+4).toString();
|
||||
path.resize(pos);
|
||||
this->downloading.path = path;
|
||||
getUserPassword(true);
|
||||
|
||||
//getUserPassword(true);
|
||||
testServicePresence(this->downloading.service, true);
|
||||
|
||||
// savepath exists in settings ?
|
||||
str = "Folder/" + this->downloading.server + "/" + this->downloading.service;
|
||||
@@ -1202,7 +1281,7 @@ void MainWindow::loadDownloadList()
|
||||
}
|
||||
|
||||
// clear object downloading
|
||||
void Downloading::clear()
|
||||
void Connexion::clear()
|
||||
{
|
||||
this->path.clear();
|
||||
this->server.clear();
|
||||
@@ -1248,21 +1327,30 @@ void MainWindow::on_actionExit_triggered()
|
||||
|
||||
void MainWindow::on_loginBox_accepted()
|
||||
{
|
||||
if (!loginD.loginEdit->text().isEmpty())
|
||||
/*Connexion * conn = this->passwordConnexion;
|
||||
|
||||
if (!loginD.loginEdit->currentText().isEmpty())
|
||||
{
|
||||
this->connexion.user = loginD.loginEdit->text();
|
||||
QString path;
|
||||
conn->user = loginD.loginEdit->currentText();
|
||||
path = "Passwords/" + conn->server + "/" + conn->service + "/" + conn->user;
|
||||
|
||||
if (!loginD.passwordEdit->text().isEmpty())
|
||||
{
|
||||
this->connexion.password = loginD.passwordEdit->text();
|
||||
this->settings.setValue("Passwords/" + this->connexion.server + "/" + this->connexion.service + "/" + this->connexion.user, this->connexion.password);
|
||||
conn->password = loginD.passwordEdit->text();
|
||||
this->settings.setValue("Passwords/" + conn->server + "/" + conn->service + "/" + conn->user, conn->password);
|
||||
this->settings.sync();
|
||||
if (this->rescan == true)
|
||||
{
|
||||
this->rescan = false;
|
||||
populateTree();
|
||||
}
|
||||
}else if (this->settings.contains(path))
|
||||
{
|
||||
conn->password = this->settings.value(path).toString();
|
||||
}
|
||||
}
|
||||
emit passwordReady();*/
|
||||
}
|
||||
|
||||
void MainWindow::setDlSpeed(QString speed)
|
||||
@@ -1281,7 +1369,7 @@ void MainWindow::on_actionHiddenService_triggered()
|
||||
if (ok && !text.isEmpty())
|
||||
{
|
||||
this->connexion.service = text;
|
||||
this->settings.setValue("Hidden/" + this->connexion.server, text);
|
||||
this->settings.setValue("Hidden/" + this->connexion.server + "/" + text, true);
|
||||
preparePopulateTree();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user