WEB, WEBphone und WEBtablet unter selber domain und port anbieten

Begonnen von Solero, 05 Januar 2016, 11:47:34

Vorheriges Thema - Nächstes Thema

Solero

Hallo,

ich schicke fhem durch einen apachen, der die Authentifizierung übernimmt und fhem im inet per https anbietet.
Folgendes möchte ich nun umsetzen:

  • alle Oberflächen erreichbar unter derselben domain. KEINE separaten subdomains
  • alle Oberflächen erreichbar unter demselben port
  • Unterscheidung ausschließlich über den pfad

Da ich ein startcom ssl Zertifikat habe, kann und will ich nicht auf subdomains ausweichen. Unterschiedliche Ports halte ich für hässlich. https hat über Port 443 zu laufen.
Mein bisheriges setup bietet mir unter domain.com/fhem, domain.com/fhem-alt/phone und domain.com/fhem-alt/tablet die diversen Oberflächen mit mehr oder minder großen Einschränkungen.
Die Desktop und Phone Oberfläche läuft, abgesehen davon, dass bei mir 99_myUtils.pm falsch angezeigt wird, fehlerfrei.
Bei Tablet wollen die Links aus der Navigation links nicht so wie ich und springen immer auf /fhem.

In meinem Wunschszenario bietet fhem von sich aus die möglichkeit pro Oberfläche den Pfad festzulegen und ist nicht auf '/fhem' hardgecodet.
Alternativ wird die Apachekonfiguration hier mit ProxyHTMLLinks etc optimiert, da sie so eben noch nicht optimal ist.

Ich poste mal meine Konfiguration, vielleicht sieht es der ein oder andere als Anregung und hat noch eine tolle Idee.

        ProxyHTMLExtended On
        ProxyHTMLLinks  a               href
        ProxyHTMLLinks  area            href
        ProxyHTMLLinks  link            href
        ProxyHTMLLinks  img             src longdesc usemap
        ProxyHTMLLinks  object          classid codebase data usemap
        ProxyHTMLLinks  q               cite
        ProxyHTMLLinks  blockquote      cite
        ProxyHTMLLinks  ins             cite
        ProxyHTMLLinks  del             cite
        ProxyHTMLLinks  form            action
        ProxyHTMLLinks  input           src usemap
        ProxyHTMLLinks  head            profile
        ProxyHTMLLinks  base            href
        ProxyHTMLLinks  script          src for
        ProxyHTMLLinks  option          value
        ProxyHTMLLinks  select          onchange
               
        ProxyRequests Off
        <Proxy *>
                Order deny,allow
                Deny from all
        </Proxy>
        <ProxyMatch (server1|server2\.com|localhost|127.0.0.1)>
                Order deny,allow
                Allow from all
        </ProxyMatch>
       
        <Location /fhem>
                AuthType Basic
                AuthName "User"
                AuthBasicProvider external
                AuthExternal pwauth
                require user user1 user2 user3
                ProxyPass http://localhost:8083/fhem
                ProxyPassReverse http://localhost:8083/fhem
                ProxyPassReverse /fhem
                SetOutputFilter proxy-html
                RequestHeader   unset   Accept-Encoding
        </Location>

        <Location /fhem-alt/phone>     
                AuthType Basic         
                AuthName "User"         
                AuthBasicProvider external
                AuthExternal pwauth
                require user user1 user2
                ProxyPass http://localhost:8084/fhem
                ProxyPassReverse http://localhost:8084/fhem
                ProxyPassReverse /fhem-alt/phone
                SetOutputFilter proxy-html
                ProxyHTMLURLMap /fhem /fhem-alt/phone
                ProxyHTMLURLMap /fhem-alt/phone /fhem-alt/phone
                RequestHeader   unset   Accept-Encoding
        </Location>
       
        <Location /fhem-alt/tab>
                AuthType Basic
                AuthName "User"
                AuthBasicProvider external
                AuthExternal pwauth
                require user user1 user2
                ProxyPass http://localhost:8085/fhem
                ProxyPassReverse http://localhost:8085/fhem
                ProxyPassReverse /fhem-alt/tab
                SetOutputFilter proxy-html
                ProxyHTMLURLMap /fhem /fhem-alt/tab
                ProxyHTMLURLMap /fhem-alt/tab /fhem-alt/tab
                RequestHeader   unset   Accept-Encoding
        </Location>
        AddExternalAuth pwauth /usr/sbin/pwauth
        SetExternalAuthMethod pwauth pipe
