📄 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/Intrface/Users.cpp,v $
* $Date: 2003/05/13 18:42:07 $
*
Description:
\*____________________________________________________________________________*/
//$SourceTop:$
#include <iostream.h>
#include <stdio.h>
#include <windowsx.h>
#include "IFaceBse.h"
#include "PIStrStr.h"
#include "StrToken.h"
#include "md5.h"
#include "Base64.h"
#include "QConfig.h"
#include "Users.hrc"
/*
** #define D { cerr << __FILE__ << ": " << __LINE__ << endl; }
*/
#define D
/*____________________________________________________________________________*\
*
Description:
\*____________________________________________________________________________*/
#define C_RESOURCENAME "UsersPage"
/*____________________________________________________________________________*\
*
Description:
\*____________________________________________________________________________*/
#if 0
/*
** HTML documentation for this handler
*/
/*___+++HTMLDOC_BEGIN+++___*/
Name:
UsersPage
Description:
Creates the eponymous property page and is used by the PropSheet object.
Example:
<PRE>
<Object>
Name UsersPage
Class UsersPageClass
PropertyPage UsersPage
</Object>
</PRE>
/*___+++HTMLDOC_END+++___*/
#endif
/*____________________________________________________________________________*\
*
Description:
\*____________________________________________________________________________*/
static BOOL CALLBACK fnDialogProc(HWND hDlg, UINT uMsg, WPARAM wParam,
LPARAM lParam);
static BOOL CALLBACK fnNewRealmDialogProc(HWND hDlg, UINT uMsg, WPARAM wParam,
LPARAM lParam);
/*____________________________________________________________________________*\
*
Class:
Description:
\*____________________________________________________________________________*/
class UsersPage : public IFaceBase
{
private:
QConfig *pConfig;
PROPSHEETPAGE tPsp;
Interface *pInterface;
/*
** window private values
*/
HWND hWndRealm;
HWND hWndList;
HWND hWndUser;
HWND hWndPassword;
HWND hWndConfirm;
HWND hWndAdd;
HWND hWndReplace;
HWND hWndDelete;
HWND hWndMethod;
DblList lUsers;
DblList lPasswords;
HWND hWndDlgOK;
HWND hWndDlgRealm;
HWND hWndDlgBasic;
HWND hWndDlgDigest;
HWND hWndDlgNtlm;
int Parameter( const char *pVariable, const char *pValue,
const char *pWhere )
{
assert( pVariable && pValue );
PIOStrStream os;
os << pWhere << "UsersPage: ";
if ( 0 )
{
}
else
{
os << "Unknown directive '" << pVariable <<
"'" << ends;
CONFIG_ERR( Object(), os.str() );
return 0;
};
return 1;
};
public:
UsersPage( PIObject *pObject, int iArgc, const char *ppArgv[] )
: IFaceBase( pObject ),
pConfig( FindParentQConfig( PIObject_getDB( pObject ) ) ),
hWndRealm( 0 ),
hWndList( 0 ),
hWndUser( 0 ),
hWndPassword( 0 ),
hWndConfirm( 0 ),
hWndAdd( 0 ),
hWndReplace( 0 ),
hWndDelete( 0 ),
hWndMethod( 0 ),
pInterface( 0 )
{
/*
** Read input parameters
*/
ReadParameters( iArgc, ppArgv );
if ( !IsOK() )
{ return; };
/*
** Setup the PROPSHEETPAGE
*/
memset( &tPsp, 0, sizeof( PROPSHEETPAGE ) );
tPsp.dwSize = sizeof( PROPSHEETPAGE );
tPsp.dwFlags = PSP_DEFAULT;
tPsp.hInstance = (HINSTANCE)PIDLL_getSystemHandle( PIClass_getLibrary(
PIObject_getClass( Object() ) ) );
/* Status page */
tPsp.pszTemplate = C_RESOURCENAME;
tPsp.pfnDlgProc = (DLGPROC)fnDialogProc;
tPsp.lParam = (LPARAM)this;
/*
** Set the data DB of this object
*/
PIDB *pDB = PIObject_getDB( Object() );
PIDB_add( pDB, PIDBTYPE_OPAQUE, INTRFACE_WINDOWTYPE,
(void *)INTRFACE_PROPPAGE, 0 );
assert(!PIDB_lookup( pDB, PIDBTYPE_OPAQUE, INTRFACE_PROPSHEETPAGE, 0));
PIDB_add( pDB, PIDBTYPE_OPAQUE, INTRFACE_PROPSHEETPAGE,
(void *)&tPsp, 0 );
/*
** Done
*/
};
~UsersPage()
{
};
virtual int Handle( Interface &tWindow )
{
switch( tWindow.iMessage )
{
case INTRFACE_MSG_INIT:
pInterface = &tWindow;
break;
case INTRFACE_MSG_WIN32CREATE:
return Win32Create( tWindow );
case INTRFACE_MSG_LOAD:
return PIAPI_ABORT;
case INTRFACE_MSG_DEFAULTS:
// temp. - LATER
M_AddValue( pConfig, "Realms", "Basic", "Administration" );
break;
default:
assert( 0 );
return PIAPI_ABORT;
};
return PIAPI_COMPLETED;
};
int Win32Create( Interface &tWindow )
{
/* --- property sheet pages should not be created --- */
return PIAPI_ABORT;
};
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() );
};
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();
};
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 );
};
};
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 ); };
};
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 = M_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 = M_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();
};
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 = M_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 \
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -