bool CLoginManager::DisplayDialog(CServer &server, wxString name, wxString challenge) { wxDialog pwdDlg; wxXmlResource::Get()->LoadDialog(&pwdDlg, wxGetApp().GetTopWindow(), _T("ID_ENTERPASSWORD")); if (name == _T("")) { pwdDlg.GetSizer()->Show(XRCCTRL(pwdDlg, "ID_NAMELABEL", wxStaticText), false, true); pwdDlg.GetSizer()->Show(XRCCTRL(pwdDlg, "ID_NAME", wxStaticText), false, true); } else XRCCTRL(pwdDlg, "ID_NAME", wxStaticText)->SetLabel(name); if (challenge == _T("")) { pwdDlg.GetSizer()->Show(XRCCTRL(pwdDlg, "ID_CHALLENGELABEL", wxStaticText), false, true); pwdDlg.GetSizer()->Show(XRCCTRL(pwdDlg, "ID_CHALLENGE", wxTextCtrl), false, true); } else { #ifdef __WXMSW__ challenge.Replace(_T("\n"), _T("\r\n")); #endif XRCCTRL(pwdDlg, "ID_CHALLENGE", wxTextCtrl)->SetLabel(challenge); pwdDlg.GetSizer()->Show(XRCCTRL(pwdDlg, "ID_REMEMBER", wxCheckBox), false, true); XRCCTRL(pwdDlg, "ID_CHALLENGE", wxTextCtrl)->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)); } XRCCTRL(pwdDlg, "ID_HOST", wxStaticText)->SetLabel(server.FormatHost()); XRCCTRL(pwdDlg, "ID_USER", wxStaticText)->SetLabel(server.GetUser()); XRCCTRL(pwdDlg, "wxID_OK", wxButton)->SetId(wxID_OK); XRCCTRL(pwdDlg, "wxID_CANCEL", wxButton)->SetId(wxID_CANCEL); pwdDlg.GetSizer()->Fit(&pwdDlg); pwdDlg.GetSizer()->SetSizeHints(&pwdDlg); if (pwdDlg.ShowModal() != wxID_OK) return false; server.SetUser(server.GetUser(), XRCCTRL(pwdDlg, "ID_PASSWORD", wxTextCtrl)->GetValue()); if (server.GetLogonType() == ASK && XRCCTRL(pwdDlg, "ID_REMEMBER", wxCheckBox)->GetValue()) { t_passwordcache entry; entry.host = server.GetHost(); entry.port = server.GetPort(); entry.user = server.GetUser(); entry.password = server.GetPass(); m_passwordCache.push_back(entry); } return true; }
void CQuickconnectBar::OnQuickconnect(wxCommandEvent& event) { CState* pState = CContextManager::Get()->GetCurrentContext(); if (!pState || !pState->m_pEngine) { wxMessageBoxEx(_("FTP Engine not initialized, can't connect"), _("FileZilla Error"), wxICON_EXCLAMATION); return; } wxString host = m_pHost->GetValue(); wxString user = m_pUser->GetValue(); wxString pass = m_pPass->GetValue(); wxString port = m_pPort->GetValue(); CServer server; wxString error; CServerPath path; if (!server.ParseUrl(host, port, user, pass, error, path)) { wxString msg = _("Could not parse server address:"); msg += _T("\n"); msg += error; wxMessageBoxEx(msg, _("Syntax error"), wxICON_EXCLAMATION); return; } host = server.FormatHost(true); ServerProtocol protocol = server.GetProtocol(); switch (protocol) { case FTP: case UNKNOWN: if (CServer::GetProtocolFromPort(server.GetPort()) != FTP && CServer::GetProtocolFromPort(server.GetPort()) != UNKNOWN) host = _T("ftp://") + host; break; default: { const wxString prefix = server.GetPrefixFromProtocol(protocol); if (!prefix.empty()) host = prefix + _T("://") + host; } break; } m_pHost->SetValue(host); if (server.GetPort() != server.GetDefaultPort(server.GetProtocol())) m_pPort->SetValue(wxString::Format(_T("%d"), server.GetPort())); else m_pPort->SetValue(_T("")); m_pUser->SetValue(server.GetUser()); if (server.GetLogonType() != ANONYMOUS) m_pPass->SetValue(server.GetPass()); else m_pPass->SetValue(_T("")); if (protocol == HTTP || protocol == HTTPS) { wxString protocolError = _("Invalid protocol specified. Valid protocols are:\nftp:// for normal FTP with optional encryption,\nsftp:// for SSH file transfer protocol,\nftps:// for FTP over TLS (implicit) and\nftpes:// for FTP over TLS (explicit)."); wxMessageBoxEx(protocolError, _("Syntax error"), wxICON_EXCLAMATION); return; } if (event.GetId() == 1) server.SetBypassProxy(true); if (server.GetLogonType() != ANONYMOUS && !CAskSavePasswordDialog::Run(this)) return; if (COptions::Get()->GetOptionVal(OPTION_DEFAULT_KIOSKMODE) && server.GetLogonType() == NORMAL) { server.SetLogonType(ASK); CLoginManager::Get().RememberPassword(server); } if (!m_pMainFrame->ConnectToServer(server, path)) return; CRecentServerList::SetMostRecentServer(server); }
bool CLoginManager::DisplayDialog(CServer &server, wxString const& name, wxString challenge) { wxDialogEx pwdDlg; if (!pwdDlg.Load(wxGetApp().GetTopWindow(), _T("ID_ENTERPASSWORD"))) { return false; } if (name.empty()) { pwdDlg.GetSizer()->Show(XRCCTRL(pwdDlg, "ID_NAMELABEL", wxStaticText), false, true); pwdDlg.GetSizer()->Show(XRCCTRL(pwdDlg, "ID_NAME", wxStaticText), false, true); } else XRCCTRL(pwdDlg, "ID_NAME", wxStaticText)->SetLabel(name); if (challenge.empty()) { pwdDlg.GetSizer()->Show(XRCCTRL(pwdDlg, "ID_CHALLENGELABEL", wxStaticText), false, true); pwdDlg.GetSizer()->Show(XRCCTRL(pwdDlg, "ID_CHALLENGE", wxTextCtrl), false, true); } else { #ifdef __WXMSW__ challenge.Replace(_T("\n"), _T("\r\n")); #endif XRCCTRL(pwdDlg, "ID_CHALLENGE", wxTextCtrl)->ChangeValue(challenge); pwdDlg.GetSizer()->Show(XRCCTRL(pwdDlg, "ID_REMEMBER", wxCheckBox), false, true); XRCCTRL(pwdDlg, "ID_CHALLENGE", wxTextCtrl)->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)); } XRCCTRL(pwdDlg, "ID_HOST", wxStaticText)->SetLabel(server.FormatHost()); if (server.GetUser().empty()) { pwdDlg.SetTitle(_("Enter username and password")); XRCCTRL(pwdDlg, "ID_OLD_USER_LABEL", wxStaticText)->Hide(); XRCCTRL(pwdDlg, "ID_OLD_USER", wxStaticText)->Hide(); XRCCTRL(pwdDlg, "ID_HEADER_PASS", wxStaticText)->Hide(); if (server.GetLogonType() == INTERACTIVE) { XRCCTRL(pwdDlg, "ID_PASSWORD_LABEL", wxStaticText)->Hide(); XRCCTRL(pwdDlg, "ID_PASSWORD", wxTextCtrl)->Hide(); XRCCTRL(pwdDlg, "ID_REMEMBER", wxCheckBox)->Hide(); XRCCTRL(pwdDlg, "ID_HEADER_BOTH", wxStaticText)->Hide(); } else XRCCTRL(pwdDlg, "ID_HEADER_USER", wxStaticText)->Hide(); XRCCTRL(pwdDlg, "ID_NEW_USER", wxTextCtrl)->SetFocus(); } else { XRCCTRL(pwdDlg, "ID_OLD_USER", wxStaticText)->SetLabel(server.GetUser()); XRCCTRL(pwdDlg, "ID_NEW_USER_LABEL", wxStaticText)->Hide(); XRCCTRL(pwdDlg, "ID_NEW_USER", wxTextCtrl)->Hide(); XRCCTRL(pwdDlg, "ID_HEADER_USER", wxStaticText)->Hide(); XRCCTRL(pwdDlg, "ID_HEADER_BOTH", wxStaticText)->Hide(); } XRCCTRL(pwdDlg, "wxID_OK", wxButton)->SetId(wxID_OK); XRCCTRL(pwdDlg, "wxID_CANCEL", wxButton)->SetId(wxID_CANCEL); pwdDlg.GetSizer()->Fit(&pwdDlg); pwdDlg.GetSizer()->SetSizeHints(&pwdDlg); wxString user; while (user.empty()) { if (pwdDlg.ShowModal() != wxID_OK) return false; if (server.GetUser().empty()) { user = XRCCTRL(pwdDlg, "ID_NEW_USER", wxTextCtrl)->GetValue(); if (user.empty()) { wxMessageBoxEx(_("No username given."), _("Invalid input"), wxICON_EXCLAMATION); continue; } } else user = server.GetUser(); } server.SetUser(user, XRCCTRL(pwdDlg, "ID_PASSWORD", wxTextCtrl)->GetValue()); if (server.GetLogonType() == ASK && XRCCTRL(pwdDlg, "ID_REMEMBER", wxCheckBox)->GetValue()) { t_passwordcache entry; entry.host = server.GetHost(); entry.port = server.GetPort(); entry.user = server.GetUser(); entry.password = server.GetPass(); m_passwordCache.push_back(entry); } return true; }
bool CManualTransfer::VerifyServer() { const wxString& host = XRCCTRL(*this, "ID_HOST", wxTextCtrl)->GetValue(); if (host == _T("")) { XRCCTRL(*this, "ID_HOST", wxTextCtrl)->SetFocus(); wxMessageBoxEx(_("You have to enter a hostname.")); return false; } enum LogonType logon_type = CServer::GetLogonTypeFromName(XRCCTRL(*this, "ID_LOGONTYPE", wxChoice)->GetStringSelection()); wxString protocolName = XRCCTRL(*this, "ID_PROTOCOL", wxChoice)->GetStringSelection(); enum ServerProtocol protocol = CServer::GetProtocolFromName(protocolName); if (protocol == SFTP && logon_type == ACCOUNT) { XRCCTRL(*this, "ID_LOGONTYPE", wxChoice)->SetFocus(); wxMessageBoxEx(_("'Account' logontype not supported by selected protocol")); return false; } if (COptions::Get()->GetOptionVal(OPTION_DEFAULT_KIOSKMODE) != 0 && (logon_type == ACCOUNT || logon_type == NORMAL)) { XRCCTRL(*this, "ID_LOGONTYPE", wxChoice)->SetFocus(); wxString msg; if (COptions::Get()->OptionFromFzDefaultsXml(OPTION_DEFAULT_KIOSKMODE)) msg = _("Saving of password has been disabled by your system administrator."); else msg = _("Saving of passwords has been disabled by you."); msg += _T("\n"); msg += _("'Normal' and 'Account' logontypes are not available, using 'Ask for password' instead."); XRCCTRL(*this, "ID_LOGONTYPE", wxChoice)->SetStringSelection(CServer::GetNameFromLogonType(ASK)); XRCCTRL(*this, "ID_PASS", wxTextCtrl)->SetValue(_T("")); logon_type = ASK; wxMessageBoxEx(msg, _("Cannot remember password"), wxICON_INFORMATION, this); } CServer server; // Set selected type server.SetLogonType(logon_type); if (protocol != UNKNOWN) server.SetProtocol(protocol); CServerPath path; wxString error; if (!server.ParseUrl(host, XRCCTRL(*this, "ID_PORT", wxTextCtrl)->GetValue(), _T(""), _T(""), error, path)) { XRCCTRL(*this, "ID_HOST", wxTextCtrl)->SetFocus(); wxMessageBoxEx(error); return false; } XRCCTRL(*this, "ID_HOST", wxTextCtrl)->ChangeValue(server.FormatHost(true)); XRCCTRL(*this, "ID_PORT", wxTextCtrl)->ChangeValue(wxString::Format(_T("%d"), server.GetPort())); protocolName = CServer::GetProtocolName(server.GetProtocol()); if (protocolName == _T("")) CServer::GetProtocolName(FTP); XRCCTRL(*this, "ID_PROTOCOL", wxChoice)->SetStringSelection(protocolName); // Require username for non-anonymous, non-ask logon type const wxString user = XRCCTRL(*this, "ID_USER", wxTextCtrl)->GetValue(); if (logon_type != ANONYMOUS && logon_type != ASK && logon_type != INTERACTIVE && user == _T("")) { XRCCTRL(*this, "ID_USER", wxTextCtrl)->SetFocus(); wxMessageBoxEx(_("You have to specify a user name")); return false; } // The way TinyXML handles blanks, we can't use username of only spaces if (user != _T("")) { bool space_only = true; for (unsigned int i = 0; i < user.Len(); ++i) { if (user[i] != ' ') { space_only = false; break; } } if (space_only) { XRCCTRL(*this, "ID_USER", wxTextCtrl)->SetFocus(); wxMessageBoxEx(_("Username cannot be a series of spaces")); return false; } } // Require account for account logon type if (logon_type == ACCOUNT && XRCCTRL(*this, "ID_ACCOUNT", wxTextCtrl)->GetValue() == _T("")) { XRCCTRL(*this, "ID_ACCOUNT", wxTextCtrl)->SetFocus(); wxMessageBoxEx(_("You have to enter an account name")); return false; } return true; }
void CQuickconnectBar::OnQuickconnect(wxCommandEvent& event) { if (!m_pState->m_pEngine) { wxMessageBox(_("FTP Engine not initialized, can't connect"), _("FileZilla Error"), wxICON_EXCLAMATION); return; } wxString host = m_pHost->GetValue(); wxString user = m_pUser->GetValue(); wxString pass = m_pPass->GetValue(); wxString port = m_pPort->GetValue(); long numericPort = 0; if (port != _T("")) port.ToLong(&numericPort); CServer server; wxString error; CServerPath path; if (!server.ParseUrl(host, numericPort, user, pass, error, path)) { wxString msg = _("Could not parse server address:"); msg += _T("\n"); msg += error; wxMessageBox(msg, _("Syntax error"), wxICON_EXCLAMATION); return; } host = server.FormatHost(true); ServerProtocol protocol = server.GetProtocol(); switch (protocol) { case FTP: case UNKNOWN: if (CServer::GetProtocolFromPort(server.GetPort()) != FTP && CServer::GetProtocolFromPort(server.GetPort()) != UNKNOWN) host = _T("ftp://") + host; break; default: { const wxString prefix = server.GetPrefixFromProtocol(protocol); if (prefix != _T("")) host = prefix + _T("://") + host; } break; } m_pHost->SetValue(host); if (server.GetPort() != server.GetDefaultPort(server.GetProtocol())) m_pPort->SetValue(wxString::Format(_T("%d"), server.GetPort())); else m_pPort->SetValue(_T("")); m_pUser->SetValue(server.GetUser()); m_pPass->SetValue(server.GetPass()); if (protocol == HTTP) { wxMessageBox(_("FileZilla does not support the HTTP protocol"), _("Syntax error"), wxICON_EXCLAMATION); return; } if (event.GetId() == 1) server.SetBypassProxy(true); if (!m_pState->Connect(server, true, path)) return; CRecentServerList::SetMostRecentServer(server); }