Fixed login form
authorSteven Barth <steven@midlink.org>
Thu, 14 Aug 2008 16:11:49 +0000 (16:11 +0000)
committerSteven Barth <steven@midlink.org>
Thu, 14 Aug 2008 16:11:49 +0000 (16:11 +0000)
Converted SSH-Keys to CBI-Map

libs/cbi/luasrc/cbi.lua
libs/cbi/luasrc/view/cbi/full_valuefooter.htm
libs/cbi/luasrc/view/cbi/full_valueheader.htm
libs/cbi/luasrc/view/cbi/simpleform.htm
libs/cbi/luasrc/view/cbi/tvalue.htm
modules/admin-core/luasrc/view/sysauth.htm
modules/admin-full/luasrc/controller/admin/system.lua
modules/admin-full/luasrc/model/cbi/admin_system/sshkeys.lua [new file with mode: 0644]
modules/admin-full/luasrc/view/admin_system/sshkeys.htm [deleted file]

index f7725c53488b49868c424167a6856387a92b0a13..399f486752d65c05a839a62339672ffdf43da9d5 100644 (file)
@@ -268,7 +268,7 @@ function SimpleForm.parse(self, ...)
                or valid and 1
                or -1
 
-       self.dorender = self:handle(state)
+       self.dorender = self:handle(state, self.data)
 end
 
 function SimpleForm.render(self, ...)
index 8933016d7d3d77865bf5f3749f5a1620f012c565..a5a6046a5a896dd4594240cb91b3464e0886fe42 100644 (file)
@@ -17,7 +17,9 @@ $Id$
                        <span class="cbi-value-helpicon"><img src="<%=resource%>/cbi/help.gif" alt="<%:help%>" /></span>
                        <div class="cbi-value-description"><%=self.description%></div>
                <%- end %>
+       <%- if self.title and #self.title > 0 then -%>
        </div>
+       <%- end -%>
 
        <% if self.tag_invalid[section] then -%>
                <div class="cbi-error"><%:cbi_invalid%></div>
index 5b890ed0beda5881c844fe8b41f9aa6ba560b750..ddc256dc72672259fdcb80144b241e296228f0bf 100644 (file)
@@ -14,9 +14,11 @@ $Id$
 -%>
 
 <div class="cbi-value" id="cbi-<%=self.config.."-"..section.."-"..self.option%>">
+       <%- if self.title and #self.title > 0 then -%>
        <label class="cbi-value-title"<%= attr("for", cbid) %>>
        <%- if self.titleref then -%><a title="<%=self.titledesc or translate('cbi_gorel')%>" class="cbi-title-ref" href="<%=self.titleref%>"><%- end -%>
                <%-=self.title-%>
        <%- if self.titleref then -%></a><%- end -%>
        </label>
                <div class="cbi-value-field">
+       <%- end -%>
index 38df61b5f919e64b339385e6a592666dd1b78f63..68c8cc91694a5525711b1bf23aaa1f02e0c7b824 100644 (file)
@@ -17,7 +17,6 @@ $Id$
        <div>
                <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
                <input type="hidden" name="cbi.submit" value="1" />
-               <input type="submit" value="<%:save%>" class="hidden" />
        </div>
        <div class="cbi-map" id="cbi-<%=self.config%>">
                <h1><%=self.title%></h1>
@@ -32,12 +31,12 @@ $Id$
        </div>
        <div>
 <%- if self.submit ~= false then %>
-               <input type="submit" value="
+               <input class="cbi-button-save" type="submit" value="
        <%- if not self.submit then -%><%-:submit-%><%-else-%><%=self.submit%><%end%>
        " />
 <% end %>
 <%- if self.reset ~= false then %>
-               <input type="reset" value="
+               <input class="cbi-button-reset" type="reset" value="
        <%- if not self.reset then -%><%-:reset-%><%-else-%><%=self.reset%><%end%>
        " />
 <% end %>
index 6a1396886c9d27bdf18d65fa572763526064ffc1..4d92545ae0bdc18e21e789f1b68f41dbd9647bf4 100644 (file)
@@ -13,7 +13,7 @@ $Id$
 
 -%>
 <%+cbi/valueheader%>
-       <textarea onchange="cbi_d_update(this.id)"<%= attr("name", cbid) .. attr("id", cbid) .. ifattr(self.size, "cols") .. ifattr(self.rows, "rows") .. ifattr(self.wrap, "wrap") %>>
+       <textarea<% if not self.size then %> style="width: 100%"<% else %> cols="<%=self.size%>"<% end %> onchange="cbi_d_update(this.id)"<%= attr("name", cbid) .. attr("id", cbid) .. ifattr(self.rows, "rows") .. ifattr(self.wrap, "wrap") %>>
        <%-=luci.util.pcdata(self:cfgvalue(section))-%>
        </textarea>
 <%+cbi/valuefooter%>
index 236ec7e6a733597540048eefec0813008d131252..e48f414c566ba138e437c06dbbcd1cade5bce7db 100644 (file)
@@ -14,27 +14,36 @@ $Id$
 -%>
 <%+header%>
 <% luci.i18n.loadc("sysauth") %>
-<h1><%:sysauth_head%></h1>
-<p><%:sysauth_prompt%></p>
-<% if fuser then %>
-<div class="error"><%:sysauth_failed%></div>
-<br />
-<% end %>
+
 <form method="post" action="<%=REQUEST_URI%>">
-               <div class="cbi-section-node">
+       <div class="cbi-map">
+               <h1><%:sysauth_head%></h1>
+               <div class="cbi-map-descr">
+                       <%:sysauth_prompt%>
+                       <%- if fuser then %>
+                       <div class="error"><%:sysauth_failed%></div>
+                       <br />
+                       <% end -%>
+               </div>
+               <fieldset class="cbi-section"><fieldset class="cbi-section-node">
                        <div class="cbi-value">
