38
38
#include "frm/frmReport.h"
39
39
#include "dlg/dlgServer.h"
41
#if defined(HAVE_OPENSSL_CRYPTO) || defined(HAVE_GCRYPT)
42
#include "utils/sshTunnel.h"
41
45
#define DEFAULT_PG_DATABASE wxT("postgres")
43
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)
47
pgServer::pgServer(const wxString &newName, const wxString &newHostAddr, const wxString &newDescription, const wxString &newService,
48
const wxString &newDatabase, const wxString &newUsername, int newPort, bool _storePwd, const wxString &newRolename, bool _restore,
49
int _ssl, const wxString &_colour, const wxString &_group, bool _sshTunnel, const wxString &newTunnelHost, const wxString &newTunnelUserName,
50
bool _authModePwd, const wxString &newTunnelPassword, const wxString &newPublicKey, const wxString &newIdentity)
44
51
: pgObject(serverFactory, newName)
46
53
description = newDescription;
188
219
dbName = GetDatabaseName();
191
pgConn *conn = new pgConn(GetName(), service, hostaddr, dbName, username, password, port, rolename, ssl, oid, applicationname, sslcert, sslkey, sslrootcert, sslcrl, sslcompression);
224
#if defined(HAVE_OPENSSL_CRYPTO) || defined(HAVE_GCRYPT)
227
conn = new pgConn(local_listenhost, service, hostaddr, dbName, username, password, local_listenport, rolename, ssl, oid, applicationname, sslcert, sslkey, sslrootcert, sslcrl, sslcompression);
232
conn = new pgConn(GetName(), service, hostaddr, dbName, username, password, port, rolename, ssl, oid, applicationname, sslcert, sslkey, sslrootcert, sslcrl, sslcompression);
193
235
if (conn && conn->GetStatus() != PGCONN_OK)
629
if (!passwordValid || !GetPasswordIsStored() || !GetStorePwd())
682
if ((sshTunnel || !passwordValid || !GetPasswordIsStored() || !GetStorePwd()) && GetSSLCert() == wxEmptyString)
632
685
txt.Printf(_("Please enter password for user %s\non server %s (%s)"), username.c_str(), description.c_str(), GetName().c_str());
633
dlgConnect dlg(form, txt, GetStorePwd());
686
dlgConnect *dlg = NULL;
687
// if sshTunnel is true then we have to hide 'Stored Password' option
689
dlg = new dlgConnect(NULL, txt, false);
691
dlg = new dlgConnect(form, txt, GetStorePwd());
638
696
// Give the UI a chance to redraw
667
730
form->StartMsg(_("Connecting to database"));
734
#if defined(HAVE_OPENSSL_CRYPTO) || defined(HAVE_GCRYPT)
737
//Ask Tunnel Password
738
if(askTunnelPassword)
743
txt.Printf(_("Please enter the SSH tunnel password for user %s\non server %s"), tunnelUserName.c_str(), tunnelHost.c_str());
747
txt.Printf(_("Please enter the pass phrase for the identity file\n%s"), identityFile.c_str());
749
dlgConnect dlg(NULL, txt, false);
754
// Give the UI a chance to redraw
758
tunnelPassword = dlg.GetPassword();
763
// Give the UI a chance to redraw
768
return PGCONN_ABORTED;
771
// Create SSH Tunnel if required
774
if(!createSSHTunnel())
777
return PGCONN_SSHTUNNEL_ERROR;
781
host = local_listenhost;
782
iPort = local_listenport;
669
791
if (database.IsEmpty())
671
conn = new pgConn(GetName(), service, hostaddr, DEFAULT_PG_DATABASE, username, password, port, rolename, ssl, 0, appearanceFactory->GetLongAppName() + _(" - Browser"), sslcert, sslkey, sslrootcert, sslcrl, sslcompression);
793
conn = new pgConn(host, service, hostaddr, DEFAULT_PG_DATABASE, username, password, iPort, rolename, ssl, 0, appearanceFactory->GetLongAppName() + _(" - Browser"), sslcert, sslkey, sslrootcert, sslcrl, sslcompression);
672
794
if (conn->GetStatus() == PGCONN_OK)
673
795
database = DEFAULT_PG_DATABASE;
674
796
else if (conn->GetStatus() == PGCONN_BAD && conn->GetLastError().Find(
675
797
wxT("database \"") DEFAULT_PG_DATABASE wxT("\" does not exist")) >= 0)
678
conn = new pgConn(GetName(), service, hostaddr, wxT("template1"), username, password, port, rolename, ssl, 0, appearanceFactory->GetLongAppName() + _(" - Browser"), sslcert, sslkey, sslrootcert, sslcrl, sslcompression);
800
conn = new pgConn(host, service, hostaddr, wxT("template1"), username, password, iPort, rolename, ssl, 0, appearanceFactory->GetLongAppName() + _(" - Browser"), sslcert, sslkey, sslrootcert, sslcrl, sslcompression);
679
801
if (conn && conn->GetStatus() == PGCONN_OK)
680
802
database = wxT("template1");
685
conn = new pgConn(GetName(), service, hostaddr, database, username, password, port, rolename, ssl, 0, appearanceFactory->GetLongAppName() + _(" - Browser"), sslcert, sslkey, sslrootcert, sslcrl, sslcompression);
807
conn = new pgConn(host, service, hostaddr, database, username, password, iPort, rolename, ssl, 0, appearanceFactory->GetLongAppName() + _(" - Browser"), sslcert, sslkey, sslrootcert, sslcrl, sslcompression);
688
810
form->EndMsg(false);
1095
1218
if (!GetDbRestriction().IsEmpty())
1096
1219
properties->AppendItem(_("DB restriction"), GetDbRestriction());
1221
#if defined(HAVE_OPENSSL_CRYPTO) || defined(HAVE_GCRYPT)
1224
properties->AppendItem(_("SSH tunneling?"), (sshTunnel ? _("Yes") : _("No")));
1225
properties->AppendItem(_("Tunnel host"), GetTunnelHost());
1226
properties->AppendItem(_("Tunnel username"), GetTunnelUserName());
1227
properties->AppendItem(_("Authentication mode"), (GetAuthModePwd() ? _("Password") : _("Identity file")));
1228
if(!GetAuthModePwd())
1230
properties->AppendItem(_("Identity file path"), GetIdentityFile());
1099
1236
if(!GetConnected())
1245
#if defined(HAVE_OPENSSL_CRYPTO) || defined(HAVE_GCRYPT)
1247
bool pgServer::createSSHTunnel()
1249
bool retVal = false;
1251
tunnelObj = new CSSHTunnelThread(tunnelHost, GetName(), port, tunnelUserName, tunnelPassword, publicKeyFile,
1252
identityFile, authModePwd ? AUTH_PASSWORD : AUTH_PUBLICKEY);
1256
if(tunnelObj->Initialize())
1258
if ( tunnelObj->Create() != wxTHREAD_NO_ERROR )
1262
wxLogError(_("SSH Error: Unable to create SSH Tunnling Thread"));
1266
if (tunnelObj->Run() != wxTHREAD_NO_ERROR )
1270
wxLogError(_("SSH Error: Unable to start SSH Tunnling Thread"));
1273
SetLocalListenHost(tunnelObj->GetLocalListenIP());
1274
SetLocalListenPort(tunnelObj->GetLocalListenPort());
1109
1289
void pgServer::ShowStatistics(frmMain *form, ctlListView *statistics)
1289
1468
wxString key, servername, hostaddr, description, service, database, username, lastDatabase, lastSchema;
1290
1469
wxString storePwd, rolename, restore, serviceID, discoveryID, dbRestriction, colour;
1291
1470
wxString group, sslcert, sslkey, sslrootcert, sslcrl, sslcompression;
1472
#if defined(HAVE_OPENSSL_CRYPTO) || defined(HAVE_GCRYPT)
1473
wxString sshTunnel, authModePwd, tunnelHost, tunnelUserName, tunnelPassword, publicKeyFile, identityFile;
1292
1475
pgServer *server = 0;
1294
1477
wxArrayString discoveredServers;
1327
1510
settings->Read(key + wxT("SSLRootCert"), &sslrootcert, wxEmptyString);
1328
1511
settings->Read(key + wxT("SSLCrl"), &sslcrl, wxEmptyString);
1329
1512
settings->Read(key + wxT("SSLCompression"), &sslcompression, wxT("true"));
1513
#if defined(HAVE_OPENSSL_CRYPTO) || defined(HAVE_GCRYPT)
1514
settings->Read(key + wxT("SSHTunnel"), &sshTunnel, wxT("false"));
1515
settings->Read(key + wxT("TunnelHost"), &tunnelHost, wxEmptyString);
1516
settings->Read(key + wxT("TunnelUserName"), &tunnelUserName, wxEmptyString);
1517
settings->Read(key + wxT("TunnelModePwd"), &authModePwd, wxT("true"));
1518
settings->Read(key + wxT("PublicKeyFile"), &publicKeyFile, wxEmptyString);
1519
settings->Read(key + wxT("IdentityFile"), &identityFile, wxEmptyString);
1331
1521
// Sanitize the colour
1332
1522
colour = colour.Trim();
1363
1553
// Add the Server node
1364
server = new pgServer(servername, hostaddr, description, service, database, username, port, StrToBool(storePwd), rolename, StrToBool(restore), ssl);
1554
#if defined(HAVE_OPENSSL_CRYPTO) || defined(HAVE_GCRYPT)
1555
server = new pgServer(servername, hostaddr, description, service, database, username, port, StrToBool(storePwd), rolename, StrToBool(restore), ssl,
1556
colour, group, StrToBool(sshTunnel), tunnelHost, tunnelUserName, StrToBool(authModePwd), tunnelPassword, publicKeyFile, identityFile);
1558
server = new pgServer(servername, hostaddr, description, service, database, username, port, StrToBool(storePwd), rolename, StrToBool(restore), ssl,
1365
1561
server->iSetLastDatabase(lastDatabase);
1366
1562
server->iSetLastSchema(lastSchema);
1367
1563
server->iSetService(service);