core/sysauth: Redirect to https on login page if possible, #317
[project/luci.git] / modules / admin-core / luasrc / view / sysauth.htm
index 8e15fbc..7c39f0d 100644 (file)
@@ -1,7 +1,7 @@
 <%#
 LuCI - Lua Configuration Interface
 Copyright 2008 Steven Barth <steven@midlink.org>
-Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
+Copyright 2008-2012 Jo-Philipp Wich <xm@subsignal.org>
 
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
@@ -9,8 +9,6 @@ You may obtain a copy of the License at
 
        http://www.apache.org/licenses/LICENSE-2.0
 
-$Id$
-
 -%>
 
 <%+header%>
@@ -32,10 +30,10 @@ $Id$
                                        <input class="cbi-input-user" type="text" name="username" value="<%=duser%>" />
                                </div>
                        </div>
-                       <div class="cbi-value">
+                       <div class="cbi-value cbi-value-last">
                                <label class="cbi-value-title"><%:Password%></label>
                                <div class="cbi-value-field">
-                                       <input class="cbi-input-password" type="password" name="password" />
+                                       <input id="focus_password" class="cbi-input-password" type="password" name="password" />
                                </div>
                        </div>
                </fieldset></fieldset>
@@ -46,4 +44,37 @@ $Id$
                <input type="reset" value="<%:Reset%>" class="cbi-button cbi-button-reset" />
        </div>
 </form>
+<script type="text/javascript">//<![CDATA[
+       var input = document.getElementById('focus_password');
+       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%>