openhab / openhab-android

openHAB client for Android
https://play.google.com/store/apps/details?id=org.openhab.habdroid
Eclipse Public License 2.0
599 stars 315 forks source link

Wrong URL for loading sitemap via rest on own openhab-cloud in same local network #3152

Open cinemarene opened 1 year ago

cinemarene commented 1 year ago

Hello everyone,

i maybe found a bug, but I can not fix it myself.

Some Infos: I use the latest android app version. I also want to use my own openhab-cloud. The cloud is in the same (local) network like my openhab server. The cloud accessable via subdomain:port => myopenhab.xyz.de:1234 and the "home" part is accessable via home.myopenhab.xyz.de:1234.

Everything works so far, but not loading sitemaps in the app. The App also shows the sitemap-list on the left menu and i control the light via widgets, so the connection is ok.

In the app-log there is an entry: okhttp.OkHttpClient: <-- 404 Not Found https://home.xyz.de/rest/sitemaps/wohnung/wohnung?includeHidden=true

So, the app tries to connect to home.xyz.de (without port) and should connect to home.myopenhab.xyz.de:1234. My problem is, that i used home.xyz.de for something else for years now. So i can not use home.xyz.de.

Is this behavior normal or is there something wrong? Can anybody help please? Thanks a lot.

mueller-ma commented 1 year ago

Do you use a reverse proxy? If so please post its configuration file.

cinemarene commented 1 year ago

https://pastebin.com/826irccv https://pastebin.com/cfMKcQrT

I tried with these two nginx configs for reverse proxy.

mueller-ma commented 1 year ago

The config seems ok so far. You can try to:

  1. Compare your config with https://www.openhab.org/docs/installation/reverse-proxy.html or
  2. Update the domain to something without myopenhab in it, e.g. my-openhab.xyz.de:1234. There's some special handling for the official myopenHAB server and maybe this causes these issues. Also see #3147
cinemarene commented 1 year ago
  1. I double checkt everything.
  2. I already tried this.

Any other ideas?

cinemarene commented 1 year ago

I decided to test it without subdomain but still using port. But the same problem occured. Domain: xyz.de:1234 and home.xyz.de:1234. The Sitemaps in the side navigation are showing up. The Logfile shows the loading of the sitemaps, but also that it is not possible to load the selected sitemap. But while trying to load the sitemap, there is no port and then the Fragment shows 404 error message.

ServerConfiguration: load: ServerConfiguration(id=1, name=XXXXXX, localPath=ServerPath(url=https://<openhab-local-address-XXXXXX>/, userName=<none>, password=<none>), remotePath=ServerPath(url=https://<openhab-remote-address-XXXXXX>:1234/, userName=<redacted>, password=<redacted>), sslClientCert=null, defaultSitemap=DefaultSitemap(name=wohnung, label=Wohnung), wifiSsids=[XXXXXX], restrictToWifiSsids=true) ServerProperties: Server returned sitemaps: [Sitemap(name=openweather, label=OpenWeatherMapOneCall, icon=null, homepageLink=http://<openhab-remote-address-XXXXXX>/rest/sitemaps/openweather/openweather), Sitemap(name=zdebug, label=Z-Debug, icon=null, homepageLink=http://<openhab-remote-address-XXXXXX>/rest/sitemaps/zdebug/zdebug), Sitemap(name=wohnung, label=Wohnung, icon=null, homepageLink=http://<openhab-remote-address-XXXXXX>/rest/sitemaps/wohnung/wohnung), Sitemap(name=tanken, label=Tanken, icon=null, homepageLink=http://<openhab-remote-address-XXXXXX>/rest/sitemaps/tanken/tanken)] MainActivity: Configured sitemap is 'wohnung', selected Sitemap(name=wohnung, label=Wohnung, icon=null, homepageLink=http://<openhab-remote-address-XXXXXX>/rest/sitemaps/wohnung/wohnung) ContentController: Opening sitemap Sitemap(name=wohnung, label=Wohnung, icon=null, homepageLink=http://<openhab-remote-address-XXXXXX>/rest/sitemaps/wohnung/wohnung) (current: null) PageConnectionHolderFragment: Creating new handler for URL http://<openhab-remote-address-XXXXXX>/rest/sitemaps/wohnung/wohnung PageConnectionHolderFragment: Loading data for http://<openhab-remote-address-XXXXXX>/rest/sitemaps/wohnung/wohnung, long polling false PageConnectionHolderFragment: Data load for http://<openhab-remote-address-XXXXXX>/rest/sitemaps/wohnung/wohnung failed

cinemarene commented 1 year ago

Got it to work. Here is what I found out.

  1. the openhab-cloud has in the routing in "routes/index.js" a line with the content "delete requestHeaders['x-forwarded-proto'];", which in the rest API caused the https protocol in the json-url to always be http. So I commented out this line.

  2. for the location parts within the servers for myopenhab.xyz.de and home.myopenhab.xyz.de in the nginx config, i added: "proxy_set_header X-Forwarded-Host "myopenhab.xyz.de:1234";" and "proxy_set_header X-Forwarded-Host "home.myopenhab.xyz.de:1234";"

  3. for the two server parts in the nginx config I added the following for each: "error_page 497 301 =307 https://myopenhab.xyz.de:1234$request_uri;" and "error_page 497 301 =307 https://home.myopenhab.xyz.de:1234$request_uri;"