Auto execute plugin puttyforward for linux.

При наличии такого плагина:
```
; SSH (Unix): tunnel putty forward
;
Title=[Putty tunnel forward]
Command=putty -load "$$TITLE"
appliesto=puttyforward
Description=Putty forward tunnel from local port.
KeyFile=
Platform=unix
ServerType=postgresql
Database=No
SetPassword=No
;
```
При попытке подключения к БД если существует конфигурация
туннеля описанного в putty то будет проверятся наличие открытого порта на localhost
и если он закрыт то запускается выше указанный плагин для организации туннеля.
This commit is contained in:
lsv 2026-03-17 11:57:33 +05:00
parent 903fd8ea9e
commit 2cde1c04f4
5 changed files with 88 additions and 9 deletions

View file

@ -267,8 +267,12 @@ frmMain::frmMain(const wxString &title)
browser->SetFocus();
wxString selServerName=settings->Read(wxT("Servers/SelectItem"), "");
if (selServerName.Len()>0) {
wxTreeItemId sel=browser->FindItem(root,selServerName,true);
if (sel.IsOk()) browser->SelectItem(sel);
wxTreeItemId sel=browser->FindItem(root,selServerName,false);
if (sel.IsOk()) {
browser->SelectItem(sel);
currentObject=browser->GetObject(sel);
//execSelChange(sel, true);
}
}
@ -1148,6 +1152,25 @@ wxTreeItemId frmMain::RestoreEnvironment(pgServer *server)
int frmMain::ReconnectServer(pgServer *server, bool restore)
{
if (server->GetPuttyTunnel()) {
// check open port
int port=server->GetPort();
wxString localhost=server->GetName(); // localhost
if (!isPortOpen(localhost,port,500)) {
server->GetPuttyTunnel()->StartDialog(winMain, server); // execute plugin
int count=0;
do {
wxMilliSleep(200);
count++;
} while (!isPortOpen(localhost,port,500) && count<20); // wait create putty tunnel
if (count>=20) {
StartMsg(_("Create putty tunnel error."));
EndMsg(true);
return -1;
}
}
}
// Create a server object and connect it.
wxBusyInfo waiting(wxString::Format(_("Connecting to server %s (%s:%d)"),
server->GetDescription().c_str(), server->GetName().c_str(), server->GetPort()), this);
@ -1312,7 +1335,7 @@ void frmMain::StoreServers()
{
wxString key;
++numServers;
if (cursoritem==serveritem) selServerName=server->GetName();
if (cursoritem==serveritem) selServerName=browser->GetItemText((serveritem));
key.Printf(wxT("Servers/%d/"), numServers);
settings->Write(key + wxT("Server"), server->GetName());
settings->Write(key + wxT("HostAddr"), server->GetHostAddr());

View file

@ -382,7 +382,7 @@ wxWindow *pluginUtilityFactory::StartDialog(frmMain *form, pgObject *obj)
return 0;
}
extern pluginUtilityFactory *puttyTunnel;
bool pluginUtilityFactory::CheckEnable(pgObject *obj)
{
// First check that this is one of the supported server types
@ -403,7 +403,6 @@ bool pluginUtilityFactory::CheckEnable(pgObject *obj)
if (server_types.Index(serverType) == wxNOT_FOUND)
return false;
}
// Now check that this is one of the supported object types
// for this plugin. If none are specified, then anything goes
if (obj && applies_to.Count() > 0)
@ -414,11 +413,14 @@ bool pluginUtilityFactory::CheckEnable(pgObject *obj)
else {
//"puttyforward"
int id=GetId();
if (winMain==NULL) return false;
wxMenu *m=winMain->GetPluginsMenu();
m->SetLabel(id,"[Putty tunnel forward]");
wxMenu *m=NULL;
if (winMain) {
m=winMain->GetPluginsMenu();
m->SetLabel(id,"[Putty tunnel forward]");
}
if (obj->GetMetaType()==PGM_SERVER) {
pgServer* srv = (pgServer*) obj;
srv->SetPuttyTunnel(NULL);
wxString host=obj->GetName();
wxString sport=NumToStr((long)srv->GetPort());
wxString f ;
@ -447,8 +449,10 @@ bool pluginUtilityFactory::CheckEnable(pgObject *obj)
if (port.Len()>0 && port[0]=='L' && sport==port.substr(1)) {
// found putty config
title=filename;
m->SetLabel(id,title);
if (winMain) m->SetLabel(id,title);
isfound=true;
srv->SetPuttyTunnel(this);
if (!winMain) return false;
return true;
}
}