I am attempting to embed home-assistant in the openwrt menu system. I can get it working with an iframe, but ran into cors / cross site / http in https issues. To avoid browser security issues and future incompatibilities, I am attempting to load pages from home-assistant (which renders http) , then echo them (as https).
but, it does not, so, I am attempting to use lua in my template (to embed yahoo.com as a simple testcase):
/usr/lib/lua/luci/view/home-assistant_tab.htm:
<%+header%>
<% local http = require("socket.http") %>
<% local body, code = http.request("http://yahoo.com") %>
<% if not body then error("code") end %>
<% print('body',body) %>
<%+footer%>
Result: XML Parsing Error: not well-formed
Questions:
Am I on the right track here?
What is wrong with above template?
Is there a better way to accomplish this?
turns out I was way on the wrong track (attempting to proxy http to https, running into cors issues)
The goal was to embed home-assistant into openwrt menu system. Do this:
configure home-assistant for https, valid certs....
embed it (/usr/lib/lua/luci/view/home-assistant_tab.htm):
<%+header%>
<script type="text/javascript">
function iframeLoaded() {
var iFrameID = document.getElementById('idHomeFrame');
if(iFrameID) {
// here you can make the height, I delete it first, then I make it again
iFrameID.height = "";
iFrameID.height = iFrameID.contentWindow.document.body.scrollHeight + "px";
}
}
</script>
<div style="align: left; width: 85%; height: 100%;">
<%local caller = luci.http.getenv("HTTP_REFERER")%>
<%local callerIP = string.match( caller, '%d+.%d+.%d+.%d+')%>
<iframe id="idHomeFrame" onload="iframeLoaded()" style="position: absolute; width: 85%; height: 100%; border: none;" src="https://<%=callerIP%>:8123"></iframe>
</div>
<%+footer%>