Hi Dave

I have added support for non standard remote SSH port. I have added one
control to take input for "Default SSH port" from the user in SSH Tunnel
tab, by default it is 22, but user can modify it.

Attached is the patch file, can you please review it. If it looks good to
you can you please commit it.


On Fri, Nov 15, 2013 at 2:29 PM, Akshay Joshi <akshay.jo...@enterprisedb.com
> wrote:

>
>
>
> On Fri, Nov 15, 2013 at 6:38 AM, Dave Page <dp...@pgadmin.org> wrote:
>
>> On Thu, Nov 14, 2013 at 10:06 PM, Alex Grechko <alex.grec...@rambler.ru>
>> wrote:
>> > Hello,
>> >
>> > It's very often that a default SSH port is changed to a non standard
>> value.
>> > In that case native SSH tunnels in pgAdmin are absolutely useless and
>> so we
>> > have to use old inconvenient methods for SSH tunnels.
>> >
>> >
>> > Would it be possible to add support for non standart remote SSH port?
>>
>> I thought we had that - guess I must have overlooked it when
>> reviewing. Akshay, how much effort would it be to add? I assume not
>> much. This seems like a usability bug.
>>
>
>    I am working on it. We will take the default SSH port as input from the
> user in "SSH Tunnel" tab of New Server Registration dialog. It will
>    take couple of hours to do that.
>
>>
>> --
>> Dave Page
>> Blog: http://pgsnake.blogspot.com
>> Twitter: @pgsnake
>>
>> EnterpriseDB UK: http://www.enterprisedb.com
>> The Enterprise PostgreSQL Company
>>
>
>
>
> --
> *Akshay Joshi*
> *Principal Software Engineer *
>
>
>
> *Phone: +91 20-3058-9517 Mobile: +91 976-788-8246*
>



-- 
*Akshay Joshi*
*Principal Software Engineer *



*Phone: +91 20-3058-9517Mobile: +91 976-788-8246*
diff --git a/pgadmin/dlg/dlgServer.cpp b/pgadmin/dlg/dlgServer.cpp
index a928930..0d4aeaf 100644
--- a/pgadmin/dlg/dlgServer.cpp
+++ b/pgadmin/dlg/dlgServer.cpp
@@ -66,6 +66,7 @@
 #define pickerPublicKeyFile	 CTRL_FILEPICKER("pickerPublicKeyFile")
 #define pickerIdentityFile	 CTRL_FILEPICKER("pickerIdentityFile")
 #define stPublicKeyFile		 CTRL_STATIC("stPublicKeyFile")
+#define txtDefaultSSHPort	 CTRL_TEXT("txtDefaultSSHPort")
 #endif
 
 BEGIN_EVENT_TABLE(dlgServer, dlgProperty)
@@ -99,6 +100,7 @@ BEGIN_EVENT_TABLE(dlgServer, dlgProperty)
 	EVT_CHECKBOX(XRCID("chkSSHTunnel"),                dlgServer::OnCheckSSHTunnel)
 	EVT_RADIOBUTTON(XRCID("radioBtnPassword"),         dlgServer::OnChangeAuthOption)
 	EVT_RADIOBUTTON(XRCID("radioBtnKeyfile"),          dlgServer::OnChangeAuthOption)
+	EVT_TEXT(XRCID("txtDefaultSSHPort"),               dlgProperty::OnChange)
 #endif
 END_EVENT_TABLE();
 
@@ -160,6 +162,7 @@ dlgServer::dlgServer(pgaFactory *f, frmMain *frame, pgServer *node)
 	radioBtnPassword->SetValue(true);
 	radioBtnKeyfile->SetValue(false);
 	txtTunnelPassword->SetMaxLength(SSH_MAX_PASSWORD_LEN);
+	txtDefaultSSHPort->SetValue(NumToStr((long)DEFAULT_SSH_PORT));
 #ifdef HAVE_OPENSSL_CRYPTO
 	stPublicKeyFile->Show(false);
 	pickerPublicKeyFile->Show(false);
@@ -238,6 +241,7 @@ void dlgServer::OnOK(wxCommandEvent &ev)
 		server->iSetSSLCompression(chkSSLCompression->GetValue());
 #if defined(HAVE_OPENSSL_CRYPTO) || defined(HAVE_GCRYPT)
 		server->iSetSSHTunnel(chkSSHTunnel->GetValue());
+		server->iSetDefaultSSHPort(StrToLong(txtDefaultSSHPort->GetValue()));
 		server->SetTunnelHost(txtTunnelHost->GetValue());
 		server->SetTunnelUserName(txtTunnelUsername->GetValue());
 		server->iSetAuthModePwd(radioBtnPassword->GetValue());
@@ -281,7 +285,8 @@ void dlgServer::OnOK(wxCommandEvent &ev)
 			    server->GetAuthModePwd(),
 			    server->GetTunnelPassword(),
 			    server->GetPublicKeyFile(),
-			    server->GetIdentityFile());
+			    server->GetIdentityFile(),
+			    server->GetDefaultSSHPort());
 #else
 			    server->GetGroup());
 #endif
@@ -480,6 +485,7 @@ int dlgServer::Go(bool modal)
 			chkStorePwd->SetValue(false);
 			chkStorePwd->Enable(false);
 		}
+		txtDefaultSSHPort->SetValue(NumToStr((long)server->GetDefaultSSHPort()));
 		txtTunnelHost->SetValue(server->GetTunnelHost());
 		txtTunnelUsername->SetValue(server->GetTunnelUserName());
 		if (server->GetAuthModePwd())
@@ -577,7 +583,7 @@ pgObject *dlgServer::CreateObject(pgCollection *collection)
 		                   chkSSHTunnel->GetValue(), txtTunnelHost->GetValue(), txtTunnelUsername->GetValue(),
 		                   radioBtnPassword->GetValue(),
 		                   txtTunnelPassword->GetValue(), pickerPublicKeyFile->GetPath(),
-		                   pickerIdentityFile->GetPath());
+		                   pickerIdentityFile->GetPath(), StrToLong(txtDefaultSSHPort->GetValue()));
 	}
 	else
 #endif
@@ -666,6 +672,7 @@ void dlgServer::CheckChange()
 #if defined(HAVE_OPENSSL_CRYPTO) || defined(HAVE_GCRYPT)
 	if(chkSSHTunnel->GetValue())
 	{
+		CheckValid(enable, !txtDefaultSSHPort->GetValue().IsEmpty(), _("Please specify default ssh port."));
 		CheckValid(enable, !txtTunnelHost->GetValue().IsEmpty(), _("Please specify ssh tunnel host."));
 		CheckValid(enable, !txtTunnelUsername->GetValue().IsEmpty(), _("Please specify ssh tunnel user name."));
 	}
@@ -718,6 +725,7 @@ void dlgServer::EnableSSHTunnelControls(const bool &bEnable)
 	radioBtnPassword->Enable(bEnable);
 	radioBtnKeyfile->Enable(bEnable);
 	txtTunnelPassword->Enable(bEnable);
+	txtDefaultSSHPort->Enable(bEnable);
 }
 
 void dlgServer::EnableAuthenticationOptions()
diff --git a/pgadmin/frm/frmMain.cpp b/pgadmin/frm/frmMain.cpp
index 258a7f1..0adb0a6 100644
--- a/pgadmin/frm/frmMain.cpp
+++ b/pgadmin/frm/frmMain.cpp
@@ -1234,6 +1234,7 @@ void frmMain::StoreServers()
 					settings->WriteBool(key + wxT("TunnelModePwd"), server->GetAuthModePwd());
 					settings->Write(key + wxT("PublicKeyFile"), server->GetPublicKeyFile());
 					settings->Write(key + wxT("IdentityFile"), server->GetIdentityFile());
+					settings->WriteInt(key + wxT("SSHDefaultPort"), server->GetDefaultSSHPort());
 #endif
 					pgCollection *coll = browser->FindCollection(databaseFactory, server->GetId());
 					if (coll)
diff --git a/pgadmin/include/schema/pgServer.h b/pgadmin/include/schema/pgServer.h
index 618ffb6..bb562b4 100644
--- a/pgadmin/include/schema/pgServer.h
+++ b/pgadmin/include/schema/pgServer.h
@@ -35,6 +35,7 @@ protected:
 	int closedId, smallClosedId;
 };
 extern pgServerFactory serverFactory;
+#define DEFAULT_SSH_PORT  22
 
 #if defined(HAVE_OPENSSL_CRYPTO) || defined(HAVE_GCRYPT)
 class CSSHTunnelThread;
@@ -48,7 +49,8 @@ public:
 	         bool storePwd = false, const wxString &newRolename = wxT(""), bool restore = true, int sslMode = 0,
 	         const wxString &colour = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW).GetAsString(wxC2S_HTML_SYNTAX), const wxString &group = wxEmptyString,
 	         bool sshTunnel = false, const wxString &newTunnelHost = wxEmptyString, const wxString &newTunnelUserName = wxEmptyString, bool authModePwd = true,
