📄 users.cpp
字号:
/*____________________________________________________________________________*\
*
Copyright (c) 1997-2003 John Roy, Holger Zimmermann. All rights reserved.
These sources, libraries and applications are
FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
as long as the following conditions are adhered to.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHORS OR ITS CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
*____________________________________________________________________________*|
*
* $Source: /cvsroot/pi3web/Pi3Web_200/Source/EnhPi3/Users.cpp,v $
* $Date: 2003/05/13 18:41:59 $
*
Description:
\*____________________________________________________________________________*/
/* $SourceTop:$ */
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <assert.h>
#include <stdio.h>
#include "DblList.h"
#include "PIString.h"
#include "StrToken.h"
#include "md5.h"
#include "Base64.h"
#include "resrc1.h"
#include "Dialogs.h"
#include "Config.h"
/*____________________________________________________________________________*\
*
Description:
Definitions and global values
\*____________________________________________________________________________*/
static HWND hWndRealm = 0;
static HWND hWndList = 0;
static HWND hWndUser = 0;
static HWND hWndPassword = 0;
static HWND hWndConfirm = 0;
static HWND hWndAdd = 0;
static HWND hWndReplace = 0;
static HWND hWndDelete = 0;
static HWND hWndMethod = 0;
static DblList lUsers;
static DblList lPasswords;
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
static void Internal_addLine( const char *pLine )
{
assert( pLine );
assert( lUsers.Size()==lPasswords.Size() );
int i;
for( i=0; pLine[i] && !isspace(pLine[i]); i++ );
/* --- scan to tab --- */
lUsers.Append( (DblList::type)PI_NEW( PIString( pLine, i ) ) );
/* --- scan over whitespace to start of Media type/subtype --- */
for( ; pLine[i] && isspace(pLine[i]); i++ );
lPasswords.Append( (DblList::type)PI_NEW( PIString( &(pLine[i]) ) ) );
assert( lUsers.Size()==lPasswords.Size() );
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
static void Internal_clearArrays()
{
DblListIterator x( lUsers );
DblListIterator y( lPasswords );
for( ; !x.BadIndex(); x++, y++ )
{
assert( !x.BadIndex() && !y.BadIndex() );
PI_DELETE( (PIString *)x.Current() );
PI_DELETE( (PIString *)y.Current() );
};
lUsers.Clear();
lPasswords.Clear();
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
static void Internal_reloadArrays()
{
enum { BUF_SIZE=1023 };
char szBuf[BUF_SIZE+1];
Internal_clearArrays();
/*
** Get number of items
*/
int iCount = SendMessage( hWndList, LB_GETCOUNT, 0, 0 );
/*
** Insert from listbox into internal arrays
*/
int i;
for( i=0; i<iCount; i++ )
{
SendMessage( hWndList, LB_GETTEXT, i, (LPARAM)szBuf );
Internal_addLine( szBuf );
};
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
static void Internal_updateButtons( WPARAM wParam, LPARAM lParam, HWND hWndEdit1,
HWND hWndEdit2, const char *pUser )
{
if ( GET_WM_COMMAND_CMD(wParam, lParam)!=EN_CHANGE )
{ return; };
/*
** If the file extension changed then check if this is an existing
** file extension
*/
int iExistingIndex = -1;
assert( pUser );
int iIndex = 0;
if ( *pUser )
{
for( DblListIterator i( lUsers ); !i.BadIndex(); i++, iIndex++ )
{
PIString *pString = (PIString *)i.Current();
assert( pString );
if ( (*pString)==pUser )
{
iExistingIndex = iIndex;
break;
};
};
};
/*
** Remove listbox selection or scroll to correct line
** as appropriate
*/
SendMessage( hWndList, LB_SETCURSEL, iExistingIndex, 0 );
/*
** Set buttons
*/
if ( SendMessage( hWndEdit1, EM_LINELENGTH, 0, 0 )==0 ||
SendMessage( hWndEdit2, EM_LINELENGTH, 0, 0 )==0 ||
SendMessage( hWndConfirm, EM_LINELENGTH, 0, 0 )==0 )
{
if ( IsWindowEnabled( hWndAdd ) ) EnableWindow( hWndAdd, FALSE );
if ( IsWindowEnabled( hWndReplace ) ) EnableWindow( hWndReplace, FALSE );
}
else
{
if ( iExistingIndex>-1 ) /* --- disable add, enable replace --- */
{
if ( IsWindowEnabled( hWndAdd ) ) EnableWindow( hWndAdd, FALSE );
if ( !IsWindowEnabled( hWndReplace ) ) EnableWindow( hWndReplace, TRUE );
}
else /* --- disable replace, enable add --- */
{
if ( !IsWindowEnabled( hWndAdd ) ) EnableWindow( hWndAdd, TRUE );
if ( IsWindowEnabled( hWndReplace ) ) EnableWindow( hWndReplace, FALSE );
};
};
/*
** If there is a selected item in the listbox then
** enable delete, otherwise disable delete
*/
if ( SendMessage( hWndList, LB_GETCURSEL, 0, 0 )==LB_ERR )
{ EnableWindow( hWndDelete, FALSE ); }
else
{ EnableWindow( hWndDelete, TRUE ); };
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
static void Internal_loadItems( const char *pRealm )
{
assert( pRealm );
/*
** Clear any existing items out of listbox
*/
SendMessage( hWndList, LB_RESETCONTENT, 0, 0 );
/*
** Load all users into list box
*/
int iTmp = 0;
for(;; iTmp++ )
{
PIString sSection( "__" );
sSection.Concatenate( pRealm );
const char *pTmp = AD_lookupValueEx( __pConfig, sSection, "Base64", iTmp );
if ( !pTmp )
{ break; };
PIString sPlain;
Base64Decode( pTmp, sPlain );
char *pPlain = (char *)(const char *)sPlain;
int iLen = sPlain.Len();
int i;
for( i=0; i<iLen && pPlain[i]!=':'; i++);
if ( pPlain[i]==':' ) { pPlain[i]='\t'; };
SendMessage( hWndList, LB_ADDSTRING, 0, (LPARAM)pPlain );
};
for(iTmp = 0;; iTmp++ )
{
PIString sSection( "__" );
sSection.Concatenate( pRealm );
PIString sPlain = AD_lookupValueEx( __pConfig, sSection, "Digest", iTmp );
int iLen = sPlain.Len();
if ( !iLen )
{ break; };
char *pPlain = (char *)(const char *)sPlain;
SendMessage( hWndList, LB_ADDSTRING, 0, (LPARAM)pPlain );
};
/*
** Clear out edit fields
*/
::SendMessage( hWndUser, WM_SETTEXT, 0, (LPARAM)"" );
::SendMessage( hWndPassword, WM_SETTEXT, 0, (LPARAM)"" );
::SendMessage( hWndConfirm, WM_SETTEXT, 0, (LPARAM)"" );
Internal_reloadArrays();
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
static int Internal_canDeleteRealm( HWND hDlg, const char *pRealm )
{
enum { BUF_SIZE=1023 };
char szBuf[BUF_SIZE+1];
int iTmp = 0;
assert( pRealm );
/*
** Check if realm is used by users
*/
iTmp = 0;
for(;; iTmp++ )
{
const char *pTmp = AD_lookupValueEx( __pConfig, "AccessControl",
"URLs", iTmp );
if ( !pTmp ) { break; };
int i;
for( i=0; pTmp[i] && pTmp[i]!='\t'; i++ );
PIString sRealm( pTmp, i );
if ( sRealm==pRealm )
{
sprintf( szBuf, "Realm '%s' is being used for access control. \
Remove all Realm-URL Path mappings in 'Access Control' before removing \
this realm.", pRealm );
MessageBox( hDlg, szBuf, "Remove Realm", MB_OK | MB_ICONEXCLAMATION );
return 0;
};
};
/*
** Check if realm is used by a mapping
*/
iTmp = 0;
for(;; iTmp++ )
{
const char *pTmp = AD_lookupValueEx( __pConfig, "Mappings",
"Mapping", iTmp );
if ( !pTmp ) { break; };
int i=0;
for( ; pTmp[i] && isspace(pTmp[i]); i++ );
for( ; pTmp[i] && pTmp[i]!='\t'; i++ );
for( ; pTmp[i] && isspace(pTmp[i]); i++ );
for( ; pTmp[i] && pTmp[i]!='\t'; i++ );
for( ; pTmp[i] && isspace(pTmp[i]); i++ );
for( ; pTmp[i] && pTmp[i]!='\t'; i++ );
for( ; pTmp[i] && isspace(pTmp[i]); i++ );
pTmp = &( pTmp[i] );
for( ; pTmp[i] && pTmp[i]!='\t'; i++ ); /* read length of realm */
PIString sRealm( pTmp, i );
if ( sRealm==pRealm )
{
sprintf( szBuf, "Realm '%s' is being used for directory mapping. \
Remove all Realm-URL Path mappings in 'Mapping' before removing \
this realm.", pRealm );
MessageBox( hDlg, szBuf, "Remove Realm", MB_OK | MB_ICONEXCLAMATION );
return 0;
};
};
return 1;
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
static int Internal_findMethod( char *pName )
{
for(int iTmp = 0;; iTmp++ ) {
const char *pTmp = AD_lookupValueEx( __pConfig, "Realms", "Basic",
iTmp );
if ( !pTmp ) { break; };
if (!strcmp(pTmp,pName)) {
strcpy(pName, "Basic");
return 1;
}
}
for(iTmp=0;; iTmp++ ) {
const char *pTmp = AD_lookupValueEx( __pConfig, "Realms", "Digest",
iTmp );
if ( !pTmp ) { break; };
if (!strcmp(pTmp,pName)) {
strcpy(pName, "Digest");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -