Main Page | Class List | File List | Class Members | File Members

ConfigDialog.cpp

Go to the documentation of this file.
00001 
00006 /*
00007 pGina ldapAuth code - based upon skeleton code for pGina plugin development
00008 Copyright (C) 2002 Micah Cooper
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00023 
00024 Email: coopermj@muohio.edu
00025 Snail Mail:
00026         Micah Cooper
00027         212A Kreger Hall
00028         Miami University
00029         Oxford OH  45056
00030 */
00031 
00032 // ConfigDialog.cpp : implementation file
00033 //
00034 
00035 #include "stdafx.h"
00036 #include "ldapauth_plus.h"
00037 #include "ConfigDialog.h"
00038 
00039 
00040 // CConfigDialog dialog
00041 
00042 IMPLEMENT_DYNAMIC(CConfigDialog, CDialog)
00043 CConfigDialog::CConfigDialog(CWnd* pParent /*=NULL*/)
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                 //c_ldapAppend.EnableWindow (false);
00083                 //m_ContextList.EnableWindow (true);
00084                 //c_newcontext.EnableWindow(true);
00085 
00086         }
00087         else if(temp.GetAt(0) == '2')
00088         {
00089                 m_searchMode = true;
00090                 //c_ldapAppend.EnableWindow (false);
00091                 //m_ContextList.EnableWindow (true);
00092                 //c_newcontext.EnableWindow(true);
00093         }
00094         else if(temp.GetAt(0) == '3')
00095         {
00096                 m_mapMode = true;
00097                 //c_ldapAppend.EnableWindow (true);
00098                 //m_ContextList.EnableWindow (false);
00099                 //c_newcontext.EnableWindow(false);
00100         }
00101         
00102 /*      int method = _wtoi(regReadString(L"ldapMethod"));
00103         switch(method){
00104                 case 1: m_multiMap = true;
00105                         break;
00106                 case 2: m_searchMode = true;
00107                         break;
00108                 case 3: m_mapMode = true;
00109                         break;
00110         } */
00111         hasLoaded = false;
00112 }
00113 
00114 CConfigDialog::~CConfigDialog()
00115 {
00116 //      EnableHtmlHelp();
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         // Global help commands
00170         ON_COMMAND(ID_HELP_FINDER, CMDIFrameWnd::OnHelpFinder)
00171 //      ON_COMMAND(ID_HELP, CMDIFrameWnd::OnHelp)
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         // TODO: Add your control notification handler code here
00179         //OnOK();
00180         UpdateData(TRUE);
00181 
00182         // Save data to registry
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         // TODO: Add your control notification handler code here
00246          //m_searchMode
00247          //m_multiMap
00248         //m_mapMode
00249         UpdateData(TRUE);
00250         if(m_searchMode)
00251         {
00252                 m_multiMap = false;
00253                 m_mapMode = false;
00254                 // Begin code to disable options inappropriate for multimap
00255                 // disable IDC_LDAPAPPEND
00256                 c_ldapAppend.EnableWindow (false);
00257                 m_ContextList.EnableWindow (true);
00258                 c_newcontext.EnableWindow(true);
00259 
00260         }
00261         if(!m_searchMode) // if they try to uncheck it
00262                 m_searchMode = true; // dont let them
00263         UpdateData(FALSE);
00264 }
00265 
00266 void CConfigDialog::OnChangeMultimap()
00267 {
00268         // TODO: Add your control notification handler code here
00269         UpdateData(TRUE);
00270         if(m_multiMap)
00271         {
00272                 m_searchMode = false;
00273                 m_mapMode = false;
00274                 // Begin code to disable options inappropriate for multimap
00275                 // disable IDC_LDAPAPPEND
00276                 c_ldapAppend.EnableWindow (false);
00277                 m_ContextList.EnableWindow (true);
00278                 c_newcontext.EnableWindow(true);
00279         }
00280         if(!m_multiMap) // if they try to uncheck it
00281                 m_multiMap = true; // dont let them
00282         
00283         UpdateData(FALSE);
00284 }
00285 
00286 void CConfigDialog::OnChangeMapMode()
00287 {
00288         // TODO: Add your control notification handler code here
00289         UpdateData(TRUE);
00290         if(m_mapMode)
00291         {
00292                 m_searchMode = false;
00293                 m_multiMap = false;
00294                 // Begin code to disable options inappropriate for multimap
00295                 // disable IDC_LDAPAPPEND
00296                 c_ldapAppend.EnableWindow (true);
00297                 m_ContextList.EnableWindow (false);
00298                 c_newcontext.EnableWindow(false);
00299         }
00300         if(!m_mapMode) // if they try to uncheck it
00301                 m_mapMode = true; // dont let them
00302         
00303         UpdateData(FALSE);
00304 }
00305 
00306 void CConfigDialog::OnAddContext()
00307 {
00308         // TODO: Add your control notification handler code here
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         // TODO: Add your control notification handler code here
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         // TODO: Add your control notification handler code here
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         // TODO: Add your control notification handler code here
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         // TODO: Add your control notification handler code here
00348         UpdateData(TRUE);
00349         m_UserList.AddString(m_newUser);
00350         m_newUser = TEXT("");
00351         UpdateData(FALSE);
00352 }
00353 
00354 void CConfigDialog::OnRemoveContext()
00355 {
00356         // TODO: Add your control notification handler code here
00357         if(m_ContextList.GetCurSel() >= 0)
00358                 m_ContextList.DeleteString(m_ContextList.GetCurSel());
00359 }
00360 
00361 void CConfigDialog::OnRemoveAdmin()
00362 {
00363         // TODO: Add your control notification handler code here
00364         if(m_AdminList.GetCurSel() >= 0)
00365                 m_AdminList.DeleteString(m_AdminList.GetCurSel());
00366 }
00367 
00368 void CConfigDialog::OnRemoveUser()
00369 {
00370         // TODO: Add your control notification handler code here
00371         if(m_UserList.GetCurSel() >= 0)
00372                 m_UserList.DeleteString(m_UserList.GetCurSel());
00373 }
00374 
00375 void CConfigDialog::loadListsFromReg(void)
00376 {
00377         // Load the content for the lists from the registry 
00378         WCHAR currentName[256];
00379         int x = 0;
00380         CString contextValue = NULL;
00381         
00382         // Do contexts first
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         // Then adminOKx
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         // Then userOKx
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         // First is contexts, save them
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         // Now loop through and delete any existing contexts above our last saved one
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         // Now for admin, save them
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         // Now loop through and delete any existing contexts above our last saved one
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         // then users
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         // Now loop through and delete any existing contexts above our last saved one
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         // TODO: Add your control notification handler code here
00502 }
00503 
00504 void CConfigDialog::OnBnClickedHelp()
00505 {
00506         /*DWORD ids[3] ;
00507      ids[0] = ControlId ;
00508      ids[1] = HelpId ;
00509      ids[2] = 0 ;*/
00510 
00511         // TODO: Add your control notification handler code here
00512         ShellExecute(NULL,NULL,L"ldapauth.chm",NULL,NULL,SW_SHOWNORMAL);
00513         /*HtmlHelp(
00514          hwndCTRL,
00515          "c:\\myHelp.chm::/popups\cshelp.txt",
00516          HH_TP_HELP_WM_HELP,
00517          (DWORD) ids) ;*/
00518         /*HtmlHelp(
00519          NULL,
00520          "ldapauth.chm",
00521          HH_TP_HELP_WM_HELP,
00522          NULL) ;*/
00523 }

Generated on Fri Feb 20 12:03:37 2004 for ldapauth plugin for pGina by doxygen 1.3.5