📄 prpsheet.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/PrpSheet.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 "QConfig.h"
#include "Admin.h"
#include "DeQuote.h"
#include "PrpSheet.hrc"
/*
** #define D { cerr << __FILE__ << ": " << __LINE__ << endl; }
*/
#define D
/*____________________________________________________________________________*\
*
Description:
\*____________________________________________________________________________*/
#define KEY_CONF_TITLE "Title"
#define KEY_CONF_PROPERTYPAGE "PropertyPage"
#define KEY_CONF_FILENAME "FileName"
#define KEY_CONF_HOST "Host"
#define KEY_CONF_PORT "Port"
#define KEY_CONF_USERNAME "AdminUser"
#define KEY_CONF_PASSWORD "AdminPassword"
#define KEY_CONF_OPTIONS "Options"
/*____________________________________________________________________________*\
*
Flags and Options
\*____________________________________________________________________________*/
#define FLG_NONE 0x00000000
#define FLG_CREATEDEFAULT 0x00000001
#define FLG_LOADFILE 0x00000002
/*___ +++++++++++++++++++++++++++++++++++++++++++++++++ ___ *
Map these flags to names
*___ +++++++++++++++++++++++++++++++++++++++++++++++++ ___ */
struct {
const char *pName;
int iFlag;
} aFlagMap[] =
{
{ "CreateDefault", FLG_CREATEDEFAULT },
{ "LoadFile", FLG_LOADFILE },
/* --- leave this last always --- */
{ 0, 0 }
};
/*____________________________________________________________________________*\
*
Description:
\*____________________________________________________________________________*/
#if 0
/*
** HTML documentation for this handler
*/
/*___+++HTMLDOC_BEGIN+++___*/
Name:
PropSheet
Description:
Generates a property sheet window for remote administration.
This object is used by the WinLoop object and expects an I/O
object of name "ClientIOObject" to be in the
configuration in case of network based remote administration.
Options:
<TABLE BORDER=1>
<TH>Option
<TH>Default
<TH>Values
<TH>Short Description
<TH>Example(s)
<TR>
<TD>Host
<TD>-
<TD><string>
<TD>A valid hostname for remote network connection
<TD>Host theserver.pi3.net
<TR>
<TD>Port
<TD>80
<TD><number>
<TD>A valid port number for remote network connection
<TD>Port 443
<TR>
<TD>AdminUser
<TD>-
<TD><string>
<TD>A valid user name for remote network connection
<TD>AdminUser
<TR>
<TD>AdminPassword
<TD>-
<TD><string>
<TD>A valid password for remote network connection
<TD>AdminPassword 0xb458378ed3de4d4eed0f32c9571e5193
<TR>
<TD>FileName
<TD>-
<TD><string>
<TD>A valid filename for file based local interface
<TD>FileName "../Conf/Config.pi3"
<TR>
<TD>Title
<TD>"Pi3Web Admin"
<TD><string>
<TD>A title string for the property sheet
<TD>Title "Pi3Web Remote Administration"
<TR>
<TD>PropertyPage
<TD>-
<TD><configuration object>
<TD>A valid name of a configuration object
<TD>PropertyPage SslPage
<TR>
<TD>Options
<TD>CreateDefault | LoadFile
<TD>Options flags as described below
<TD>Options which effect behaviour
<TD>Options CreateDefault
</TABLE>
<STRONG>-</STRONG> in the <IT>default</IT> indicates no default<BR>
<STRONG>+</STRONG> in the <IT>default</IT> indicates the field is mandatory<BR>
<H4>Description of Options</H4>
<H5>Host</H5>
The Host parameter is used to establish a remote interface connection to the
specified host. It must contain a valid hostname or IP address. A corresponding
Port parameter may exist. This parameter is mutual exclusive with the FileName
parameter.
<H5>Port</H5>
The Port parameter is optional used to establish a remote interface connection
using the specified port. It must contain a valid TCP port number.
<H5>AdminUser</H5>
The username is used to establish a remote interface connection. A corresponding
authentication setting (realm, user) must exist at the server. The interface
client determines the authentication type automatically. Supported authentication
types are "Basic" and "Digest" (recommended). If the AdminUser
is set but the AdminPassword is omitted, the Login Dialog is prefilled with the
value of AdminUser (recommended for Basic Authentication).
<H5>AdminPassword</H5>
The password is used to establish a remote interface connection. A corresponding
authentication setting (realm, user) must exist at the server. The interface
client determines the authentication type automatically. Supported authentication
types are "Basic" and "Digest" (recommended). If both AdminUser
and AdminPassword are set, the Login Dialog is omitted (not recommended for Basic
authentication). For Digest authentication the Admin password is the hexified MD5
hash of the username:password combination, which makes it nearly impossible to
compute the plain password from the stored password string.
<H5>FileName</H5>
The FileName is used to load the wanted configuration file locally. This parameter
is mutual exclusive with the Host parameter.
<H5>Title</H5>
The given string is used in the title bar of the PropSheet window.
<H5>PropertyPage</H5>
The PropertyPage directive may be repeated multiple times in order to fill the
PropSheet with the wanted property pages. You may simply comment out all pages,
which are unwanted for remote administration.
<H5>Options</H5>
Specifies options which effect the behaviour of the interface application.
<CENTER>
<TABLE BORDER=1>
<TH>Option
<TH>Meaning
<TR>
<TD>CreateDefault
<TD>Set appropriate default values in all PropertyPage objects.
Makes sense as an alternative to LoadFile option in order to
generate an initial configuration.
<TR>
<TD>LoadFile
<TD>Loads the configuration file dependant on the Host/FileName settings
either remotely or locally. Makes sense as an alternative to CreateDefault
option in order to edit an already existing configuration file.
</TABLE>
</CENTER>
Multiple options may be listed together by seperating them using the pipe
('|') character. Whitespace will be stripped from the option pattern.
Options are matched without regard to case sensitivity. Unknown options
will raise a configuration error. The Option directive may be repeated
multiple times.
Example:
<PRE>
<Object>
Name PropSheet
Class PropSheetClass
Host localhost
Port 80
Title "Pi3Web Remote Administration"
Options LoadFile
PropertyPage GeneralPage
PropertyPage PerformancePage
PropertyPage HttpPage
PropertyPage UsersPage
PropertyPage MIMETypesPage
PropertyPage MappingsPage
PropertyPage LogFilePage
PropertyPage IPVHostsPage
PropertyPage NonIPVHostsPage
PropertyPage DirIndexPage
PropertyPage SslPage
</Object>
</PRE>
/*___+++HTMLDOC_END+++___*/
#endif
static BOOL CALLBACK fnAuthDialogProc(HWND hDlg, UINT uMsg, WPARAM wParam,
LPARAM lParam);
static int GetAuthenticationData( void *pUserData )
{
HINSTANCE hInstance = (HINSTANCE)PIDLL_getSystemHandle( PIClass_getLibrary(
PIObject_getClass( ((IFaceBase *)pUserData)->Object() )));
return DialogBoxParam(
hInstance,
MAKEINTRESOURCE(IDD_AUTHENTICATE),
NULL,
(DLGPROC)fnAuthDialogProc,
(LPARAM)pUserData
);
}
/*____________________________________________________________________________*\
*
Class:
Description:
\*____________________________________________________________________________*/
class PropSheet : public IFaceBase
{
private:
Interface *pInterface;
Admin *pAdmin;
PIString sTitle;
DblList lPages;
PIString sFileName;
PIString sUserName;
PIString sPassword;
PIString sHost;
QConfig *pConfig;
int iPort;
int iOptions;
HWND hWndOK,
hWndRealm,
hWndUser,
hWndPassword;
protected:
int Parameter( const char *pVariable, const char *pValue,
const char *pWhere )
{
assert( pVariable && pValue );
PIOStrStream os;
os << pWhere << "PropSheet: ";
if ( !PIUtil_stricmp( pVariable, KEY_CONF_TITLE ) )
{
sTitle = pValue;
}
else if ( !PIUtil_stricmp( pVariable, KEY_CONF_PROPERTYPAGE ) )
{
/*
** Attempt to load the object
*/
PIObject *pPageObject = PIObject_load(
PIObject_getDB( Object() ), 0, pValue, 0, 0 );
/* --- error message already set --- */
if ( !pPageObject ) { return 0; };
/*
** Page created
*/
lPages.Append( (DblList::type)pPageObject );
}
else if ( !PIUtil_stricmp( pVariable, KEY_CONF_OPTIONS ) )
{
/* ---
Split the options up by the bar ('|') character and then
strip trailing and leading whitespace from option before
attempting to match it.
--- */
StringTokenizer tTokens( pValue, "|" );
for(int i=0; i<tTokens.NumTokens(); i++)
{
const char *pToken = tTokens.GetToken( i );
/* --- skip leading whitespace --- */
for( ; *pToken && (isspace(*pToken)); pToken++ );
/* ---
include only to first whitespace trailing whitespace
--- */
int j=0;
for( ; pToken[j] && !(isspace(pToken[j])); j++ );
/* ---
j now contains the length of the first word in pToken
--- */
/* ---
cycle through the list of available flags
comparing them with this one
--- */
int i=0;
for( ; aFlagMap[i].pName; i++ )
{
if ( !PIUtil_strncmpi( aFlagMap[i].pName, pToken, j ) )
{ break; };
};
if ( !aFlagMap[i].pName )
{
/* --- flag not found --- */
PIString sTmp( pToken, j );
os << "Unknown option flag '" << sTmp << "'." << ends;
CONFIG_ERR( Object(), os.str() );
return 0;
};
iOptions |= aFlagMap[i].iFlag;
}; /* --- loop over tokens seperated by '|' --- */
}
else if ( !PIUtil_stricmp( pVariable, KEY_CONF_FILENAME ) )
{
// Configuration error, one resource must be specified, 2 are specified
if (sFileName.Len())
{
os << "Local file not allowed here. "
<< "A remote host is already specified."
<< ends;
CONFIG_ERR( Object(), os.str() );
return 0;
}
sFileName = pValue;
}
else if ( !PIUtil_stricmp( pVariable, KEY_CONF_HOST ) )
{
// Configuration error, one resource must be specified, 2 are specified
if (sFileName.Len())
{
os << "Remote host not allowed here. "
<< "A local filename is already specified."
<< ends;
CONFIG_ERR( Object(), os.str() );
return 0;
}
/* --- host is read below --- */
sHost = (const char *)DeQuote( pValue );
}
else if ( !PIUtil_stricmp( pVariable, KEY_CONF_PORT ) )
{
iPort = atoi(pValue);
}
else if ( !PIUtil_stricmp( pVariable, KEY_CONF_USERNAME ) )
{
sUserName = pValue;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -