#include "frmNewAccount.h"
+DEFINE_EVENT_TYPE(UPDATERESULTS);
+DEFINE_EVENT_TYPE(RUNCALDAVTEST);
+
+BEGIN_EVENT_TABLE(frmNewAccount, wxDialog)
+EVT_COMMAND(wxID_ANY, UPDATERESULTS, frmNewAccount::UpdateResults)
+EVT_COMMAND(wxID_ANY, RUNCALDAVTEST, frmNewAccount::RunCalDAVTest)
+END_EVENT_TABLE()
+
frmNewAccount::frmNewAccount( wxWindow* parent )
:
frmNewAccountADT( parent )
void frmNewAccount::UpdateRequirements( wxCommandEvent& event )
{
-// TODO: Implement UpdateRequirements
-}
-
-void frmNewAccount::ProcessPrevious( wxCommandEvent& event )
-{
-// TODO: Implement ProcessPrevious
+ // Update the options.
+
+ if (cmbServerType->GetCurrentSelection() == 1){
+
+ txtServerAddress->Enable();
+ txtServerPort->Enable();
+ txtUsername->Enable();
+ txtPassword->Enable();
+ chkUseSSL->Enable();
+
+ } else if (cmbServerType->GetCurrentSelection() == 0){
+
+ txtServerAddress->Disable();
+ txtServerPort->Disable();
+ txtUsername->Disable();
+ txtPassword->Disable();
+ chkUseSSL->Disable();
+
+ }
}
-void frmNewAccount::ProcessNext( wxCommandEvent& event )
+void frmNewAccount::Navigate( wxCommandEvent& event )
{
- pageSeek++;
-
- if (pageSeek == 1){
+ if (event.GetId() == wxID_NEXT)
pageSeek++;
- }
+ else
+ pageSeek--;
if (pageSeek == 1){
// Skip this page.
+
+ btnPrevious->Disable();
+ btnNext->Enable();
+
+ tabConn->Hide();
+ tabFinish->Hide();
+ tabType->Show();
+ btnNext->SetLabel(_("Next >"));
} else if (pageSeek == 2){
+
+ if (cmbServerType->GetCurrentSelection() == 0){
+
+ tabType->Hide();
+ tabConn->Hide();
+ tabFinish->Show();
+ szrNewAccount->RecalcSizes();
+ pageSeek = 2;
+
+ btnNext->Disable();
+ btnPrevious->Enable();
+ btnNext->SetLabel(_("Finish"));
+ return;
+
+ }
+
+ // Check if server address matches against the blacklist.
+ // Bring up warning message if it does.
+
+ if (CheckBlacklist(txtServerAddress->GetValue())){
+
+ int MessageBoxResult = wxMessageBox(_("The server with the address given does not support the CalDAV protocol properly and shouldn't be used.\n\nData loss is very likely.\n\nDo you still want to continue using this server?"), _("Server warning"), wxYES_NO, this);
+
+ if (MessageBoxResult == wxNO){
+ pageSeek--;
+ return;
+ }
+
+ }
+
+ btnNext->Disable();
+
+ bool ServerResult = FALSE;
+ bool ServerAction = FALSE;
+ bool UseSSL = TRUE;
+ wxString ServerMessage;
+
+ // Connection test screen.
+
+ tabType->Hide();
+ tabConn->Show();
+ tabFinish->Hide();
+ szrNewAccount->RecalcSizes();
+ btnPrevious->Disable();
+
+ // Reset screen.
+
+ lblServerConnResult->SetLabel(wxT(""));
+ lblServerResponse->SetLabel(wxT(""));
+ lblServerSSLResult->SetLabel(wxT(""));
+ lblServerSSLValid->SetLabel(wxT(""));
+ lblAbleToLoginResult->SetLabel(wxT(""));
+ lblCalDAVSupportResult->SetLabel(wxT(""));
+
+ // Depending on account type, run the test.
+
+ if (cmbServerType->GetCurrentSelection() == 1){
+ wxCommandEvent RunTest(RUNCALDAVTEST);
+ wxPostEvent(this, RunTest);
+ }
+
+ } else if (pageSeek == 3){
// Finish screen.
szrNewAccount->RecalcSizes();
btnNext->Disable();
+ btnPrevious->Enable();
btnNext->SetLabel(_("Finish"));
if (txtAccountName->IsEmpty() && pageSeek == 2){
}
- } else if (pageSeek == 3){
+ } else if (pageSeek == 4){
// Finished.
}
- if (cmbServerType->GetCurrentSelection() == 0){
+ if (cmbServerType->GetCurrentSelection() == 1){
// Create the account directory.
}
- if (cmbServerType->GetCurrentSelection() == 0){
+ if (cmbServerType->GetCurrentSelection() == 1){
// Create the account directory.
cfgFileIn->Write(wxT("refresh"), wxT("1800"));
cfgFileIn->Write(wxT("type"), accountType);
+}
+
+void frmNewAccount::UpdateResults( wxCommandEvent &event )
+{
+
+}
+
+void frmNewAccount::RunCalDAVTest( wxCommandEvent &event )
+{
+ NewAccountResult *resultData = new NewAccountResult;
+
+ lblServerConnResult->SetLabel(_("Testing..."));
+ lblCalDAVSupportResult->SetLabel(wxT(""));
+ lblServerResponse->SetLabel(wxT(""));
+ lblServerSSLResult->SetLabel(wxT(""));
+ lblServerSSLValid->SetLabel(wxT(""));
+ lblAbleToLoginResult->SetLabel(wxT(""));
+ bool usingSSLBypass = false;
+
+ // Setup a CalDAV connection object for testing.
+
+ CalDAVConnectionData connData;
+ connData.hostname = txtServerAddress->GetValue().ToStdString();
+ connData.port = wxAtoi(txtServerPort->GetValue());
+ connData.username = txtUsername->GetValue().ToStdString();
+ connData.password = txtPassword->GetValue().ToStdString();
+ connData.useSSL = chkUseSSL->GetValue() ? true : false);
+
+ CalDAV testConnection;
+ testConnection.SetupConnectionData(&connData);
+
+ /*CardDAV2 TestConnection(txtServerAddress->GetValue().ToStdString(),
+ wxAtoi(txtServerPort->GetValue()),
+ txtUsername->GetValue().ToStdString(),
+ txtPassword->GetValue().ToStdString(),
+ chkUseSSL->GetValue() ? true : false);*/
+
+ // Test the connection.
+
+ testConnection.SetupConnectionObject();
+ CalDAVServerResult testConnectionResult = testConnection.Connect(false);
+
+ // If server is using SSL, verify that the SSL connection is valid.
+
+ if (testConnection.SSLVerify() == COSSL_UNABLETOVERIFY){
+#if defined(__APPLE__)
+
+ testConnection.BypassSSLVerification(true);
+
+ CalDAVServerResult testConnection = testConnection.Connect(false);
+
+ testConnection.BypassSSLVerification(false);
+
+ int SSLResult = DisplayTrustPanel(&TestConnection);
+
+ if (SSLResult != NSOKButton){
+
+ lblServerConnResult->SetLabel(_("Failed"));
+ lblServerResponse->SetLabel(_("Not applicable"));
+ lblServerSSLResult->SetLabel(_("Used"));
+ lblServerSSLValid->SetLabel(_("No"));
+ lblConnectionResultText->SetLabel(_("An error occured whilst connnecting: ") + TestConnection.GetErrorMessage());
+ btnPrevious->Enable(true);
+ return;
+
+ } else {
+
+ // Evalulate the trust object.
+
+ SecTrustResultType evalResult = ProcessResultType(&testConnection);
+
+ switch(evalResult){
+ case kSecTrustResultProceed:
+ lblServerSSLValid->SetLabel(_("Verified"));
+ break;
+ case kSecTrustResultConfirm:
+ lblServerSSLValid->SetLabel(_("Verified (user)"));
+ break;
+ default:
+ lblServerSSLValid->SetLabel(_("Unable to verify"));
+ }
+
+ lblServerResponse->SetLabel(_("Not applicable"));
+ lblServerSSLResult->SetLabel(_("Used"));
+
+ if (evalResult != kSecTrustResultProceed){
+ return;
+ }
+
+ }
+
+#elif defined(__WIN32__)
+
+ testConnection.BypassSSLVerification(true);
+
+ CalDAVServerResult testConnectionResult = testConnection.Connect(false);
+
+ testConnection.BypassSSLVerification(false);
+
+ bool modifiedCertificateData = false;
+
+ CRYPTUI_VIEWCERTIFICATE_STRUCTW certificateDialogData = BuildCertificateData(&testConnection, (HWND)this->GetHandle());
+
+ if (!CryptUIDlgViewCertificate(&certificateDialogData, &modifiedCertificateData)){
+ wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog"));
+ }
+
+ if (modifiedCertificateData == false){
+
+ lblServerConnResult->SetLabel(_("Failed"));
+ lblServerResponse->SetLabel(_("Not applicable"));
+ lblServerSSLResult->SetLabel(_("Used"));
+ lblServerSSLValid->SetLabel(_("No"));
+ lblConnectionResultText->SetLabel(_("An error occured whilst connnecting: ") + testConnection.GetErrorMessage());
+ btnPrevious->Enable(true);
+ return;
+
+ }
+
+#else
+
+ // Connect again and fetch SSL certificate information.
+
+ testConnection.BypassSSLVerification(true);
+
+ CalDAVServerResult testConnectionResult = testConnection.Connect(false);
+
+ testConnection.BypassSSLVerification(false);
+
+ SSLCertCollectionString certData = testConnection.BuildSSLCollection();
+ frmInvalidSSLCertificate *frmICPtr = new frmInvalidSSLCertificate(this);
+
+ frmICPtr->LoadDataNew(CertData, txtServerAddress->GetValue().ToStdString());
+ frmICPtr->ShowModal();
+
+ int sslResult = frmICPtr->GetResult();
+
+ // Clean up before processing response.
+
+ delete frmICPtr;
+ frmICPtr = NULL;
+
+ // Process the response from the user.
+
+ if (sslResult == 1){
+
+ // Accept the Certificate.
+
+ usingSSLBypass = true;
+ testConnection.BypassSSLVerification(true);
+
+ CalDAVServerResult testConnectionResult = testConnection.Connect(true);
+
+ testConnection.BypassSSLVerification(false);
+
+ } else if (sslResult == 2){
+
+ // Reject the certificate, abort the task and mark as failed.
+
+ // TODO: Integrate into the code.
+
+ //lblConnectionResultText->SetLabel(_("An error occured whilst connnecting: ") + CardDAVConn.GetErrorMessage() + wxString::Format(wxT(" (%i)\n%s"), sslcode, CardDAVConn.GetErrorBuffer().mb_str()));
+
+ }
+
+#endif
+ }
+
+ testConnectionResult = testConnection.Connect(true);
+
+ // Get the server prefix if the connection was successful.
+
+ if (testConnectionResult == COCONNECT_OK){
+
+ if (usingSSLBypass == true){
+ testConnection.BypassSSLVerification(true);
+ }
+
+ std::string receivedServerPrefix;
+
+ receivedServerPrefix = testConnection.GetUserPrincipal();
+ serverPrefix = receivedServerPrefix;
+
+ if (usingSSLBypass == true){
+ testConnection.BypassSSLVerification(true);
+ }
+
+ }
+
+ testConnectionResult == COCONNECT_OK ? resultData->Connected = true : resultData->Connected = false;
+
+ resultData->SSLStatus = TestConnection.CanDoSSL();
+ resultData->SSLVerified = TestConnection.SSLVerify();
+ resultData->ValidResponse = TestConnection.HasValidResponse();
+ resultData->AuthPassed = TestConnection.AbleToLogin();
+ resultData->CanProcess = TestConnection.CanDoProcessing();
+ resultData->ErrorMessage = TestConnection.GetErrorMessage();
+
+ // Post event back confirming the tests.
+
+ wxCommandEvent resultsEvent(UPDATERESULTS);
+ resultsEvent.SetClientData(resultData);
+ wxPostEvent(this, resultsEvent);
}
\ No newline at end of file