D
DreamTiger
Unregistered / Unconfirmed
GUEST, unregistred user!
这是一个可以从IE的Favorite中把URL转换为HTML显示的。
我想用它输入用户和密码,校验正确后,显示转换结果。
当我输入正确的时候,转换结果正常显示,怪事出在如果
我输入了用户名和密码,但是密码不正确(用户名是选择
的,所以正确),这时候会跳出一个窗口,“
请输入用户名和密码。
站点: 111.111.111.111(机器IP)
领域: 111.111.111.111(同上)
用户名(U):
密码(P):
将密码存入密码表中(S)
确定 取消”
如果在别的机器上(用的是PWIN98,本机是NT)使用这个cgi,
输入密码不正确的时候,会跳出一个窗口“
请输入您的身份验证信息。
资源: 111.111.111.111
用户名(U):
密码(P):
将密码存入密码表中(S)
确定 取消”
好像是要连接网络邻居一样,这是怎么回事?
运行调试的时候,如果输入密码出错后,运行到了
HttpMemoFilter_Unauthorized.put;
然后就退出这个函数,也就是说运行次序没有问题。
F9继续后,出现上述输入窗口。
HttpMemoFilter_Unauthorized的Text就是很简单的
Access Denied一句话,这句话在上述窗口出现三次
后显示在浏览器窗口。
HttpMemoFilter_Init中语句是用于选择用户名,
输入密码,将参数返回给cgi自身的。
下面是主程序:
unit main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
HttpEng, HUtils, GenEng, IniFiles;
type
TForm1 = class(TForm)
GeneralHttpEngine1: TGeneralHttpEngine;
HttpMemoFilter_Unauthorized: THttpMemoFilter;
HttpMemoFilter_Result: THttpMemoFilter;
HttpMemoFilter_Init: THttpMemoFilter;
procedure GeneralHttpEngine1ExecRequest(Sender: TObject);
private
tslFavorite:TStringList;
procedure ConvertFavorite;
procedure ScanDir(Dir, { Directory name for Hdr }
Path : string; { Path to search }
Indent : integer); { Left Margin }
procedure AddHeader(Name : string);
procedure AddUrl(Name, URL : string);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
const REC_FOUND = 0; { OK-Result of FindFirst }
ROOT_DIR = 'C:/WinNT/Profiles/sqh/Favorites'; { Where to start looking }
DIR_EXT = '/*.*'; { mask for Directories }
URL_EXT = '/*.URL'; { mask for URLs }
{ The .URL files used by IE have the same format that was used in }
{ Windows 3.x's .INI files. Thus, we can use the TIniFile class and }
{ TIniFile.Readstring method to extract the information. }
{ Methinks it should be possible to store additional information in }
{ the .URL files for managing shortcuts, etc. Play with it if you }
{ have time. Maybe set it to *not* export some shortcuts, or to }
{ include pictures (IMG=), or set different fonts for HTML generation }
INI_SECTION = 'InternetShortcut'; { Section in the URL file }
INI_ITEM = 'URL'; { Item in the section }
INI_DEFAULT = 'N/A'; { ...if URL not found }
STARTINDENT = 0; { Left Margin in Memo }
ADD_INDENT = 4; { Indent for each level }
DIR_INDENT = 2; { back up two for dir. }
MISCELLANEOUS = 'Miscellaneous'; { Header for Root Dir }
procedure TForm1.ConvertFavorite;
begin
ScanDir('',ROOT_DIR,0);
end;
procedure TForm1.ScanDir(Dir, { Directory name for Hdr }
Path : string; { Path to search }
Indent : integer); { Left Margin }
var SearchRec : TSearchRec;
Err : integer;
URL : string;
begin { of ScanDir }
{ Scan for Directories first }
Err:=FindFirst(Path+DIR_EXT, faDirectory, SearchRec);
while (Err = REC_FOUND) do with SearchRec do begin
if Name[1] <> '.' then begin { Avoid Directories '.' and '..' }
ScanDir(Name, Path+'/'+Name, Indent+ADD_INDENT) { Recurse down }
end;
Err:=FindNext(SearchRec) { Find Next Directory name }
end;
FindClose(SearchRec); { We're done here }
{ Scan for URLs }
Err:=FindFirst(Path+URL_EXT, faAnyFile, SearchRec);
{ if a URL was found in this directory, output the directory name or
generate and HTML Header with the directory name. This assures that
a the header will not be generated for empty directories, or non-URL
directories. }
if (Err = REC_FOUND) then begin
if Dir>'' then AddHeader(Dir) { Generate HTML }
else AddHeader(MISCELLANEOUS)
end;
{ now begin scanning the dir }
while (Err = REC_FOUND) do with SearchRec do begin
{ Get the URL information from the current URL file }
with TIniFile.Create(Path+'/'+Name) do begin
URL:=ReadString(INI_SECTION, INI_ITEM, INI_DEFAULT);
Free;
end;
{ output or generate html for the name and URL }
AddURL(Copy(Name, 1,Length(Name)-4), URL); { Copy deletes the extension ".URL" }
Err:=FindNext(SearchRec);
end;
FindClose(SearchRec)
{ OK, all done }
end;
procedure TForm1.AddHeader(Name : string);
begin
{ Write a header (i.e. Directory name ) }
tslFavorite.Add('<p><font size=5><strong>'+Name+'</strong></font></p>');
end;
procedure TForm1.AddUrl(Name, URL : string);
begin
{ Write a URL }
tslFavorite.Add(Format('<p><a href="%s"><strong>%s</strong></a></p>',[URL,Name]));
end;
procedure TForm1.GeneralHttpEngine1ExecRequest(Sender: TObject);
var
sUsername: string;
sPassword: string;
begin
sUsername:=FormVar('Username','');
sPassword:=FormVar('Password','');
if (Length(sUsername)>0) and (Length(sPassword)>0) then // Here you should do some check
begin
if(sUserName = 'sqh') and (sPassword = '1234567') then
begin
HttpMemoFilter_Result.Text.Clear;
tslFavorite := TStringList.Create;
try
ConvertFavorite;
HttpMemoFilter_Result.Text.Assign(tslFavorite);
finally
tslFavorite.Free;
end;
PutLine('<html><head><title>Favorites</title></head><body>');
HttpMemoFilter_Result.Put;
PutLine('</body></html>')
end
else
begin
PutHttpHeader('HTTP/1.0 401 Unauthorized to access the document','');
PutHttpHeader('Content-Type','text/html');
PutHttpHeader('WWW-Authenticate','Basic realm="' + RemoteAddress + '"');
PutLine('<HTML><TITLE>' + sUsername + ':' + sPassword + '</TITLE></HTML>');
HttpMemoFilter_Unauthorized.put;
end;
end
else
begin
HttpMemoFilter_Init.put;
end;
end;
end.
我想用它输入用户和密码,校验正确后,显示转换结果。
当我输入正确的时候,转换结果正常显示,怪事出在如果
我输入了用户名和密码,但是密码不正确(用户名是选择
的,所以正确),这时候会跳出一个窗口,“
请输入用户名和密码。
站点: 111.111.111.111(机器IP)
领域: 111.111.111.111(同上)
用户名(U):
密码(P):
将密码存入密码表中(S)
确定 取消”
如果在别的机器上(用的是PWIN98,本机是NT)使用这个cgi,
输入密码不正确的时候,会跳出一个窗口“
请输入您的身份验证信息。
资源: 111.111.111.111
用户名(U):
密码(P):
将密码存入密码表中(S)
确定 取消”
好像是要连接网络邻居一样,这是怎么回事?
运行调试的时候,如果输入密码出错后,运行到了
HttpMemoFilter_Unauthorized.put;
然后就退出这个函数,也就是说运行次序没有问题。
F9继续后,出现上述输入窗口。
HttpMemoFilter_Unauthorized的Text就是很简单的
Access Denied一句话,这句话在上述窗口出现三次
后显示在浏览器窗口。
HttpMemoFilter_Init中语句是用于选择用户名,
输入密码,将参数返回给cgi自身的。
下面是主程序:
unit main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
HttpEng, HUtils, GenEng, IniFiles;
type
TForm1 = class(TForm)
GeneralHttpEngine1: TGeneralHttpEngine;
HttpMemoFilter_Unauthorized: THttpMemoFilter;
HttpMemoFilter_Result: THttpMemoFilter;
HttpMemoFilter_Init: THttpMemoFilter;
procedure GeneralHttpEngine1ExecRequest(Sender: TObject);
private
tslFavorite:TStringList;
procedure ConvertFavorite;
procedure ScanDir(Dir, { Directory name for Hdr }
Path : string; { Path to search }
Indent : integer); { Left Margin }
procedure AddHeader(Name : string);
procedure AddUrl(Name, URL : string);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
const REC_FOUND = 0; { OK-Result of FindFirst }
ROOT_DIR = 'C:/WinNT/Profiles/sqh/Favorites'; { Where to start looking }
DIR_EXT = '/*.*'; { mask for Directories }
URL_EXT = '/*.URL'; { mask for URLs }
{ The .URL files used by IE have the same format that was used in }
{ Windows 3.x's .INI files. Thus, we can use the TIniFile class and }
{ TIniFile.Readstring method to extract the information. }
{ Methinks it should be possible to store additional information in }
{ the .URL files for managing shortcuts, etc. Play with it if you }
{ have time. Maybe set it to *not* export some shortcuts, or to }
{ include pictures (IMG=), or set different fonts for HTML generation }
INI_SECTION = 'InternetShortcut'; { Section in the URL file }
INI_ITEM = 'URL'; { Item in the section }
INI_DEFAULT = 'N/A'; { ...if URL not found }
STARTINDENT = 0; { Left Margin in Memo }
ADD_INDENT = 4; { Indent for each level }
DIR_INDENT = 2; { back up two for dir. }
MISCELLANEOUS = 'Miscellaneous'; { Header for Root Dir }
procedure TForm1.ConvertFavorite;
begin
ScanDir('',ROOT_DIR,0);
end;
procedure TForm1.ScanDir(Dir, { Directory name for Hdr }
Path : string; { Path to search }
Indent : integer); { Left Margin }
var SearchRec : TSearchRec;
Err : integer;
URL : string;
begin { of ScanDir }
{ Scan for Directories first }
Err:=FindFirst(Path+DIR_EXT, faDirectory, SearchRec);
while (Err = REC_FOUND) do with SearchRec do begin
if Name[1] <> '.' then begin { Avoid Directories '.' and '..' }
ScanDir(Name, Path+'/'+Name, Indent+ADD_INDENT) { Recurse down }
end;
Err:=FindNext(SearchRec) { Find Next Directory name }
end;
FindClose(SearchRec); { We're done here }
{ Scan for URLs }
Err:=FindFirst(Path+URL_EXT, faAnyFile, SearchRec);
{ if a URL was found in this directory, output the directory name or
generate and HTML Header with the directory name. This assures that
a the header will not be generated for empty directories, or non-URL
directories. }
if (Err = REC_FOUND) then begin
if Dir>'' then AddHeader(Dir) { Generate HTML }
else AddHeader(MISCELLANEOUS)
end;
{ now begin scanning the dir }
while (Err = REC_FOUND) do with SearchRec do begin
{ Get the URL information from the current URL file }
with TIniFile.Create(Path+'/'+Name) do begin
URL:=ReadString(INI_SECTION, INI_ITEM, INI_DEFAULT);
Free;
end;
{ output or generate html for the name and URL }
AddURL(Copy(Name, 1,Length(Name)-4), URL); { Copy deletes the extension ".URL" }
Err:=FindNext(SearchRec);
end;
FindClose(SearchRec)
{ OK, all done }
end;
procedure TForm1.AddHeader(Name : string);
begin
{ Write a header (i.e. Directory name ) }
tslFavorite.Add('<p><font size=5><strong>'+Name+'</strong></font></p>');
end;
procedure TForm1.AddUrl(Name, URL : string);
begin
{ Write a URL }
tslFavorite.Add(Format('<p><a href="%s"><strong>%s</strong></a></p>',[URL,Name]));
end;
procedure TForm1.GeneralHttpEngine1ExecRequest(Sender: TObject);
var
sUsername: string;
sPassword: string;
begin
sUsername:=FormVar('Username','');
sPassword:=FormVar('Password','');
if (Length(sUsername)>0) and (Length(sPassword)>0) then // Here you should do some check
begin
if(sUserName = 'sqh') and (sPassword = '1234567') then
begin
HttpMemoFilter_Result.Text.Clear;
tslFavorite := TStringList.Create;
try
ConvertFavorite;
HttpMemoFilter_Result.Text.Assign(tslFavorite);
finally
tslFavorite.Free;
end;
PutLine('<html><head><title>Favorites</title></head><body>');
HttpMemoFilter_Result.Put;
PutLine('</body></html>')
end
else
begin
PutHttpHeader('HTTP/1.0 401 Unauthorized to access the document','');
PutHttpHeader('Content-Type','text/html');
PutHttpHeader('WWW-Authenticate','Basic realm="' + RemoteAddress + '"');
PutLine('<HTML><TITLE>' + sUsername + ':' + sPassword + '</TITLE></HTML>');
HttpMemoFilter_Unauthorized.put;
end;
end
else
begin
HttpMemoFilter_Init.put;
end;
end;
end.