diff --git a/fhem/FHEM/02_HTTPSRV.pm b/fhem/FHEM/02_HTTPSRV.pm new file mode 100644 index 000000000..960b57dd1 --- /dev/null +++ b/fhem/FHEM/02_HTTPSRV.pm @@ -0,0 +1,102 @@ +# +# +# 02_HTTPSRV.pm +# written by Dr. Boris Neubert 2012-08-27 +# e-mail: omega at online dot de +# +############################################## +# $Id$ + +package main; +use strict; +use warnings; +use vars qw(%data); + + +######################### +sub +HTTPSRV_addExtension($$$) { + my ($func,$link,$friendlyname)= @_; + + my $url = "/" . $link; + $data{FWEXT}{$url}{FUNC} = $func; + $data{FWEXT}{$url}{LINK} = $link; + $data{FWEXT}{$url}{NAME} = $friendlyname; +} + +################## +sub +HTTPSRV_Initialize($) { + my ($hash) = @_; + $hash->{DefFn} = "HTTPSRV_Define"; + #$hash->{AttrFn} = "HTTPSRV_Attr"; + $hash->{AttrList}= "loglevel:0,1,2,3,4,5"; + #$hash->{SetFn} = "HTTPSRV_Set"; + + return undef; + } + +################## +sub +HTTPSRV_Define($$) { + + my ($hash, $def) = @_; + + my @a = split("[ \t]+", $def, 5); + + return "Usage: define HTTPSRV " if(int(@a) != 5); + my $name= $a[0]; + my $infix= $a[2]; + my $directory= $a[3]; + my $friendlyname= $a[4]; + + $hash->{fhem}{infix}= $infix; + $hash->{fhem}{directory}= $directory; + $hash->{fhem}{friendlyname}= $friendlyname; + + HTTPSRV_addExtension("HTTPSRV_CGI", $infix, $friendlyname); + + $hash->{STATE} = $name; + return undef; +} + +################## +# +# here we answer any request to http://host:port/fhem/$infix and below +sub +HTTPSRV_CGI(){ + + my ($request) = @_; # /$infix/filename + + if($request !~ m,^/.+/.*,) { + $request= "$request/index.html"; + } + if($request =~ m,^\/(.*)/(.*)$,) { + my $name= $1; + my $filename= $2; + if(!defined($defs{$name})) { + return("text/plain; charset=utf-8", "Unknown HTTPSRV device: $name"); + } + my $directory= $defs{$name}{fhem}{directory}; + $filename= "$directory/$filename"; + my @contents; + if(open(INPUTFILE, $filename)) { + binmode(INPUTFILE); + @contents= ; + close(INPUTFILE); + return("", join("", @contents)); + } else { + return("text/plain; charset=utf-8", "File not found: $filename"); + } + } else { + return("text/plain; charset=utf-8", "Illegal request: $request"); + } + +} + +#### + +1; + + + diff --git a/fhem/docs/commandref.html b/fhem/docs/commandref.html index c2a4923a8..cfb85a718 100644 --- a/fhem/docs/commandref.html +++ b/fhem/docs/commandref.html @@ -96,6 +96,7 @@ FS20   HMS   HMLAN   + HTTPSRV   IPCAM   IPWE   IT   @@ -5296,6 +5297,56 @@ To send the data, both send or write could be used.

+ +

HTTPSRV

+
    + Provides a mini HTTP server plugin for FHEMWEB. It serves files from a given directory.

    + + HTTPSRV is an extension to FHEMWEB. You must install FHEMWEB to use HTTPSRV.

    + + + Define +
      + define <name> <infix> <directory> <friendlyname>

      + + Defines the HTTP server. <infix> is the portion behind the FHEMWEB base URL (usually + http://hostname:8083/fhem), <directory> is the absolute path the + files are served from, and <friendlyname> is the name displayed in the side menu of FHEMWEB.

      + + Example: +

        + define myJSFrontend HTTPSRV jsf /usr/share/jsfrontend My little frontend
        +
      +
      +
    + + + Set +
      + n/a +
    +

    + + + Attributes +

    +
      + n/a +
    +

    + + Usage information +

    +
      + + The above example on http://hostname:8083/fhem will return the file + /usr/share/jsfrontend/foo.html for http://hostname:8083/fhem/jsf/foo.html. + If no filename is given, index.html is returned.

      + + Notice: All links are relative to http://hostname:8083/fhem. +

    +

    +

    USF1000