Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added copyright and license header to the C++ files and headers in the top source...
[xestiaab/.git] / source / frmNewAccount.cpp
index 1681134..e320223 100644 (file)
@@ -1,3 +1,21 @@
+// frmNewAccount.cpp - New 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 "frmNewAccount.h"
 #include <thread>
 #include <cstdlib>
@@ -6,6 +24,7 @@
 
 #include "carddav/carddav.h"
 #include "common/dirs.h"
+#include "frmInvalidSSLCertificate.h"
 
 frmNewAccount::frmNewAccount( wxWindow* parent )
 :
@@ -128,7 +147,6 @@ void frmNewAccount::ProcessNext( wxCommandEvent& event )
         lblServerConnResult->SetLabel(_("Testing..."));
         
         UseSSL = chkUseSSL->GetValue();
-        
         CardDAVConn.SetupConnection(txtServerAddress->GetValue(),
                                     wxAtoi(txtServerPort->GetValue()),
                                     txtUsername->GetValue(),
@@ -136,6 +154,98 @@ void frmNewAccount::ProcessNext( wxCommandEvent& event )
                                     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.
+
+                               //SSLInvalidCertNotifObj SSLICNProcData;
+
+                               //bool *PauseMode = new bool;
+                               int SSLResult;
+                               //QRNotif qrn;
+
+                               //*PauseMode = TRUE;            
+                               //qrn.QResponse = &SSLResult;
+                               //qrn.PausePtr = PauseMode;
+                               
+                               //SSLICNProcData.CertCollection = CardDAVConn.GetSSLVerifyResults();
+                               //SSLICNProcData.QRNotifData = &qrn;
+                               //SSLICNProcData.AccountName = _("New account");
+                       
+                               frmInvalidSSLCertificate *frmICPtr = new frmInvalidSSLCertificate(this);
+
+                               frmICPtr->LoadDataNew(CardDAVConn.GetSSLVerifyResults(), txtServerAddress->GetValue());
+                               frmICPtr->ShowModal();
+                       
+                               //wxCommandEvent event(INVALIDSSLCERT);
+                               //event.SetClientData(&SSLICNProcData);
+                               //wxPostEvent(this->GetParent(), event);
+       
+                               /*timespec n1, n2;
+               
+                               // Fall asleep until we get an response.
+               
+                               n1.tv_sec = 0;
+                               n1.tv_nsec = 250000000L;*/
+                                       
+                               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;
+                                                               
+                               }
+
+                               //frmInvalidSSLCertificate *frmICPtr = new frmInvalidSSLCertificate(this);
+
+                               //frmICPtr->LoadDataNew(CardDAVConn.GetSSLVerifyResults(), txtServerAddress->GetValue());
+                               //frmICPtr->ShowModal();
+                               
+
+                       } 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();
@@ -143,7 +253,6 @@ void frmNewAccount::ProcessNext( wxCommandEvent& event )
         if (ServerResult == FALSE){
             
             lblServerConnResult->SetLabel(_("Failed"));
-            wxMessageBox(CardDAVConn.GetErrorMessage());
             return;
             
         } else {
@@ -152,19 +261,9 @@ void frmNewAccount::ProcessNext( wxCommandEvent& event )
             
         }
         
-        if (CardDAVConn.HasValidResponse() == TRUE){
-            
-            lblServerResponse->SetLabel(_("Yes"));
-            
-        } else {
-            
-            lblServerResponse->SetLabel(_("No"));
-            
-        }
-        
         if (CardDAVConn.CanDoSSL() == TRUE){
             
-            lblCardDAVSupportResult->SetLabel(_("Used"));
+           lblServerSSLResult->SetLabel(_("Used"));
             
         } else {
             
@@ -175,13 +274,17 @@ void frmNewAccount::ProcessNext( wxCommandEvent& event )
         
         if (CardDAVConn.SSLVerify() == TRUE && CardDAVConn.CanDoSSL() == TRUE){
             
-            lblCardDAVSupportResult->SetLabel(_("Verified"));
+            lblServerSSLValid->SetLabel(_("Verified"));
             
-        } else if (CardDAVConn.SSLVerify() == FALSE && CardDAVConn.CanDoSSL() == TRUE) {
+        } else if (CardDAVConn.SSLVerify() == FALSE && CardDAVConn.CanDoSSL() == TRUE && CardDAVConn.IsSelfSigned() == TRUE){
+       
+            lblServerSSLValid->SetLabel(_("Verified (user)"));
+       
+       } else if (CardDAVConn.SSLVerify() == FALSE && CardDAVConn.CanDoSSL() == TRUE) {
             
-            lblServerSSLResult->SetLabel(_("Unable to verify"));
+            lblServerSSLValid->SetLabel(_("Unable to verify"));
             
-        }
+        }      
         
         if (CardDAVConn.CanDoCardDAV() == TRUE){
             
@@ -207,7 +310,15 @@ void frmNewAccount::ProcessNext( wxCommandEvent& event )
         
         ServerPrefix = CardDAVConn.GetDefaultAddressBookURL();
         
-        wxMessageBox(ServerPrefix);
+       if (CardDAVConn.HasValidResponse() == TRUE){
+            
+            lblServerResponse->SetLabel(_("Yes"));
+            
+        } else {
+            
+            lblServerResponse->SetLabel(_("No"));
+            
+        }
         
         if (ServerResult == TRUE && CardDAVConn.HasValidResponse() == TRUE &&
             //CardDAVConn.CanDoSSL() == TRUE && CardDAVConn.SSLVerify() == TRUE &&
@@ -245,6 +356,7 @@ void frmNewAccount::ProcessNext( wxCommandEvent& event )
         // Finished.
         
         wxString XestiaABPrefDirectory;
+       wxString XestiaABDirectory;
         wxString AccountSettingsFile;
         //wxFile ASFile;
         wxString RandomNumberSuffix = wxString::Format(wxT("%i"), rand() % 32767);
@@ -256,8 +368,9 @@ void frmNewAccount::ProcessNext( wxCommandEvent& event )
         
 #elif defined(__WIN32__)
         
-        XestiaABPrefDirectory = GetUserDir();
-        
+        XestiaABPrefDirectory = GetUserPrefDir();
+        XestiaABDirectory = GetUserDir();
+       
         AccountSettingsFile = XestiaABPrefDirectory + wxT("accounts");
         
         // Open the file for writing.
@@ -292,7 +405,7 @@ void frmNewAccount::ProcessNext( wxCommandEvent& event )
             
             wxString DirectoryName = txtAccountName->GetValue().Mid(0, 30) + RandomNumberSuffix;
             
-            if (wxMkdir(XestiaABPrefDirectory + wxT("/accounts/") + DirectoryName + wxT(".carddav"), 0740) == TRUE){
+            if (wxMkdir(XestiaABDirectory + wxT("\\accounts\\") + DirectoryName + wxT(".carddav"), 0740) == TRUE){
                 
                 DirectoryCreated = TRUE;
                 
@@ -315,7 +428,7 @@ void frmNewAccount::ProcessNext( wxCommandEvent& event )
             
             wxString DirectoryName = txtAccountName->GetValue().Mid(0, 30) + RandomNumberSuffix;
             
-            if (wxMkdir(XestiaABPrefDirectory + wxT("/accounts/") + DirectoryName + wxT(".local"), 0740) == TRUE){
+            if (wxMkdir(XestiaABDirectory + wxT("\\accounts\\") + DirectoryName + wxT(".local"), 0740) == TRUE){
                 
                 DirectoryCreated = TRUE;
                 
@@ -341,9 +454,10 @@ void frmNewAccount::ProcessNext( wxCommandEvent& event )
         
 #else
         
-        XestiaABPrefDirectory = GetUserDir();
+        XestiaABPrefDirectory = GetUserPrefDir();
+       XestiaABDirectory = GetUserDir();
         
-        AccountSettingsFile = GetUserPrefDir() + wxT("accounts");
+        AccountSettingsFile = XestiaABPrefDirectory + wxT("accounts");
         
         // Open the file for writing.
         
@@ -377,7 +491,7 @@ void frmNewAccount::ProcessNext( wxCommandEvent& event )
             
             wxString DirectoryName = txtAccountName->GetValue().Mid(0, 30) + RandomNumberSuffix;
             
-            if (wxMkdir(XestiaABPrefDirectory + wxT("/accounts/") + DirectoryName + wxT(".carddav"), 0740) == TRUE){
+            if (wxMkdir(XestiaABDirectory + wxT("/accounts/") + DirectoryName + wxT(".carddav"), 0740) == TRUE){
                 
                 DirectoryCreated = TRUE;
                 
@@ -400,7 +514,7 @@ void frmNewAccount::ProcessNext( wxCommandEvent& event )
             
             wxString DirectoryName = txtAccountName->GetValue().Mid(0, 30) + RandomNumberSuffix;
             
-            if (wxMkdir(XestiaABPrefDirectory + wxT("/accounts/") + DirectoryName + wxT(".local"), 0740) == TRUE){
+            if (wxMkdir(XestiaABDirectory + wxT("/accounts/") + DirectoryName + wxT(".local"), 0740) == TRUE){
                 
                 DirectoryCreated = TRUE;
                 
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