From 8a6b2ba9201d4c3ff564d28137162598affc8312 Mon Sep 17 00:00:00 2001
From: Husson <nicolas.husson@tactualities.com>
Date: Wed, 25 Feb 2015 16:09:23 +0100
Subject: [PATCH] enable use of ssh proxy conf with x2goplugin

---
 onmainwindow.cpp        | 175 ++++++++++++++++++++++++++++++++++--------------
 sshmasterconnection.cpp |   8 ++-
 2 files changed, 133 insertions(+), 50 deletions(-)

diff --git a/onmainwindow.cpp b/onmainwindow.cpp
index 3c29870..a4169e0 100644
--- a/onmainwindow.cpp
+++ b/onmainwindow.cpp
@@ -16,6 +16,7 @@
 ***************************************************************************/
 
 #include "onmainwindow_privat.h"
+#include <iostream>
 
 void x2goSession::operator = ( const x2goSession& s )
 {
@@ -58,7 +59,7 @@ ONMainWindow::ONMainWindow ( QWidget *parent ) :QMainWindow ( parent )
     image=shape=0;
 #endif
     x2goInfof(1) << tr("Starting x2goclient...");
-    debugging = false;
+    debugging = true;
 
     setFocusPolicy ( Qt::NoFocus );
     installTranslator();
@@ -3204,6 +3205,7 @@ QString ONMainWindow::findSshKeyForServer(QString user, QString server, QString
 
 bool ONMainWindow::startSession ( const QString& sid )
 {
+
     setEnabled ( false );
 #ifdef Q_OS_LINUX
     directRDP=false;
@@ -3261,6 +3263,7 @@ bool ONMainWindow::startSession ( const QString& sid )
                                     ( QVariant ) QString::null ).toString();
     }
 
+
     QString cmd=st->setting()->value ( sid+"/command",
                                        ( QVariant ) QString::null ).toString();
     autologin=st->setting()->value ( sid+"/autologin",
@@ -3296,45 +3299,68 @@ bool ONMainWindow::startSession ( const QString& sid )
         currentKey=findSshKeyForServer(user, host, sshPort);
     }
 
-    useproxy=(st->setting()->value (
-                  sid+"/usesshproxy",
-                  false
-              ).toBool() );
-
-    QString prtype= st->setting()->value (
-                        sid+"/sshproxytype",
-                        "SSH"
-                    ).toString() ;
-
-    if(prtype=="HTTP")
-    {
-        proxyType=SshMasterConnection::PROXYHTTP;
-    }
-    else
-    {
-        proxyType=SshMasterConnection::PROXYSSH;
-    }
-
-    proxylogin=(st->setting()->value (
-                    sid+"/sshproxyuser",
-                    QString()
-                ).toString() );
-
-    proxyKey=(st->setting()->value (
-                  sid+"/sshproxykeyfile",
-                  QString()
-              ).toString() );
-    proxyKey=expandHome(proxyKey);
-
-    proxyserver=(st->setting()->value (
-                     sid+"/sshproxyhost",
-                     QString()
-                 ).toString() );
+    if (embedMode)
+	{
+    	useproxy=config.useproxy;
+    	proxyType=config.proxyType;
+    	proxylogin=config.proxylogin;
+    	proxyKey=config.proxyKey;
+    	proxyserver=config.proxyserver;
+    	proxyport=config.proxyport;
+    	proxyAutologin=config.proxyAutologin;
+    	proxyKrbLogin=config.proxyKrbLogin;
+	}
+	else
+	{
+		useproxy=(st->setting()->value (
+					  sid+"/usesshproxy",
+					  false
+				  ).toBool() );
+		QString prtype= st->setting()->value (
+							 sid+"/sshproxytype",
+							 "SSH"
+						 ).toString() ;
+		if(prtype=="HTTP")
+		{
+		  proxyType=SshMasterConnection::PROXYHTTP;
+		}
+		else
+		{
+		  proxyType=SshMasterConnection::PROXYSSH;
+
+		}
+
+		proxylogin=(st->setting()->value (
+						sid+"/sshproxyuser",
+						QString()
+					).toString() );
+
+		proxyKey=(st->setting()->value (
+					  sid+"/sshproxykeyfile",
+					  QString()
+				  ).toString() );
+		proxyKey=expandHome(proxyKey);
+
+		proxyserver=(st->setting()->value (
+						 sid+"/sshproxyhost",
+						 QString()
+					 ).toString() );
+
+		proxyport=(st->setting()->value (
+					   sid+"/sshproxyport",
+					   22
+				   ).toInt() );
+		proxyAutologin=(st->setting()->value (
+						sid+"/sshproxyautologin",
+						false
+					).toBool() );
+
+	    proxyKrbLogin=(st->setting()->value (
+	                       sid+"/sshproxykrblogin",
+	                       false
+	                   ).toBool() );
+	}
 
-    proxyport=(st->setting()->value (
-                   sid+"/sshproxyport",
-                   22
-               ).toInt() );
     if(proxyserver.indexOf(":")!=-1)
     {
         QStringList parts=proxyserver.split(":");
@@ -3350,15 +3376,6 @@ bool ONMainWindow::startSession ( const QString& sid )
                             sid+"/sshproxysameuser",
                             false
                         ).toBool() );
