[X2go-Commits] x2goclient.git - master (branch) updated: 3.99.2.2-58-gdd0bb5c

X2Go dev team git-admin at x2go.org
Thu Sep 27 17:12:10 CEST 2012


The branch, master has been updated
       via  dd0bb5c56aab629a2476e7d3890382da462f25d7 (commit)
       via  7fb1879eb1e103522a5c5696e126d81ee4181594 (commit)
       via  5e08c788d5003464b5f576eac1398748bdffc448 (commit)
       via  53a6371c0d98e5735abdbb9971b4aef933524e37 (commit)
      from  6607e91be09fbbf18972e14fa65fef2a71e54833 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit dd0bb5c56aab629a2476e7d3890382da462f25d7
Author: Oleksandr Shneyder <oleksandr.shneyder at obviously-nice.de>
Date:   Thu Sep 27 17:12:02 2012 +0200

    commandline options --broker-user and --broker-noauth

commit 7fb1879eb1e103522a5c5696e126d81ee4181594
Author: Oleksandr Shneyder <oleksandr.shneyder at obviously-nice.de>
Date:   Thu Sep 27 16:18:11 2012 +0200

    improve brocker code add support for "usebrockerpass" config variable to use brocker pass for ssh auth on X2Go server

commit 5e08c788d5003464b5f576eac1398748bdffc448
Author: Oleksandr Shneyder <oleksandr.shneyder at obviously-nice.de>
Date:   Thu Sep 27 13:23:48 2012 +0200

    it is possible to add several ssh keys from commandline in form: --ssh-key=[user@][server:][port:]<path to key> it can be usefull for TCE or login over broker

commit 53a6371c0d98e5735abdbb9971b4aef933524e37
Author: Oleksandr Shneyder <oleksandr.shneyder at obviously-nice.de>
Date:   Thu Sep 27 12:30:55 2012 +0200

    clean some broker code

-----------------------------------------------------------------------

Summary of changes:
 debian/changelog     |    7 +
 httpbrokerclient.cpp |  372 ++++++++++----------------------------------------
 httpbrokerclient.h   |   11 +-
 onmainwindow.cpp     |  285 ++++++++++++++++++++++++--------------
 onmainwindow.h       |   16 ++-
 5 files changed, 275 insertions(+), 416 deletions(-)

The diff of changes is:
diff --git a/debian/changelog b/debian/changelog
index 682eb7c..3193042 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -60,6 +60,13 @@ x2goclient (3.99.3.0-0~x2go1) UNRELEASED; urgency=low
     - SshMasterConnection emit signal to GUI thread if it need a passphrase to decrypt a ssh key.
       GUI thread use input dialog to read a passphrase from user
     - Add support for SSH proxy (HTTP and SSH) to X2Go Client Gui
+    - clean some broker code 
+    - it is possible to add several ssh keys from commandline in form:
+      --ssh-key=[user@][server:][port:]<path to key>
+      it can be usefull for TCE or login over broker   
+    - improve brocker code
+      add support for "usebrockerpass" config variable to use brocker pass for ssh auth on X2Go server 
+    - commandline options --broker-user and --broker-noauth
 
   [ Ricardo Diaz ]
   * New upstream version (3.99.3.0):
diff --git a/httpbrokerclient.cpp b/httpbrokerclient.cpp
index 8402e0c..36d3e1b 100644
--- a/httpbrokerclient.cpp
+++ b/httpbrokerclient.cpp
@@ -30,7 +30,6 @@ HttpBrokerClient::HttpBrokerClient ( ONMainWindow* wnd, ConfigFile* cfg )
 {
     config=cfg;
     mainWindow=wnd;
-    cmdRequest=sinfoKeyRequest=sinfoRequest=-1;
     QUrl lurl ( config->brokerurl );
     http=new QHttp ( this );
 
@@ -45,24 +44,21 @@ HttpBrokerClient::HttpBrokerClient ( ONMainWindow* wnd, ConfigFile* cfg )
               SLOT ( slotRequestFinished ( int,bool ) ) );
     connect ( http,SIGNAL ( sslErrors ( const QList<QSslError>& ) ),this,
               SLOT ( slotSslErrors ( const QList<QSslError>& ) ) );
