00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "stdafx.h"
00036 #include "ldapauth_plus.h"
00037 #include "ConfigDialog.h"
00038
00039
00040
00041
00042 IMPLEMENT_DYNAMIC(CConfigDialog, CDialog)
00043 CConfigDialog::CConfigDialog(CWnd* pParent )
00044 : CDialog(CConfigDialog::IDD, pParent)
00045 , m_version(LDAPAUTHVERSION)
00046 , m_server(_T(""))
00047 , m_ldapPrePend(_T(""))
00048 , m_ldapAppend(_T(""))
00049 , m_ldapAdminUsername(_T(""))
00050 , m_ldapAdminPassword(_T(""))
00051 , m_useSSL(FALSE)
00052 , m_port(_T(""))
00053 , m_ldapFilter(_T(""))
00054 , m_ldapGroupAttr(_T(""))
00055 , m_searchMode(FALSE)
00056 , m_multiMap(FALSE)
00057 , m_mapMode(FALSE)
00058 , m_newContext(_T(""))
00059 , m_NewAdmin(_T(""))
00060 , m_newUser(_T(""))
00061 {
00062 CString temp;
00063 m_server = regReadString(L"ldapServer");
00064 m_ldapPrePend = regReadString(L"ldapPrePend");
00065 m_ldapAppend = regReadString(L"ldapAppend");
00066 m_ldapAdminUsername = regReadString(L"ldapAdminUsername");
00067 m_ldapAdminPassword = regReadString(L"ldapAdminPassword");
00068 m_port = regReadString(L"ldapPort");
00069 m_ldapFilter = regReadString(L"ldapFilter");
00070 m_ldapGroupAttr = regReadString(L"ldapGroupAttr");
00071
00072 temp = regReadString(L"useSSL");
00073 if(temp.GetAt(0) == '1')
00074 m_useSSL = true;
00075 else
00076 m_useSSL = false;
00077
00078 temp = regReadString(L"ldapMethod");
00079 if(temp.GetAt(0) == '1')
00080 {
00081 m_multiMap = true;
00082
00083
00084
00085
00086 }
00087 else if(temp.GetAt(0) == '2')
00088 {
00089 m_searchMode = true;
00090
00091
00092
00093 }
00094 else if(temp.GetAt(0) == '3')
00095 {
00096 m_mapMode = true;
00097
00098
00099
00100 }
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111 hasLoaded = false;
00112 }
00113
00114 CConfigDialog::~CConfigDialog()
00115 {
00116
00117 }
00118
00119 void CConfigDialog::DoDataExchange(CDataExchange* pDX)
00120 {
00121 CDialog::DoDataExchange(pDX);
00122 DDX_Text(pDX, IDC_VERSION, m_version);
00123 DDX_Text(pDX, IDC_LDAPSERVER, m_server);
00124 DDX_Text(pDX, IDC_LDAPPREPEND, m_ldapPrePend);
00125 DDX_Text(pDX, IDC_LDAPAPPEND, m_ldapAppend);
00126 DDX_Text(pDX, IDC_ADMINUSERNAME, m_ldapAdminUsername);
00127 DDX_Text(pDX, IDC_ADMINPASSWORD, m_ldapAdminPassword);
00128 DDX_Check(pDX, IDC_USESSL, m_useSSL);
00129 DDX_Text(pDX, IDC_PORT, m_port);
00130 DDX_Text(pDX, IDC_LDAPFILTER, m_ldapFilter);
00131 DDX_Text(pDX, IDC_LDAPGROUPATTR, m_ldapGroupAttr);
00132 DDX_Check(pDX, IDC_SEARCH, m_searchMode);
00133 DDX_Check(pDX, IDC_MULTIMAP, m_multiMap);
00134 DDX_Check(pDX, IDC_MAP, m_mapMode);
00135 DDX_Control(pDX, IDC_CONTEXTLIST, m_ContextList);
00136 DDX_Text(pDX, IDC_NEWCONTEXT, m_newContext);
00137 DDX_Control(pDX, IDC_CONTEXTLIST2, m_AdminList);
00138 DDX_Text(pDX, IDC_NEWCONTEXT2, m_NewAdmin);
00139 DDX_Control(pDX, IDC_CONTEXTLIST3, m_UserList);
00140 DDX_Text(pDX, IDC_NEWCONTEXT3, m_newUser);
00141 if(!hasLoaded)
00142 {
00143 loadListsFromReg();
00144 hasLoaded = true;
00145 }
00146
00147 DDX_Control(pDX, IDC_LDAPPREPEND, c_ldapPrePend);
00148 DDX_Control(pDX, IDC_LDAPAPPEND, c_ldapAppend);
00149 DDX_Control(pDX, IDC_NEWCONTEXT, c_newcontext);
00150 DDX_Control(pDX, IDC_USESSL, c_usessl);
00151 }
00152
00153
00154 BEGIN_MESSAGE_MAP(CConfigDialog, CDialog)
00155 ON_BN_CLICKED(IDOK, OnSave)
00156 ON_BN_CLICKED(IDC_SEARCH, OnChangeSearch)
00157 ON_BN_CLICKED(IDC_MULTIMAP, OnChangeMultimap)
00158 ON_BN_CLICKED(IDC_MAP, OnChangeMapMode)
00159 ON_BN_CLICKED(IDC_ADDCONTEXTBUTTON, OnAddContext)
00160 ON_BN_CLICKED(IDC_MOVECTXUP, OnMoveContextUp)
00161 ON_BN_CLICKED(IDC_MOVECTXDWN, OnMoveContextDown)
00162 ON_BN_CLICKED(IDC_ADDCONTEXTBUTTON2, OnAddAdmin)
00163 ON_BN_CLICKED(IDC_ADDCONTEXTBUTTON3, OnAddNewUser)
00164 ON_BN_CLICKED(IDC_MOVECTXUP2, OnRemoveContext)
00165 ON_BN_CLICKED(IDC_MOVECTXUP3, OnRemoveAdmin)
00166 ON_BN_CLICKED(IDC_MOVECTXUP4, OnRemoveUser)
00167 ON_LBN_SELCHANGE(IDC_CONTEXTLIST2, OnLbnSelchangeContextlist2)
00168 ON_BN_CLICKED(IDHELP, OnBnClickedHelp)
00169
00170 ON_COMMAND(ID_HELP_FINDER, CMDIFrameWnd::OnHelpFinder)
00171
00172 ON_COMMAND(ID_CONTEXT_HELP, CMDIFrameWnd::OnContextHelp)
00173 ON_COMMAND(ID_DEFAULT_HELP, CMDIFrameWnd::OnHelpFinder)
00174 END_MESSAGE_MAP()
00175
00176 void CConfigDialog::OnSave()
00177 {
00178
00179
00180 UpdateData(TRUE);
00181
00182
00183 CString temp;
00184
00185 if(m_server.GetLength() > 0)
00186 regWriteString(m_server.GetBuffer(m_server.GetLength()),L"ldapServer");
00187 else
00188 regDelValue(L"ldapServer");
00189
00190 if(m_ldapPrePend.GetLength() > 0)
00191 regWriteString(m_ldapPrePend.GetBuffer(m_ldapPrePend.GetLength()),L"ldapPrePend");
00192 else
00193 regDelValue(L"ldapPrePend");
00194
00195 if(m_ldapAppend.GetLength() > 0)
00196 regWriteString(m_ldapAppend.GetBuffer(m_ldapAppend.GetLength()),L"ldapAppend");
00197 else
00198 regDelValue(L"ldapAppend");
00199
00200 if(m_ldapAdminUsername.GetLength() > 0)
00201 regWriteString(m_ldapAdminUsername.GetBuffer(m_ldapAdminUsername.GetLength()),L"ldapAdminUsername");
00202 else
00203 regDelValue(L"ldapAdminUsername");
00204
00205 if(m_ldapAdminPassword.GetLength() > 0)
00206 regWriteString(m_ldapAdminPassword.GetBuffer(m_ldapAdminPassword.GetLength()),L"ldapAdminPassword");
00207 else
00208 regDelValue(L"ldapAdminPassword");
00209
00210 if(m_port.GetLength() > 0)
00211 regWriteString(m_port.GetBuffer(m_port.GetLength()),L"ldapPort");
00212 else
00213 regDelValue(L"ldapPort");
00214
00215 if(m_ldapFilter.GetLength() > 0)
00216 regWriteString(m_ldapFilter.GetBuffer(m_ldapFilter.GetLength()),L"ldapFilter");
00217 else
00218 regDelValue(L"ldapFilter");
00219
00220 if(m_ldapGroupAttr.GetLength() > 0)
00221 regWriteString(m_ldapGroupAttr.GetBuffer(m_ldapGroupAttr.GetLength()),L"ldapGroupAttr");
00222 else
00223 regDelValue(L"ldapGroupAttr");
00224
00225 if(m_useSSL)
00226 regWriteString(TEXT("1"),L"useSSL");
00227 else
00228 regWriteString(TEXT("0"),L"useSSL");
00229
00230 if(m_multiMap)
00231 regWriteString(TEXT("1"),L"ldapMethod");
00232
00233 if(m_searchMode)
00234 regWriteString(TEXT("2"),L"ldapMethod");
00235
00236 if(m_mapMode)
00237 regWriteString(TEXT("3"),L"ldapMethod");
00238
00239 saveListsToReg();
00240 MessageBox(TEXT("Settings Saved"),TEXT("Saved"),MB_OK);
00241 }
00242
00243 void CConfigDialog::OnChangeSearch()
00244 {
00245
00246
00247
00248
00249 UpdateData(TRUE);
00250 if(m_searchMode)
00251 {
00252 m_multiMap = false;
00253 m_mapMode = false;
00254
00255
00256 c_ldapAppend.EnableWindow (false);
00257 m_ContextList.EnableWindow (true);
00258 c_newcontext.EnableWindow(true);
00259
00260 }
00261 if(!m_searchMode)
00262 m_searchMode = true;
00263 UpdateData(FALSE);
00264 }
00265
00266 void CConfigDialog::OnChangeMultimap()
00267 {
00268
00269 UpdateData(TRUE);
00270 if(m_multiMap)
00271 {
00272 m_searchMode = false;
00273 m_mapMode = false;
00274
00275
00276 c_ldapAppend.EnableWindow (false);
00277 m_ContextList.EnableWindow (true);
00278 c_newcontext.EnableWindow(true);
00279 }
00280 if(!m_multiMap)
00281 m_multiMap = true;
00282
00283 UpdateData(FALSE);
00284 }
00285
00286 void CConfigDialog::OnChangeMapMode()
00287 {
00288
00289 UpdateData(TRUE);
00290 if(m_mapMode)
00291 {
00292 m_searchMode = false;
00293 m_multiMap = false;
00294
00295
00296 c_ldapAppend.EnableWindow (true);
00297 m_ContextList.EnableWindow (false);
00298 c_newcontext.EnableWindow(false);
00299 }
00300 if(!m_mapMode)
00301 m_mapMode = true;
00302
00303 UpdateData(FALSE);
00304 }
00305
00306 void CConfigDialog::OnAddContext()
00307 {
00308
00309 UpdateData(TRUE);
00310 m_ContextList.AddString(m_newContext);
00311 m_newContext = TEXT("");
00312 UpdateData(FALSE);
00313 }
00314
00315 void CConfigDialog::OnMoveContextUp()
00316 {
00317 UpdateData(TRUE);
00318
00319 if(m_ContextList.GetCurSel() > 0)
00320 swapItem(&m_ContextList,m_ContextList.GetCurSel(),m_ContextList.GetCurSel() - 1);
00321
00322 UpdateData(FALSE);
00323 }
00324
00325 void CConfigDialog::OnMoveContextDown()
00326 {
00327 UpdateData(TRUE);
00328
00329 if(m_ContextList.GetCurSel() >= 0 && m_ContextList.GetCurSel() < m_ContextList.GetCount() - 1)
00330 swapItem(&m_ContextList,m_ContextList.GetCurSel(),m_ContextList.GetCurSel() + 1);
00331
00332 UpdateData(FALSE);
00333 }
00334
00335 void CConfigDialog::OnAddAdmin()
00336 {
00337
00338 UpdateData(TRUE);
00339 m_AdminList.AddString(m_NewAdmin);
00340 m_NewAdmin = TEXT("");
00341 UpdateData(FALSE);
00342 }
00343
00344
00345 void CConfigDialog::OnAddNewUser()
00346 {
00347
00348 UpdateData(TRUE);
00349 m_UserList.AddString(m_newUser);
00350 m_newUser = TEXT("");
00351 UpdateData(FALSE);
00352 }
00353
00354 void CConfigDialog::OnRemoveContext()
00355 {
00356
00357 if(m_ContextList.GetCurSel() >= 0)
00358 m_ContextList.DeleteString(m_ContextList.GetCurSel());
00359 }
00360
00361 void CConfigDialog::OnRemoveAdmin()
00362 {
00363
00364 if(m_AdminList.GetCurSel() >= 0)
00365 m_AdminList.DeleteString(m_AdminList.GetCurSel());
00366 }
00367
00368 void CConfigDialog::OnRemoveUser()
00369 {
00370
00371 if(m_UserList.GetCurSel() >= 0)
00372 m_UserList.DeleteString(m_UserList.GetCurSel());
00373 }
00374
00375 void CConfigDialog::loadListsFromReg(void)
00376 {
00377
00378 WCHAR currentName[256];
00379 int x = 0;
00380 CString contextValue = NULL;
00381
00382
00383 swprintf(currentName,TEXT("ldapContext%d"),x);
00384 contextValue = regReadString(currentName);
00385 while(contextValue.GetLength() > 0)
00386 {
00387 m_ContextList.AddString(contextValue);
00388 x++;
00389 swprintf(currentName,TEXT("ldapContext%d"),x);
00390 contextValue = regReadString(currentName);
00391 }
00392 x = 0;
00393
00394 swprintf(currentName,TEXT("adminOK%d"),x);
00395 contextValue = regReadString(currentName);
00396 while(contextValue.GetLength() > 0)
00397 {
00398 m_AdminList.AddString(contextValue);
00399 x++;
00400 swprintf(currentName,TEXT("adminOK%d"),x);
00401 contextValue = regReadString(currentName);
00402 }
00403
00404 x = 0;
00405
00406 swprintf(currentName,TEXT("userOK%d"),x);
00407 contextValue = regReadString(currentName);
00408 while(contextValue.GetLength() > 0)
00409 {
00410 m_UserList.AddString(contextValue);
00411 x++;
00412 swprintf(currentName,TEXT("userOK%d"),x);
00413 contextValue = regReadString(currentName);
00414 }
00415
00416 }
00417
00418 void CConfigDialog::saveListsToReg(void)
00419 {
00420 WCHAR currentName[256];
00421 CString value = NULL;
00422 int x = 0;
00423
00424
00425 for(x = 0; x < m_ContextList.GetCount(); x++)
00426 {
00427 m_ContextList.GetText(x,value);
00428 swprintf(currentName,TEXT("ldapContext%d"),x);
00429 regWriteString(value.GetBuffer(value.GetLength()),currentName);
00430 }
00431
00432
00433 x = m_ContextList.GetCount();
00434 swprintf(currentName,TEXT("ldapContext%d"),x);
00435 value = regReadString(currentName);
00436
00437 while(value.GetLength() > 0)
00438 {
00439 regDelValue(currentName);
00440 x++;
00441 swprintf(currentName,TEXT("ldapContext%d"),x);
00442 value = regReadString(currentName);
00443 }
00444
00445
00446 for(x = 0; x < m_AdminList.GetCount(); x++)
00447 {
00448 m_AdminList.GetText(x,value);
00449 swprintf(currentName,TEXT("adminOK%d"),x);
00450 regWriteString(value.GetBuffer(value.GetLength()),currentName);
00451 }
00452
00453
00454 x = m_AdminList.GetCount();
00455 swprintf(currentName,TEXT("adminOK%d"),x);
00456 value = regReadString(currentName);
00457
00458 while(value.GetLength() > 0)
00459 {
00460 regDelValue(currentName);
00461 x++;
00462 swprintf(currentName,TEXT("adminOK%d"),x);
00463 value = regReadString(currentName);
00464 }
00465
00466
00467 for(x = 0; x < m_UserList.GetCount(); x++)
00468 {
00469 m_UserList.GetText(x,value);
00470 swprintf(currentName,TEXT("userOK%d"),x);
00471 regWriteString(value.GetBuffer(value.GetLength()),currentName);
00472 }
00473
00474
00475 x = m_UserList.GetCount();
00476 swprintf(currentName,TEXT("userOK%d"),x);
00477 value = regReadString(currentName);
00478
00479 while(value.GetLength() > 0)
00480 {
00481 regDelValue(currentName);
00482 x++;
00483 swprintf(currentName,TEXT("userOK%d"),x);
00484 value = regReadString(currentName);
00485 }
00486 }
00487
00488 void CConfigDialog::swapItem(CListBox *listbox,int old, int next)
00489 {
00490 CString valueA;
00491 CString valueB;
00492
00493
00494 listbox->GetText(old,valueA);
00495 listbox->DeleteString(old);
00496 listbox->InsertString(next,valueA);
00497 listbox->SetCurSel(next);
00498 }
00499 void CConfigDialog::OnLbnSelchangeContextlist2()
00500 {
00501
00502 }
00503
00504 void CConfigDialog::OnBnClickedHelp()
00505 {
00506
00507
00508
00509
00510
00511
00512 ShellExecute(NULL,NULL,L"ldapauth.chm",NULL,NULL,SW_SHOWNORMAL);
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523 }