1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709
|
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
//
// Copyright (C) 2002 - 2014, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// pgServer.h - PostgreSQL Server
//
//////////////////////////////////////////////////////////////////////////
#ifndef PGSERVER_H
#define PGSERVER_H
#include "db/pgConn.h"
#include "pgCollection.h"
class frmMain;
class pgServer;
class pgServerFactory : public pgaFactory
{
public:
pgServerFactory();
virtual dlgProperty *CreateDialog(frmMain *frame, pgObject *node, pgObject *parent);
virtual pgObject *CreateObjects(pgCollection *obj, ctlTree *browser, const wxString &restr = wxEmptyString);
virtual pgCollection *CreateCollection(pgObject *obj);
int GetClosedIconId()
{
return WantSmallIcon() ? smallClosedId : closedId;
}
protected:
int closedId, smallClosedId;
};
extern pgServerFactory serverFactory;
#define DEFAULT_SSH_PORT 22
#if defined(HAVE_OPENSSL_CRYPTO) || defined(HAVE_GCRYPT)
class CSSHTunnelThread;
#endif
class pgServer : public pgObject
{
public:
pgServer(const wxString &newServer = wxT(""), const wxString &newHostAddr = wxT(""), const wxString &newDescription = wxT(""),
const wxString &newService = wxT(""), const wxString &newDatabase = wxT(""), const wxString &newUsername = wxT(""), int newPort = 5432,
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 int &sshPort = DEFAULT_SSH_PORT);
~pgServer();
int GetIconId();
wxString GetTypeName() const
{
return wxT("Server");
}
wxString GetTranslatedMessage(int kindOfMessage) const;
int Connect(frmMain *form, bool askPassword = true, const wxString &pwd = wxEmptyString, bool forceStorePassword = false, bool askTunnelPassword = false);
bool Disconnect(frmMain *form);
void StorePassword();
bool GetPasswordIsStored();
void InvalidatePassword()
{
passwordValid = false;
}
bool StartService();
bool StopService();
bool GetServerRunning();
bool GetServerControllable();
bool ReloadConfiguration();
bool IsReplayPaused();
bool PauseReplay();
bool ResumeReplay();
bool AddNamedRestorePoint();
pgServer *GetServer() const;
wxString GetIdentifier() const;
wxString GetVersionString();
wxString GetVersionNumber();
OID GetLastSystemOID();
wxString GetHostAddr() const
{
return hostaddr;
}
wxString GetService() const
{
return service;
}
wxString GetDatabaseName() const
{
return database;
}
wxString GetUsername() const
{
return username;
}
wxString GetPassword() const
{
return (password == wxEmptyString ? conn->GetPassword() : password);
}
bool GetStorePwd() const
{
return storePwd;
}
wxString GetRolename() const
{
return rolename;
}
bool GetRestore() const
{
return restore;
}
wxString GetLastError() const;
bool GetDiscovered() const
{
return discovered;
}
void iSetDiscovered(const bool b)
{
discovered = b;
}
wxString GetServiceID() const
{
return serviceId;
}
void iSetServiceID(const wxString &s);
wxString GetDiscoveryID() const
{
return discoveryId;
}
void iSetDiscoveryID(const wxString &s)
{
discoveryId = s;
}
bool GetCreatePrivilege() const
{
return createPrivilege;
}
void iSetCreatePrivilege(const bool b)
{
createPrivilege = b;
}
bool GetSuperUser() const
{
return superUser;
}
void iSetSuperUser(const bool b)
{
superUser = b;
}
bool GetCreateRole() const
{
return createRole;
}
void iSetCreateRole(const bool b)
{
createRole = b;
}
bool GetInRecovery() const
{
return inRecovery;
}
void iSetInRecovery(const bool b)
{
inRecovery = b;
}
bool GetReplayPaused() const
{
return replayPaused;
}
void SetReplayPaused(const bool b)
{
replayPaused = b;
}
wxDateTime GetConfLoadedSince()
{
return confLoadedSince;
}
void iSetConfLoadedSince(const wxDateTime &d)
{
confLoadedSince = d;
}
wxString GetReceiveLoc() const
{
return receiveLoc;
}
void iSetReceiveLoc(const wxString &s)
{
receiveLoc = s;
}
wxString GetReplayLoc() const
{
return replayLoc;
}
void iSetReplayLoc(const wxString &s)
{
replayLoc = s;
}
wxString GetReplayTimestamp() const
{
return replayTimestamp;
}
void iSetReplayTimestamp(const wxString &s)
{
replayTimestamp = s;
}
pgConn *CreateConn(wxString dbName = wxEmptyString, OID oid = 0, wxString applicationname = wxEmptyString);
wxString GetLastDatabase() const
{
return lastDatabase;
}
void iSetLastDatabase(const wxString &s)
{
lastDatabase = s;
}
wxString GetLastSchema() const
{
return lastSchema;
}
void iSetLastSchema(const wxString &s)
{
lastSchema = s;
}
wxString GetDescription() const
{
return description;
}
void iSetDescription(const wxString &s)
{
description = s;
}
void iSetHostAddr(const wxString &s)
{
hostaddr = s;
}
wxString GetDbRestriction() const
{
return dbRestriction;
}
void iSetDbRestriction(const wxString &s)
{
dbRestriction = s;
}
long GetServerIndex() const
{
return serverIndex;
}
void iSetServerIndex(long l)
{
serverIndex = l;
}
wxString GetFullName();
wxString GetFullIdentifier();
int GetPort() const
{
return port;
}
int GetSSL() const
{
return ssl;
}
bool GetConnected() const
{
return connected;
}
void iSetService(const wxString &newVal)
{
service = newVal;
}
void iSetDatabase(const wxString &newVal)
{
database = newVal;
}
void iSetPort(int newval)
{
port = newval;
}
void iSetSSL(int newval)
{
ssl = newval;
}
void iSetUsername(const wxString &newVal)
{
username = newVal;
}
void iSetPassword(const wxString &newVal)
{
password = newVal;
}
void iSetStorePwd(const bool b)
{
storePwd = b;
}
void iSetRolename(const wxString &newVal)
{
rolename = newVal;
}
void iSetRestore(const bool b)
{
restore = b;
}
bool SetPassword(const wxString &newVal);
wxDateTime GetUpSince()
{
return upSince;
}
void iSetUpSince(const wxDateTime &d)
{
upSince = d;
}
void iSetColour(const wxString &s)
{
colour = s;
}
wxString GetColour()
{
return colour;
}
void iSetGroup(const wxString &s)
{
group = s;
}
wxString GetGroup()
{
return group;
}
bool HasPrivilege(const wxString &objTyp, const wxString &objName, const wxString &priv)
{
return conn->HasPrivilege(objTyp, objName, priv);
}
bool ExecuteVoid(const wxString &sql)
{
return conn->ExecuteVoid(sql);
}
wxString ExecuteScalar(const wxString &sql)
{
return conn->ExecuteScalar(sql);
}
pgSet *ExecuteSet(const wxString &sql)
{
return conn->ExecuteSet(sql);
}
void ShowTreeDetail(ctlTree *browser, frmMain *form = 0, ctlListView *properties = 0, ctlSQLBox *sqlPane = 0);
void ShowHint(frmMain *form, bool force);
void ShowStatistics(frmMain *form, ctlListView *statistics);
wxString GetHelpPage(bool forCreate) const
{
return wxT("pg/managing-databases");
}
wxMenu *GetNewMenu();
bool DropObject(wxFrame *frame, ctlTree *browser, bool cascaded)
{
return true;
}
bool GetCanHint();
bool CanEdit()
{
return true;
}
bool CanDrop()
{
return true;
}
bool CanBackupGlobals()
{
return true;
}
bool HasStats()
{
return true;
}
bool HasDepends()
{
return false;
}
bool HasReferences()
{
return false;
}
pgConn *connection()
{
return conn;
}
wxString GetSSLCert() const
{
return sslcert;
}
void SetSSLCert(const wxString &s)
{
sslcert = s;
}
wxString GetSSLKey() const
{
return sslkey;
}
void SetSSLKey(const wxString &s)
{
sslkey = s;
}
wxString GetSSLRootCert() const
{
return sslrootcert;
}
void SetSSLRootCert(const wxString &s)
{
sslrootcert = s;
}
wxString GetSSLCrl() const
{
return sslcrl;
}
void SetSSLCrl(const wxString &s)
{
sslcrl = s;
}
bool GetSSLCompression() const
{
return sslcompression;
}
void iSetSSLCompression(const bool b)
{
sslcompression = b;
}
#if defined(HAVE_OPENSSL_CRYPTO) || defined(HAVE_GCRYPT)
//SSH Tunnel
bool GetSSHTunnel() const
{
return sshTunnel;
}
void iSetSSHTunnel(const bool b)
{
sshTunnel = b;
}
bool GetAuthModePwd() const
{
return authModePwd;
}
void iSetAuthModePwd(const bool b)
{
authModePwd = b;
}
wxString GetLocalListenHost() const
{
return local_listenhost;
}
void SetLocalListenHost(const wxString &s)
{
local_listenhost = s;
}
int GetLocalListenPort() const
{
return local_listenport;
}
void SetLocalListenPort(int newVal)
{
local_listenport = newVal;
}
wxString GetTunnelHost() const
{
return tunnelHost;
}
void SetTunnelHost(const wxString &s)
{
tunnelHost = s;
}
wxString GetTunnelUserName() const
{
return tunnelUserName;
}
void SetTunnelUserName(const wxString &s)
{
tunnelUserName = s;
}
wxString GetTunnelPassword() const
{
return tunnelPassword;
}
void SetTunnelPassword(const wxString &s)
{
tunnelPassword = s;
}
wxString GetPublicKeyFile() const
{
return publicKeyFile;
}
void SetPublicKeyFile(const wxString &s)
{
publicKeyFile = s;
}
wxString GetIdentityFile() const
{
return identityFile;
}
void SetIdentityFile(const wxString &s)
{
identityFile = s;
}
int GetTunnelPort() const
{
return tunnelPort;
}
void iSetTunnelPort(const int newval)
{
tunnelPort = newval;
}
#endif
void ShowDependencies(frmMain *form, ctlListView *Dependencies, const wxString &where = wxEmptyString);
void ShowDependents(frmMain *form, ctlListView *referencedBy, const wxString &where = wxEmptyString);
private:
wxString passwordFilename();
pgConn *conn;
long serverIndex;
bool connected, passwordValid, autovacuumRunning;
wxString service, hostaddr, database, username, password, rolename, ver, error;
wxString lastDatabase, lastSchema, description, serviceId, discoveryId;
wxDateTime upSince;
int port, ssl;
bool storePwd, restore, discovered, createPrivilege, superUser, createRole;
OID lastSystemOID;
OID dbOid;
wxString versionNum;
wxString dbRestriction;
wxString colour;
wxString group;
wxString sslcert, sslkey, sslrootcert, sslcrl;
bool sslcompression;
bool sshTunnel;
bool inRecovery, replayPaused;
wxString receiveLoc, replayLoc, replayTimestamp;
wxDateTime confLoadedSince;
#if defined(HAVE_OPENSSL_CRYPTO) || defined(HAVE_GCRYPT)
bool createSSHTunnel();
//SSH Tunnel
CSSHTunnelThread *tunnelObj;
bool authModePwd;
int local_listenport;
int tunnelPort;
wxString tunnelHost, tunnelUserName, tunnelPassword, publicKeyFile, identityFile, local_listenhost;
#endif
#ifdef WIN32
SC_HANDLE scmHandle;
SC_HANDLE serviceHandle;
wxArrayString GetDependentServices(SC_HANDLE handle);
#endif
};
// collection of pgServer
class pgServerCollection : public pgCollection
{
public:
pgServerCollection(pgaFactory *factory);
wxString GetTranslatedMessage(int kindOfMessage) const;
void ShowTreeDetail(ctlTree *browser, frmMain *form = 0, ctlListView *properties = 0, ctlSQLBox *sqlPane = 0) {};
};
///////////////////////////////////////////////
class pgServerObjFactory : public pgaFactory
{
public:
pgServerObjFactory(const wxChar *tn, const wxChar *ns, const wxChar *nls, wxImage *img, wxImage *imgSm = 0)
: pgaFactory(tn, ns, nls, img, imgSm) {}
virtual pgCollection *CreateCollection(pgObject *obj);
};
// Object that lives under a server
class pgServerObject : public pgObject
{
public:
pgServerObject(pgaFactory &factory, const wxString &newName = wxEmptyString) : pgObject(factory, newName) {}
pgServerObject(int newType, const wxString &newName) : pgObject(newType, newName) {}
void iSetServer(pgServer *s)
{
server = s;
}
pgServer *GetServer() const
{
return server;
}
void FillOwned(ctlTree *browser, ctlListView *referencedBy, const wxArrayString &dblist, const wxString &query);
bool CanCreate();
bool CanDrop();
bool CanEdit()
{
return true;
}
protected:
pgServer *server;
};
// collection of pgServerObject
class pgServerObjCollection : public pgCollection
{
public:
pgServerObjCollection(pgaFactory *factory, pgServer *server);
bool CanCreate();
};
class addServerFactory : public actionFactory
{
public:
addServerFactory(menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar);
wxWindow *StartDialog(frmMain *form, pgObject *obj);
};
class startServiceFactory : public contextActionFactory
{
public:
startServiceFactory (menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar);
wxWindow *StartDialog(frmMain *form, pgObject *obj);
bool CheckEnable(pgObject *obj);
};
class stopServiceFactory : public contextActionFactory
{
public:
stopServiceFactory (menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar);
wxWindow *StartDialog(frmMain *form, pgObject *obj);
bool CheckEnable(pgObject *obj);
};
class connectServerFactory : public contextActionFactory
{
public:
connectServerFactory(menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar);
wxWindow *StartDialog(frmMain *form, pgObject *obj);
bool CheckEnable(pgObject *obj);
};
class disconnectServerFactory : public contextActionFactory
{
public:
disconnectServerFactory(menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar);
wxWindow *StartDialog(frmMain *form, pgObject *obj);
bool CheckEnable(pgObject *obj);
};
class reloadconfServiceFactory : public contextActionFactory
{
public:
reloadconfServiceFactory (menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar);
wxWindow *StartDialog(frmMain *form, pgObject *obj);
bool CheckEnable(pgObject *obj);
};
class pausereplayServiceFactory : public contextActionFactory
{
public:
pausereplayServiceFactory (menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar);
wxWindow *StartDialog(frmMain *form, pgObject *obj);
bool CheckEnable(pgObject *obj);
};
class resumereplayServiceFactory : public contextActionFactory
{
public:
resumereplayServiceFactory (menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar);
wxWindow *StartDialog(frmMain *form, pgObject *obj);
bool CheckEnable(pgObject *obj);
};
class addnamedrestorepointServiceFactory : public contextActionFactory
{
public:
addnamedrestorepointServiceFactory (menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar);
wxWindow *StartDialog(frmMain *form, pgObject *obj);
bool CheckEnable(pgObject *obj);
};
#endif
|