Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Label servers that can cause data loss as dangerous
[xestiaab/.git] / source / frmNewAccount.cpp
index 49d278e..9d0873e 100644 (file)
 #include <wx/filefn.h>
 #include <wx/fileconf.h>
 
-#include "carddav/carddav.h"
+#if defined(__WIN32__)
+#include <cryptuiapi.h>
+#include "common/win32ssl.h"
+#endif
+
 #include "common/dirs.h"
-#include "common/svrblist.h"
+#include "common/svrdlist.h"
 #include "frmInvalidSSLCertificate.h"
 
+DEFINE_EVENT_TYPE(UPDATERESULTS);
+DEFINE_EVENT_TYPE(RUNCARDDAV2TEST);
+
+BEGIN_EVENT_TABLE(frmNewAccount, wxDialog)
+EVT_COMMAND(wxID_ANY, UPDATERESULTS, frmNewAccount::UpdateResults)
+EVT_COMMAND(wxID_ANY, RUNCARDDAV2TEST, frmNewAccount::RunCardDAV2Test)
+END_EVENT_TABLE()
+
 frmNewAccount::frmNewAccount( wxWindow* parent )
 :
 frmNewAccountADT( parent )
@@ -90,7 +102,7 @@ void frmNewAccount::ProcessPrevious( wxCommandEvent& event )
                        return;
             
                }
-        
+               
                // Currently at the Finish screen.
         
                tabType->Hide();
@@ -128,10 +140,10 @@ void frmNewAccount::ProcessNext( wxCommandEvent& event )
             
                }
         
-               // Check if server address matches against the blacklist.
+               // Check if server address matches against the dangerous list.
                // Bring up warning message if it does.
                