-                               <div class="cbi-value-title"><%:username%></div>
-                               <div class="cbi-value-field"><input class="cbi-input-user" type="text" name="username" value="<%=duser%>" /></div>
+                               <label class="cbi-value-title"><%:username%></label>
+                               <div class="cbi-value-field">
+                                       <input class="cbi-input-user" type="text" name="username" value="<%=duser%>" />
+                               </div>
                        </div>
                        <div class="cbi-value">
-                               <div class="cbi-value-title"><%:password%></div>
-                               <div class="cbi-value-field"><input class="cbi-input-key" type="password" name="password" /></div>
+                               <label class="cbi-value-title"><%:password%></label>
+                               <div class="cbi-value-field">
+                                       <input class="cbi-input-key" type="password" name="password" />
+                               </div>
                        </div>
-                       <br />
-                       <div>
-                               <input type="submit" class="cbi-button cbi-button-apply" value="<%:login%>" />
-                               <input type="reset" class="cbi-button cbi-button-reset" value="<%:reset%>" />
-                       </div>
-               </div>
+               </fieldset></fieldset>
+       </div>
+
+       <div>
+               <input type="submit" value="<%:login%>" class="cbi-button cbi-button-apply" />
+               <input type="reset" value="<%:reset%>" class="cbi-button cbi-button-reset" />
+       </div>
 </form>
 <%+footer%>
\ No newline at end of file
index fec652699125ca052d39ce7ff52167c23d5684a0..cf39483cfb5bdd479cfd2f60676330cfe8b5b9b4 100644 (file)
@@ -21,7 +21,7 @@ function index()
        entry({"admin", "system", "packages"}, call("action_packages"), i18n("a_s_packages"), 10)
        entry({"admin", "system", "packages", "ipkg"}, call("action_ipkg"), i18n("a_s_p_ipkg"))
        entry({"admin", "system", "passwd"}, call("action_passwd"), i18n("a_s_changepw"), 20)
-       entry({"admin", "system", "sshkeys"}, call("action_sshkeys"), i18n("a_s_sshkeys"), 30)
+       entry({"admin", "system", "sshkeys"}, form("admin_system/sshkeys"), i18n("a_s_sshkeys"), 30)
        entry({"admin", "system", "system"}, cbi("admin_system/system"), i18n("system"), 40)
        entry({"admin", "system", "fstab"}, cbi("admin_system/fstab"), i18n("a_s_fstab"), 50)
        entry({"admin", "system", "leds"}, cbi("admin_system/leds"), i18n("leds", "LEDs"), 60)
@@ -220,24 +220,6 @@ function action_reboot()
        end
 end
 
-function action_sshkeys()
-       local file = "/etc/dropbear/authorized_keys"
-       local data = luci.http.formvalue("data")
-       local stat = nil
-       local err  = nil
-       
-       if data then
-               stat, err = luci.fs.writefile(file, data)
-       end     
-       
-       local cnt  = luci.fs.readfile(file)     
-       if cnt then
-               cnt = luci.util.pcdata(cnt)
-       end
-       
-       luci.template.render("admin_system/sshkeys", {cnt=cnt, msg=err})        
-end
-
 function action_upgrade()
        require("luci.model.uci")
 
diff --git a/modules/admin-full/luasrc/model/cbi/admin_system/sshkeys.lua b/modules/admin-full/luasrc/model/cbi/admin_system/sshkeys.lua
new file mode 100644 (file)
index 0000000..a204d42
--- /dev/null
@@ -0,0 +1,34 @@
+--[[
+LuCI - Lua Configuration Interface
+
+Copyright 2008 Steven Barth <steven@midlink.org>
+Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+$Id$
+]]--
+local keyfile = "/etc/dropbear/authorized_keys" 
+
+f = SimpleForm("sshkeys", translate("a_s_sshkeys"), translate("a_s_sshkeys1"))
+
+t = f:field(TextValue, "keys")
+t.rows = 10
+function t.cfgvalue()
+       return luci.fs.readfile(keyfile) or ""
+end
+
+function f.handle(self, state, data)
+       if state == FORM_VALID then
+               if (luci.fs.readfile(keyfile) or "") ~= data.keys then
+                       luci.fs.writefile(keyfile, data.keys)
+               end
+       end
+       return true
+end
+
+return f
\ No newline at end of file
diff --git a/modules/admin-full/luasrc/view/admin_system/sshkeys.htm b/modules/admin-full/luasrc/view/admin_system/sshkeys.htm
deleted file mode 100644 (file)
index 7b63609..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-<%#
-LuCI - Lua Configuration Interface
-Copyright 2008 Steven Barth <steven@midlink.org>
-Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-$Id$
-
--%>
-
-<%+header%>
-
-<form method="post" action="<%=controller%>/admin/system/sshkeys">
-       <div class="cbi-map">
-               <h1><%:a_s_sshkeys%></h1>
-               <div class="cbi-map-descr">
-                       <%:a_s_sshkeys1%>
-               </div>
-               <fieldset class="cbi-section">
-                       <legend><%:a_s_sshkeys%></legend>
-                       <textarea style="width: 100%" rows="10" name="data" wrap="off"><%=cnt%></textarea>
-                       <% if msg then -%>
-                               <div class="cbi-error"><%:error%>: <%=msg%></div>
-                       <% end %>
-               </fieldset>
-       </div>
-
-       <div>
-               <input type="submit" value="<%:save%>" class="cbi-button cbi-button-save" />
-               <input type="reset" value="<%:reset%>" class="cbi-button cbi-button-reset" />
-       </div>
-</form>
-
-<%+footer%>