void HandleTunnelError() { server_.DisableAccept(); socks5_conns_.clear(); tunnel_reconnect_timer_.ExpireFromNow(snet::Seconds(1)); tunnel_reconnect_timer_.SetOnTimeout([this] () { CreateTunnel(); }); }
wyBool ConnectionCommunity::OnNewSameConnection(HWND hwndactive, MDIWindow *pcquerywnd, ConnectionInfo &conninfo) { MYSQL *mysqlnew, *mysqlold, *mysqltemp; Tunnel *oldtunnel, *newtunnel; wyString msg; if(hwndactive) { oldtunnel = pcquerywnd->m_tunnel; newtunnel = CreateTunnel(wyFalse); mysqlnew = newtunnel->mysql_init((MYSQL*)0); mysqlold = pcquerywnd->m_mysql; if(!mysqlnew) { yog_message(pGlobals->m_pcmainwin->m_hwndmain, _(L"Could not initialize a new window."), pGlobals->m_appname.GetAsWideChar(), MB_ICONERROR | MB_OK | MB_HELP); delete newtunnel; return wyFalse; } SetCursor(LoadCursor(NULL, IDC_WAIT )); ShowCursor(1); InitConInfo(pcquerywnd->m_conninfo, conninfo); //Get SQL_MODE info //following function remarked for issue #1654 //GetAdvancedTabDetailsFromFile(&conninfo, (wyChar *)pcquerywnd->m_currentconn.GetString(), NULL); //post 8.01 /*InvalidateRect(pcquerywnd->GetActiveTabEditor()->m_peditorbase->m_hwnd, NULL, FALSE); UpdateWindow(pcquerywnd->GetActiveTabEditor()->m_peditorbase->m_hwnd);*/ if(conninfo.m_initcommand.GetLength()) ExecuteInitCommands(mysqlnew, newtunnel, conninfo.m_initcommand); SetMySQLOptions(&pcquerywnd->m_conninfo, newtunnel, &mysqlnew); mysqltemp = newtunnel->mysql_real_connect(mysqlnew, mysqlold->host, mysqlold->user, mysqlold->passwd, NULL, mysqlold->port, NULL, mysqlold->client_flag | CLIENT_MULTI_RESULTS, NULL); if(!mysqltemp) { ShowMySQLError(pGlobals->m_pcmainwin->m_hwndmain, oldtunnel, &mysqlnew, NULL, wyTrue); newtunnel->mysql_close(mysqlnew); delete newtunnel; return wyFalse; } /* change the conninfo things */ conninfo.m_tunnel = newtunnel; conninfo.m_mysql = mysqlnew; conninfo.m_hprocess = INVALID_HANDLE_VALUE; } return wyTrue; }
wyBool ConnectionCommunity::CreateTargetInstance(CopyDatabase *copydb) { MYSQL *tempmysql, *newtargetmysql; copydb->m_newtargettunnel = NULL; copydb->m_tgtprocess = INVALID_HANDLE_VALUE; // create a tunnel and mysql object copydb->m_newtargettunnel = CreateTunnel((wyBool)copydb->m_targettunnel->IsTunnel()); VERIFY(tempmysql = copydb->m_newtargettunnel->mysql_init((MYSQL*)0)); SetMySQLOptions(copydb->m_tgtinfo, copydb->m_newtargettunnel, &tempmysql); newtargetmysql = copydb->m_newtargettunnel->mysql_real_connect(tempmysql, (*copydb->m_targetmysql)->host, (*copydb->m_targetmysql)->user, (*copydb->m_targetmysql)->passwd, NULL, (*copydb->m_targetmysql)->port, NULL, (*copydb->m_targetmysql)->client_flag | CLIENT_MULTI_RESULTS, NULL); if(!newtargetmysql) { ShowMySQLError(copydb->m_hwnddlg, copydb->m_newtargettunnel, &tempmysql, NULL, wyTrue); return wyFalse; } else { copydb->m_newtargetmysql=newtargetmysql; } if(!copydb->CreateTargetDB()) return wyFalse; if(UseDatabase(copydb->m_targetdb, newtargetmysql, copydb->m_newtargettunnel) == wyFalse) { ShowMySQLError(copydb->m_hwnddlg, copydb->m_newtargettunnel, &tempmysql, NULL, wyTrue); return wyFalse; } copydb->m_newtargettunnel->SetServerInfo(newtargetmysql, copydb->m_targettunnel->mysql_get_server_info(*copydb->m_targetmysql)); copydb->m_newtargetmysql = newtargetmysql; return wyTrue; }
LRESULT CBaseDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_MAKETUNNELWAIT: { if (m_bReBuildConnect) { m_bReBuildConnect = false; if (IsWindow(m_MsgNotifyWnd)) ::PostMessage(m_MsgNotifyWnd, m_nQuitMessageID, FF_REBUILDCHANNELAk, 1); //rebuild status: wait for connection. else OutputDebugString("CBaseDlg::WindowProc WM_MAKETUNNELWAIT !IsWindow(m_MsgNotifyWnd).\n"); } else OutputDebugString("CBaseDlg::WindowProc WM_MAKETUNNELWAIT !m_bReBuildConnect.\n"); } break; case WM_MAKETUNNEL: { TunnelMode mode = (TunnelMode)wParam; if (!m_ConnectNode.bMaking) { return CreateTunnel(mode); } return false; } break; case WM_MAKETUNNELEND: { bool bRes = (bool)wParam; TunnelMode mode = (TunnelMode)lParam; OnMakeTunnelEnd(bRes, mode); } break; case FF_REBUILDCHANNEL: { m_bReBuildConnect = true; int nPort = (int)wParam; return BuildConnect(nPort); } break; } return CDialog::WindowProc(message, wParam, lParam); }
void ConnectionCommunity::OnConnect(ConnectionInfo *dbname) { Tunnel *tunnel; MYSQL *mysql; HWND lastfocus = GetFocus(); tunnel = CreateTunnel(wyFalse); if( ! tunnel ) { return; } dbname->m_tunnel = tunnel; mysql = ConnectToMySQL(dbname); if(mysql == NULL) { delete tunnel; tunnel = NULL; SetFocus(lastfocus); } else if(dbname->m_db.GetLength() ==0 || (IsDatabaseValid(dbname->m_db, mysql, tunnel) == wyTrue)) { dbname->m_mysql = mysql; dbname->m_tunnel = tunnel; if(!pGlobals->m_conrestore) { m_rgbobbkcolor = dbname->m_rgbconn; m_rgbobfgcolor = dbname->m_rgbfgconn; } pGlobals->m_isconnected = wyTrue; } else { ShowMySQLError(NULL, tunnel, &mysql, NULL, wyTrue); return; } }
wyBool ConnectionCommunity::CreateSourceInstance(CopyDatabase *copydb) { MYSQL *tempmysql, *newsrcmysql; copydb->m_newsrctunnel = NULL; copydb->m_srcprocess = INVALID_HANDLE_VALUE; // create a tunnel and mysql object copydb->m_newsrctunnel = CreateTunnel(wyFalse); VERIFY(tempmysql = copydb->m_newsrctunnel->mysql_init((MYSQL*)0)); //if(IsMySQL41(copydb->m_newtargettunnel, &tempmysql)) //VERIFY((copydb->m_newtargettunnel->mysql_options(tempmysql, MYSQL_SET_CHARSET_NAME, "utf8"))); VERIFY(!(copydb->m_newsrctunnel->mysql_options(tempmysql, MYSQL_INIT_COMMAND, "/*40030 SET net_write_timeout=3600 */"))); SetMySQLOptions(copydb->m_srcinfo, copydb->m_newsrctunnel, &tempmysql, wyTrue); newsrcmysql = copydb->m_newsrctunnel->mysql_real_connect(tempmysql, (*copydb->m_srcmysql)->host, (*copydb->m_srcmysql)->user, (*copydb->m_srcmysql)->passwd, NULL, (*copydb->m_srcmysql)->port, NULL, (*copydb->m_srcmysql)->client_flag | CLIENT_MULTI_RESULTS, NULL); if(!newsrcmysql) { ShowMySQLError(copydb->m_hwnddlg, copydb->m_newsrctunnel, &tempmysql, NULL, wyTrue); return wyFalse; } if(UseDatabase(copydb->m_srcdb, newsrcmysql, copydb->m_newsrctunnel) == wyFalse) { ShowMySQLError(copydb->m_hwnddlg, copydb->m_newsrctunnel, &tempmysql, NULL, wyTrue); return wyFalse; } copydb->m_newsrctunnel->SetServerInfo(newsrcmysql, copydb->m_srctunnel->mysql_get_server_info(*copydb->m_srcmysql)); copydb->m_newsrcmysql = newsrcmysql; return wyTrue; }
Server(const std::string &tunnel_ip, unsigned short tunnel_port, const std::string &tunnel_key, snet::EventLoop *loop, snet::TimerList *timer_list) : id_generator_(0), tunnel_port_(tunnel_port), tunnel_ip_(tunnel_ip), tunnel_key_(tunnel_key), loop_(loop), timer_list_(timer_list), server_(SOCKS5_LISTEN_IP, SOCKS5_LISTEN_PORT, loop), tunnel_reconnect_timer_(timer_list) { server_.DisableAccept(); server_.SetOnNewConnection( [this] (std::unique_ptr<socks5::Connection> connection) { HandleSocks5NewConn(std::move(connection)); }); CreateTunnel(); }
BOOL CBaseDlg::BuildConnect(int nPort) { try { if (gl_pLogger) gl_pLogger->log_info("CBaseDlg::BuildConnect(int nPort) Port:%d, m_bBuildConnect:%d", nPort, m_bBuildConnect); if (!m_bBuildConnect) { this->m_nCtrlPort = nPort; Stop(); if (m_pThreadShell) { m_pThreadShell->SetExit(false); } m_bHaveExited = false; m_bBuildConnect = true; return CreateTunnel(CONTROL); } } catch(...){} return FALSE; }
void ConnectionCommunity::OnConnect(HWND hwnd, ConnectionInfo * dbname) { Tunnel *tunnel; MYSQL *mysql; HWND lastfocus = GetFocus(); wyString conn, temp, dirnamestr; wyWChar directory[MAX_PATH + 1] = {0}, *lpfileport = 0, pass[MAX_PATH + 1] = {0}; HWND hwndcombo; wyInt32 count, storepwd, ret; // DEBUG_ENTER("clicked ok"); tunnel = CreateTunnel(wyFalse); // DEBUG_LOG("created tunnel"); // Call ConnectToMySQL function to initialize a new mySQL structure and connect to // mySQL server with the connection details. The function will return a valid mysql // pointer if connection successful and if not then it will return NULL. // If null then show the standard mySQL errors given by the mySQL API. /* set correct values for tunnel to use HTTP authentication */ dbname->m_tunnel = tunnel; mysql = ConnectToMySQL(hwnd, dbname); if(mysql == NULL) { delete tunnel; SetFocus(lastfocus); } else if(dbname->m_db.GetLength() ==0 ||(IsDatabaseValid(dbname->m_db, mysql, tunnel) == wyTrue)) { // Successful so write the current details in connection .ini file // so that when the user uses the software again it will show the same details. dbname->m_mysql = mysql; dbname->m_tunnel = tunnel; WriteConnDetails(hwnd); ret = SearchFilePath(L"sqlyog", L".ini", MAX_PATH, directory, &lpfileport); if(ret == 0) { yog_enddialog(hwnd, (wyInt32)1); return; } /* if the user has changed any information then we ask him whether he wants to save */ if(m_conndetaildirty == wyTrue) { if(ConfirmAndSaveConnection(hwnd, wyTrue) == wyFalse) return; } else { /* even if he has not selected to save, we need to check for password thing as the user might diable on the store_password first and then make modification to the password, in that case the state will not be dirty and the value will not be stored */ VERIFY(hwndcombo = GetDlgItem(hwnd, IDC_DESC)); count = SendMessage(hwndcombo, CB_GETCOUNT, 0, 0); if(!count) { yog_enddialog(hwnd,(wyInt32)1); return; } VERIFY ((count = SendMessage(hwndcombo, CB_GETCURSEL, 0, 0))!= CB_ERR); count = SendMessage(hwndcombo, CB_GETITEMDATA, count, 0); conn.Sprintf("Connection %u", count); storepwd = Button_GetCheck(GetDlgItem(hwnd, IDC_DLGCONNECT_STOREPASSWORD)); /* now we only save the password if the user has asked for otherwise we remove it only */ /* feature implemented in v5.0 */ dirnamestr.SetAs(directory); //WritePrivateProfileStringA(conn.GetString(), "Password01", NULL, dirnamestr.GetString()); wyIni::IniDeleteKey(conn.GetString(), "Password01", dirnamestr.GetString()); if(!storepwd) { //WritePrivateProfileStringA(conn.GetString(), "Password", NULL, dirnamestr.GetString()); wyIni::IniDeleteKey(conn.GetString(), "Password", dirnamestr.GetString()); } else { GetWindowText(GetDlgItem(hwnd, IDC_DLGCONNECT_PASSWORD), pass, MAX_PATH); temp.SetAs(pass); EncodePassword(temp); wyIni::IniWriteString(conn.GetString(), "Password", temp.GetString(), dirnamestr.GetString()); } /* write the store password value too */ temp.Sprintf("%d", storepwd); ret = wyIni::IniWriteString (conn.GetString(), "StorePassword", temp.GetString(), dirnamestr.GetString()); } m_rgbobbkcolor = m_rgbconnection; m_rgbobfgcolor = m_rgbconnectionfg; yog_enddialog(hwnd,(wyInt32)1); } else { ShowMySQLError(hwnd, tunnel, &mysql, NULL, wyTrue); //fix a bug, database neme was erasing on error //SendMessage(GetDlgItem(hwnd, IDC_DLGCONNECT_DATABASE), WM_SETTEXT, 0,(LPARAM)L""); SetFocus(GetDlgItem(hwnd,IDC_DLGCONNECT_DATABASE)); return; } }
/* Function just tests the connection and checks whether it is correct or not */ wyBool ConnectionCommunity::TestConnection(HWND hwnd, wyBool showmsg /*=wyTrue*/) { ConnectionInfo dbname; MYSQL *mysql; Tunnel *tunnel; wyString query("select version()"), version; wyInt32 ret; MYSQL_RES *res; MYSQL_ROW row; wyString myrowstr; InitConnectionDetails(&dbname); tunnel = CreateTunnel(wyFalse); dbname.m_tunnel = tunnel; // Call ConnectToMySQL function to initialize a new mySQL structure and connect to // mySQL server with the connection details. The function will return a valid mysql // pointer if connection successful and if not then it will return NULL. // If null then show the standard mySQL errors given by the mySQL API. //if database name is not correct, then throw error mysql = pGlobals->m_pcmainwin->m_connection->ConnectToMySQL(hwnd, &dbname); if(mysql == NULL) { if(tunnel) delete tunnel; return wyFalse; } else if((dbname.m_db.GetLength() != 0) && (IsDatabaseValid(dbname.m_db, mysql, tunnel) == wyFalse)) { query.Clear(); goto cleanup; } /* now we send a test query "select version()", if everything is ok then we show a message with the version number */ ret = HandleMySQLRealQuery(tunnel, mysql, query.GetString(), query.GetLength(), false); if(ret) goto cleanup; res = tunnel->mysql_store_result(mysql); if(!res && mysql->affected_rows == -1) goto cleanup; row = tunnel->mysql_fetch_row(res); myrowstr.SetAs(row[0], IsMySQL41(dbname.m_tunnel, &mysql)); version.Sprintf(_("Connection successful!\nMySQL version: %s"), myrowstr.GetString()); if(showmsg) yog_message(hwnd, version.GetAsWideChar(), _(L"Connection Info"), MB_OK | MB_ICONINFORMATION); tunnel->mysql_free_result(res); tunnel->mysql_close(mysql); delete tunnel; return wyTrue; cleanup: if(query.GetLength()) ShowMySQLError(hwnd, tunnel, &mysql, query.GetString()); else ShowMySQLError(hwnd, tunnel, &mysql, NULL, wyTrue); delete tunnel; return wyFalse; }