mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 12:49:34 +00:00
HTTPSRV: new attribute directoryindex
HTTPSRV: directoryindex is loaded no matter if the request contains a trailing / or not HTTPSRV: HTTPSRV_CGI() finds the correct device by name (bugfix) HTTPSRV: undef unregisters extension git-svn-id: https://svn.fhem.de/fhem/trunk@1849 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
bf6cfad12d
commit
41d0f308cd
@ -15,22 +15,36 @@ use HttpUtils;
|
|||||||
|
|
||||||
#########################
|
#########################
|
||||||
sub
|
sub
|
||||||
HTTPSRV_addExtension($$$) {
|
HTTPSRV_addExtension($$$$) {
|
||||||
my ($func,$link,$friendlyname)= @_;
|
my ($name,$func,$link,$friendlyname)= @_;
|
||||||
|
|
||||||
my $url = "/" . $link;
|
my $url = "/$link";
|
||||||
|
Log 3, "Registering HTTPSRV $name for URL $url...";
|
||||||
|
$data{FWEXT}{$url}{deviceName}= $name;
|
||||||
$data{FWEXT}{$url}{FUNC} = $func;
|
$data{FWEXT}{$url}{FUNC} = $func;
|
||||||
$data{FWEXT}{$url}{LINK} = $link;
|
$data{FWEXT}{$url}{LINK} = $link;
|
||||||
$data{FWEXT}{$url}{NAME} = $friendlyname;
|
$data{FWEXT}{$url}{NAME} = $friendlyname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub
|
||||||
|
HTTPSRV_removeExtension($) {
|
||||||
|
my ($link)= @_;
|
||||||
|
|
||||||
|
my $url = "/$link";
|
||||||
|
my $name= $data{FWEXT}{$url}{deviceName};
|
||||||
|
Log 3, "Unregistering HTTPSRV $name for URL $url...";
|
||||||
|
delete $data{FWEXT}{$url};
|
||||||
|
}
|
||||||
|
|
||||||
##################
|
##################
|
||||||
sub
|
sub
|
||||||
HTTPSRV_Initialize($) {
|
HTTPSRV_Initialize($) {
|
||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
$hash->{DefFn} = "HTTPSRV_Define";
|
$hash->{DefFn} = "HTTPSRV_Define";
|
||||||
|
$hash->{DefFn} = "HTTPSRV_Define";
|
||||||
|
$hash->{UndefFn} = "HTTPSRV_Undef";
|
||||||
#$hash->{AttrFn} = "HTTPSRV_Attr";
|
#$hash->{AttrFn} = "HTTPSRV_Attr";
|
||||||
$hash->{AttrList}= "loglevel:0,1,2,3,4,5";
|
$hash->{AttrList} = "loglevel:0,1,2,3,4,5 directoryindex";
|
||||||
#$hash->{SetFn} = "HTTPSRV_Set";
|
#$hash->{SetFn} = "HTTPSRV_Set";
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
@ -54,31 +68,50 @@ HTTPSRV_Define($$) {
|
|||||||
$hash->{fhem}{directory}= $directory;
|
$hash->{fhem}{directory}= $directory;
|
||||||
$hash->{fhem}{friendlyname}= $friendlyname;
|
$hash->{fhem}{friendlyname}= $friendlyname;
|
||||||
|
|
||||||
HTTPSRV_addExtension("HTTPSRV_CGI", $infix, $friendlyname);
|
HTTPSRV_addExtension($name, "HTTPSRV_CGI", $infix, $friendlyname);
|
||||||
|
|
||||||
$hash->{STATE} = $name;
|
$hash->{STATE} = $name;
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
##################
|
||||||
|
sub
|
||||||
|
HTTPSRV_Undef($$) {
|
||||||
|
|
||||||
|
my ($hash, $name) = @_;
|
||||||
|
|
||||||
|
HTTPSRV_removeExtension($hash->{fhem}{infix});
|
||||||
|
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
|
||||||
##################
|
##################
|
||||||
#
|
#
|
||||||
# here we answer any request to http://host:port/fhem/$infix and below
|
# here we answer any request to http://host:port/fhem/$infix and below
|
||||||
sub
|
|
||||||
HTTPSRV_CGI(){
|
sub HTTPSRV_CGI() {
|
||||||
|
|
||||||
my ($request) = @_; # /$infix/filename
|
my ($request) = @_; # /$infix/filename
|
||||||
|
|
||||||
if($request !~ m,^/.+/.*,) {
|
if($request =~ m,^(/[^/]+)(/(.*)?)?$,) {
|
||||||
$request= "$request/index.html";
|
my $link= $1;
|
||||||
}
|
my $filename= $3;
|
||||||
if($request =~ m,^/([^/]+)/(.*)$,) {
|
my $name;
|
||||||
my $name= $1;
|
|
||||||
my $filename= $2;
|
# get device name
|
||||||
|
$name= $data{FWEXT}{$link}{deviceName} if($data{FWEXT}{$link});
|
||||||
|
|
||||||
|
Debug "link= $link";
|
||||||
|
Debug "filename= $filename";
|
||||||
|
Debug "name= $name";
|
||||||
|
|
||||||
|
# return error if no such device
|
||||||
|
return("text/plain; charset=utf-8", "No HTTPSRV device for $link") unless($name);
|
||||||
|
|
||||||
|
# set directory index
|
||||||
|
$filename= AttrVal($name,"directoryindex","index.html") unless($filename);
|
||||||
my $MIMEtype= filename2MIMEType($filename);
|
my $MIMEtype= filename2MIMEType($filename);
|
||||||
#return("text/plain; charset=utf-8", "HTTPSRV device: $name, filename: $filename, MIME type: $MIMEtype");
|
|
||||||
if(!defined($defs{$name})) {
|
|
||||||
return("text/plain; charset=utf-8", "Unknown HTTPSRV device: $name");
|
|
||||||
}
|
|
||||||
my $directory= $defs{$name}{fhem}{directory};
|
my $directory= $defs{$name}{fhem}{directory};
|
||||||
$filename= "$directory/$filename";
|
$filename= "$directory/$filename";
|
||||||
my @contents;
|
my @contents;
|
||||||
@ -90,12 +123,17 @@ HTTPSRV_CGI(){
|
|||||||
} else {
|
} else {
|
||||||
return("text/plain; charset=utf-8", "File not found: $filename");
|
return("text/plain; charset=utf-8", "File not found: $filename");
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return("text/plain; charset=utf-8", "Illegal request: $request");
|
return("text/plain; charset=utf-8", "Illegal request: $request");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
####
|
####
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
@ -5371,7 +5371,7 @@ To send the data, both send or write could be used.<br>
|
|||||||
<b>Attributes</b>
|
<b>Attributes</b>
|
||||||
<br><br>
|
<br><br>
|
||||||
<ul>
|
<ul>
|
||||||
n/a
|
<li>directoryindex: if the request is sent with no filename, i.e. the infix (with or without trailing slash) only, the file given in this attribute is loaded. Defaults to <code>index.html</code>.</li>
|
||||||
</ul>
|
</ul>
|
||||||
<br><br>
|
<br><br>
|
||||||
|
|
||||||
@ -5381,7 +5381,7 @@ To send the data, both send or write could be used.<br>
|
|||||||
|
|
||||||
The above example on <code>http://hostname:8083/fhem</code> will return the file
|
The above example on <code>http://hostname:8083/fhem</code> will return the file
|
||||||
<code>/usr/share/jsfrontend/foo.html</code> for <code>http://hostname:8083/fhem/jsf/foo.html</code>.
|
<code>/usr/share/jsfrontend/foo.html</code> for <code>http://hostname:8083/fhem/jsf/foo.html</code>.
|
||||||
If no filename is given, <code>index.html</code> is returned.<p>
|
If no filename is given, the filename prescribed by the <code>directoryindex</code> attribute is returned.<p>
|
||||||
|
|
||||||
Notice: All links are relative to <code>http://hostname:8083/fhem</code>.
|
Notice: All links are relative to <code>http://hostname:8083/fhem</code>.
|
||||||
</ul>
|
</ul>
|
||||||
|
Loading…
Reference in New Issue
Block a user