Password authentication (stage 1 - without xosso-terminal)
authorArto Hyvättinen <arto.hyvattinen@gmail.com>
Fri, 13 Aug 2010 10:54:03 +0000 (13:54 +0300)
committerArto Hyvättinen <arto.hyvattinen@gmail.com>
Fri, 13 Aug 2010 10:54:03 +0000 (13:54 +0300)
src/settingsdialog.cpp
src/urpoconnection.h
src/urpoconnectionsettings.cpp
src/urpoconnectionsettings.h
src/urpoprocess.cpp
src/urpoprocess.h

index fa0e278..a0ffc26 100644 (file)
@@ -149,7 +149,8 @@ void SettingsDialog::serverChanged(const QString& text)
 
 void SettingsDialog::browse()
 {
 
 void SettingsDialog::browse()
 {
-    QString path = QFileDialog::getOpenFileName(this, tr("Identity file"));
+    // 2010-08-13 default path -> /home/user (bug#6219)
+    QString path = QFileDialog::getOpenFileName(this, tr("Identity file"),"/home/user");
     if(!path.isNull())
         identityEdit->setText(path);
 }
     if(!path.isNull())
         identityEdit->setText(path);
 }
index c647de7..6035ec9 100644 (file)
@@ -94,6 +94,10 @@ public:
       */
     QString getKeyOption();
 
       */
     QString getKeyOption();
 
+    /*!  Password or passphrase (UNSECURE!)
+      */
+    virtual QString getPassword() const = 0;
+
 private:
     /*! Receiver for debugMsg(QString&) signals */
     QObject* debugMonitor_;
 private:
     /*! Receiver for debugMsg(QString&) signals */
     QObject* debugMonitor_;
index d245b43..3ca4d09 100644 (file)
@@ -49,16 +49,29 @@ QString UrpoConnectionSettings::getUserid() const
 void UrpoConnectionSettings::setHost(const QString &host)
 {
     host_ = host;
 void UrpoConnectionSettings::setHost(const QString &host)
 {
     host_ = host;
+    password_ = QString();
 }
 
 void UrpoConnectionSettings::setIdentity(const QString &identity)
 {
     identity_ = identity;
 }
 
 void UrpoConnectionSettings::setIdentity(const QString &identity)
 {
     identity_ = identity;
+    password_ = QString();
 }
 
 void UrpoConnectionSettings::setUserid(const QString &userid)
 {
     userid_ = userid;
 }
 
 void UrpoConnectionSettings::setUserid(const QString &userid)
 {
     userid_ = userid;
+    password_ = QString();
+}
+
+QString UrpoConnectionSettings::getPassword() const
+{
+    return password_;
+}
+
+void UrpoConnectionSettings::setPassword(QString &password)
+{
+    password_ = password;
 }
 
 void UrpoConnectionSettings::store() const
 }
 
 void UrpoConnectionSettings::store() const
index d518a1a..ab780dc 100644 (file)
@@ -47,6 +47,9 @@ public:
     QString getIdentity() const;
     QString getUserid() const;
 
     QString getIdentity() const;
     QString getUserid() const;
 
+    QString getPassword() const;
+    void setPassword(QString &password);
+
     void setHost(const QString &host);
     void setIdentity(const QString &password);
     void setUserid(const QString &userid);
     void setHost(const QString &host);
     void setIdentity(const QString &password);
     void setUserid(const QString &userid);
@@ -60,6 +63,7 @@ private:
     QString host_;  /*! Host name or ip address */
     QString identity_;  /*! Identity (private key) file path */
     QString userid_; /*! Userid in remote host */
     QString host_;  /*! Host name or ip address */
     QString identity_;  /*! Identity (private key) file path */
     QString userid_; /*! Userid in remote host */
+    QString password_; /*! Password */
 
     bool storePassword_; /*! Allow to store password */
 
 
     bool storePassword_; /*! Allow to store password */
 
index 600e306..7900617 100644 (file)
@@ -23,6 +23,8 @@
 #include "urpoprocess.h"
 #include "urpoconnection.h"
 #include <QTimer>
 #include "urpoprocess.h"
 #include "urpoconnection.h"
 #include <QTimer>
+#include <QInputDialog>
+#include <QLineEdit>
 
 
 int const UrpoProcess::DEFAULTTIMEOUT;
 
 
 int const UrpoProcess::DEFAULTTIMEOUT;
@@ -59,7 +61,33 @@ void UrpoProcess::timeout()
 {
     // If process is still running, it means timeout!
     if( status_ == Running)
 {
     // If process is still running, it means timeout!
     if( status_ == Running)
-        fail(Timeout);
+    {
+        // Read output
+        QByteArray bytes = qprocess_.readAllStandardOutput();
+        QString string(bytes);
+        sendDebugMessage(string);
+
+        if(string.contains("'s password:") || string.contains("passphrase:"))
+        {
+            // Try to ask password
+            if( storedPassword_.isEmpty())
+            {
+                if( string.contains("'s password:") )
+                    storedPassword_ = QInputDialog::getText( 0, tr("Server ask password"), tr("Password:"), QLineEdit::PasswordEchoOnEdit );
+                else
+                    storedPassword_ = QInputDialog::getText( 0, tr("Server ask passphrase"), tr("Passphrase:"), QLineEdit::PasswordEchoOnEdit );
+            }
+            qprocess_.write(storedPassword_.toAscii());
+            qprocess_.write("\n");
+
+            QTimer::singleShot( getTimeout(), this, SLOT(timeout()) );
+            status_ = PasswdRunning;
+        }
+        else
+            fail( Timeout );
+    }
+    else if( status_ == PasswdRunning )
+        fail(Timeout);  // FAILS !!!
 }
 
 void UrpoProcess::start(const QString &command)
 }
 
 void UrpoProcess::start(const QString &command)
@@ -104,6 +132,8 @@ void UrpoProcess::processFinished(int exitCode,QProcess::ExitStatus exitStatus)
         output_=string.split("\n");
         status_=Successed;
         emit finished(true);
         output_=string.split("\n");
         status_=Successed;
         emit finished(true);
+
+
     }
 }
 
     }
 }
 
index 6a3d07a..1a0cf02 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <QObject>
 #include <QStringList>
 
 #include <QObject>
 #include <QStringList>
+#include <QString>
 #include <QProcess>
 class UrpoConnection;
 
 #include <QProcess>
 class UrpoConnection;
 
@@ -86,7 +87,8 @@ public:
         Ready       /*! Ready for connecting */         = 0,
         Running     /*! Command running */              = 1,
         Successed   /*! Command successed */            = 2,
         Ready       /*! Ready for connecting */         = 0,
         Running     /*! Command running */              = 1,
         Successed   /*! Command successed */            = 2,
-        Failed      /*! Command failed */               = 3
+        Failed      /*! Command failed */               = 3,
+        PasswdRunning /*! Running after password sent */ = 11
     };
 
     enum UrpoError {
     };
 
     enum UrpoError {
@@ -202,6 +204,7 @@ private:
     UrpoStatus status_;
     UrpoError error_;
     int timeout_;   /*! Timeout in msecs */
     UrpoStatus status_;
     UrpoError error_;
     int timeout_;   /*! Timeout in msecs */
+    QString storedPassword_; /* Password to store */
 };
 
 #endif // URPOPROCESS_H
 };
 
 #endif // URPOPROCESS_H