RaspberryPi 4 (4GB) mit Raspbian und FHEM als Docker-Container; Homematic, CCU3, HM-LC-Dim1TPBU-FM, HM-LC-Sw1PBU-FM, HM-ES-PMSw1-Pl, HM-SEC-SD-2; Z-Wave, ZME_UZB1, FGRM222; CUL; Enocean, TCM_ESP3, PTM-215, Tasmota

rapster

Schaut komisch aus was du da gebaut hast :-)

Ich hab dir mal einen vereinfachten Ausschnitt meines apache-vhost angehangen der das übernimmt.

der macht i.M.
- Form-Auth bei https://fhem.domain.tld/
- Basic-Auth bei https://fhem.domain.tld/app
- Basic-Auth bei https://fhem.domain.tld/fhem/geo
- Leitet iPhones automatisch auf eine eigene FHEMWEB Instanz um.

Sind jeweils (insgesamt 3) eigene FHEMWEB Instanzen.

Evtl. kannst du dir da ja das benötigte rausziehen :-)

<VirtualHost *:80>
        RewriteEngine On
        RewriteCond %{HTTPS} off
        RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}  [L]
</VirtualHost>

<VirtualHost *:443>
        DocumentRoot /opt/fhem/apache.www

    <Directory /opt/fhem/apache.www>
                Options FollowSymLinks
                AllowOverride None
                Require all granted
    </Directory>

    SSLEngine on
    SSLProxyEngine on

   
### Default proxy / authentication
<ProxyMatch ^https?://[^/]+(?!(/fhem/geo|/app))(/.*)?$ >
                AuthFormProvider file
                AuthType form
                AuthName "FHEM/fhem"
                Session On
                SessionCookieName session path=/
                SessionCryptoPassphrase XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
                SessionCryptoCipher aes256
                require valid-user
                # login page and credentials
                ErrorDocument 401 /login/login.html
                AuthUserFile "/opt/fhem/apache.htpasswd"
</ProxyMatch>

<ProxyMatch ^https?://[^/]+/fhem/geo$ >
                AuthType Basic
                AuthName "FHEM/fhem/geo"
                AuthUserfile "/opt/fhem/apache.htpasswd"
                Require valid-user
        </ProxyMatch>

<ProxyMatch ^https?://[^/]+/app >
                AuthType Basic
                AuthName "FHEM/app"
                AuthUserfile "/opt/fhem/apache.htpasswd"
                Require valid-user
        </ProxyMatch>

        RewriteEngine On
# Proxy for /app
        RewriteCond %{REQUEST_URI} ^/app.*
        RewriteCond %{REQUEST_URI} !^/login/login.html$
        RewriteRule (.*) http://127.0.0.1:8085%{REQUEST_URI} [P,END]
        # Proxy for iPhone
        RewriteCond %{HTTP_USER_AGENT} .*iPhone.* [NC]
        RewriteCond %{REQUEST_URI} !^/login/login.html$
        RewriteRule (.*) http://127.0.0.1:8084%{REQUEST_URI} [P,END]
        # Default Proxy
        RewriteCond %{REQUEST_URI} !^/login/login.html$
        RewriteRule (.*) http://127.0.0.1:8083%{REQUEST_URI} [P,END]

        ProxyPassReverse / http://127.0.0.1:8083
        ProxyPassReverse / http://127.0.0.1:8084
        ProxyPassReverse / http://127.0.0.1:8085
</VirtualHost>