-    if (!wnd->brokerMode)
-        getSInfoFromBroker ( true );
 }
 
 
 HttpBrokerClient::~HttpBrokerClient()
 {
-
 }
 
 void HttpBrokerClient::getUserSessions()
 {
     QString req;
     QTextStream ( &req ) <<
-    "task=listsessions&"<<
-    "user="<<config->brokerUser<<"&"<<
-    "password="<<config->brokerPass<<"&"<<
-    "authid="<<config->brokerUserId;
+                         "task=listsessions&"<<
+                         "user="<<config->brokerUser<<"&"<<
+                         "password="<<config->brokerPass<<"&"<<
+                         "authid="<<config->brokerUserId;
     QUrl lurl ( config->brokerurl );
     httpSessionAnswer.close();
     httpSessionAnswer.setData ( 0,0 );
@@ -76,11 +72,11 @@ void HttpBrokerClient::selectUserSession(const QString& session)
 //     x2goDebug<<"selected sid: "<<session;
     QString req;
     QTextStream ( &req ) <<
-    "task=selectsession&"<<
-    "sid="<<session<<"&"<<
-    "user="<<config->brokerUser<<"&"<<
-    "password="<<config->brokerPass<<"&"<<
-    "authid="<<config->brokerUserId;
+                         "task=selectsession&"<<
+                         "sid="<<session<<"&"<<
+                         "user="<<config->brokerUser<<"&"<<
+                         "password="<<config->brokerPass<<"&"<<
+                         "authid="<<config->brokerUserId;
     QUrl lurl ( config->brokerurl );
     httpSessionAnswer.close();
     httpSessionAnswer.setData ( 0,0 );
@@ -93,11 +89,11 @@ void HttpBrokerClient::changePassword(QString newPass)
     newBrokerPass=newPass;
     QString req;
     QTextStream ( &req ) <<
-    "task=setpass&"<<
-    "newpass="<<newPass<<"&"<<
-    "user="<<config->brokerUser<<"&"<<
-    "password="<<config->brokerPass<<"&"<<
-    "authid="<<config->brokerUserId;
+                         "task=setpass&"<<
+                         "newpass="<<newPass<<"&"<<
+                         "user="<<config->brokerUser<<"&"<<
+                         "password="<<config->brokerPass<<"&"<<
+                         "authid="<<config->brokerUserId;
     QUrl lurl ( config->brokerurl );
     httpSessionAnswer.close();
     httpSessionAnswer.setData ( 0,0 );
@@ -109,14 +105,13 @@ void HttpBrokerClient::testConnection()
 {
     QString req;
     QTextStream ( &req ) <<
-    "task=testcon";
-    
+                         "task=testcon";
+
     QUrl lurl ( config->brokerurl );
     httpSessionAnswer.close();
     httpSessionAnswer.setData ( 0,0 );
     requestTime.start();
     testConRequest=http->post ( lurl.path(),req.toUtf8(),&httpSessionAnswer );
-
 }
 
 
@@ -134,169 +129,6 @@ void HttpBrokerClient::createIniFile(const QString& content)
     mainWindow->config.iniFile=cont;
 }
 
-QString HttpBrokerClient::getSInfoFromBroker ( bool getKey )
-{
-
-    QString pack;
-    bool fullscreen;
-    int height;
-    int width;
-    int quality;
-    int speed;
-    bool usekbd;
-    bool setDPI=false;
-    uint dpi=96;
-    QString layout;
-    QString type;
-    QString homeDir=mainWindow->getHomeDirectory();
-    X2goSettings st( "sessions" );
-
-    QString sid;
-    sid="embedded";
-    pack=st.setting()->value ( sid+"/pack",
-                               ( QVariant ) "16m-jpeg" ).toString();
-    fullscreen=st.setting()->value ( sid+"/fullscreen",
-                                     ( QVariant )
-                                     false ).toBool();
-    height=st.setting()->value ( sid+"/height",
-                                 ( QVariant ) 600 ).toInt();
-    width=st.setting()->value ( sid+"/width",
-                                ( QVariant ) 800 ).toInt();
-    setDPI=st.setting()->value ( sid+"/setdpi",
-                                 ( QVariant ) false ).toBool();
-    dpi=st.setting()->value ( sid+"/dpi",
-                              ( QVariant ) 96 ).toUInt();
-    quality=st.setting()->value (
-                sid+"/quality",
-                ( QVariant ) 9 ).toInt();
-    speed=st.setting()->value ( sid+"/speed",
-                                ( QVariant ) 2 ).toInt();
-    usekbd=st.setting()->value ( sid+"/usekbd",
-                                 ( QVariant ) true ).toBool();
-    layout=st.setting()->value ( sid+"/layout",
-                                 ( QVariant )
-                                 tr ( "us" ) ).toString();
-    type=st.setting()->value ( sid+"/type",
-                               ( QVariant )
-                               tr ( "pc105/us" ) ).toString();
-    bool startEmbedded=false;
-    if ( st.setting()->value ( sid+"/startembed",
-                               ( QVariant ) true ).toBool() )
-    {
-        startEmbedded=true;
-        fullscreen=false;
-        QSize sz=mainWindow->getEmbedAreaSize();
-        height=sz.height();
-        width=sz.width();
-
-    }
-
-    QString geometry;
-    if ( fullscreen )
-    {
-        geometry="fullscreen";
-#ifdef Q_OS_WIN
-        fullscreen=false;
-#endif
-    }
-    if ( ! fullscreen )
-    {
-        geometry=QString::number ( width ) +"x"+
-                 QString::number ( height );
-
-    }
-    QString link;
-    switch ( speed )
-    {
-    case 0:
-        link="modem";
-        break;
-    case 1:
-        link="isdn";
-        break;
-    case 2:
-        link="adsl";
-        break;
-    case 3:
-        link="wan";
-        break;
-    case 4:
-        link="lan";
-        break;
-    }
-
-    QFile file ( ":/txt/packs" );
-    file.open ( QIODevice::ReadOnly | QIODevice::Text );
-    QTextStream in ( &file );
-    while ( !in.atEnd() )
-    {
-        QString pc=in.readLine();
-        if ( pc.indexOf ( "-%" ) !=-1 )
-        {
-            pc=pc.left ( pc.indexOf ( "-%" ) );
-            if ( pc==pack )
-            {
-                pack+="-"+QString::number ( quality );
-                break;
-            }
-        }
-    }
-    file.close();
-
-    QDesktopWidget wd;
-    QString depth=QString::number ( wd.depth() );
-#ifdef Q_OS_DARWIN
-    usekbd=0;
-    type="query";
-#endif
-    QString dpiS;
-    if ( setDPI )
-    {
-        dpiS=QString::number ( dpi );
-    }
-    else
-        dpiS="noset";
-    QString useKbdS;
-    if ( usekbd )
-        useKbdS="1";
-    else
-        useKbdS="0";
-
-
-    QString req;
-    QTextStream ( &req ) <<
-    "mode=getsinfo&"<<
-    "geometry="<<geometry<<"&"
-    "link="<<link<<"&"
-    "pack="<<pack<<"&"
-    "depth="<<depth<<"&"
-    "layout="<<layout<<"&"
-    "type="<<type<<"&"
-    "usekbd="<<useKbdS<<"&"
-    "dpi="<<dpiS<<"&"
-    "user="<<config->user<<"&"<<
-    "connectionts="<<config->connectionts<<"&"<<
-    "cookie="<<config->cookie;
-    QUrl lurl ( config->brokerurl );
-    httpSIAnswer.close();
-    httpSIAnswer.setData ( 0,0 );
-    if ( getKey )
-    {
-        QTextStream ( &req ) <<"&"
-        "getkey=true";
-        sinfoKeyRequest=http->post ( lurl.path(),
-                                     req.toUtf8(),&httpSIAnswer );
-        x2goDebug<<"requested key :"<<sinfoKeyRequest;
-    }
-    else
-    {
-        sinfoRequest=http->post ( lurl.path(),
-                                  req.toUtf8(),&httpSIAnswer );
-        x2goDebug<<"requested session :"<<sinfoRequest;
-    }
-    return QString::null;
-}
-
 
 void HttpBrokerClient::slotRequestFinished ( int id, bool error )
 {
@@ -312,10 +144,10 @@ void HttpBrokerClient::slotRequestFinished ( int id, bool error )
 
     if (id==testConRequest)
     {
-        
+
         //x2goDebug<<"cmd request answer: "<<answer;
-	x2goDebug<<"elapsed: "<<requestTime.elapsed()<<"received:"<<httpSessionAnswer.size()<<endl;
-	emit connectionTime(requestTime.elapsed(),httpSessionAnswer.size());
+        x2goDebug<<"elapsed: "<<requestTime.elapsed()<<"received:"<<httpSessionAnswer.size()<<endl;
+        emit connectionTime(requestTime.elapsed(),httpSessionAnswer.size());
         return;
     }
     if ( id== sessionsRequest || id == selSessRequest || id==chPassRequest)
@@ -339,7 +171,8 @@ void HttpBrokerClient::slotRequestFinished ( int id, bool error )
         }
         if (id == selSessRequest)
         {
-            emit getSession(answer);
+            parseSession(answer);
+
         }
         if ( id == chPassRequest)
         {
@@ -354,67 +187,27 @@ void HttpBrokerClient::slotRequestFinished ( int id, bool error )
 
         }
     }
+}
 
-    if ( id==sinfoKeyRequest || id==sinfoRequest )
-    {
-// 		x2goDebug<<"Answer:"<<httpSIAnswer.data();
-        QString key ( httpSIAnswer.data() );
-        if ( key.indexOf ( "X2GO_BROKER_ERRORR-ACESS DENIED" ) !=-1 )
-        {
-            QMessageBox::critical (
-                0,tr ( "Error" ),
-                tr ( "Your session was disconnected. "
-                     "To get access to your running "
-                     "session, please return to the login page "
-                     "or use the \"reload\" function of "
-                     "your browser." ) );
-            emit fatalHttpError();
-            return;
-        }
-        QStringList strings=key.split ( "\n" );
-        for ( int i=0;i<strings.count();++i )
-        {
-            if ( strings[i].indexOf ( "x2gosession=" ) !=-1 )
-            {
-                QStringList vals=strings[i].split ( "=" );
-                config->sessiondata=vals[1];
-            }
-            if ( strings[i]=="rootless=false" )
-            {
-                config->rootless=false;
-            }
-            if ( strings[i]=="rootless=true" )
-            {
-                config->rootless=true;
-            }
-        }
-        if ( id==sinfoKeyRequest )
-        {
-            emit haveSshKey ( key );
-            QTimer::singleShot ( 5000, this,
-                                 SLOT ( slotGetConnectionCmd() ) );
-        }
-        else
-            emit haveAgentInfo();
-    }
-    if ( id==cmdRequest )
+void HttpBrokerClient::parseSession(QString sinfo)
+{
+    QStringList lst=sinfo.split("SERVER:",QString::SkipEmptyParts);
+    int keyStartPos=sinfo.indexOf("-----BEGIN DSA PRIVATE KEY-----");
+    QString endStr="-----END DSA PRIVATE KEY-----";
+    int keyEndPos=sinfo.indexOf(endStr);
+    if (! (keyEndPos == -1 || keyStartPos == -1 || lst.size()==0))
+        config->key=sinfo.mid(keyStartPos, keyEndPos+endStr.length()-keyStartPos);
+    QString serverLine=(lst[1].split("\n"))[0];
+    QStringList words=serverLine.split(":",QString::SkipEmptyParts);
+    config->serverIp=words[0];
+    if (words.count()>1)
+        config->sshport=words[1];
+    if (sinfo.indexOf("SESSION_INFO")!=-1)
     {
-        QString answer ( httpCmdAnswer.data() );
-//  		x2goDebug<<"cmd request answer: "<<answer;
-        if ( !error )
-        {
-            answer=answer.split (
-                       "<body onload=\"checkPlugin()\">" ) [1];
-            answer=answer.split ( "</body>" ) [0];
-            if ( answer.indexOf ( "CMD:0:" ) !=-1 )
-            {
-                x2goDebug<<"brocker sent reconnect cmd";
-                emit cmdReconnect();
-            }
-        }
-        QTimer::singleShot ( 3000, this,
-                             SLOT ( slotGetConnectionCmd() ) );
+        QStringList lst=sinfo.split("SESSION_INFO:",QString::SkipEmptyParts);
+        config->sessiondata=(lst[1].split("\n"))[0];
     }
+    emit sessionSelected();
 }
 
 
