Modul 85_WEBPROXY.pm - Mini-Reverse-Proxy

Begonnen von ThoTo, 10 Juli 2018, 22:58:40

Vorheriges Thema - Nächstes Thema

ThoTo

Hallo,

im Anhang die erste Version eines Moduls das ich aus der Not heraus gebastelt habe um Bilder meiner IP Cams direkt von FHEMWEB ausliefern zu lassen.
Enstanden ist ein Mini-Reverse-Proxy, der über /webproxy/?url= interne URLs annimmt und über FHEM an den Client weitergibt.

Beschreibung:
WEBPROXY

    Module to provide a very simple reverse proxy that retrieves resources on behalf of FHEM from internal sources.
    Useful to proxy surveillance camera images for example and block direct web access to devices behind FHEM.

    Notes:
        This module needs the LWP::UserAgent, HTTP::Request and URI::Escape perl modules.
        WEBPROXY is an extension to FHEMWEB.
        The reverse proxy allows only internal IP addresses as destination.

    Full proxy URL is /webproxy/?url= behind the FHEMWEB base URL. Examples:
        -http://fhemhostname:8083/fhem/webproxy/?url=http://192.168.0.1:1234/webcamimage.jpg
        -For weblink use /fhem/webproxy/?url=http://192.168.0.1:1234/webcamimage.jpg as image path/url.

        Define
            define <name> WEBPROXY

            Defines a WEBPROXY reverse proxy instance - only one instance is allowed.

            Example:
                define webproxy WEBPROXY
        Attributes
            -disable

            -wp_AllowedFrom
            Comma-separated list of IP addresses allowed to use the reverse proxy.
            An empty or undefined list (default) means that all remote IPs are allowed.

            -wp_AllowedTo
            Comma-separated list of internal IP addresses (RFC 1918) the reverse proxy is allowed to connect.
            An empty or undefined list (default) means that all internal IPs are allowed in ?url= parameter.

            -wp_IgnoreContentType
            0: Only content type image is allowed.
            1: All content types are allowed.
            Default is 0.

            -wp_RedirectBlocked
            Behaviour when wp_AllowedFrom/wp_AllowedTo is set and a proxy request is blocked.
            0: The reverse proxy returns 'Forbidden'.
            1: The reverse proxy redirects via 302 to the original ressource.
            Default is 0.

            -wp_RedirectInvalidUrl
            Behaviour when the proxy destination ?url= is invalid or non-private.
            0: The reverse proxy returns 'Forbidden'.
            1: The reverse proxy redirects via 302 to the original ressource.
            Default is 0.

            -wp_Timeout
            Defines the timeout in seconds for retrieving content through the reverse proxy.
            Default is 5.


Mit den Attributen können sowohl die erlaubten Source-IP-Adressen als auch jene IPs festgelegt werden auf die vom Reverse-Proxy im LAN zugegriffen werden darf.
Wird ein Proxy-Aufruf blockiert, wird entweder ein Fehler ausgegeben oder auf die Original-Ressource weitergeleitet, so als ob sie direkt eingebunden wäre.
Im ?url= Parameter dürfen nur private IP-Adressen angegeben werden, keine Hostnamen und keine öffentlichen IPs - das Verhalten bei einem Block kann mit wp_RedirectInvalidUrl gesteuert werden.

Vielleicht hat jemand Verwendung dafür - Wünsche, Anregungen und Beschwerden bitte gerne.

LG Thomas
KNX | MQTT | Docker | Sonos | FHEMapp

"Zwei Dinge sind unendlich, das Universum und die menschliche Dummheit, aber bei dem Universum bin ich mir noch nicht ganz sicher." (Albert Einstein)