Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Check server address matches against the blacklist, bring up dialog if so
[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 "frmInvalidSSLCertificate.h"
21 #include "carddav/carddav.h"
22 #include "common/svrblist.h"
24 frmEditAccount::frmEditAccount( wxWindow* parent )
25 :
26 frmEditAccountADT( parent )
27 {
29 }
31 void frmEditAccount::DetectAddressBook( wxCommandEvent& event )
32 {
34         // Check data before connecting.
36         wxString ValueData;
37         
38         long PortNum;
39         ValueData = txtPort->GetValue();
40         ValueData.ToLong(&PortNum, 10);
41         long RefreshNum;
42         ValueData = txtRefresh->GetValue();
43         ValueData.ToLong(&RefreshNum, 10);
44         bool UseSSL;
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         }
81         
82         // Setup a CardDAV object.
83         
84         CardDAV CDavObj;
85         
86         CDavObj.SetupConnection(txtAddress->GetValue(), (int)PortNum, txtUsername->GetValue(), txtPassword->GetValue(), UseSSL);
87         
88         // Verify SSL trust first before doing anything.
90         if (UseSSL == TRUE){
92                 CURLcode sslcode = CDavObj.SSLVerifyTest();
94                 if (sslcode == CURLE_OK){
95                                 
96                         // Certificate is okay. Do nothing.
98                 } else if (sslcode == CURLE_SSL_CACERT || sslcode == CURLE_SSL_CONNECT_ERROR){
100                         // Certificate is more than likely a self-signed or
101                         // expired certificate so display the invalid
102                         // SSL certificate message.
104                         // Setup the data to be sent in the wxPostEvent command.
106                         int SSLResult;
107                         
108                         frmInvalidSSLCertificate *frmICPtr = new frmInvalidSSLCertificate(this);
110                         frmICPtr->LoadDataNew(CDavObj.GetSSLVerifyResults(), txtAddress->GetValue());
111                         frmICPtr->ShowModal();
112                                         
113                         SSLResult = frmICPtr->GetResult();
114                                                         
115                         // Clean up before processing response.
116                                 
117                         delete frmICPtr;
118                         frmICPtr = NULL;
119                                                 
120                         // Process the response from the user.
121                                                         
122                         if (SSLResult == 1){
123                                                                 
124                                 // Accept the Certificate.
126                                 CDavObj.AllowSelfSignTest(TRUE);
127                                                                 
128                         } else if (SSLResult == 2){
129                                                                 
130                                 // Reject the certificate, abort the task and mark as failed.
132                                 wxMessageBox(_("An error occured whilst connnecting: ") + CDavObj.GetErrorMessage() + wxString::Format(wxT(" (%i)\n%s"), sslcode, CDavObj.GetErrorBuffer().mb_str()), _("Failed"), wxOK+wxICON_ERROR);
133                                 return;
134                                                                 
135                         }
136                                 
138                 } else {
140                         // Something else happened. Stop the process and
141                         // display an error message instead.
143                         wxMessageBox(_("An error occured whilst connnecting: ") + CDavObj.GetErrorMessage() + wxString::Format(wxT(" (%i)\n%s"), sslcode, CDavObj.GetErrorBuffer().mb_str()), _("Failed"), wxOK+wxICON_ERROR);
144                         return;
146                 }
148         }
149         
150         // Attempt to extract the CardDAV address.
151         
152         wxString ABURL = CDavObj.GetDefaultAddressBookURL();
153         
154         txtPrefix->SetValue(ABURL);
155         
158 void frmEditAccount::LoadPointers( wxFileConfig* cfgin ){
160         // Setup the account configuration file pointer.
161         
162         cfgfile = cfgin;
166 void frmEditAccount::LoadSettings( wxString AccNameIn ){
168         // Get the data from the accounts settings file and
169         // fill in the account fields.
171         AccName = AccNameIn;
172         long itemindex = 0;
173         bool ContinueAcc = TRUE;
174         wxString AccountName;
175         wxString AccountData;
177         ContinueAcc = cfgfile->GetFirstGroup(AccountName, itemindex);
179         while (ContinueAcc){
181                 if (AccountName == AccName){
183                         cfgfile->SetPath(AccountName);
184                         txtAccountName->SetValue(AccountName);
186                         cfgfile->Read("address", &AccountData);
187                         txtAddress->SetValue(AccountData);
189                         cfgfile->Read("port", &AccountData);
190                         txtPort->SetValue(AccountData);
192                         cfgfile->Read("username", &AccountData);
193                         txtUsername->SetValue(AccountData);
195                         cfgfile->Read("password", &AccountData);
196                         txtPassword->SetValue(AccountData);
198                         cfgfile->Read("prefix", &AccountData);
199                         txtPrefix->SetValue(AccountData);
201                         cfgfile->Read("ssl", &AccountData);
202                         if (AccountData == wxT("true")){
203                         
204                                 chkSSL->SetValue(TRUE);
205                         
206                         }
207                         
208                         cfgfile->Read("refresh", &AccountData);
209                         txtRefresh->SetValue(AccountData);
210                         
211                         break;
213                 }
214                 
215                 cfgfile->SetPath(wxT("/"));
216                 ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex);
218         }
222 void frmEditAccount::UpdateSettings( wxCommandEvent& event )
225         // Check if server address matches against the blacklist.
226         // Bring up warning message if it does.
227         
228         if (CheckBlacklist(txtAddress->GetValue())){
229                 
230                 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);
231                 
232                 if (MessageBoxResult == wxNO){
233                         return;
234                 }
235                         
236         }
237         
238         // Update the settings for the account.
240         long itemindex = 0;
241         bool ContinueAcc = TRUE;
242         wxString AccountName;
244         // Look for the account
245         
246         while (ContinueAcc){
248                 if (AccountName == AccName){
250                         // Update the settings for the account.
252                         cfgfile->RenameGroup(AccountName, txtAccountName->GetValue());
254                         cfgfile->SetPath(txtAccountName->GetValue());
255                         //txtAccountName->SetValue(AccountName);
256                         
257                         cfgfile->DeleteEntry(wxT("address"), FALSE);
258                         cfgfile->Write(wxT("address"), txtAddress->GetValue());
260                         cfgfile->DeleteEntry(wxT("port"), FALSE);
261                         cfgfile->Write(wxT("port"), txtPort->GetValue());
263                         cfgfile->DeleteEntry(wxT("username"), FALSE);
264                         cfgfile->Write(wxT("username"), txtUsername->GetValue());
266                         cfgfile->DeleteEntry(wxT("password"), FALSE);
267                         cfgfile->Write(wxT("password"), txtPassword->GetValue());
269                         cfgfile->DeleteEntry(wxT("prefix"), FALSE);
270                         cfgfile->Write(wxT("prefix"), txtPrefix->GetValue());
272                         cfgfile->DeleteEntry(wxT("ssl"), FALSE);
274                         if (chkSSL->GetValue() == TRUE){
275                         
276                                 cfgfile->Write(wxT("ssl"), wxT("true"));
277                         
278                         } else {
279                         
280                                 cfgfile->Write(wxT("ssl"), wxT("false"));
281                         
282                         }
284                         cfgfile->DeleteEntry(wxT("refresh"), FALSE);
285                         cfgfile->Write(wxT("refresh"), txtRefresh->GetValue());
287                         break;
289                 }
290                 
291                 cfgfile->SetPath(wxT("/"));
292                 ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex);
294         }
296         // Set the dialog result to true and close the window.
297         
298         DialogResult = true;    
299         this->Close();  
303 void frmEditAccount::CloseWindow( wxCommandEvent& event )
305         
306         // Set the dialog result to false and close the window.
307         
308         DialogResult = false;
309         this->Close();
310         
313 bool frmEditAccount::GetDialogResult(){
315         // Get the result of the dialog.
316         
317         return DialogResult;
318         
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