@@ -422,7 +215,7 @@ void HttpBrokerClient::slotSslErrors ( const QList<QSslError> & errors )
 {
     QStringList err;
     QSslCertificate cert;
-    for ( int i=0;i<errors.count();++i )
+    for ( int i=0; i<errors.count(); ++i )
     {
         x2goDebug<<"sslError ,code:"<<errors[i].error() <<":";
         err<<errors[i].errorString();
@@ -463,37 +256,37 @@ void HttpBrokerClient::slotSslErrors ( const QList<QSslError> & errors )
                      text );
     text=QString::null;
     QTextStream ( &text ) <<err.join ( "\n" ) <<"\n"<<
-    "------------\n"<<
-    tr ( "Issued to:\n" ) <<
-    tr ( "Common Name(CN)\t" ) <<
-    cert.issuerInfo ( QSslCertificate::CommonName )
-    <<endl<<
-    tr ( "Organization(O)\t" ) <<
-    cert.issuerInfo ( QSslCertificate::Organization )
-    <<endl<<
-    tr ( "Organizational Unit(OU)\t" ) <<
-    cert.issuerInfo ( QSslCertificate::OrganizationalUnitName )
-    <<endl<<
-    tr ( "Serial Number\t" ) <<getHexVal ( cert.serialNumber() )
-    <<endl<<endl<<
-    tr ( "Issued by:\n" ) <<
-    tr ( "Common Name(CN)\t" ) <<
-    cert.subjectInfo ( QSslCertificate::CommonName )
-    <<endl<<
-    tr ( "Organization(O)\t" ) <<
-    cert.subjectInfo ( QSslCertificate::Organization )
-    <<endl<<
-    tr ( "Organizational Unit(OU)\t" ) <<
-    cert.subjectInfo ( QSslCertificate::OrganizationalUnitName )
-    <<endl<<endl<<
-
-    tr ( "Validity:\n" ) <<
-    tr ( "Issued on\t" ) <<cert.effectiveDate().toString() <<endl<<
-    tr ( "expires on\t" ) <<cert.expiryDate().toString() <<endl<<endl<<
-    tr ( "Fingerprints:\n" ) <<
-    tr ( "SHA1\t" ) <<
-    getHexVal ( cert.digest ( QCryptographicHash::Sha1 ) ) <<endl<<
-    tr ( "MD5\t" ) <<md5;
+                          "------------\n"<<
+                          tr ( "Issued to:\n" ) <<
+                          tr ( "Common Name(CN)\t" ) <<
+                          cert.issuerInfo ( QSslCertificate::CommonName )
+                          <<endl<<
+                          tr ( "Organization(O)\t" ) <<
+                          cert.issuerInfo ( QSslCertificate::Organization )
+                          <<endl<<
+                          tr ( "Organizational Unit(OU)\t" ) <<
+                          cert.issuerInfo ( QSslCertificate::OrganizationalUnitName )
+                          <<endl<<
+                          tr ( "Serial Number\t" ) <<getHexVal ( cert.serialNumber() )
+                          <<endl<<endl<<
+                          tr ( "Issued by:\n" ) <<
+                          tr ( "Common Name(CN)\t" ) <<
+                          cert.subjectInfo ( QSslCertificate::CommonName )
+                          <<endl<<
+                          tr ( "Organization(O)\t" ) <<
+                          cert.subjectInfo ( QSslCertificate::Organization )
+                          <<endl<<
+                          tr ( "Organizational Unit(OU)\t" ) <<
+                          cert.subjectInfo ( QSslCertificate::OrganizationalUnitName )
+                          <<endl<<endl<<
+
+                          tr ( "Validity:\n" ) <<
+                          tr ( "Issued on\t" ) <<cert.effectiveDate().toString() <<endl<<
+                          tr ( "expires on\t" ) <<cert.expiryDate().toString() <<endl<<endl<<
+                          tr ( "Fingerprints:\n" ) <<
+                          tr ( "SHA1\t" ) <<
+                          getHexVal ( cert.digest ( QCryptographicHash::Sha1 ) ) <<endl<<
+                          tr ( "MD5\t" ) <<md5;
 
 
 
@@ -518,7 +311,7 @@ void HttpBrokerClient::slotSslErrors ( const QList<QSslError> & errors )
         fl.close();
         http->ignoreSslErrors();
         x2goDebug<<"store certificate in  "<<homeDir+"/ssl/exceptions/"+
-        lurl.host() +"/"+fname;
+                 lurl.host() +"/"+fname;
         requestTime.restart();
     }
     else
@@ -529,7 +322,7 @@ void HttpBrokerClient::slotSslErrors ( const QList<QSslError> & errors )
 QString HttpBrokerClient::getHexVal ( const QByteArray& ba )
 {
     QStringList val;
-    for ( int i=0;i<ba.size();++i )
+    for ( int i=0; i<ba.size(); ++i )
     {
         QString bt;
         bt.sprintf ( "%02X", ( unsigned char ) ba[i] );
@@ -537,22 +330,3 @@ QString HttpBrokerClient::getHexVal ( const QByteArray& ba )
     }
     return val.join ( ":" );
 }
-
-
-void HttpBrokerClient::slotGetConnectionCmd()
-{
-    QString req;
-    QTextStream ( &req ) <<
-    "mode=getcmd&"<<
-    "user="<<config->user<<"&"<<
-    "connectionts="<<config->connectionts<<"&"<<
-    "cookie="<<config->cookie;
-
-    QUrl lurl ( config->brokerurl );
-    httpCmdAnswer.close();
-    httpCmdAnswer.setData ( 0,0 );
-
-    cmdRequest=http->post ( lurl.path(),
-                            req.toUtf8(),&httpCmdAnswer );
-// 	x2goDebug<<"requested brocker cmd :"<<cmdRequest;
-}
diff --git a/httpbrokerclient.h b/httpbrokerclient.h
index 02d519c..e7b3b57 100644
--- a/httpbrokerclient.h
+++ b/httpbrokerclient.h
@@ -29,44 +29,37 @@ class HttpBrokerClient: public QObject
 public:
     HttpBrokerClient ( ONMainWindow* wnd, ConfigFile* cfg );
     ~HttpBrokerClient();
-    QString getSInfoFromBroker ( bool getKey=false );
     void selectUserSession(const QString& session );
     void changePassword(QString newPass);
     void testConnection();
 private:
-    QBuffer httpSIAnswer;
     QBuffer httpCmdAnswer;
     QBuffer httpSessionAnswer;
     QHttp* http;
-    int sinfoRequest;
-    int sinfoKeyRequest;
     int sessionsRequest;
     int selSessRequest;
-    int cmdRequest;
     int chPassRequest;
     int testConRequest;
     QString newBrokerPass;
     ConfigFile* config;
     ONMainWindow* mainWindow;
     void createIniFile(const QString& content);
+    void parseSession(QString sInfo);
     QTime requestTime;
 
 private slots:
     void slotRequestFinished ( int id, bool error );
     void slotSslErrors ( const QList<QSslError> & errors ) ;
     QString getHexVal ( const QByteArray& ba );
-    void slotGetConnectionCmd();
 public slots:
     void getUserSessions();
 
 signals:
     void haveSshKey ( QString );
     void fatalHttpError();
-    void haveAgentInfo ();
-    void cmdReconnect ();
     void authFailed();
     void sessionsLoaded();
-    void getSession( QString );
+    void sessionSelected( );
     void passwordChanged( QString );
     void connectionTime(int, int);
 };
diff --git a/onmainwindow.cpp b/onmainwindow.cpp
index 1ffd02c..2825e38 100644
--- a/onmainwindow.cpp
+++ b/onmainwindow.cpp
@@ -432,17 +432,11 @@ ONMainWindow::ONMainWindow ( QWidget *parent ) :QMainWindow ( parent )
     if (brokerMode)
     {
         broker=new HttpBrokerClient ( this, &config );
-        connect ( broker,SIGNAL ( haveSshKey ( QString ) ),this,
-                  SLOT ( slotStartSshAgent ( QString ) ) );
-        connect ( broker,SIGNAL ( haveAgentInfo () ),this,
-                  SLOT ( slotStartNewBrokerSession () ) );
         connect ( broker,SIGNAL ( fatalHttpError() ),this,
                   SLOT ( close() ) );
-        connect ( broker,SIGNAL ( cmdReconnect() ),this,
-                  SLOT ( slotReconnectSession() ) );
         connect ( broker, SIGNAL ( authFailed()), this ,SLOT ( slotGetBrokerAuth()));
         connect ( broker, SIGNAL( sessionsLoaded()), this, SLOT (slotReadSessions()));
-        connect ( broker, SIGNAL ( getSession(QString)), this, SLOT (slotGetBrokerSession(QString)));
+        connect ( broker, SIGNAL ( sessionSelected()), this, SLOT (slotGetBrokerSession()));
         connect ( broker, SIGNAL ( passwordChanged(QString)), this, SLOT ( slotPassChanged(QString)));
     }
 
@@ -975,6 +969,13 @@ void ONMainWindow::slotGetBrokerAuth()
     nameLabel->setText ( text );
     slotShowPassForm();
     config.brokerAuthenticated=false;
+    if(config.brokerUser.length()>=0)
+    {
+        login->setText(config.brokerUser);
+        pass->setFocus();
+    }
+    if(config.brokerNoAuth)
+        slotSessEnter();
 }
 
 
@@ -2552,6 +2553,7 @@ void ONMainWindow::slotSelectedFromList ( SessionButton* session )
     QString userName;
     bool autologin=false;
     bool krblogin=false;
+    bool usebrokerpass=false;
     QString sessIcon;
     QPalette pal;
     QString sessionName;
@@ -2563,50 +2565,56 @@ void ONMainWindow::slotSelectedFromList ( SessionButton* session )
         sessionName=session->name();
 
         QString sid=session->id();
+        X2goSettings* st;
         if (brokerMode)
         {
-            broker->selectUserSession(session->id());
-            setStatStatus ( tr ( "Connecting to broker" ) );
-            stInfo->insertPlainText ( "broker url: "+config.brokerurl );
-            setEnabled ( false );
-            uname->hide();
-            u->hide();
-            return;
+            st=new X2goSettings( config.iniFile, QSettings::IniFormat );
+        }
+        else
+        {
+            st = new X2goSettings( "sessions" );
         }
 
-        X2goSettings st ( "sessions" );
 
