Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Label servers that can cause data loss as dangerous
[xestiaab/.git] / source / frmEditAccount.cpp
index b7c8fef..920f526 100644 (file)
@@ -1,5 +1,23 @@
+// frmEditAccount.cpp - Edit Account form.
+//
+// (c) 2012-2015 Xestia Software Development.
+//
+// This file is part of Xestia Address Book.
+//
+// Xestia Address Book is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by the
+// Free Software Foundation, version 3 of the license.
+//
+// Xestia Address Book is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
+
 #include "frmEditAccount.h"
-#include "carddav/carddav.h"
+#include "common/svrdlist.h"
 
 frmEditAccount::frmEditAccount( wxWindow* parent )
 :
@@ -13,15 +31,17 @@ void frmEditAccount::DetectAddressBook( wxCommandEvent& event )
 
        // Check data before connecting.
 
-       wxString ValueData;
+       wxString ValueData = "";
+       std::string ReceivedServerPrefix = "";
        
-       long PortNum;
+       long PortNum = 80;
        ValueData = txtPort->GetValue();
        ValueData.ToLong(&PortNum, 10);
-       long RefreshNum;
+       long RefreshNum = 1800;
        ValueData = txtRefresh->GetValue();
        ValueData.ToLong(&RefreshNum, 10);
-       bool UseSSL;
+       bool UseSSL = true;
+       bool UsingSSLBypass = false;
        
        if (txtAddress->IsEmpty()){
        
@@ -58,39 +78,157 @@ void frmEditAccount::DetectAddressBook( wxCommandEvent& event )
                RefreshNum = 1800;
                
        }
+
+       CardDAV2 TestConnection(txtAddress->GetValue().ToStdString(),
+               wxAtoi(txtPort->GetValue()),
+               txtUsername->GetValue().ToStdString(),
+               txtPassword->GetValue().ToStdString(),
+               chkSSL->GetValue());
+       
+       // Test the connection.
        
-       // Setup a CardDAV object.
+       TestConnection.SetupConnectionObject();
+       COConnectResult TestConnectionResult = TestConnection.Connect(false);
        
-       CardDAV CDavObj;
+       // If server is using SSL, verify that the SSL connection is valid.
        
-       CDavObj.SetupConnection(txtAddress->GetValue(), PortNum, txtUsername->GetValue(), txtPassword->GetValue(), UseSSL);
+       if (TestConnection.SSLVerify() == COSSL_UNABLETOVERIFY){
+#if defined(__APPLE__)
+               
+               TestConnection.BypassSSLVerification(true);
+               
+               COConnectResult TestConnectionResult = TestConnection.Connect(false);
+               
+               TestConnection.BypassSSLVerification(false);
+               
+               int SSLResult = DisplayTrustPanel(&TestConnection);
+               
+               if (SSLResult != NSOKButton){
+                       
+                       wxMessageBox(_("An error occured whilst connnecting: ") + TestConnection.GetErrorMessage(), _("Failed"), wxOK+wxICON_ERROR);
+                       return;
+                       
+               }
+               
+#elif defined(__WIN32__)
+
+               TestConnection.BypassSSLVerification(true);
+
+               COConnectResult TestConnectionResult = TestConnection.Connect(false);
+
+               TestConnection.BypassSSLVerification(false);
+
+               BOOL ModifiedCertificateData = false;
+               CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(&TestConnection, (HWND)this->GetHandle());
+
+               if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)) {
+                       wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog"));
+                       return;
+               }
+
+               if (ModifiedCertificateData == false) {
+                       wxMessageBox(_("An invalid certificate was received from the server."), _("Invalid certificate"));
+                       return;
+               } else {
+                       TestConnection.BypassSSLVerification(true);
+                       COConnectResult TestConnectionResult = TestConnection.Connect(true);
+                       TestConnection.BypassSSLVerification(false);
+               }
+
+#else
        
-       // Attempt to extract the CardDAV address.
+               // Connect again and fetch SSL certificate information.
+               
+               TestConnection.BypassSSLVerification(true);
+               
+               COConnectResult TestConnectionResult = TestConnection.Connect(false);
+               
+               TestConnection.BypassSSLVerification(false);
+
+               SSLCertCollectionString CertData = TestConnection.BuildSSLCollection();
+               frmInvalidSSLCertificate *frmICPtr = new frmInvalidSSLCertificate(this);
+               
+               frmICPtr->LoadDataNew(CertData, txtAddress->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);
+               
+                       COConnectResult TestConnectionResult = TestConnection.Connect(true);
+                                                               
+               } else if (SSLResult == 2){
+                                                               
+                       // Reject the certificate, abort the task.
+
+                       wxMessageBox(_("Server certficiate rejected. Unable to detect the prefix."), _("Failed"), wxOK+wxICON_ERROR);
+                       
+                       return; 
+                       
+               }               
+               
+#endif
+       }
        
-       wxString ABURL = CDavObj.GetDefaultAddressBookURL();
+       // Get the server prefix if the connection was successful.
+
+       if (TestConnectionResult == COCONNECT_OK){
+
+               COConnectResult TestConnectionResult = TestConnection.Connect(true);
+
+               if (UsingSSLBypass == true){
+                       TestConnection.BypassSSLVerification(true);                     
+               }
+               
+               COServerResponse PrefixRequestResult = TestConnection.GetDefaultPrefix(&ReceivedServerPrefix);
+
+               if (UsingSSLBypass == true){
+                       TestConnection.BypassSSLVerification(true);                     
+               }
+               
+       } else {
+               
+               wxMessageBox(_("An error occured whilst detecting the prefix: ") + TestConnection.GetErrorMessage(), _("Failed"), wxOK+wxICON_ERROR);
+               
+       }
        
-       txtPrefix->SetValue(ABURL);
+       txtPrefix->SetValue(ReceivedServerPrefix);
        
 }
 
 void frmEditAccount::LoadPointers( wxFileConfig* cfgin ){
 
+       // Setup the account configuration file pointer.
+       
        cfgfile = cfgin;
 
 }
 
 void frmEditAccount::LoadSettings( wxString AccNameIn ){
 
-       // Get the data from the accounts settings file.
+       // Get the data from the accounts settings file and
+       // fill in the account fields.
 
        AccName = AccNameIn;
        long itemindex = 0;
        bool ContinueAcc = TRUE;
        wxString AccountName;
        wxString AccountData;
-
+       
        ContinueAcc = cfgfile->GetFirstGroup(AccountName, itemindex);
-
+       
        while (ContinueAcc){
 
                if (AccountName == AccName){
@@ -137,6 +275,19 @@ void frmEditAccount::LoadSettings( wxString AccNameIn ){
 void frmEditAccount::UpdateSettings( wxCommandEvent& event )
 {
 
+       // Check if server address matches against the dangerous list.
+       // Bring up warning message if it does.
+       
+       if (CheckDangerousList(txtAddress->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);
+               
+               if (MessageBoxResult == wxNO){
+                       return;
+               }
+                       
+       }
+       
        // Update the settings for the account.
 
        long itemindex = 0;
@@ -186,32 +337,6 @@ void frmEditAccount::UpdateSettings( wxCommandEvent& event )
                        cfgfile->DeleteEntry(wxT("refresh"), FALSE);
                        cfgfile->Write(wxT("refresh"), txtRefresh->GetValue());
 
-                       /*cfgfile->Read("address", &AccountData);
-                       //txtAddress->SetValue(AccountData);
-
-                       cfgfile->Read("port", &AccountData);
-                       //txtPort->SetValue(AccountData);
-
-                       cfgfile->Read("username", &AccountData);
-                       //txtUsername->SetValue(AccountData);
-
-                       cfgfile->Read("password", &AccountData);
-                       //txtPassword->SetValue(AccountData);
-
-                       cfgfile->Read("prefix", &AccountData);
-                       //txtPrefix->SetValue(AccountData);
-
-                       cfgfile->Read("ssl", &AccountData);
-                       if (AccountData == wxT("true")){
-                       
-                               chkSSL->SetValue(TRUE);
-                       
-                       }
-                       
-                       cfgfile->Read("refresh", &AccountData);
-                       //txtRefresh->SetValue(AccountData);*/
-
-                       
                        break;
 
                }
@@ -220,12 +345,28 @@ void frmEditAccount::UpdateSettings( wxCommandEvent& event )
                ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex);
 
        }
+
+       // Set the dialog result to true and close the window.
        
+       DialogResult = true;    
        this->Close();  
 
 }
 
 void frmEditAccount::CloseWindow( wxCommandEvent& event )
 {
+       
+       // Set the dialog result to false and close the window.
+       
+       DialogResult = false;
        this->Close();
+       
+}
+
+bool frmEditAccount::GetDialogResult(){
+
+       // Get the result of the dialog.
+       
+       return DialogResult;
+       
 }
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