📄 users.cpp
字号:
) )
{ Changed( hDlg ); };
break;
case IDC_REMOVE:
{
int iSel = SendMessage( hWndRealm, CB_GETCURSEL, 0, 0 );
if ( iSel==CB_ERR )
{ break; };
SendMessage( hWndRealm, WM_GETTEXT, BUF_SIZE,
(LPARAM)szBuf );
if ( !Internal_canDeleteRealm( hDlg, szBuf ) )
{ break; };
SendMessage( hWndRealm, CB_DELETESTRING, iSel, 0 );
int iCount = SendMessage( hWndRealm, CB_GETCOUNT, 0, 0);
if (iSel >= iCount) {
SendMessage( hWndRealm, CB_SETCURSEL, iCount-1, 0 );
} else {
SendMessage( hWndRealm, CB_SETCURSEL, iSel, 0 );
};
PIString sSection( "__" );
sSection.Concatenate( szBuf );
M_DeleteValue( pConfig, sSection, "Base64" );
Internal_clearArrays();
SendMessage( hWndList, LB_RESETCONTENT, 0, 0 );
SendMessage( hWndUser, WM_SETTEXT, 0, (LPARAM)"" );
SendMessage( hWndPassword, WM_SETTEXT, 0, (LPARAM)"" );
SendMessage( hWndConfirm, WM_SETTEXT, 0, (LPARAM)"" );
Changed( hDlg );
/*
** remove realm from configuration
*/
PIString sRealm = szBuf;
PIString sTmp = "";
*szBuf = '\0';
SendMessage( hWndMethod, WM_GETTEXT, BUF_SIZE, (LPARAM)szBuf );
int iTmp = 0;
for(;; iTmp++ ) {
const char *pTmp = M_LookupValueEx( pConfig, "Realms", szBuf, iTmp );
if ( !pTmp ) { break; };
if (!strcmp(pTmp,sRealm)) { continue; };
if (sTmp.Len()) sTmp.Concatenate(":");
sTmp.Concatenate(pTmp);
};
M_DeleteValue( pConfig, "Realms", szBuf );
if (sTmp.Len()) {
StringTokenizer tTokens(sTmp,":");
for(iTmp=0;iTmp<tTokens.NumTokens();iTmp++) {
M_AddValue(pConfig,"Realms",szBuf,tTokens.GetToken(iTmp));
}
}
if ( SendMessage( hWndRealm, CB_GETCURSEL, 0, 0 )==CB_ERR )
{
SendMessage( hWndRealm, CB_SETCURSEL, (WPARAM)iSel, 0 );
SendMessage( hWndMethod, WM_SETTEXT, 0, (LPARAM)"" );
EnableWindow( hWndUser, FALSE );
EnableWindow( hWndPassword, FALSE );
EnableWindow( hWndConfirm, FALSE );
};
};
/*
** update static method text for realm
*/
*szBuf = '\0';
SendMessage( hWndRealm, WM_GETTEXT, BUF_SIZE, (LPARAM)szBuf );
if ( Internal_findMethod( szBuf )) {
SendMessage( hWndMethod, WM_SETTEXT, 0, (LPARAM)szBuf );
if (!strcmp(szBuf,"Ntlm")) {
EnableWindow( hWndUser, FALSE);
EnableWindow( hWndPassword, FALSE );
EnableWindow( hWndConfirm, FALSE );
}
}
break;
case IDC_ADD:
{
int i;
*szBuf = '\0';
SendMessage( hWndUser, WM_GETTEXT, BUF_SIZE,
(LPARAM)szBuf );
/*
** Username cannot contain ':' character
*/
for( i=0; i<BUF_SIZE && szBuf[i] && szBuf[i]!=':';i++);
if ( szBuf[i]==':' )
{
MessageBox( hDlg, "A username may not contain the \
colon (:) character.", "Add User",
MB_OK | MB_ICONEXCLAMATION );
SetFocus( hWndUser );
SendMessage( hWndUser, EM_SETSEL, 0, -1 );
break;
};
for( i=0; i<BUF_SIZE && szBuf[i] &&
!isspace( szBuf[i] ); i++ );
if ( szBuf[i] ) { szBuf[i] = '\0'; };
PIString sUser( szBuf );
szBuf[i++] = '\t';
SendMessage( hWndPassword, WM_GETTEXT, BUF_SIZE-i,
(LPARAM)&(szBuf[i]) );
PIString sPassword( &(szBuf[i]) );
SendMessage( hWndConfirm, WM_GETTEXT, BUF_SIZE-i,
(LPARAM)&(szBuf[i]) );
PIString sConfirm( &(szBuf[i]) );
if ( !(sPassword==sConfirm) )
{
MessageBox( hDlg, "Passwords do not match",
"New User", MB_OK | MB_ICONEXCLAMATION );
SetFocus( hWndPassword );
SendMessage( hWndPassword, EM_SETSEL, 0, -1 );
break;
};
/*
** Compute digest password if appropriate
*/
*szBuf = '\0';
SendMessage( hWndMethod, WM_GETTEXT, BUF_SIZE, (LPARAM)szBuf );
if (!strcmp(szBuf,"Digest"))
{
*szBuf = '\0';
SendMessage( hWndRealm, WM_GETTEXT, BUF_SIZE, (LPARAM)szBuf );
sConfirm = sUser;
sConfirm.Concatenate(':');
sConfirm.Concatenate(szBuf);
sConfirm.Concatenate(':');
sConfirm.Concatenate(sPassword);
sPassword = "";
MD5Encode((const char *)sConfirm, sPassword);
}
strcpy(szBuf,sUser);
strcat(szBuf,"\t");
strcpy(&szBuf[i],sPassword);
lUsers.Append( (DblList::type)PI_NEW( PIString( sUser ) ) );
lPasswords.Append( (DblList::type)PI_NEW( PIString ( sPassword ) ) );
SendMessage( hWndList, LB_ADDSTRING, 0, (LPARAM)szBuf );
/*
** Clear edit fields, focus to list
*/
SendMessage( hWndUser, WM_SETTEXT, 0, (LPARAM)"" );
SendMessage( hWndPassword, WM_SETTEXT, 0, (LPARAM)"" );
SendMessage( hWndConfirm, WM_SETTEXT, 0, (LPARAM)"" );
Internal_reloadArrays();
int iIndex = SendMessage( hWndList,
LB_FINDSTRINGEXACT, 0, (LPARAM)szBuf );
if ( iIndex!=LB_ERR ) SendMessage( hWndList,
LB_SETTOPINDEX, iIndex, 0 );
SetFocus( hWndList );
Changed( hDlg );
};
break;
case IDC_REPLACE:
{
/*
** Get selected item index
*/
int iCurSel = SendMessage( hWndList, LB_GETCURSEL, 0, 0 );
/*
** Get text to add and add it to internal lists only
*/
int i;
*szBuf = '\0';
SendMessage( hWndUser, WM_GETTEXT, BUF_SIZE,
(LPARAM)szBuf );
/*
** Username cannot contain ':' character
*/
for( i=0; i<BUF_SIZE && szBuf[i] && szBuf[i]!=':';
i++ );
if ( szBuf[i]==':' )
{
MessageBox( hDlg, "A username may not contain \
the colon (:) character.", "Add User",
MB_OK | MB_ICONEXCLAMATION );
SetFocus( hWndUser );
SendMessage( hWndUser, EM_SETSEL, 0, -1 );
break;
};
for( i=0; i<BUF_SIZE && szBuf[i] &&
!isspace( szBuf[i] ); i++ );
if ( szBuf[i] ) { szBuf[i] = '\0'; };
PIString sUser( szBuf );
szBuf[i++] = '\t';
SendMessage( hWndPassword, WM_GETTEXT, BUF_SIZE-i,
(LPARAM)&(szBuf[i]) );
PIString sPassword( &(szBuf[i]) );
SendMessage( hWndConfirm, WM_GETTEXT, BUF_SIZE-i,
(LPARAM)&(szBuf[i]) );
PIString sConfirm( &(szBuf[i]) );
if ( !(sPassword==sConfirm) )
{
MessageBox( hDlg, "Passwords do not match",
"New User", MB_OK | MB_ICONEXCLAMATION );
SetFocus( hWndPassword );
SendMessage( hWndPassword, EM_SETSEL, 0, -1 );
break;
};
/*
** Compute digest password if appropriate
*/
*szBuf = '\0';
SendMessage( hWndMethod, WM_GETTEXT, BUF_SIZE, (LPARAM)szBuf );
if (!strcmp(szBuf,"Digest"))
{
*szBuf = '\0';
SendMessage( hWndRealm, WM_GETTEXT, BUF_SIZE, (LPARAM)szBuf );
sConfirm = sUser;
sConfirm.Concatenate(':');
sConfirm.Concatenate(szBuf);
sConfirm.Concatenate(':');
sConfirm.Concatenate(sPassword);
MD5Encode((const char *)sConfirm, sPassword);
}
strcpy(szBuf,sUser);
strcat(szBuf,"\t");
strcpy(&szBuf[i],sPassword);
lUsers.Append( (DblList::type)PI_NEW(
PIString( sUser ) ) );
lPasswords.Append( (DblList::type)PI_NEW(
PIString ( sPassword ) ) );
/*
** Delete the item from the list and internal lists
*/
SendMessage( hWndList, LB_DELETESTRING, iCurSel, 0 );
PI_DELETE( (PIString *)lUsers.Detach( iCurSel) );
PI_DELETE( (PIString *)lPasswords.Detach( iCurSel) );
/*
** Add new item to listbox
*/
SendMessage( hWndList, LB_ADDSTRING, 0, (LPARAM)szBuf );
/*
** Clear edit fields, focus to list
*/
SendMessage( hWndUser, WM_SETTEXT, 0, (LPARAM)"" );
SendMessage( hWndPassword, WM_SETTEXT, 0, (LPARAM)"" );
SendMessage( hWndConfirm, WM_SETTEXT, 0, (LPARAM)"" );
Internal_reloadArrays();
int iIndex = SendMessage( hWndList,
LB_FINDSTRINGEXACT, 0, (LPARAM)szBuf );
if ( iIndex!=LB_ERR ) SendMessage( hWndList,
LB_SETTOPINDEX, iIndex, 0 );
SetFocus( hWndList );
Changed( hDlg );
};
break;
case IDC_DELETE:
{
int iCurSel = SendMessage( hWndList, LB_GETCURSEL,
0, 0 );
SendMessage( hWndList, LB_DELETESTRING, iCurSel, 0 );
PI_DELETE( (PIString *)lUsers.Detach( iCurSel) );
PI_DELETE( (PIString *)lPasswords.Detach( iCurSel) );
/*
** Clear edit fields, focus to list
*/
SendMessage( hWndUser, WM_SETTEXT, 0, (LPARAM)"" );
SendMessage( hWndPassword, WM_SETTEXT, 0, (LPARAM)"" );
SendMessage( hWndConfirm, WM_SETTEXT, 0, (LPARAM)"" );
SetFocus( hWndList );
Changed( hDlg );
};
break;
case IDC_USER:
if ( GET_WM_COMMAND_CMD(wParam, lParam)==EN_CHANGE ) {
*szBuf = '\0';
SendMessage( hWndUser, WM_GETTEXT, BUF_SIZE, (LPARAM)szBuf );
Internal_updateButtons( wParam, lParam, hWndUser,
hWndPassword, szBuf );
/*
** If user exist, fill password field, otherwise delete,
*/
*szBuf = '\0';
SendMessage( hWndMethod, WM_GETTEXT, BUF_SIZE,(LPARAM)szBuf );
int iSel;
iSel = SendMessage( hWndList, LB_GETCURSEL, 0, 0 );
if (iSel != LB_ERR && !strcmp(szBuf,"Basic")) {
SendMessage( hWndPassword, WM_SETTEXT, 0,
(LPARAM)(const char *)*((PIString *)lPasswords[iSel]) );
SendMessage( hWndConfirm, WM_SETTEXT, 0,
(LPARAM)(const char *)*((PIString *)lPasswords[iSel]) );
} else {
SendMessage( hWndPassword, WM_SETTEXT, 0, (LPARAM)"" );
SendMessage( hWndConfirm, WM_SETTEXT, 0, (LPARAM)"" );
}
}
break;
case IDC_PASSWORD:
case IDC_CONFIRM:
if ( GET_WM_COMMAND_CMD(wParam, lParam)==EN_CHANGE ) {
*szBuf = '\0';
SendMessage( hWndUser, WM_GETTEXT, BUF_SIZE,(LPARAM)szBuf );
Internal_updateButtons( wParam, lParam, hWndPassword,
hWndUser, szBuf );
}
break;
case IDC_LIST:
if ( GET_WM_COMMAND_CMD(wParam, lParam)==LBN_SELCHANGE )
{
*szBuf = '\0';
SendMessage( hWndMethod, WM_GETTEXT, BUF_SIZE,(LPARAM)szBuf );
int iSel = SendMessage( hWndList, LB_GETCURSEL, 0, 0 );
if (iSel != LB_ERR)
{
assert( iSel>=0 && iSel<lUsers.Size() );
EnableWindow( hWndDelete, TRUE );
SendMessage( hWndUser, WM_SETTEXT, 0,
(LPARAM)(const char *)*((PIString *)lUsers[iSel]) );
if (!strcmp(szBuf,"Basic"))
{
SendMessage( hWndPassword, WM_SETTEXT, 0,
(LPARAM)(const char *)*((PIString *)lPasswords[iSel]) );
SendMessage( hWndConfirm, WM_SETTEXT, 0,
(LPARAM)(const char *)*((PIString *)lPasswords[iSel]) );
};
};
};
break;
default:;
}
break;
case WM_NOTIFY:
switch( ((NMHDR *)lParam)->code )
{
case PSN_QUERYCANCEL:
return SHEET->Cancel(pInterface, hDlg);
case PSN_KILLACTIVE:
/*
** Save values
*/
*szBuf = '\0';
SendMessage( hWndRealm, WM_GETTEXT, BUF_SIZE,
(LPARAM)szBuf );
Internal_saveItems( szBuf );
SetWindowLong( hDlg, DWL_MSGRESULT, FALSE );
break;
case PSN_APPLY:
return SHEET->SaveConfig(pInterface, hDlg);
default:
return (FALSE);
};
break;
default:
return (FALSE);
};
return (TRUE);
};
};
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
static BOOL CALLBACK fnDialogProc(HWND hDlg, UINT uMsg, WPARAM wParam,
LPARAM lParam)
{
if ( uMsg==WM_INITDIALOG )
{
::SetWindowLong( hDlg, DWL_USER, ((LPPROPSHEETPAGE)lParam)->lParam );
};
UsersPage *pPage = (UsersPage *)::GetWindowLong( hDlg, DWL_USER );
return pPage ? pPage->DialogProc( hDlg, uMsg, wParam, lParam ) : FALSE;
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
static BOOL CALLBACK fnNewRealmDialogProc(HWND hDlg, UINT uMsg, WPARAM wParam,
LPARAM lParam)
{
if ( uMsg==WM_INITDIALOG )
{
::SetWindowLong( hDlg, DWL_USER, lParam );
};
UsersPage *pPage = (UsersPage *)::GetWindowLong( hDlg, DWL_USER );
return pPage ? pPage->NewRealmDialogProc( hDlg, uMsg, wParam, lParam ) :
FALSE;
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
PUBLIC_PIAPI int UsersPage_constructor( PIObject *pObj,
int iArgc, const char *ppArgv[] )
{
return IFaceBase_constructor( pObj, PI_NEW( UsersPage( pObj,
iArgc, ppArgv ) ) );
}
#if 0
/*___+++CNF_BEGIN+++___*/
<Class>
Name UsersPageClass
Type LogicExtension
Library IntrFace
OnClassLoad IFaceBase_onClassLoad
Constructor UsersPage_constructor
CopyConstructor IFaceBase_copyConstructor
Destructor IFaceBase_destructor
Execute IFaceBase_execute
</Class>
<Object>
Name UsersPage
Class UsersPageClass
</Object>
/*___+++CNF_END+++___*/
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -