mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 06:39:11 +00:00
new module 02_HTTPSRV.pm
git-svn-id: https://svn.fhem.de/fhem/trunk@1815 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
c0aa71ae70
commit
9516b9f95e
102
fhem/FHEM/02_HTTPSRV.pm
Normal file
102
fhem/FHEM/02_HTTPSRV.pm
Normal file
@ -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 <name> HTTPSRV <infix> <directory> <friendlyname>" 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= <INPUTFILE>;
|
||||
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;
|
||||
|
||||
|
||||
|
@ -96,6 +96,7 @@
|
||||
<a href="#FS20">FS20</a>
|
||||
<a href="#HMS">HMS</a>
|
||||
<a href="#HMLAN">HMLAN</a>
|
||||
<a href="#HTTPSRV">HTTPSRV</a>
|
||||
<a href="#IPCAM">IPCAM</a>
|
||||
<a href="#IPWE">IPWE</a>
|
||||
<a href="#IT">IT</a>
|
||||
@ -5296,6 +5297,56 @@ To send the data, both send or write could be used.<br>
|
||||
<br>
|
||||
</ul>
|
||||
|
||||
<a name="HTTPSRV"></a>
|
||||
<h3>HTTPSRV</h3>
|
||||
<ul>
|
||||
Provides a mini HTTP server plugin for FHEMWEB. It serves files from a given directory.<p>
|
||||
|
||||
HTTPSRV is an extension to <a href="HTTPSRV">FHEMWEB</a>. You must install FHEMWEB to use HTTPSRV.</p>
|
||||
|
||||
<a name="HTTPSRVdefine"></a>
|
||||
<b>Define</b>
|
||||
<ul>
|
||||
<code>define <name> <infix> <directory> <friendlyname></code><br><br>
|
||||
|
||||
Defines the HTTP server. <code><infix></code> is the portion behind the FHEMWEB base URL (usually
|
||||
<code>http://hostname:8083/fhem</code>), <code><directory></code> is the absolute path the
|
||||
files are served from, and <code><friendlyname></code> is the name displayed in the side menu of FHEMWEB.<p><p>
|
||||
|
||||
Example:
|
||||
<ul>
|
||||
<code>define myJSFrontend HTTPSRV jsf /usr/share/jsfrontend My little frontend</code><br>
|
||||
</ul>
|
||||
<br>
|
||||
</ul>
|
||||
|
||||
<a name="HTTPSRVset"></a>
|
||||
<b>Set</b>
|
||||
<ul>
|
||||
n/a
|
||||
</ul>
|
||||
<br><br>
|
||||
|
||||
<a name="HTTPSRVattr"></a>
|
||||
<b>Attributes</b>
|
||||
<br><br>
|
||||
<ul>
|
||||
n/a
|
||||
</ul>
|
||||
<br><br>
|
||||
|
||||
<b>Usage information</b>
|
||||
<br><br>
|
||||
<ul>
|
||||
|
||||
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>.
|
||||
If no filename is given, <code>index.html</code> is returned.<p>
|
||||
|
||||
Notice: All links are relative to <code>http://hostname:8083/fhem</code>.
|
||||
</ul>
|
||||
<br><br>
|
||||
|
||||
<a name="USF1000"></a>
|
||||
<h3>USF1000</h3>
|
||||
<ul>
|
||||
|
Loading…
Reference in New Issue
Block a user