core/sysauth: Redirect to https on login page if possible, #317
authorManuel Munz <freifunk@somakoma.de>
Tue, 3 Sep 2013 17:40:55 +0000 (17:40 +0000)
committerManuel Munz <freifunk@somakoma.de>
Tue, 3 Sep 2013 17:40:55 +0000 (17:40 +0000)
modules/admin-core/luasrc/view/sysauth.htm

index 8c4b19c7c8884ad6188f1744953e5341ec46df3d..7c39f0da518d0d1dd218ec0189f58187d97e522f 100644 (file)
@@ -9,8 +9,6 @@ You may obtain a copy of the License at
 
        http://www.apache.org/licenses/LICENSE-2.0
 
-$Id$
-
 -%>
 
 <%+header%>
@@ -51,4 +49,32 @@ $Id$
        if (input)
                input.focus();
 //]]></script>
+
+<%
+local uci  = require "luci.model.uci".cursor()
+local fs  = require "nixio.fs"
+local https_key = uci:get("uhttpd", "main", "key")
+local https_port = uci:get("uhttpd", "main", "listen_https")
+if type(https_port) == "table" then
+       https_port = https_port[1]
+end
+
+if https_port and fs.access(https_key) then
+       https_port = https_port:match("(%d+)$")
+%>
+
+<script type="text/javascript">//<![CDATA[
+       if (document.location.protocol != 'https:') {
+               var url = 'https://' + window.location.hostname + ':' + '<%=https_port%>' + window.location.pathname;
+               var img=new Image;
+               img.onload=function(){window.location = url};
+               img.src='https://' + window.location.hostname + ':' + '<%=https_port%>' + '<%=resource%>/cbi/up.gif?' + Math.random();;
+               setTimeout(function(){
+                       img.src=''
+               }, 5000);
+       }
+//]]></script>
+
+<% end %>
+
 <%+footer%>