* Allow to specify address

This commit is contained in:
Michaël Van Canneyt 2021-09-15 11:22:52 +02:00
parent 711e659f5c
commit 3e621f2014

View File

@ -100,6 +100,7 @@ Type
FPassword:String; FPassword:String;
FEcho:Boolean; FEcho:Boolean;
FMaxAge: integer; FMaxAge: integer;
FInterfaceAddress : String;
procedure AddToStatus(O: TJSONObject); procedure AddToStatus(O: TJSONObject);
procedure DoEcho(ARequest: TRequest; AResponse: TResponse); procedure DoEcho(ARequest: TRequest; AResponse: TResponse);
procedure DoProxyLog(Sender: TObject; const aMethod, aLocation, aFromURL, aToURL: String); procedure DoProxyLog(Sender: TObject; const aMethod, aLocation, aFromURL, aToURL: String);
@ -133,6 +134,7 @@ Type
Property MimeFile : String Read FMimeFile; Property MimeFile : String Read FMimeFile;
Property NoIndexPage : Boolean Read FNoIndexPage Write FNoIndexPage; Property NoIndexPage : Boolean Read FNoIndexPage Write FNoIndexPage;
Property IndexPageName : String Read FIndexPageName Write FIndexPageName; Property IndexPageName : String Read FIndexPageName Write FIndexPageName;
Property InterfaceAddress : String Read FInterfaceAddress Write FInterfaceAddress;
end; end;
@ -281,6 +283,7 @@ begin
Writeln(' Default is current working directory: ',GetCurrentDir); Writeln(' Default is current working directory: ',GetCurrentDir);
Writeln('-h --help This help text'); Writeln('-h --help This help text');
Writeln('-i --indexpage=name Directory index page to use (default: index.html)'); Writeln('-i --indexpage=name Directory index page to use (default: index.html)');
Writeln('-I --interface=IP Listen on this interface address only.');
Writeln('-m --mimetypes=file Set Filename for loading mimetypes. Default is ',GetDefaultMimeTypesFile); Writeln('-m --mimetypes=file Set Filename for loading mimetypes. Default is ',GetDefaultMimeTypesFile);
Writeln('-n --noindexpage Do not allow index page.'); Writeln('-n --noindexpage Do not allow index page.');
Writeln('-p --port=NNNN TCP/IP port to listen on (default is 3000)'); Writeln('-p --port=NNNN TCP/IP port to listen on (default is 3000)');
@ -639,6 +642,7 @@ Const
SLocations = 'Locations'; SLocations = 'Locations';
KeyPort = 'Port'; KeyPort = 'Port';
KeyInterface = 'Interface';
KeyDir = 'Directory'; KeyDir = 'Directory';
KeyIndexPage = 'IndexPage'; KeyIndexPage = 'IndexPage';
KeyHostName = 'hostname'; KeyHostName = 'hostname';
@ -664,6 +668,7 @@ begin
try try
FBaseDir:=ReadString(SConfig,KeyDir,BaseDir); FBaseDir:=ReadString(SConfig,KeyDir,BaseDir);
Port:=ReadInteger(SConfig,KeyPort,Port); Port:=ReadInteger(SConfig,KeyPort,Port);
InterfaceAddress:=ReadString(SConfig,KeyInterface,InterfaceAddress);
Quiet:=ReadBool(SConfig,KeyQuiet,Quiet); Quiet:=ReadBool(SConfig,KeyQuiet,Quiet);
FMimeFile:=ReadString(SConfig,keyMimetypes,MimeFile); FMimeFile:=ReadString(SConfig,keyMimetypes,MimeFile);
NoIndexPage:=ReadBool(SConfig,KeyNoIndexPage,NoIndexPage); NoIndexPage:=ReadBool(SConfig,KeyNoIndexPage,NoIndexPage);
@ -717,6 +722,7 @@ begin
D:=GetCurrentDir; D:=GetCurrentDir;
if HasOption('m','mimetypes') then if HasOption('m','mimetypes') then
MimeTypesFile:=GetOptionValue('m','mimetypes'); MimeTypesFile:=GetOptionValue('m','mimetypes');
if MimeTypesFile='' then if MimeTypesFile='' then
begin begin
MimeTypesFile:=GetDefaultMimeTypesFile; MimeTypesFile:=GetDefaultMimeTypesFile;
@ -740,6 +746,8 @@ begin
NoIndexPage:=NoIndexPage or HasOption('n','noindexpage'); NoIndexPage:=NoIndexPage or HasOption('n','noindexpage');
if HasOption('i','indexpage') then if HasOption('i','indexpage') then
IndexPage:=GetOptionValue('i','indexpage'); IndexPage:=GetOptionValue('i','indexpage');
if HasOption('I','interface') then
InterfaceAddress:=GetOptionValue('I','interface');
If not NoIndexPage then If not NoIndexPage then
begin begin
if (IndexPage='') then if (IndexPage='') then
@ -800,6 +808,8 @@ begin
Log(etError,'API support missing, Compile with fpc 3.3.1+'); Log(etError,'API support missing, Compile with fpc 3.3.1+');
{$ENDIF} {$ENDIF}
TSimpleFileModule.RegisterDefaultRoute; TSimpleFileModule.RegisterDefaultRoute;
if InterfaceAddress<>'' then
HTTPHandler.Address:=InterfaceAddress;
inherited; inherited;
end; end;