-               if (CheckBlacklist(txtServerAddress->GetValue())){
+               if (CheckDangerousList(txtServerAddress->GetValue())){
                
                        int MessageBoxResult = wxMessageBox(_("The server with the address given does not support the CardDAV 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);
                
@@ -155,7 +167,7 @@ void frmNewAccount::ProcessNext( wxCommandEvent& event )
                tabConn->Show();
                tabFinish->Hide();
                szrNewAccount->RecalcSizes();
-               btnPrevious->Enable();
+               btnPrevious->Disable();
         
                // Reset screen.
         
@@ -165,170 +177,12 @@ void frmNewAccount::ProcessNext( wxCommandEvent& event )
                lblServerSSLValid->SetLabel(wxT(""));
                lblAbleToLoginResult->SetLabel(wxT(""));
                lblCardDAVSupportResult->SetLabel(wxT(""));
-        
-               // Spawn a thread and check if server supports CardDAV.
-        
-               CardDAV CardDAVConn;
-        
-               lblServerConnResult->SetLabel(_("Testing..."));
-        
-               UseSSL = chkUseSSL->GetValue();
-               CardDAVConn.SetupConnection(txtServerAddress->GetValue(),
-                       wxAtoi(txtServerPort->GetValue()),
-                       txtUsername->GetValue(),
-                       txtPassword->GetValue(),
-                       UseSSL);
-               CardDAVConn.SetupResultBools(&ServerResult, &ServerAction);
-        
-               // Verify SSL trust first before doing anything.
-
-               if (UseSSL == TRUE){
-
-                       CURLcode sslcode = CardDAVConn.SSLVerifyTest();
-
-                       if (sslcode == CURLE_OK){
-                               
-
-
-                       } else if (sslcode == CURLE_SSL_CACERT || sslcode == CURLE_SSL_CONNECT_ERROR){
-
-                               // Certificate is more than likely a self-signed or
-                               // expired certificate so display the invalid
-                               // SSL certificate message.
-
-                               // Setup the data to be sent in the wxPostEvent command.
-
-                               int SSLResult;
-                       
-                               frmInvalidSSLCertificate *frmICPtr = new frmInvalidSSLCertificate(this);
-
-                               frmICPtr->LoadDataNew(CardDAVConn.GetSSLVerifyResults(), txtServerAddress->GetValue());
-                               frmICPtr->ShowModal();
-                                                               
-                               SSLResult = frmICPtr->GetResult();
-                                                       
-                               // Clean up before processing response.
-                               
-                               delete frmICPtr;
-                               frmICPtr = NULL;
-                                                       
-                               // Process the response from the user.
-                                                       
-                               if (SSLResult == 1){
-                                                               
-                                       // Accept the Certificate.
-
-                                       CardDAVConn.AllowSelfSignTest(TRUE);
-                                                               
-                               } else if (SSLResult == 2){
-                                                               
-                                       // Reject the certificate, abort the task and mark as failed.
-
-                                       lblServerConnResult->SetLabel(_("Failed"));
-                                       lblConnectionResultText->SetLabel(_("An error occured whilst connnecting: ") + CardDAVConn.GetErrorMessage() + wxString::Format(wxT(" (%i)\n%s"), sslcode, CardDAVConn.GetErrorBuffer().mb_str()));
-                                       return;
-                                                               
-                               }
-
-                       } else {
-
-                               // Something else happened. Stop the process and
-                               // display an error message instead.
-
-                               lblServerConnResult->SetLabel(_("Failed"));
-                               lblConnectionResultText->SetLabel(_("An error occured whilst connnecting: ") + CardDAVConn.GetErrorMessage() + wxString::Format(wxT(" (%i)\n%s"), sslcode, CardDAVConn.GetErrorBuffer().mb_str()));
-                               return;
-
-                       }
-
-               }
-
-               std::thread ConnTest(&CardDAV::Connect, &CardDAVConn);
-        
-               ConnTest.join();
-        
-               if (ServerResult == FALSE){
-            
-                       lblServerConnResult->SetLabel(_("Failed"));
-                       return;
-            
-               } else {
-            
-                       lblServerConnResult->SetLabel(_("Connected"));
-            
-               }
-        
-               if (CardDAVConn.CanDoSSL() == TRUE){
-            
-                       lblServerSSLResult->SetLabel(_("Used"));
-            
-               } else {
-            
-                       lblServerSSLResult->SetLabel(_("Not Used"));
-                       lblServerSSLValid->SetLabel(_("Not Applicable"));
-            
-               }
-        
-               if (CardDAVConn.SSLVerify() == TRUE && CardDAVConn.CanDoSSL() == TRUE){
-            
-                       lblServerSSLValid->SetLabel(_("Verified"));
-            
-               } else if (CardDAVConn.SSLVerify() == FALSE && CardDAVConn.CanDoSSL() == TRUE && CardDAVConn.IsSelfSigned() == TRUE){
        
-                       lblServerSSLValid->SetLabel(_("Verified (user)"));
-       
-               } else if (CardDAVConn.SSLVerify() == FALSE && CardDAVConn.CanDoSSL() == TRUE) {
-            
-                       lblServerSSLValid->SetLabel(_("Unable to verify"));
-            
-               }       
+               // Depending on account type, run the test.
         
-               if (CardDAVConn.CanDoCardDAV() == TRUE){
-            
-                       lblCardDAVSupportResult->SetLabel(_("Supported"));
-            
-               } else {
-            
-                       lblCardDAVSupportResult->SetLabel(_("Unsupported"));
-            
-               }
-        
-               if (CardDAVConn.AbleToLogin() == TRUE){
-            
-                       lblAbleToLoginResult->SetLabel(_("Yes"));
-            
-               } else {
-            
-                       lblAbleToLoginResult->SetLabel(_("No"));
-            
-               }
-        
-               // Get the address to process CardDAV requests.
-        
-               ServerPrefix = CardDAVConn.GetDefaultAddressBookURL();
-        
-               if (CardDAVConn.HasValidResponse() == TRUE){
-            
-                       lblServerResponse->SetLabel(_("Yes"));
-            
-               } else {
-            
-                       lblServerResponse->SetLabel(_("No"));
-            
-               }
-        
-               if (ServerResult == TRUE && CardDAVConn.HasValidResponse() == TRUE &&
-
-                       CardDAVConn.CanDoCardDAV() == TRUE && CardDAVConn.AbleToLogin() == TRUE){
-            
-                       btnNext->Enable();
-            
-                       lblConnectionResultText->SetLabel(_("Click on Next to set the account name."));
-            
-               } else {
-            
-                       lblConnectionResultText->SetLabel(_("A problem has occured whilst connecting to the CardDAV server.\nPlease review the above information and change the server details if needed.\nIf there are still problems, please speak to your system administrator(s)."));
-            
+               if (cmbServerType->GetCurrentSelection() == 1){
+                       wxCommandEvent RunTest(RUNCARDDAV2TEST);
+                       wxPostEvent(this, RunTest);
                }
         
        } else if (PageSeek == 2){
@@ -361,7 +215,10 @@ void frmNewAccount::ProcessNext( wxCommandEvent& event )
                wxString XestiaABDirectory;
                wxString AccountSettingsFile;
                //wxFile ASFile;
-               wxString RandomNumberSuffix = wxString::Format(wxT("%i"), rand() % 32767);
+               
+               srand(time(0));
+               int RandomNumber = rand() % 32767;
+               wxString RandomNumberSuffix = wxString::Format(wxT("%i"), RandomNumber);
                bool DirectoryCreated = FALSE;
         
 #if defined(__HAIKU__)
@@ -610,10 +467,99 @@ void frmNewAccount::UpdateRequirements( wxCommandEvent& event )
     
 }
 
+void frmNewAccount::UpdateResults( wxCommandEvent& event )
+{
+
+       NewAccountResult *ResultDataPointer = static_cast<NewAccountResult*>(event.GetClientData());
+       NewAccountResult ResultData = (*ResultDataPointer);
+       
+       delete(ResultDataPointer);
+       ResultDataPointer = nullptr;
+       bool ServerResult = true;
+       
+       // Process the result if the server connected.
+
+       if (ResultData.Connected == false){
+               lblServerConnResult->SetLabel(_("Failed"));
+               ServerResult = false;
+       } else {
+               lblServerConnResult->SetLabel(_("Success"));            
+       }
+       
+       // Check the result if the server gave a valid response.
+       
+       if (ResultData.ValidResponse == false){
+               lblServerResponse->SetLabel(_("No"));
+               ServerResult = false;
+       } else {
+               lblServerResponse->SetLabel(_("Yes"));
+       }
+       
+       // Check the result if the server uses SSL.     
+       
+       if (ResultData.SSLStatus == false){
+               lblServerSSLResult->SetLabel(_("No"));
+       } else {
+               lblServerSSLResult->SetLabel(_("Yes"));
+       }
+       
+       // Check the server has a valid SSL certificate.
+       
+       switch(ResultData.SSLVerified){
+               case COSSL_VERIFIED:
+                       lblServerSSLValid->SetLabel(_("Verified"));
+                       break;
+               case COSSL_VERIFIED_USER:
+                       lblServerSSLValid->SetLabel(_("Verified (User)"));
+                       break;
+               case COSSL_UNABLETOVERIFY:
+                       lblServerSSLValid->SetLabel(_("Unable to verify"));
+                       ServerResult = false;
+                       break;
+               case COSSL_NOTAPPLICABLE:
+                       lblServerSSLValid->SetLabel(_("Not applicable"));
+                       break;
+       }
+       
+       // Check if able to log into the server.
+       
+       if (ResultData.AuthPassed == false){
+               lblAbleToLoginResult->SetLabel(_("No"));
+               ServerResult = false;
+       } else {
+               lblAbleToLoginResult->SetLabel(_("Yes"));               
+       }
+       
+       // Check if server has CardDAV support.
+       
+       if (ResultData.CanProcess == false){
+               lblCardDAVSupportResult->SetLabel(_("No"));
+               ServerResult = false;
+       } else {
+               lblCardDAVSupportResult->SetLabel(_("Yes"));
+       }
+       
+       if (ServerResult == false){
+               lblConnectionResultText->SetLabel(wxString::Format(_("An error occured whilst connecting: %s"), ResultData.ErrorMessage));
+       } else {
+               btnNext->Enable();
+               lblConnectionResultText->SetLabel(_("Click on Next to set the account name."));
+       }
+       
+       btnPrevious->Enable();
+       
+}
+
 void frmNewAccount::SetupPointers(bool *ReloadAccountInc){
 
        // Setup the pointers for the new account window.
    
        ReloadAccountConfig = ReloadAccountInc;
     
+}
+
+void frmNewAccount::SetErrorMessageLabel(){
+       
+       lblConnectionResultText->SetLabel(_("A problem has occured whilst connecting to the CardDAV server.\nPlease review the above information and change the server details if needed.\nIf there are still problems, please speak to your system administrator(s)."));
+       
 }
\ No newline at end of file
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy