Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Label servers that can cause data loss as dangerous
[xestiaab/.git] / source / frmEditAccount.cpp
1 // frmEditAccount.cpp - Edit Account form.
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
10 //
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
19 #include "frmEditAccount.h"
20 #include "common/svrdlist.h"
22 frmEditAccount::frmEditAccount( wxWindow* parent )
23 :
24 frmEditAccountADT( parent )
25 {
27 }
29 void frmEditAccount::DetectAddressBook( wxCommandEvent& event )
30 {
32         // Check data before connecting.
34         wxString ValueData = "";
35         std::string ReceivedServerPrefix = "";
36         
37         long PortNum = 80;
38         ValueData = txtPort->GetValue();
39         ValueData.ToLong(&PortNum, 10);
40         long RefreshNum = 1800;
41         ValueData = txtRefresh->GetValue();
42         ValueData.ToLong(&RefreshNum, 10);
43         bool UseSSL = true;
44         bool UsingSSLBypass = false;
45         
46         if (txtAddress->IsEmpty()){
47         
48                 wxMessageBox(wxT("The server address cannot be blank."), wxT("Error"), wxICON_ERROR);
49                 return;
50         
51         }
52         
53         if (txtPort->IsEmpty() || PortNum < 0 || PortNum > 65535){
54         
55                 wxMessageBox(wxT("The server port needs to be between number 1 and 65535."), wxT("Error"), wxICON_ERROR);
56                 return;
57         
58         }
59         
60         if (txtUsername->IsEmpty()){
61         
62                 wxMessageBox(wxT("The server username cannot be blank."), wxT("Error"), wxICON_ERROR);
63                 return;
64         
65         }
67         if (txtPassword->IsEmpty()){
68         
69                 wxMessageBox(wxT("The server password cannot be blank."), wxT("Error"), wxICON_ERROR);  
70                 return;
71         
72         }
73         
74         UseSSL = chkSSL->GetValue();
75         
76         if (txtRefresh->IsEmpty() || RefreshNum < 300 || RefreshNum > 86400){
77         
78                 RefreshNum = 1800;
79                 
80         }
82         CardDAV2 TestConnection(txtAddress->GetValue().ToStdString(),
83                 wxAtoi(txtPort->GetValue()),
84                 txtUsername->GetValue().ToStdString(),
85                 txtPassword->GetValue().ToStdString(),
86                 chkSSL->GetValue());
87         
88         // Test the connection.
89         
90         TestConnection.SetupConnectionObject();
91         COConnectResult TestConnectionResult = TestConnection.Connect(false);
92         
93         // If server is using SSL, verify that the SSL connection is valid.
94         
95         if (TestConnection.SSLVerify() == COSSL_UNABLETOVERIFY){
96 #if defined(__APPLE__)
97                 
98                 TestConnection.BypassSSLVerification(true);
99                 
100                 COConnectResult TestConnectionResult = TestConnection.Connect(false);
101                 
102                 TestConnection.BypassSSLVerification(false);
103                 
104                 int SSLResult = DisplayTrustPanel(&TestConnection);
105                 
106                 if (SSLResult != NSOKButton){
107                         
108                         wxMessageBox(_("An error occured whilst connnecting: ") + TestConnection.GetErrorMessage(), _("Failed"), wxOK+wxICON_ERROR);
109                         return;
110                         
111                 }
112                 
113 #elif defined(__WIN32__)
115                 TestConnection.BypassSSLVerification(true);
117                 COConnectResult TestConnectionResult = TestConnection.Connect(false);
119                 TestConnection.BypassSSLVerification(false);
121                 BOOL ModifiedCertificateData = false;
122                 CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(&TestConnection, (HWND)this->GetHandle());
124                 if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)) {
125                         wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog"));
126                         return;
127                 }
129                 if (ModifiedCertificateData == false) {
130                         wxMessageBox(_("An invalid certificate was received from the server."), _("Invalid certificate"));
131                         return;
132                 } else {
133                         TestConnection.BypassSSLVerification(true);
134                         COConnectResult TestConnectionResult = TestConnection.Connect(true);
135                         TestConnection.BypassSSLVerification(false);
136                 }
138 #else
139         
140                 // Connect again and fetch SSL certificate information.
141                 
142                 TestConnection.BypassSSLVerification(true);
143                 
144                 COConnectResult TestConnectionResult = TestConnection.Connect(false);
145                 
146                 TestConnection.BypassSSLVerification(false);
148                 SSLCertCollectionString CertData = TestConnection.BuildSSLCollection();
149                 frmInvalidSSLCertificate *frmICPtr = new frmInvalidSSLCertificate(this);
150                 
151                 frmICPtr->LoadDataNew(CertData, txtAddress->GetValue().ToStdString());
152                 frmICPtr->ShowModal();
153                                                                 
154                 int SSLResult = frmICPtr->GetResult();
155                                                         
156                 // Clean up before processing response.
157                                 
158                 delete frmICPtr;
159                 frmICPtr = NULL;
160                                                         
161                 // Process the response from the user.
162                                                         
163                 if (SSLResult == 1){
164                                                                 
165                         // Accept the Certificate.
166                         
167                         UsingSSLBypass = true;
168                         TestConnection.BypassSSLVerification(true);
169                 
170                         COConnectResult TestConnectionResult = TestConnection.Connect(true);
171                                                                 
172                 } else if (SSLResult == 2){
173                                                                 
174                         // Reject the certificate, abort the task.
176                         wxMessageBox(_("Server certficiate rejected. Unable to detect the prefix."), _("Failed"), wxOK+wxICON_ERROR);
177                         
178                         return; 
179                         
180                 }               
181                 
182 #endif
183         }
184         
185         // Get the server prefix if the connection was successful.
187         if (TestConnectionResult == COCONNECT_OK){
189                 COConnectResult TestConnectionResult = TestConnection.Connect(true);
191                 if (UsingSSLBypass == true){
192                         TestConnection.BypassSSLVerification(true);                     
193                 }
194                 
195                 COServerResponse PrefixRequestResult = TestConnection.GetDefaultPrefix(&ReceivedServerPrefix);
197                 if (UsingSSLBypass == true){
198                         TestConnection.BypassSSLVerification(true);                     
199                 }
200                 
201         } else {
202                 
203                 wxMessageBox(_("An error occured whilst detecting the prefix: ") + TestConnection.GetErrorMessage(), _("Failed"), wxOK+wxICON_ERROR);
204                 
205         }
206         
207         txtPrefix->SetValue(ReceivedServerPrefix);
208         
211 void frmEditAccount::LoadPointers( wxFileConfig* cfgin ){
213         // Setup the account configuration file pointer.
214         
215         cfgfile = cfgin;
219 void frmEditAccount::LoadSettings( wxString AccNameIn ){
221         // Get the data from the accounts settings file and
222         // fill in the account fields.
224         AccName = AccNameIn;
225         long itemindex = 0;
226         bool ContinueAcc = TRUE;
227         wxString AccountName;
228         wxString AccountData;
229         
230         ContinueAcc = cfgfile->GetFirstGroup(AccountName, itemindex);
231         
232         while (ContinueAcc){
234                 if (AccountName == AccName){
236                         cfgfile->SetPath(AccountName);
237                         txtAccountName->SetValue(AccountName);
239                         cfgfile->Read("address", &AccountData);
240                         txtAddress->SetValue(AccountData);
242                         cfgfile->Read("port", &AccountData);
243                         txtPort->SetValue(AccountData);
245                         cfgfile->Read("username", &AccountData);
246                         txtUsername->SetValue(AccountData);
248                         cfgfile->Read("password", &AccountData);
249                         txtPassword->SetValue(AccountData);
251                         cfgfile->Read("prefix", &AccountData);
252                         txtPrefix->SetValue(AccountData);
254                         cfgfile->Read("ssl", &AccountData);
255                         if (AccountData == wxT("true")){
256                         
257                                 chkSSL->SetValue(TRUE);
258                         
259                         }
260                         
261                         cfgfile->Read("refresh", &AccountData);
262                         txtRefresh->SetValue(AccountData);
263                         
264                         break;
266                 }
267                 
268                 cfgfile->SetPath(wxT("/"));
269                 ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex);
271         }
275 void frmEditAccount::UpdateSettings( wxCommandEvent& event )
278         // Check if server address matches against the dangerous list.
279         // Bring up warning message if it does.
280         
281         if (CheckDangerousList(txtAddress->GetValue())){
282                 
283                 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);
284                 
285                 if (MessageBoxResult == wxNO){
286                         return;
287                 }
288                         
289         }
290         
291         // Update the settings for the account.
293         long itemindex = 0;
294         bool ContinueAcc = TRUE;
295         wxString AccountName;
297         // Look for the account
298         
299         while (ContinueAcc){
301                 if (AccountName == AccName){
303                         // Update the settings for the account.
305                         cfgfile->RenameGroup(AccountName, txtAccountName->GetValue());
307                         cfgfile->SetPath(txtAccountName->GetValue());
308                         //txtAccountName->SetValue(AccountName);
309                         
310                         cfgfile->DeleteEntry(wxT("address"), FALSE);
311                         cfgfile->Write(wxT("address"), txtAddress->GetValue());
313                         cfgfile->DeleteEntry(wxT("port"), FALSE);
314                         cfgfile->Write(wxT("port"), txtPort->GetValue());
316                         cfgfile->DeleteEntry(wxT("username"), FALSE);
317                         cfgfile->Write(wxT("username"), txtUsername->GetValue());
319                         cfgfile->DeleteEntry(wxT("password"), FALSE);
320                         cfgfile->Write(wxT("password"), txtPassword->GetValue());
322                         cfgfile->DeleteEntry(wxT("prefix"), FALSE);
323                         cfgfile->Write(wxT("prefix"), txtPrefix->GetValue());
325                         cfgfile->DeleteEntry(wxT("ssl"), FALSE);
327                         if (chkSSL->GetValue() == TRUE){
328                         
329                                 cfgfile->Write(wxT("ssl"), wxT("true"));
330                         
331                         } else {
332                         
333                                 cfgfile->Write(wxT("ssl"), wxT("false"));
334                         
335                         }
337                         cfgfile->DeleteEntry(wxT("refresh"), FALSE);
338                         cfgfile->Write(wxT("refresh"), txtRefresh->GetValue());
340                         break;
342                 }
343                 
344                 cfgfile->SetPath(wxT("/"));
345                 ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex);
347         }
349         // Set the dialog result to true and close the window.
350         
351         DialogResult = true;    
352         this->Close();  
356 void frmEditAccount::CloseWindow( wxCommandEvent& event )
358         
359         // Set the dialog result to false and close the window.
360         
361         DialogResult = false;
362         this->Close();
363         
366 bool frmEditAccount::GetDialogResult(){
368         // Get the result of the dialog.
369         
370         return DialogResult;
371         
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