-        sessIcon=st.setting()->value (
+
+        sessIcon=st->setting()->value (
                      sid+"/icon",
                      ( QVariant ) ":icons/128x128/x2gosession.png"
                  ).toString();
 
 
-        command=st.setting()->value (
+        command=st->setting()->value (
                     sid+"/command",
                     ( QVariant ) tr ( "KDE" ) ).toString();
 
-        server=st.setting()->value ( sid+"/host",
-                                     ( QVariant ) QString::null
-                                   ).toString();
-        userName=st.setting()->value (
+        server=st->setting()->value ( sid+"/host",
+                                      ( QVariant ) QString::null
+                                    ).toString();
+        userName=st->setting()->value (
                      sid+"/user",
                      ( QVariant ) QString::null ).toString();
         if (defaultUser && userName.length()<1)
             userName=defaultUserName;
 
-        sshPort=st.setting()->value (
+        if(brokerMode)
+            usebrokerpass=st->setting()->value (
+                              sid+"/usebrokerpass",
+                              false ).toBool();
+
+
+        sshPort=st->setting()->value (
                     sid+"/sshport",
                     ( QVariant ) defaultSshPort ).toString();
-        currentKey=st.setting()->value (
+        currentKey=st->setting()->value (
                        sid+"/key",
                        ( QVariant ) QString::null ).toString();
-        autologin=st.setting()->value (
+        autologin=st->setting()->value (
                       sid+"/autologin",
                       ( QVariant ) false ).toBool();
-        krblogin=st.setting()->value (
+        krblogin=st->setting()->value (
                      sid+"/krblogin",
                      ( QVariant ) false ).toBool();
+        delete st;
 #ifdef Q_OS_WIN
         if ( portable &&
                 u3Device.length() >0 )
@@ -2625,6 +2633,7 @@ void ONMainWindow::slotSelectedFromList ( SessionButton* session )
         sessionName=config.session;
         currentKey=config.key;
     }
+
     selectedCommand=command;
     command=transAppName ( command );
     login->setText ( userName );
@@ -2646,6 +2655,11 @@ void ONMainWindow::slotSelectedFromList ( SessionButton* session )
         fotoLabel->setFixedSize ( 48,48 );
     }
 
+    if(currentKey.length()<=0)
+    {
+        currentKey=findSshKeyForServer(userName, server, sshPort);
+    }
+
 
     if ( command=="RDP" )
     {
@@ -2673,6 +2687,12 @@ void ONMainWindow::slotSelectedFromList ( SessionButton* session )
 
 ///////////////////////////////////////////////////
 
+    if(brokerMode &&usebrokerpass)
+    {
+        pass->setText(config.brokerPass);
+        slotSessEnter();
+    }
+
     if ( currentKey.length() >0 )
     {
         nopass=true;
@@ -2682,7 +2702,7 @@ void ONMainWindow::slotSelectedFromList ( SessionButton* session )
         x2goDebug<<"Have key, starting session"<<endl;
         slotSessEnter();
     }
-    if ( cardReady || autologin || krblogin )
+    if ( cardReady || autologin || krblogin  )
     {
         nopass=true;
         if ( cardReady )
@@ -2738,10 +2758,6 @@ SshMasterConnection* ONMainWindow::startSshConnection ( QString host, QString po
     /////key/sshagent/env/
 
     passForm->setEnabled ( false );
-    if(cmdSshKey.length()>0)
-    {
-        currentKey=cmdSshKey;
-    }
     if(cmdAutologin)
     {
         autologin=true;
@@ -2779,7 +2795,6 @@ void ONMainWindow::slotSshConnectionError ( QString message, QString lastSession
     QMessageBox::critical ( 0l,message,lastSessionError,
                             QMessageBox::Ok,
                             QMessageBox::NoButton );
-// 	currentKey=QString::null;
     setEnabled ( true );
     passForm->setEnabled ( true );
     slotShowPassForm();
@@ -2955,7 +2970,6 @@ void ONMainWindow::slotSshUserAuthError ( QString error )
     QMessageBox::critical ( 0l,tr ( "Authentication failed" ),error,
                             QMessageBox::Ok,
                             QMessageBox::NoButton );
-// 	currentKey=QString::null;
     setEnabled ( true );
     passForm->setEnabled ( true );
     slotShowPassForm();
@@ -2993,11 +3007,25 @@ void ONMainWindow::slotSessEnter()
         }
     }
 
+
+
     resumingSession.sessionId=QString::null;
     resumingSession.server=QString::null;
     resumingSession.display=QString::null;
     setStatStatus ( tr ( "connecting" ) );
 
+    if(brokerMode)
+    {
+        broker->selectUserSession(lastSession->id());
+        config.session=lastSession->id();
+        setStatStatus ( tr ( "Connecting to broker" ) );
+        stInfo->insertPlainText ( "broker url: "+config.brokerurl );
+        setEnabled ( false );
+        uname->hide();
+        u->hide();
+        return;
+    }
+
     QString sid="";
     if ( !embedMode )
         sid=lastSession->id();
@@ -3124,6 +3152,38 @@ void ONMainWindow::startDirectRDP()
 #endif
 
 
+QString ONMainWindow::findSshKeyForServer(QString user, QString server, QString port)
+{
+    foreach (sshKey key, cmdSshKeys)
+    {
+        if(key.server == server && key.user == user && key.port == port)
+            return key.key;
+    }
+    foreach (sshKey key, cmdSshKeys)
+    {
+        if(key.server == server && key.user == user && key.port.length()<=0)
+            return key.key;
+    }
+
+    foreach (sshKey key, cmdSshKeys)
+    {
+        if(key.server == server && key.user.length()<=0 && key.port==port)
+            return key.key;
+    }
+
+    foreach (sshKey key, cmdSshKeys)
+    {
+        if(key.server == server && key.user.length()<=0 && key.port.length()<=0)
+            return key.key;
+    }
+
+    foreach (sshKey key, cmdSshKeys)
+    {
+        if(key.server.length()<=0 && key.user.length()<=0 && key.port.length()<=0)
+            return key.key;
+    }
+    return QString::null;
+}
 
 
 bool ONMainWindow::startSession ( const QString& sid )
@@ -3159,65 +3219,51 @@ bool ONMainWindow::startSession ( const QString& sid )
         return true;
     }
 
-    if ( !embedMode && !brokerMode )
-    {
+    X2goSettings* st;
+    if(!brokerMode)
+        st=new  X2goSettings( "sessions" );
+    else
+        st=new X2goSettings(config.iniFile, QSettings::IniFormat);
 
-        X2goSettings st ( "sessions" );
+    passForm->setEnabled ( false );
+    host=st->setting()->value ( sid+"/host",
+                                ( QVariant ) QString::null ).toString();
+    if(brokerMode)
+    {
+        sshPort=config.sshport;
+        x2goDebug<<"server: "<<host;
+    }
 
-        passForm->setEnabled ( false );
-        host=st.setting()->value ( sid+"/host",
-                                   ( QVariant ) QString::null ).toString();
-        QString cmd=st.setting()->value ( sid+"/command",
-                                          ( QVariant ) QString::null ).toString();
-        autologin=st.setting()->value ( sid+"/autologin",
-                                        ( QVariant ) false ).toBool();
-        krblogin=st.setting()->value ( sid+"/krblogin",
-                                       ( QVariant ) false ).toBool();
+    QString cmd=st->setting()->value ( sid+"/command",
+                                       ( QVariant ) QString::null ).toString();
+    autologin=st->setting()->value ( sid+"/autologin",
+                                     ( QVariant ) false ).toBool();
+    krblogin=st->setting()->value ( sid+"/krblogin",
+                                    ( QVariant ) false ).toBool();
 #ifdef Q_OS_LINUX
-        directRDP=st.setting()->value ( sid+"/directrdp",
-                                        ( QVariant ) false ).toBool();
-        if (cmd =="RDP" && directRDP)
-        {
-            startDirectRDP();
-            return true;
-        }
-#endif
-        if ( cmd=="SHADOW" )
-            shadowSession=true;
-    }
-    else
+    directRDP=st->setting()->value ( sid+"/directrdp",
+                                     ( QVariant ) false ).toBool();
+    if (cmd =="RDP" && directRDP)
     {
-        host=config.server;
-        sshPort=config.sshport;
-        selectedCommand=config.command;
+        startDirectRDP();
+        return true;
     }
-    if (!brokerMode)
-        passwd=getCurrentPass();
-    else
+#endif
+    if ( cmd=="SHADOW" )
+        shadowSession=true;
+    passwd=getCurrentPass();
+    if(brokerMode)
     {
         currentKey=config.key;
-        host=config.server;
-        X2goSettings st ( config.iniFile, QSettings::IniFormat );
-        passForm->setEnabled ( false );
-        user=st.setting()->value ( sid+"/user",
-                                   ( QVariant ) QString::null ).toString();
-        login->setText(user);
         sshPort=config.sshport;
-        /*        sshPort=st.setting()->value ( sid+"/sshport",
-                                              ( QVariant ) "22" ).toString();*/
     }
     if (sshConnection)
         sshConnection->disconnectSession();
 
-
-    X2goSettings* st;
-    if(!brokerMode)
-        st=new  X2goSettings( "sessions" );
-    else
-        st=new X2goSettings(config.iniFile, QSettings::IniFormat);
-
-
-
+    if(currentKey.length()<=0)
+    {
+        currentKey=findSshKeyForServer(user, host, sshPort);
+    }
 
     useproxy=(st->setting()->value (
                   sid+"/usesshproxy",
@@ -3277,6 +3323,11 @@ bool ONMainWindow::startSession ( const QString& sid )
                         false
                     ).toBool() );
 
+    if(proxyKey.length()<=0 && proxyType==SshMasterConnection::PROXYSSH)
+    {
+        proxyKey=findSshKeyForServer(proxylogin, proxyserver, QString::number(proxyport));
+    }
+
     if(proxySameUser)
         proxylogin=user;
     if(proxySamePass)
@@ -3287,12 +3338,18 @@ bool ONMainWindow::startSession ( const QString& sid )
         {
             bool ok;
             proxypassword=QInputDialog::getText(0,proxylogin+"@"+proxyserver+":"+QString::number(proxyport),
-                                                tr("Enter passwort for SSH proxy"),QLineEdit::Password,QString::null, &ok);
+                                                tr("Enter password for SSH proxy"),QLineEdit::Password,QString::null, &ok);
         }
     }
 
     delete st;
 
+    if(brokerMode)
+    {
+        host=config.serverIp;
+    }
+
+
     sshConnection=startSshConnection ( host,sshPort,acceptRsa,user,passwd,autologin, krblogin, false, useproxy,proxyType,proxyserver,
                                        proxyport, proxylogin, proxypassword, proxyKey,proxyAutologin);
     return true;
@@ -6153,6 +6210,11 @@ bool ONMainWindow::parseParameter ( QString param )
         return true;
     }
 
+    if ( param == "--broker-noauth")
+    {
+        config.brokerNoAuth=true;
+        return true;
+    }
 
 
     QString setting,value;
@@ -6277,9 +6339,42 @@ bool ONMainWindow::parseParameter ( QString param )
         config.brokerurl=value;
         return true;
     }
+    if ( setting == "--broker-user")
+    {
+        config.brokerUser=value;
+        return true;
+    }
     if ( setting == "--ssh-key")
     {
-        cmdSshKey=value;
+        sshKey key;
+        QStringList parts=value.split(":");
+        QString authPart;
+        switch(parts.length())
+        {
+        case 1:
+            key.key=parts[0];
+            break;
+        case 2:
+            key.key=parts[1];
+            authPart=parts[0];
+            break;
+        case 3:
+            authPart=parts[0];
+            key.key=parts[2];
+            key.port=parts[1];
+            break;
+        }
+        if(authPart.length()>0)
+        {
+            if(authPart.indexOf("@")!=-1)
+            {
+                key.user=authPart.split("@")[0];
+                key.server=authPart.split("@")[1];
+            }
+            else
+                key.server=authPart;
+        }
+        cmdSshKeys<<key;
         return true;
     }
     if ( setting == "--broker-name")
@@ -6670,7 +6765,6 @@ void ONMainWindow::slotGetServers ( bool result, QString output,
         QMessageBox::critical ( 0l,tr ( "Error" ),message,
                                 QMessageBox::Ok,
                                 QMessageBox::NoButton );
-// 		currentKey=QString::null;
         setEnabled ( true );
         passForm->setEnabled ( true );
         pass->setFocus();
@@ -8234,7 +8328,6 @@ void ONMainWindow::slotCmdMessage ( bool result,QString output,
         QMessageBox::critical ( 0l,tr ( "Error" ),message,
                                 QMessageBox::Ok,
                                 QMessageBox::NoButton );
-// 		currentKey=QString::null;
         setEnabled ( true );
         passForm->setEnabled ( true );
         pass->setFocus();
@@ -10805,7 +10898,6 @@ void ONMainWindow::slotReconnectSession()
         slotSelectedFromList ( ( SessionButton* ) 0 );
     else
     {
-        broker->getSInfoFromBroker();
         setEnabled ( false );
     }
 }
@@ -10832,28 +10924,9 @@ void ONMainWindow::slotStartBroker()
     broker->getUserSessions();
 }
 
-void ONMainWindow::slotGetBrokerSession(const QString& sinfo)
-{
-    //x2goDebug<<"broker session: "<<sinfo;
-    QStringList lst=sinfo.split("SERVER:",QString::SkipEmptyParts);
-    int keyStartPos=sinfo.indexOf("-----BEGIN DSA PRIVATE KEY-----");
-    QString endStr="-----END DSA PRIVATE KEY-----";
-    int keyEndPos=sinfo.indexOf(endStr);
-    if (! (keyEndPos == -1 || keyStartPos == -1 || lst.size()==0))
-        config.key=sinfo.mid(keyStartPos, keyEndPos+endStr.length()-keyStartPos);
-    QString serverLine=(lst[1].split("\n"))[0];
-    QStringList words=serverLine.split(":",QString::SkipEmptyParts);
-    config.server=words[0];
-    if (words.count()>1)
-        config.sshport=words[1];
-//    x2goDebug<<"server: "<<config.server<<endl<<" key: "<<config.key;
-    if (sinfo.indexOf("SESSION_INFO")!=-1)
-    {
-        QStringList lst=sinfo.split("SESSION_INFO:",QString::SkipEmptyParts);
-        config.sessiondata=(lst[1].split("\n"))[0];
-// 	x2goDebug<<"data: "<<config.sessiondata;
-    }
-    slotSessEnter();
+void ONMainWindow::slotGetBrokerSession()
+{
+    startSession ( config.session);
 }
 
 void ONMainWindow::slotStartNewBrokerSession ( )
diff --git a/onmainwindow.h b/onmainwindow.h
index de15136..831599a 100644
--- a/onmainwindow.h
+++ b/onmainwindow.h
@@ -166,8 +166,10 @@ struct ConfigFile
     QString brokerUserId;
     QString brokerName;
     bool brokerAuthenticated;
+    bool brokerNoAuth;
     QString iniFile;
     QString server;
+    QString serverIp;//Can be different from server (use for loadballancing)
     QString sshport;
     QString command;
     QString key;
@@ -214,6 +216,15 @@ struct ConfigFile
 };
 
 
+struct sshKey
+{
+    QString server;
+    QString port;
+    QString user;
+    QString key;
+};
+
+
 //wrapper to send mouse events under windows in embedded mode
 #ifdef Q_OS_WIN
 class WWrapper : public QPushButton
@@ -510,7 +521,6 @@ private:
     QString statusString;
     QString autostartApp;
     bool cmdAutologin;
-    QString cmdSshKey;
     int defaultLink;
     int defaultQuality;
     int defaultWidth;
@@ -549,6 +559,7 @@ private:
     int retSessions;
     QList<serv> x2goServers;
     QList<Application> applications;
+    QList<sshKey> cmdSshKeys;
 
     QPushButton* bSusp;
     QPushButton* bTerm;
@@ -800,6 +811,7 @@ private:
     bool trayMaxDiscon;
     bool trayAutoHidden;
 
+    QString findSshKeyForServer(QString user, QString server, QString port);
     void installTranslator();
     void loadSettings();
     void showPass ( UserButton* user );
@@ -925,7 +937,7 @@ private slots:
     void slotTermSess();
     void slotNewSess();
     void slotGetBrokerAuth();
-    void slotGetBrokerSession(const QString& sinfo);
+    void slotGetBrokerSession();
     void slotCmdMessage ( bool result,QString output,
                           SshProcess* );
     void slotListSessions ( bool result,QString output,


hooks/post-receive
-- 
x2goclient.git (X2Go Client)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "x2goclient.git" (X2Go Client).




More information about the x2go-commits mailing list