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

ConfigHooks.cpp

Go to the documentation of this file.
00001 
00005 /*
00006 pGina ldapAuth code - based upon skeleton code for pGina plugin development
00007 Copyright (C) 2002 Micah Cooper
00008 
00009 This program is free software; you can redistribute it and/or
00010 modify it under the terms of the GNU General Public License
00011 as published by the Free Software Foundation; either version 2
00012 of the License, or (at your option) any later version.
00013 
00014 This program is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 GNU General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with this program; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00023 Email: coopermj@muohio.edu
00024 Snail Mail:
00025         Micah Cooper
00026         212A Kreger Hall
00027         Miami University
00028         Oxford OH  45056
00029 */
00030 // ConfigHooks.cpp : implementation file
00031 //
00032 
00033 #include "stdafx.h"
00034 #include "ldapauth_plus.h"
00035 #include "ConfigHooks.h"
00036 #include ".\confighooks.h"
00037 #include "SelectFile.h"
00038 
00039 // CConfigHooks dialog
00040 
00041 IMPLEMENT_DYNAMIC(CConfigHooks, CDialog)
00042 CConfigHooks::CConfigHooks(CWnd* pParent /*=NULL*/)
00043         : CDialog(CConfigHooks::IDD, pParent)
00044         , m_newLoginHook(_T(""))
00045         , m_newLogoutHook(_T(""))
00046 {
00047         hasLoaded = false;
00048 }
00049 
00050 CConfigHooks::~CConfigHooks()
00051 {
00052 }
00053 
00054 void CConfigHooks::DoDataExchange(CDataExchange* pDX)
00055 {
00056         CDialog::DoDataExchange(pDX);
00057         DDX_Text(pDX, IDC_LOGINHOOK, m_newLoginHook);
00058         DDX_Control(pDX, IDC_LOGINHOOKLIST, m_LoginHookList);
00059         DDX_Text(pDX, IDC_LOGOUTHOOK, m_newLogoutHook);
00060         DDX_Control(pDX, IDC_LOGOUTHOOKLIST, m_LogoutHookList);
00061 
00062         if(!hasLoaded)
00063         {
00064                 loadListsFromReg();
00065                 hasLoaded = true;
00066         }
00067 }
00068 
00069 
00070 BEGIN_MESSAGE_MAP(CConfigHooks, CDialog)
00071         ON_BN_CLICKED(IDC_ADDLOGINHOOK, OnAddLoginHook)
00072         ON_BN_CLICKED(IDC_DELLOGINHOOK, OnRemoveLoginHook)
00073         ON_BN_CLICKED(IDC_ADDLOGOUTHOOK, OnAddLogoutHook)
00074         ON_BN_CLICKED(IDC_DELLOGOUTHOOK, OnRemoveLogoutHook)
00075         ON_BN_CLICKED(IDC_BROWSEFILES, OnBrowseLogin)
00076         ON_BN_CLICKED(IDC_BROWSEFILES2, OnBrowseLogout)
00077         ON_BN_CLICKED(IDC_MOVECTXUP, OnMoveLoginUp)
00078         ON_BN_CLICKED(IDC_MOVECTXDWN, OnMoveLoginDown)
00079         ON_BN_CLICKED(IDC_MOVECTXUP5, OnMoveLogoutUp)
00080         ON_BN_CLICKED(IDC_MOVECTXDWN2, OnMoveLogoutDown)
00081 END_MESSAGE_MAP()
00082 
00083 
00084 // CConfigHooks message handlers
00085 void CConfigHooks::OnOK()
00086 {
00087         return;
00088 }
00089 
00090 void CConfigHooks::OnAddLoginHook()
00091 {
00092         UpdateData(TRUE);
00093         if (m_newLoginHook == "") {
00094                 MessageBox(L"Please enter a valid executable.", L"LDAPAuth", MB_OK);
00095                 return;
00096         }
00097         m_LoginHookList.AddString(m_newLoginHook);
00098         m_newLoginHook = TEXT("");
00099         UpdateData(FALSE);
00100 }
00101 
00102 void CConfigHooks::OnRemoveLoginHook()
00103 {
00104         // TODO: Add your control notification handler code here
00105         if(m_LoginHookList.GetCurSel() >= 0)
00106                 m_LoginHookList.DeleteString(m_LoginHookList.GetCurSel());
00107 }
00108 
00109 void CConfigHooks::OnAddLogoutHook()
00110 {
00111         UpdateData(TRUE);
00112         if (m_newLogoutHook == "") {
00113                 MessageBox(L"Please enter a valid executable.", L"LDAPAuth", MB_OK);
00114                 return;
00115         }
00116         m_LogoutHookList.AddString(m_newLogoutHook);
00117         m_newLogoutHook = TEXT("");
00118         UpdateData(FALSE);
00119 }
00120 
00121 void CConfigHooks::OnRemoveLogoutHook()
00122 {
00123         // TODO: Add your control notification handler code here
00124         if(m_LogoutHookList.GetCurSel() >= 0)
00125                 m_LogoutHookList.DeleteString(m_LogoutHookList.GetCurSel());
00126 }
00127 
00128 void CConfigHooks::saveListsToReg(void)
00129 {
00130         WCHAR currentName[256];
00131         CString value = NULL;
00132         int x = 0;
00133 
00134         // now for login hooks
00135         for(x = 0; x < m_LoginHookList.GetCount(); x++)
00136         {
00137                 m_LoginHookList.GetText(x,value);
00138                 swprintf(currentName,TEXT("loginHook%d"),x);
00139                 regWriteString(value.GetBuffer(value.GetLength()),currentName);
00140         }
00141 
00142         // Now loop through and delete any existing contexts above our last saved one
00143         x = m_LoginHookList.GetCount();
00144         swprintf(currentName,TEXT("loginHook%d"),x);
00145         value = regReadString(currentName);
00146 
00147         while(value.GetLength() > 0)
00148         {
00149                 regDelValue(currentName);
00150                 x++;
00151                 swprintf(currentName,TEXT("loginHook%d"),x);
00152                 value = regReadString(currentName);
00153         }
00154 
00155         // now for logout hooks
00156         for(x = 0; x < m_LogoutHookList.GetCount(); x++)
00157         {
00158                 m_LogoutHookList.GetText(x,value);
00159                 swprintf(currentName,TEXT("logoutHook%d"),x);
00160                 regWriteString(value.GetBuffer(value.GetLength()),currentName);
00161         }
00162 
00163         // Now loop through and delete any existing contexts above our last saved one
00164         x = m_LogoutHookList.GetCount();
00165         swprintf(currentName,TEXT("logoutHook%d"),x);
00166         value = regReadString(currentName);
00167 
00168         while(value.GetLength() > 0)
00169         {
00170                 regDelValue(currentName);
00171                 x++;
00172                 swprintf(currentName,TEXT("logoutHook%d"),x);
00173                 value = regReadString(currentName);
00174         }
00175 }
00176 
00177 void CConfigHooks::loadListsFromReg(void)
00178 {
00179         // Load the content for the lists from the registry 
00180         WCHAR currentName[256];
00181         int x = 0;
00182         CString contextValue = NULL;
00183         
00184         // Then loginHookOKx
00185         swprintf(currentName,TEXT("loginHook%d"),x);
00186         contextValue = regReadString(currentName);
00187         while(contextValue.GetLength() > 0)
00188         {
00189                 m_LoginHookList.AddString(contextValue);
00190                 x++;
00191         swprintf(currentName,TEXT("loginHook%d"),x);
00192                 contextValue = regReadString(currentName);
00193         }
00194 
00195         x = 0;
00196         // Then logoutHookOKx
00197         swprintf(currentName,TEXT("logoutHook%d"),x);
00198         contextValue = regReadString(currentName);
00199         while(contextValue.GetLength() > 0)
00200         {
00201                 m_LogoutHookList.AddString(contextValue);
00202                 x++;
00203         swprintf(currentName,TEXT("logoutHook%d"),x);
00204                 contextValue = regReadString(currentName);
00205         }
00206 }
00207 
00208 void CConfigHooks::OnSave()
00209 {
00210         UpdateData(TRUE);
00211         WCHAR currentName[256];
00212         CString value = NULL;
00213         int x = 0;
00214 
00215         // now for login hooks
00216         for(x = 0; x < m_LoginHookList.GetCount(); x++)
00217         {
00218                 m_LoginHookList.GetText(x,value);
00219                 swprintf(currentName,TEXT("loginHook%d"),x);
00220                 regWriteString(value.GetBuffer(value.GetLength()),currentName);
00221         }
00222 
00223         // Now loop through and delete any existing contexts above our last saved one
00224         x = m_LoginHookList.GetCount();
00225         swprintf(currentName,TEXT("loginHook%d"),x);
00226         value = regReadString(currentName);
00227 
00228         while(value.GetLength() > 0)
00229         {
00230                 regDelValue(currentName);
00231                 x++;
00232                 swprintf(currentName,TEXT("loginHook%d"),x);
00233                 value = regReadString(currentName);
00234         }
00235 
00236         // now for logout hooks
00237         for(x = 0; x < m_LogoutHookList.GetCount(); x++)
00238         {
00239                 m_LogoutHookList.GetText(x,value);
00240                 swprintf(currentName,TEXT("logoutHook%d"),x);
00241                 regWriteString(value.GetBuffer(value.GetLength()),currentName);
00242         }
00243 
00244         // Now loop through and delete any existing contexts above our last saved one
00245         x = m_LogoutHookList.GetCount();
00246         swprintf(currentName,TEXT("logoutHook%d"),x);
00247         value = regReadString(currentName);
00248 
00249         while(value.GetLength() > 0)
00250         {
00251                 regDelValue(currentName);
00252                 x++;
00253                 swprintf(currentName,TEXT("logoutHook%d"),x);
00254                 value = regReadString(currentName);
00255         }
00256 }
00257 
00258 void CConfigHooks::OnBrowseLogin()
00259 {
00260         // TODO: Add your control notification handler code here
00261         // Create a new file selection dialog box
00262         //    The parameters state that we want to Open a file,
00263         //        hide files marked as read-only, filter for *.pgina, *.dll and *.*
00264         //    and we do not belong to a particular hWnd for callback.
00265         SelectFile *t = new SelectFile(TRUE,NULL,NULL,OFN_HIDEREADONLY, TEXT("Executable files (*.exe)|*.exe|All files (*.*)|*.*"), NULL);
00266         
00267         // Call the file selection dialog
00268         if(t->DoModal() == IDOK)
00269         {       
00270                 // The user selected a file, or pressed okay
00271                 //   so call LoadFunctions on the selected path.
00272                 UpdateData(TRUE);
00273                 m_newLoginHook = t->GetPathName();
00274                 UpdateData(FALSE);
00275         }
00276         else
00277         {
00278                 // If we get here the user canceled the open process
00279                 m_newLoginHook = TEXT("");
00280         }
00281 }
00282 
00283 void CConfigHooks::OnBrowseLogout()
00284 {
00285         // TODO: Add your control notification handler code here
00286         // Create a new file selection dialog box
00287         //    The parameters state that we want to Open a file,
00288         //        hide files marked as read-only, filter for *.pgina, *.dll and *.*
00289         //    and we do not belong to a particular hWnd for callback.
00290         SelectFile *t = new SelectFile(TRUE,NULL,NULL,OFN_HIDEREADONLY, TEXT("Executable files (*.exe)|*.bat|All files (*.*)|*.*"), NULL);
00291         
00292         // Call the file selection dialog
00293         if(t->DoModal() == IDOK)
00294         {       
00295                 // The user selected a file, or pressed okay
00296                 //   so call LoadFunctions on the selected path.
00297                 UpdateData(TRUE);
00298                 m_newLogoutHook = t->GetPathName();
00299                 UpdateData(FALSE);
00300         }
00301         else
00302         {
00303                 // If we get here the user canceled the open process
00304                 m_newLogoutHook = TEXT("");
00305         }
00306 }
00307 
00308 void CConfigHooks::swapItem(CListBox *listbox,int old, int next)
00309 {
00310         CString valueA;
00311         CString valueB;
00312         
00313 
00314         listbox->GetText(old,valueA);
00315         listbox->DeleteString(old);
00316         listbox->InsertString(next,valueA);     
00317         listbox->SetCurSel(next);
00318 }
00319 
00320 void CConfigHooks::OnMoveLoginUp()
00321 {
00322         // TODO: Add your control notification handler code here
00323         UpdateData(TRUE);
00324         if(m_LoginHookList.GetCurSel() > 0)
00325                 swapItem(&m_LoginHookList,m_LoginHookList.GetCurSel(),m_LoginHookList.GetCurSel() - 1);
00326         UpdateData(FALSE);
00327 }
00328 
00329 void CConfigHooks::OnMoveLoginDown()
00330 {
00331         // TODO: Add your control notification handler code here
00332         UpdateData(TRUE);
00333         if(m_LoginHookList.GetCurSel() >= 0 && m_LoginHookList.GetCurSel() < m_LoginHookList.GetCount() - 1)
00334                 swapItem(&m_LoginHookList,m_LoginHookList.GetCurSel(),m_LoginHookList.GetCurSel() + 1);
00335         UpdateData(FALSE);
00336 }
00337 
00338 void CConfigHooks::OnMoveLogoutUp()
00339 {
00340         // TODO: Add your control notification handler code here
00341         UpdateData(TRUE);
00342         if(m_LogoutHookList.GetCurSel() > 0)
00343                 swapItem(&m_LogoutHookList,m_LogoutHookList.GetCurSel(),m_LogoutHookList.GetCurSel() - 1);
00344         UpdateData(FALSE);
00345 }
00346 
00347 void CConfigHooks::OnMoveLogoutDown()
00348 {
00349         // TODO: Add your control notification handler code here
00350         UpdateData(TRUE);
00351         if(m_LogoutHookList.GetCurSel() >= 0 && m_LogoutHookList.GetCurSel() < m_LogoutHookList.GetCount() - 1)
00352                 swapItem(&m_LogoutHookList,m_LogoutHookList.GetCurSel(),m_LogoutHookList.GetCurSel() + 1);
00353         UpdateData(FALSE);
00354 }

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