-    proxyAutologin=(st->setting()->value (
-                        sid+"/sshproxyautologin",
-                        false
-                    ).toBool() );
-
-    proxyKrbLogin=(st->setting()->value (
-                       sid+"/sshproxykrblogin",
-                       false
-                   ).toBool() );
 
     if(proxyKey.length()<=0 && proxyType==SshMasterConnection::PROXYSSH)
     {
@@ -10471,7 +10488,7 @@ void ONMainWindow::processSessionConfig()
     {
         QString line = lines[i];
 
-        // strip left/right whitespaces, important for plugin settings via x2goconfig
+        // strip left/right whitespaces, important for plugin settings via x2go
         line.remove(QRegExp("^\\s+"));
         line.remove(QRegExp("\\s+$"));
 
@@ -10702,6 +10719,66 @@ void ONMainWindow::processCfgLine ( QString line )
         config.connectionts=lst[1];
         return;
     }
+    if ( lst[0]=="usesshproxy" )
+	{
+    	config.useproxy=true;
+    	/*if (lst[1]=="true"){
+    		std::cout << "usesshproxy" << std::endl;
+    		config.useproxy=true;
+    	}
+    	else
+    		config.useproxy=false;*/
+    	 return;
+	}
+    if ( lst[0]=="sshproxytype" )
+   	{
+    	if (lst[1]=="HTTP"){
+    		config.proxyType=SshMasterConnection::PROXYHTTP;
+    	}
+    	else{
+    		std::cout << "ssh" << std::endl;
+    		config.proxyType=SshMasterConnection::PROXYSSH;
+    	}
+       	return;
+   	}
+    if ( lst[0]=="sshproxyuser" )
+	{
+		 config.proxylogin=lst[1];
+		 return;
+	}
+    if ( lst[0]=="sshproxyhost" )
+   	{
+   		 config.proxyserver=lst[1];
+   		 return;
+   	}
+    if ( lst[0]=="sshproxyport" )
+	{
+		 config.proxyport=lst[1].toInt();
+		 return;
+	}
+    if ( lst[0]=="sshproxyautologin" )
+	{
+    	if (lst[1]=="true")
+    		config.proxyAutologin=true;
+		else
+			config.proxyAutologin=false;
+		return;
+	}
+    if ( lst[0]=="sshproxykrblogin" )
+   	{
+    	if (lst[1]=="true")
+    		config.proxyKrbLogin=true;
+		else
+			config.proxyKrbLogin=false;
+		return;
+   	}
+    if ( lst[0]=="sshproxykeyfile" )
+	{
+		 config.proxyKey=lst[1];
+		 return;
+	}
+
+
 }
 
 void ONMainWindow::slotChangeKbdLayout(const QString& layout)
diff --git a/sshmasterconnection.cpp b/sshmasterconnection.cpp
index c8669a5..729110e 100755
--- a/sshmasterconnection.cpp
+++ b/sshmasterconnection.cpp
@@ -165,6 +165,7 @@ SshMasterConnection::SshMasterConnection (QObject* parent, QString host, int por
 
     breakLoop=false;
     kerberosDelegation=false;
+    //x2goDebug<<"SshMasterConnection, host "<<host  <<"port "<< port <<"user "<<user<<"useproxy "<< useproxy<<"proxyserver "<< proxyserver<<"proxyport "<< proxyport ;
     this->host=host;
     this->port=port;
     this->user=user;
@@ -441,9 +442,14 @@ void SshMasterConnection::run()
 #ifdef DEBUG
     x2goDebug<<"SshMasterConnection, instance "<<this<<" entering thread";
 #endif
+    x2goDebug<<"use of proxyssh?";
+    if (useproxy)
+    	 //x2goDebug<<"useproxy ssh";
+    if (proxytype==PROXYSSH)
+    	//x2goDebug<<"PROXYSSH";
     if(useproxy && proxytype==PROXYSSH)
     {
-
+    	// x2goDebug<<"yes "<<"proxyserver : "<<proxyserver<<"proxyport : "<<proxyport<<"proxylogin : "<<proxylogin;
         sshProxy=new SshMasterConnection (0, proxyserver, proxyport,acceptUnknownServers,
                                           proxylogin, proxypassword, proxykey, proxyautologin, proxyKrbLogin, false);
         connect ( sshProxy, SIGNAL ( connectionOk(QString) ), this, SLOT ( slotSshProxyConnectionOk() ) );
-- 
1.9.1

