Displaying log texts in openhab

Hi
Now I’m a bit confused: The client (the computer displaying the frontend) tries to load the Webview URL??? In my oppinion the openhab server is trying to get the data and send it to the client computer who just did the rendering of the received data. If that is true, it is completly impossible to use the file protocol or the localhost adress, as this must be available on every possible client including smart-phone, -watch, -etc.

Regards
Dieter

My understanding is that the Webview is rendered in an iframe element that loads the content (on the client side) from the URL specified for the widget. I don’t have an easy way to double-check that at the moment.

Ok, in that case I revoke all my postings in this thread :wink:

Indeed that was my fear from the beginning… I’ll simply use the DNS path then and be happy. Thanks for your time!

Hi
That’s probably the best way to do it…

But, nevertheless, it might not solve your problem completly (sorry, but I work in Software Testing and it’s my job to find things that probably won’t work ;-)): When the query is done by your client (e.g. smart-) it is quite sure that this device doesn’t have access to this (LAN) URL when you’re away from home, unless you really make it public to the world and even then you need a public DNS name.
You might give it a try one day…

Regards
Dieter

Yes. For now when I use openhab remotely, I tunnel to my LAN at home, and configure the web browser to use it as a proxy server (possible with Firefox on Android it turns out!). So not really an issue for me.

If I want to make it public I probably want a DNS name for openhab itself, so I could use the same for the file (although then anyone can see the file of course)

Hi!
I’m having a related problem, not regarding the log file function but what is expressed in the later question by ulfwin.

One remaining question: I tried “localhost” instead of the LAN address, but it didn’t find the file. My guess is that localhost is interpreted as the IP of the client, rather than the server. Does anyone know how to solve this? (feels silly to refer to the LAN address when the files are already on the same computer)

My webview content is public through the use of a DDNS service. I can access my Openhab from outside my router, externally, but the DDNS address can’t be resolved while I’m at home on the LAN. After reading some posts on the web I’m positive that this has something to do with lack of possibility to resolve the DDNS address locally, either through a so called loopback by my router (or a static DNS entry in the router ) or perhaps a hosts definition in the Raspberry Os.

For information: I’m running an Apache2 server, on the same Raspberry as the Openhab server, hosting a RPi-web-cam interface and some py-scripts.

Help with this problem is much appreciated!

Hi Niklas

From my understanding: your DNS Server (the router) requests a name and get’s it’s own (public) IP. So it decides not to produce outgoing traffic but to keep the request but, on the other hand, didn’t know what to do with the request as the forwarding rule you have in your router is only relevant for external, incomming traffic…

But the thing I’m wondering is: Are you asking just out of interest or do you really have a problem? Or, asked the other way round, if you don’t have a problem with the log file (content), why would you access your server internal by it’s DDNS name? If there is a problem with the content we’re back to the original problem of Ulf which can not really be solved besides using a VPN access when not at home (my understanding)
Nevertheless an interesstig new idea for “what else can go wrong” and “why this is not such a good idea to do it that way” :wink:

Regards
Dieter

Hi Dieter!

No this is an actual problem for me. As I want to be able to connect to my Openhab away from home I use a DDNS service which means that I’m pointing to this address in my weburl frame. But by doing this I’m unable to reach this content while at home as the DDNS adress is not resolved. My understanding and experience of this is the same as how steve1 explaines it.

One way of solving this could be for me to maintain two sitemaps which are more or less identical with the difference that the “local” sitemap referrs to the local address e.g. 192.168.0.xxx. But this feels like a very inefficient solution as I would need to maintain two sites.

Could I perhaps integrate my Apache2 web content in the sitemap in a different way which uses a more local solution? My thought was that I could “bounce” the DDNS request locally in the Raspberry through a hosts configuration or in my router (dlink dir825). I’ve looked in my router settings and I cant find a relevant option for this.

A VPN connection is of course also an option but that means that other users must also use the VPN. Although I have a Synology NAS so configuring a VPN is interesting for other reasons.

Note: I can reach the Openhab sitemap from my LAN using the local address but the weburl content in the sitemap cant be resolved.

@Frasier I’m probably not understanding the situation completely, but if your LAN router/gateway is configured properly you should be able to resolve any DNS address. DDNS is just referring to a technique of occasionally updating DNS data with a dynamically-assigned IP address.

Are you able to do an nslookup on the LAN for the DDNS hostname? If so, that will give some hints if the problem is some special LAN configuration. Otherwise, are you able to ping the DDNS hostname from the LAN? That will also attempt to resolve the name using DNS and display it.