-	         const wxString &newTunnelPassword = wxEmptyString, const wxString &newPublicKey = wxEmptyString, const wxString &newIdentityFile = wxEmptyString);
+	         const wxString &newTunnelPassword = wxEmptyString, const wxString &newPublicKey = wxEmptyString, const wxString &newIdentityFile = wxEmptyString,
+	         const int &sshPort = DEFAULT_SSH_PORT);
 	~pgServer();
 	int GetIconId();
 
@@ -513,6 +515,14 @@ public:
 	{
 		identityFile = s;
 	}
+	int GetDefaultSSHPort() const
+	{
+		return defaultSSHPort;
+	}
+	void iSetDefaultSSHPort(const int newval)
+	{
+		defaultSSHPort = newval;
+	}
 #endif
 
 	void ShowDependencies(frmMain *form, ctlListView *Dependencies, const wxString &where = wxEmptyString);
@@ -550,6 +560,7 @@ private:
 	CSSHTunnelThread *tunnelObj;
 	bool authModePwd;
 	int local_listenport;
+	int defaultSSHPort;
 	wxString tunnelHost, tunnelUserName, tunnelPassword, publicKeyFile, identityFile, local_listenhost;
 #endif
 
diff --git a/pgadmin/include/utils/sshTunnel.h b/pgadmin/include/utils/sshTunnel.h
index b06ff14..4977dd7 100644
--- a/pgadmin/include/utils/sshTunnel.h
+++ b/pgadmin/include/utils/sshTunnel.h
@@ -57,7 +57,7 @@ class CSSHTunnelThread :
 public:
 	CSSHTunnelThread(const wxString tunnelhost, const wxString remote_desthost, const unsigned int remote_destport,
 	                 const wxString username, const wxString password, const wxString publickey, const wxString privatekey,
-	                 const enAuthenticationMethod &enAuthMethod);
+	                 const enAuthenticationMethod &enAuthMethod, const unsigned int defaultSSHPort = 22);
 	virtual ~CSSHTunnelThread(void);
 	virtual void *Entry();
 	bool Initialize();
@@ -94,6 +94,7 @@ private:
 	wxString m_remote_desthost;
 	unsigned int m_local_listenport;
 	unsigned int m_remote_destport;
+	unsigned int m_defaultSSHPort;
 	enAuthenticationMethod m_enAuthMethod;
 };
 
