Added support for password protected services
This commit is contained in:
parent
e7eafb3117
commit
f47160622c
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE QtCreatorProject>
|
<!DOCTYPE QtCreatorProject>
|
||||||
<!-- Written by QtCreator 4.14.2, 2023-02-26T22:25:49. -->
|
<!-- Written by QtCreator 4.14.2, 2023-03-01T13:05:08. -->
|
||||||
<qtcreator>
|
<qtcreator>
|
||||||
<data>
|
<data>
|
||||||
<variable>EnvironmentId</variable>
|
<variable>EnvironmentId</variable>
|
||||||
|
30
login.ui
30
login.ui
@ -2,6 +2,9 @@
|
|||||||
<ui version="4.0">
|
<ui version="4.0">
|
||||||
<class>LoginDialog</class>
|
<class>LoginDialog</class>
|
||||||
<widget class="QDialog" name="LoginDialog">
|
<widget class="QDialog" name="LoginDialog">
|
||||||
|
<property name="windowModality">
|
||||||
|
<enum>Qt::ApplicationModal</enum>
|
||||||
|
</property>
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
@ -13,6 +16,9 @@
|
|||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Dialog</string>
|
<string>Dialog</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="modal">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
<widget class="QDialogButtonBox" name="loginBox">
|
<widget class="QDialogButtonBox" name="loginBox">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
@ -54,11 +60,20 @@
|
|||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="loginEdit">
|
<widget class="QLineEdit" name="loginEdit">
|
||||||
|
<property name="mouseTracking">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="focusPolicy">
|
||||||
|
<enum>Qt::TabFocus</enum>
|
||||||
|
</property>
|
||||||
|
<property name="acceptDrops">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Enter login name</string>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
<property name="maxLength">
|
<property name="maxLength">
|
||||||
<number>128</number>
|
<number>32767</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="placeholderText">
|
<property name="placeholderText">
|
||||||
<string>Enter login</string>
|
<string>Enter login</string>
|
||||||
@ -74,7 +89,16 @@
|
|||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="passwordEdit">
|
<widget class="QLineEdit" name="passwordEdit">
|
||||||
<property name="text">
|
<property name="focusPolicy">
|
||||||
|
<enum>Qt::TabFocus</enum>
|
||||||
|
</property>
|
||||||
|
<property name="acceptDrops">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="echoMode">
|
||||||
|
<enum>QLineEdit::Password</enum>
|
||||||
|
</property>
|
||||||
|
<property name="placeholderText">
|
||||||
<string>Enter password</string>
|
<string>Enter password</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
|
@ -49,6 +49,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
|
|
||||||
//init login dialog
|
//init login dialog
|
||||||
loginD.setupUi(&loginDialog);
|
loginD.setupUi(&loginDialog);
|
||||||
|
loginD.loginEdit->setFocus();
|
||||||
|
|
||||||
// text of About
|
// text of About
|
||||||
QString aboutText = tr("<h2>Client for rsync server</h2>") +
|
QString aboutText = tr("<h2>Client for rsync server</h2>") +
|
||||||
@ -290,7 +291,7 @@ void MainWindow::populateTree(QTreeWidgetItem * parent)
|
|||||||
{
|
{
|
||||||
// server is validated, scanning directory
|
// server is validated, scanning directory
|
||||||
path = ui->listWidget->currentItem()->text().section('\n', 0, 0) + "/";
|
path = ui->listWidget->currentItem()->text().section('\n', 0, 0) + "/";
|
||||||
scanDir(this->connexion.server, this->connexion.port, parent, path);
|
scanDir(this->connexion.server, this->connexion.port, parent, path);
|
||||||
}
|
}
|
||||||
// Restoring cursor
|
// Restoring cursor
|
||||||
QGuiApplication::restoreOverrideCursor();
|
QGuiApplication::restoreOverrideCursor();
|
||||||
@ -401,7 +402,7 @@ void MainWindow::listServices()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// connect to rsync server to get list of files
|
// connect to rsync server to get list of files
|
||||||
void MainWindow::scanDir(QString server, int portN, QTreeWidgetItem *parent, QString path)
|
bool MainWindow::scanDir(QString server, int portN, QTreeWidgetItem *parent, QString path)
|
||||||
{
|
{
|
||||||
QString cmd;
|
QString cmd;
|
||||||
QStringList param;
|
QStringList param;
|
||||||
@ -413,23 +414,26 @@ void MainWindow::scanDir(QString server, int portN, QTreeWidgetItem *parent, QSt
|
|||||||
bool flag = false;
|
bool flag = false;
|
||||||
bool readOk = false;
|
bool readOk = false;
|
||||||
int nChild = 0;
|
int nChild = 0;
|
||||||
QMessageBox::StandardButton reply;
|
|
||||||
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
||||||
|
|
||||||
myProcess = new QProcess(this);
|
myProcess = new QProcess(this);
|
||||||
if (!this->connexion.user.isEmpty())
|
|
||||||
{
|
|
||||||
server.prepend(this->connexion.user + "@");
|
|
||||||
env.insert("RSYNC_PASSWORD", "Test"); // Add an environment variable
|
|
||||||
myProcess->setProcessEnvironment(env);
|
|
||||||
}
|
|
||||||
if (parent != nullptr)
|
if (parent != nullptr)
|
||||||
{
|
{
|
||||||
nChild = parent->childCount();
|
nChild = parent->childCount();
|
||||||
}
|
}
|
||||||
if (nChild == 0)
|
if (nChild == 0)
|
||||||
{
|
{
|
||||||
|
if (!this->connexion.user.isEmpty())
|
||||||
|
{
|
||||||
|
server.prepend(this->connexion.user + "@");
|
||||||
|
env.insert("RSYNC_PASSWORD", this->connexion.password); // Add an environment variable
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
server.prepend("anonymous@");
|
||||||
|
env.insert("RSYNC_PASSWORD", "anonymous"); // Add an environment variable
|
||||||
|
}
|
||||||
|
myProcess->setProcessEnvironment(env);
|
||||||
cmd = "rsync";
|
cmd = "rsync";
|
||||||
param << "--contimeout=10" << "--port=" + QString::number(portN) << server + "::" + path;
|
param << "--contimeout=10" << "--port=" + QString::number(portN) << server + "::" + path;
|
||||||
|
|
||||||
@ -439,7 +443,7 @@ void MainWindow::scanDir(QString server, int portN, QTreeWidgetItem *parent, QSt
|
|||||||
// waiting for response of the server with a timeout of 10 seconds
|
// waiting for response of the server with a timeout of 10 seconds
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
readOk = myProcess->waitForReadyRead(5000);
|
readOk = myProcess->waitForReadyRead(10000);
|
||||||
if (readOk)
|
if (readOk)
|
||||||
{
|
{
|
||||||
while (!flag)
|
while (!flag)
|
||||||
@ -480,39 +484,12 @@ void MainWindow::scanDir(QString server, int portN, QTreeWidgetItem *parent, QSt
|
|||||||
{
|
{
|
||||||
if (myProcess->state() == QProcess::Running)
|
if (myProcess->state() == QProcess::Running)
|
||||||
{
|
{
|
||||||
if (myProcess->write("\n") == -1)
|
if (myProcess->waitForFinished(10000) == 0)
|
||||||
{
|
{
|
||||||
QMessageBox::warning(
|
QMessageBox::warning(
|
||||||
this,
|
this,
|
||||||
"RsyncUI",
|
"RsyncUI",
|
||||||
tr("Can't write to processus: ") + myProcess->errorString());
|
tr("The processus does'nt respond: ") + myProcess->errorString());
|
||||||
}
|
|
||||||
if (myProcess->waitForBytesWritten(5000) == 0)
|
|
||||||
{
|
|
||||||
QMessageBox::warning(
|
|
||||||
this,
|
|
||||||
"RsyncUI",
|
|
||||||
tr("writing to processus did not respond: ") + myProcess->errorString());
|
|
||||||
}
|
|
||||||
if (myProcess->state() == QProcess::Running)
|
|
||||||
{
|
|
||||||
/* if (myProcess->waitForFinished(10000) == 0)
|
|
||||||
{
|
|
||||||
QMessageBox::warning(
|
|
||||||
this,
|
|
||||||
"RsyncUI",
|
|
||||||
tr("The processus does'nt respond: do you need a password ? ") + myProcess->errorString());
|
|
||||||
}*/
|
|
||||||
reply = QMessageBox::question(
|
|
||||||
this,
|
|
||||||
"RsyncUI",
|
|
||||||
tr("The processus does'nt respond: do you need a password ? "),
|
|
||||||
QMessageBox::Yes|QMessageBox::No,
|
|
||||||
QMessageBox::No);
|
|
||||||
if (reply == QMessageBox::Yes)
|
|
||||||
{
|
|
||||||
loginDialog.show();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -522,6 +499,7 @@ void MainWindow::scanDir(QString server, int portN, QTreeWidgetItem *parent, QSt
|
|||||||
testRsyncReturn(this, myProcess);
|
testRsyncReturn(this, myProcess);
|
||||||
myProcess->close();
|
myProcess->close();
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify if server address is IP address
|
// Verify if server address is IP address
|
||||||
@ -665,6 +643,7 @@ void MainWindow::on_listWidget_clicked()
|
|||||||
QString str;
|
QString str;
|
||||||
QStringList logins;
|
QStringList logins;
|
||||||
|
|
||||||
|
this->rescan = true;
|
||||||
this->connexion.user = nullptr;
|
this->connexion.user = nullptr;
|
||||||
this->connexion.password = nullptr; this->connexion.service = ui->listWidget->currentItem()->text().section("\n", 0 ,0);
|
this->connexion.password = nullptr; this->connexion.service = ui->listWidget->currentItem()->text().section("\n", 0 ,0);
|
||||||
str = "Folder/" + this->connexion.server + "/" + this->connexion.service;
|
str = "Folder/" + this->connexion.server + "/" + this->connexion.service;
|
||||||
@ -686,14 +665,23 @@ void MainWindow::on_listWidget_clicked()
|
|||||||
populateTree(NULL);
|
populateTree(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MainWindow::getUserPassword()
|
// get password and user login
|
||||||
|
// if object = false ==> searching from connexion object
|
||||||
|
// else searching from downloading object
|
||||||
|
bool MainWindow::getUserPassword(bool object = false)
|
||||||
{
|
{
|
||||||
QStringList logins;
|
QStringList logins;
|
||||||
bool returnValue;
|
bool returnValue;
|
||||||
|
|
||||||
this->settings.beginGroup("Passwords/" + this->connexion.server + "/" + this->connexion.service);
|
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();
|
logins = this->settings.allKeys();
|
||||||
//TODO choose login in case of multiples logins
|
//TODO choose login in case of multiples logins
|
||||||
if (logins.count() != 0)
|
if (logins.count() != 0)
|
||||||
{
|
{
|
||||||
this->downloading.user = logins[0];
|
this->downloading.user = logins[0];
|
||||||
@ -835,7 +823,7 @@ void MainWindow::startDownloading()
|
|||||||
|
|
||||||
ui->progressBar->setValue(0);
|
ui->progressBar->setValue(0);
|
||||||
ui->progressBar->show();
|
ui->progressBar->show();
|
||||||
getUserPassword();
|
getUserPassword(false);
|
||||||
|
|
||||||
//QtConcurrent::run(&this->downloadO, &downloadFile::download, this);
|
//QtConcurrent::run(&this->downloadO, &downloadFile::download, this);
|
||||||
this->download();
|
this->download();
|
||||||
@ -877,7 +865,6 @@ void MainWindow::downloadFinished(int exitCode, QProcess::ExitStatus exitStatus)
|
|||||||
aborted = tr("stopped by user");
|
aborted = tr("stopped by user");
|
||||||
}else if (exitCode == 5) // password asked
|
}else if (exitCode == 5) // password asked
|
||||||
{
|
{
|
||||||
//TODO
|
|
||||||
loginDialog.show();
|
loginDialog.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -895,13 +882,6 @@ void MainWindow::downloadFinished(int exitCode, QProcess::ExitStatus exitStatus)
|
|||||||
// Some downloads staying in queue
|
// Some downloads staying in queue
|
||||||
if (ui->listDownload->count() != 0)
|
if (ui->listDownload->count() != 0)
|
||||||
{
|
{
|
||||||
// autosave is activated
|
|
||||||
/*if (config.autosaveCheckbox->checkState() == Qt::Checked)
|
|
||||||
{
|
|
||||||
// saving download list
|
|
||||||
saveDownloadList();
|
|
||||||
}*/
|
|
||||||
|
|
||||||
// initializing download
|
// initializing download
|
||||||
path = ui->listDownload->item(0)->text();
|
path = ui->listDownload->item(0)->text();
|
||||||
pos = path.lastIndexOf("/");
|
pos = path.lastIndexOf("/");
|
||||||
@ -911,6 +891,7 @@ void MainWindow::downloadFinished(int exitCode, QProcess::ExitStatus exitStatus)
|
|||||||
this->downloading.server = path.midRef(pos+4).toString();
|
this->downloading.server = path.midRef(pos+4).toString();
|
||||||
path.resize(pos);
|
path.resize(pos);
|
||||||
this->downloading.path = path;
|
this->downloading.path = path;
|
||||||
|
getUserPassword(true);
|
||||||
|
|
||||||
// savepath exists in settings ?
|
// savepath exists in settings ?
|
||||||
str = "Folder/" + this->downloading.server + "/" + this->downloading.service;
|
str = "Folder/" + this->downloading.server + "/" + this->downloading.service;
|
||||||
@ -1217,6 +1198,11 @@ void MainWindow::on_loginBox_accepted()
|
|||||||
this->connexion.password = loginD.passwordEdit->text();
|
this->connexion.password = loginD.passwordEdit->text();
|
||||||
this->settings.setValue("Passwords/" + this->connexion.server + "/" + this->connexion.service + "/" + this->connexion.user, this->connexion.password);
|
this->settings.setValue("Passwords/" + this->connexion.server + "/" + this->connexion.service + "/" + this->connexion.user, this->connexion.password);
|
||||||
this->settings.sync();
|
this->settings.sync();
|
||||||
|
if (this->rescan == true)
|
||||||
|
{
|
||||||
|
this->rescan = false;
|
||||||
|
populateTree(NULL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ class Downloading
|
|||||||
QString savePath;
|
QString savePath;
|
||||||
QString user;
|
QString user;
|
||||||
QString password;
|
QString password;
|
||||||
int port;
|
int port = 873;
|
||||||
QProcess * process = nullptr;
|
QProcess * process = nullptr;
|
||||||
bool quit = false;
|
bool quit = false;
|
||||||
void clear();
|
void clear();
|
||||||
@ -115,6 +115,8 @@ class MainWindow : public QMainWindow
|
|||||||
std::vector <QString> serversList;
|
std::vector <QString> serversList;
|
||||||
QSystemTrayIcon * trayIcon;
|
QSystemTrayIcon * trayIcon;
|
||||||
QString icon = "/usr/share/icons/RsyncUI.png";
|
QString icon = "/usr/share/icons/RsyncUI.png";
|
||||||
|
bool rescan = false;
|
||||||
|
|
||||||
QList<QString> bwUnitText {
|
QList<QString> bwUnitText {
|
||||||
"KB",
|
"KB",
|
||||||
"MB",
|
"MB",
|
||||||
@ -148,7 +150,7 @@ class MainWindow : public QMainWindow
|
|||||||
bool isIpAddress(QString server);
|
bool isIpAddress(QString server);
|
||||||
QTreeWidgetItem * addTreeRoot(QString name, QString description, bool isDir);
|
QTreeWidgetItem * addTreeRoot(QString name, QString description, bool isDir);
|
||||||
QTreeWidgetItem * addTreeChild(QTreeWidgetItem *parent, QString name, QString size, bool isDir);
|
QTreeWidgetItem * addTreeChild(QTreeWidgetItem *parent, QString name, QString size, bool isDir);
|
||||||
void scanDir(QString server, int portN, QTreeWidgetItem *parent = NULL, QString path = "" );
|
bool scanDir(QString server, int portN, QTreeWidgetItem *parent = NULL, QString path = "" );
|
||||||
void startDownloading();
|
void startDownloading();
|
||||||
void loadSettings();
|
void loadSettings();
|
||||||
void saveSettings();
|
void saveSettings();
|
||||||
@ -160,7 +162,7 @@ class MainWindow : public QMainWindow
|
|||||||
void hideWindow();
|
void hideWindow();
|
||||||
void showWindow();
|
void showWindow();
|
||||||
void init();
|
void init();
|
||||||
bool getUserPassword();
|
bool getUserPassword(bool);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user