So I’m clear, you are able to access the webview content from outside your LAN, right? (Just verifying that you have the Apache port open on the gateway.)

I might be referring to DDNS in the wrong way but I roughly understand its funtionality. But still if I’m trying to access a registered DNS address while in the LAN the connection attempt must still first reach a DNS server in order to point back to the accociated IP number and either way I find this step unneccesary as I already know that the host is local. The address lookup time could be a lot less if this step was eliminated in some way. I’ve read Dieters answer once more and perhaps its a matter of forwarding rules, I’ll look into that.

I will investigate using nslookup and ping later when I’m at home. thanks for your patience. And yes outside my LAN I can reach the Apache content.

Hi

I haven’t doubted that you are able to reach your Webview content from the outside. Without the exact protocol knowledge of DNS here is what’s going on when accessing the DNS from LAN:
The DNS Server in your router will query it’s master dns server (usually the dns of your ISP) for the ddns name. That server will return the WAN address of the router itself (Router DNS: “Who has <your>.<ddns>.<domain>”, ISP DNS: “you”). This will bring your router to the point and try to resolve the address by itself. As the internal DNS server goes only for the LAN part (where the router dns server is responsible) but the name belongs to the WAN part it is not able to resolve it if only the domain part does not match.
I’m not sure whether or not it is possible to configure your router to handle <ddns>.<domain> requests as well with his internal dns server and also configure your raspberry to react on these calls (normally yes, but not the standard setting) I can’t say as I haven’t done it myself yet.
As @steve1 just wrote the ddns is “just” dns and the nslookup will quite surely work and probably even the ping will work (in the end you are pinging your router) but with a little inteligence your router will notice that as well and then block itself out…

Regards
Dieter

HI Niklas

In your Post there might be an interesting topic when thinking about it but I don’t know about the implications for Openhab…

Is it possible to call an PHP script on the apache that generates the sitemap (e.g. depending from where you call it, internal or external) and then forward to this address? With this there might be some other nice effects :smile:

But how does Openhab react in that case? Maybe @steve1 could give us a clue as developer?

Regards
Dieter

I’m probably misunderstanding something you are saying, but this part doesn’t sound correct to me. In my experience most home routers/gateways do not do name resolution for the LAN (although it may be possible depending on the router firmware). For example, the only local names that are resolved on my LAN are through mDNS, NetBIOS, local hostname configurations, etc., none of which are router-based.

However, the router may cache WAN addresses as a performance optimization after querying the WAN DNS servers. As @Frasier said, a TCP connection to the WAN (DDNS) address will go through the ISP’s gateway and back to the WAN->LAN router/gateway. The router then may forward the messages to the LAN if port forwarding is enabled. If the port is forwarded, the WAN address is converted to a LAN address using NAT inside the router. At that point the connection proceeds on the LAN side of the router.

Unless one has a very slow or intermittent connection to the ISP, the extra hop from the ISP gateway back to the LAN will not have a significant impact on performance when the information is accessed from the LAN.

The results of nslookup, traceroute or dig should give a definitive indication whether the hostname is being resolved to a LAN or WAN address and at least a hint about why it’s being resolved that way.

I’m not sure, but I think that openhab loads the sitemap file from the file system when a web request is made. I think you may need to modify the openhab web application to dynamically choose a sitemap for LAN vs WAN access. There might be some way to configure the openhab Jetty server to rewrite the request URL depending on the requester’s IP address (LAN or WAN), but this is just a guess.

Hi @steve1

Thank you for your quick answer.

First my thoughts to what @Frasier wrote: I couldn’t agree with you completly that there is no name resolution as I have one here. Reason why I know that if that I had to change all bookmarks on my PC after I’ve moved OH related items to a different subnet in my LAN to use FQDN after getting message “could not resolve name”. But this is just my observation and maybe only in my network and as I’ve said I’m not the protocol expert in this case. As you’ve written we will see the results of the tests but I can’t think of being completly wrong…