diff --git a/pgadmin/schema/pgServer.cpp b/pgadmin/schema/pgServer.cpp
index a71d111..ac756a7 100644
--- a/pgadmin/schema/pgServer.cpp
+++ b/pgadmin/schema/pgServer.cpp
@@ -47,7 +47,7 @@
 pgServer::pgServer(const wxString &newName, const wxString &newHostAddr, const wxString &newDescription, const wxString &newService,
                    const wxString &newDatabase, const wxString &newUsername, int newPort, bool _storePwd, const wxString &newRolename, bool _restore,
                    int _ssl, const wxString &_colour, const wxString &_group, bool _sshTunnel, const wxString &newTunnelHost, const wxString &newTunnelUserName,
-                   bool _authModePwd, const wxString &newTunnelPassword, const wxString &newPublicKey, const wxString &newIdentity)
+                   bool _authModePwd, const wxString &newTunnelPassword, const wxString &newPublicKey, const wxString &newIdentity, const int &sshPort)
 	: pgObject(serverFactory, newName)
 {
 	description = newDescription;
@@ -83,6 +83,7 @@ pgServer::pgServer(const wxString &newName, const wxString &newHostAddr, const w
 	tunnelPassword = newTunnelPassword;
 	publicKeyFile = newPublicKey;
 	identityFile = newIdentity;
+	defaultSSHPort = sshPort;
 #endif
 
 #ifdef WIN32
@@ -1249,7 +1250,7 @@ bool pgServer::createSSHTunnel()
 	bool retVal = false;
 
 	tunnelObj = new CSSHTunnelThread(tunnelHost, GetName(), port, tunnelUserName, tunnelPassword, publicKeyFile,
-	                                 identityFile, authModePwd ? AUTH_PASSWORD : AUTH_PUBLICKEY);
+	                                 identityFile, authModePwd ? AUTH_PASSWORD : AUTH_PUBLICKEY, defaultSSHPort);
 
 	if(tunnelObj)
 	{
@@ -1471,6 +1472,7 @@ pgObject *pgServerFactory::CreateObjects(pgCollection *obj, ctlTree *browser, co
 
 #if defined(HAVE_OPENSSL_CRYPTO) || defined(HAVE_GCRYPT)
 	wxString sshTunnel, authModePwd, tunnelHost, tunnelUserName, tunnelPassword, publicKeyFile, identityFile;
+	long defaultSSHPort;
 #endif
 	pgServer *server = 0;
 
@@ -1517,6 +1519,7 @@ pgObject *pgServerFactory::CreateObjects(pgCollection *obj, ctlTree *browser, co
 		settings->Read(key + wxT("TunnelModePwd"), &authModePwd, wxT("true"));
 		settings->Read(key + wxT("PublicKeyFile"), &publicKeyFile, wxEmptyString);
 		settings->Read(key + wxT("IdentityFile"), &identityFile, wxEmptyString);
+		settings->Read(key + wxT("SSHDefaultPort"), &defaultSSHPort, DEFAULT_SSH_PORT);
 #endif
 		// Sanitize the colour
 		colour = colour.Trim();
@@ -1553,7 +1556,7 @@ pgObject *pgServerFactory::CreateObjects(pgCollection *obj, ctlTree *browser, co
 		// Add the Server node
 #if defined(HAVE_OPENSSL_CRYPTO) || defined(HAVE_GCRYPT)
 		server = new pgServer(servername, hostaddr, description, service, database, username, port, StrToBool(storePwd), rolename, StrToBool(restore), ssl,
-		                      colour, group, StrToBool(sshTunnel), tunnelHost, tunnelUserName, StrToBool(authModePwd), tunnelPassword, publicKeyFile, identityFile);
+			colour, group, StrToBool(sshTunnel), tunnelHost, tunnelUserName, StrToBool(authModePwd), tunnelPassword, publicKeyFile, identityFile, defaultSSHPort);
 #else
 		server = new pgServer(servername, hostaddr, description, service, database, username, port, StrToBool(storePwd), rolename, StrToBool(restore), ssl,
 		                      colour, group);
diff --git a/pgadmin/ui/dlgServer.xrc b/pgadmin/ui/dlgServer.xrc
index 4d03436..581d8f7 100644
--- a/pgadmin/ui/dlgServer.xrc
+++ b/pgadmin/ui/dlgServer.xrc
@@ -284,6 +284,18 @@
                   <border>4</border>
                 </object>
                 <object class="sizeritem">
+                  <object class="wxStaticText" name="stSSHPort">
+                    <label>Default SSH Port</label>
+                  </object>
+                  <flag>wxALIGN_CENTRE_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+                  <border>4</border>
+                </object>
+                <object class="sizeritem">
+                  <object class="wxTextCtrl" name="txtDefaultSSHPort"/>
+                  <flag>wxEXPAND|wxALIGN_CENTRE_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+                  <border>4</border>
+                </object>
+                <object class="sizeritem">
                   <object class="wxStaticText" name="stTunnelHost">
                     <label>Tunnel host</label>
                   </object>
diff --git a/pgadmin/utils/sshTunnel.cpp b/pgadmin/utils/sshTunnel.cpp
index ec917f1..9293980 100644
--- a/pgadmin/utils/sshTunnel.cpp
+++ b/pgadmin/utils/sshTunnel.cpp
@@ -50,9 +50,9 @@ char CSSHTunnelThread::m_keyboard_interactive_pwd[SSH_MAX_PASSWORD_LEN];
 
 CSSHTunnelThread::CSSHTunnelThread(const wxString tunnelhost, const wxString remote_desthost, const unsigned int remote_destport,
                                    const wxString username, const wxString password, const wxString publickey, const wxString privatekey,
-                                   const enAuthenticationMethod &enAuthMethod)
+                                   const enAuthenticationMethod &enAuthMethod, const unsigned int defaultSSHPort)
 	: m_tunnelhost(tunnelhost), m_remote_desthost(remote_desthost), m_remote_destport(remote_destport), m_username(username),
-	  m_password(password), m_publickey(publickey), m_privatekey(privatekey), m_enAuthMethod(enAuthMethod)
+	  m_password(password), m_publickey(publickey), m_privatekey(privatekey), m_enAuthMethod(enAuthMethod), m_defaultSSHPort(defaultSSHPort)
 {
 	m_local_listenip = wxEmptyString;
 	m_local_listenport = 0;
@@ -108,7 +108,7 @@ bool CSSHTunnelThread::Initialize()
 			LogSSHTunnelErrors(wxString::Format(_("SSH error: Error in inet address with error code %d"), wxSysErrorCode()), GetId());
 			return false;
 		}
-		m_sin.sin_port = htons(22);
+		m_sin.sin_port = htons(m_defaultSSHPort);
 		if (connect(m_sock, (struct sockaddr *)(&m_sin),
 		            sizeof(struct sockaddr_in)) != 0)
 		{
-- 
Sent via pgadmin-support mailing list (pgadmin-support@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-support

Reply via email to