For the second part: I’m impressed that you came to a more complicate solution of a non existing problem than I did, only a few people are able to do this ;-). But let me explain: Having thought it over again my idea now is the following. One can create a “template” (call it this way) sitemap as file somewhere. This file is read by a script and that script creates the different versions of the real sitemaps, for example local or remote, also as files in OH sitemap directory. (here was my problem first for that I’ve asked for your help) The script is either called by some trigger (are there file-changed-trigger in Linux?) or online when calling a url on the apache (@Frasier mentioned that). When online generating is done, the client will be forwarded to the normal OH url as you have it on thousands of websites (like: “…you will be forwarded in x seconds, if not click here…”). In any subsequent call or when offline generation is active (“real” sitemap is newer than “template” sitemap) you will be directly forwarded by the apache script by sending http 303/307 return code (temporary redirect, temporary because the browser should not cache the forwarding). So OH will never notice that it is not called directly but using a different server with redirection first.

The benefits of the solution are that you manually still have to deal with only one sitemap (the template), your system is still available on one address (the routing script on the apache) and the routing can be done based on any information available when the script is called, which are a lot. For me it could be interesting to change the sitemap when calling from my computer (24" display) or phone (4" display)…

Regards
Dieter

@steve1, both ping and nslookup were successful in resolving my true IP in 1 ms. I really cant understand this. The behaviour is the same independantly if I try with my DNS hostname or WAN IP address.

From time to time I’ve actually been able to reach my Openhab site from within the LAN pointing at my DNS hostname with my Windows Phone. Although the connection is extremely slow and my PiCam interface updates one frame per like 20s.

I guess this might be router dependant and there are a lot of options in there that might complicate things. Like virtual server, port forwarding (which I use), application rules, Network Filter, Access Control, Routing, Firewall etc. Perhaps my ISP could be effecting things as well.

Perhaps I should try with a different router as a next step.

Not really surprising for me (or, to quote Sheldon Cooper: I told you so ;-)). When you do a tracert you will see that you don’t leave your network.

If I were you, before buying a new router, I would try to configure the raspberry to react on your ddns name. But I don’t know how to do it myself, you might ask google (“linux hostname external” or something similar). Even if that doesn’t work, at least you haven’t spent money. If you really would buy a new router you might look for one that offers a DMZ (or exposed host) port as this is what you are doing here. But I’ve also no idea whether or not they are available for an acceptable price…

Or you implement the solution I’ve described in my last post and when it’s done and working, provide it to me so I don’t have to do it myself :wink:

Regards
Dieter

I solved it finally. As I thought one way of fixing it was to target the router. I was one google search away from a good description of the issue. Serverfault.com : Loopback to forwarded Public IP address from local network - Hairpin NAT

Luckily my dlink router could be fed with a new firmware from dd-wrt.com and after defining my port forward rules everything just works (so far). Apparently the so called NAT loopback functionality is enabled by default. And as a bonus the router firmware seems quite capable!

Thanks @steve1 and @DieterL for your thoughts and suggestions. Hopefully this thread can be of use for someone else as well.

The WAN vs LAN address issue is a router problem, and nothing to do with openhab as such.

I was having a similar problem, as I use my DDNS name everywhere, and port forwarding on my router to map the external ports to my internal ports.

I found a bug in my router firmware (Netgear 7500) where it would fail to resolve the external DNS name when used on the internal LAN - this is supposed to be a feature of this router (some routers don’t do this at all). A later version of firmware fixed this bug, and now my DDNS name resolves correctly whether I’m at home (LAN), or away (WAN). My other router (Netgear 7000) did not have this bug, so it would resolve correctly.

So a router issue/feature -something to look for when shopping for a new router.

I have used DD-WRT firmware before, and it has lots of features, so it’s a good choice for adding features to a router that doesn’t have them built in. It’s not for the faint of heart though! Still if you’re running openhab, you’re probably up for a challenge…

As to displaying log files in openhab -which was how I found this thread - I am trying to do the same thing. I already have a web page that will display any log file (like tail -f), but it’s complicated, and uses web sockets, so I’m not sure if it will work with the webview widget on all platforms.

I was looking at the sitemap list widget (display text broken at delimiter), which may work, I’ll experiment and let you know what works.

Just an update, the List widget doesn’t seem to work at all, but the Webview widget works just fine.

A couple if gotchas, for JavaScript and css file names you have to use the full name (or http address) -doesn’t work with relative names for some reason.

The height variable is important, too large and the page continually refreshes, too small and you can’t see anything. It also isn’t device specific, so you can’t easily switch from browser to iPad to phone. You can manually change the height value (using visibility). I don’t think this parameter is well thought out. Value of 22 is full height on my iPad mini.

I moved my index, css and js files to my Apache2 server sub directory (because of the relative file names issue), and used this URLs for the Webview URL -and it works!

I can now view any of my logs in openhab using my tail web-app.