diff options
author | Steven Barth <steven@midlink.org> | 2008-03-30 19:12:16 +0000 |
---|---|---|
committer | Steven Barth <steven@midlink.org> | 2008-03-30 19:12:16 +0000 |
commit | 9b4e269bea4db2e75d3d33757a53d2ab89bf05bf (patch) | |
tree | 0e67237edc84967682aa67eaa9afb61630e56b29 /src | |
parent | eee28047913d9bc159ebc49e72807db413ec73c7 (diff) |
* Added reboot page
* Added SSH-Keys page
* ffluci.template: Removed a debugging statement
Diffstat (limited to 'src')
-rw-r--r-- | src/ffluci/controller/admin/system.lua | 50 | ||||
-rw-r--r-- | src/ffluci/fs.lua | 10 | ||||
-rw-r--r-- | src/ffluci/http.lua | 10 | ||||
-rw-r--r-- | src/ffluci/sys.lua | 21 | ||||
-rw-r--r-- | src/ffluci/template.lua | 21 | ||||
-rw-r--r-- | src/ffluci/view/admin_system/editor.htm | 2 | ||||
-rw-r--r-- | src/ffluci/view/admin_system/passwd.htm | 33 | ||||
-rw-r--r-- | src/ffluci/view/admin_system/reboot.htm | 4 | ||||
-rw-r--r-- | src/ffluci/view/admin_system/sshkeys.htm | 23 |
9 files changed, 136 insertions, 38 deletions
diff --git a/src/ffluci/controller/admin/system.lua b/src/ffluci/controller/admin/system.lua index 5e3204153..455424eb8 100644 --- a/src/ffluci/controller/admin/system.lua +++ b/src/ffluci/controller/admin/system.lua @@ -9,19 +9,21 @@ menu = { descr = "System", order = 20, entries = { - {action = "passwd", descr = "Passwort"}, + {action = "passwd", descr = "Passwort ändern"}, + {action = "sshkeys", descr = "SSH-Schlüssel"}, + {action = "reboot", descr = "Neu starten"}, } } function action_editor() - local file = ffluci.http.formvalue("file") + local file = ffluci.http.formvalue("file", "") local data = ffluci.http.formvalue("data") local err = nil local msg = nil - local stat = nil + local stat = true if file and data then - stat, err = pcall(ffluci.fs.writefile, file, data) + stat, err = ffluci.fs.writefile(file, data) end if not stat then @@ -30,11 +32,9 @@ function action_editor() msg = table.concat(err, " ") end - local stat, cnt = pcall(ffluci.fs.readfile, fname) - if stat and cnt then + local cnt, err = ffluci.fs.readfile(file) + if cnt then cnt = ffluci.util.pcdata(cnt) - else - cnt = nil end ffluci.template.render("admin_system/editor", {fn=file, cnt=cnt, msg=msg}) end @@ -42,12 +42,38 @@ end function action_passwd() local p1 = ffluci.http.formvalue("pwd1") local p2 = ffluci.http.formvalue("pwd2") - local msg = nil - local cm + local stat = nil if p1 or p2 then - msg = ffluci.sys.user.setpasswd("root", p1, p2) + if p1 == p2 then + stat = ffluci.sys.user.setpasswd("root", p1) + else + stat = 10 + end + end + + ffluci.template.render("admin_system/passwd", {stat=stat}) +end + +function action_reboot() + ffluci.template.render("admin_system/reboot") + ffluci.sys.reboot() +end + +function action_sshkeys() + local file = "/etc/dropbear/authorized_keys" + local data = ffluci.http.formvalue("data") + local stat = nil + local err = nil + + if data then + stat, err = ffluci.fs.writefile(file, data) + end + + local cnt = ffluci.fs.readfile(file) + if cnt then + cnt = ffluci.util.pcdata(cnt) end - ffluci.template.render("admin_system/passwd", {msg=msg}) + ffluci.template.render("admin_system/sshkeys", {cnt=cnt, msg=err}) end
\ No newline at end of file diff --git a/src/ffluci/fs.lua b/src/ffluci/fs.lua index e262caa3c..897308c10 100644 --- a/src/ffluci/fs.lua +++ b/src/ffluci/fs.lua @@ -40,7 +40,7 @@ function readfile(filename) local fp, err = io.open(filename) if fp == nil then - error(err) + return nil, err end local data = fp:read("*a") @@ -55,7 +55,7 @@ function readfilel(filename) local data = {} if fp == nil then - error(err) + return nil, err end while true do @@ -71,11 +71,15 @@ end -- Writes given data to a file function writefile(filename, data) local fp, err = io.open(filename, "w") + if fp == nil then - error(err) + return nil, err end + fp:write(data) fp:close() + + return true end -- Returns the file modification date/time of "path" diff --git a/src/ffluci/http.lua b/src/ffluci/http.lua index 81076233b..b7ce92ffa 100644 --- a/src/ffluci/http.lua +++ b/src/ffluci/http.lua @@ -38,20 +38,24 @@ end -- Asks the browser to redirect to "url" -function redirect(url) +function redirect(url, qs) + if qs then + url = url .. "?" .. qs + end + status(302, "Found") print("Location: " .. url .. "\n") end -- Same as redirect but accepts category, module and action for internal use -function request_redirect(category, module, action) +function request_redirect(category, module, action, ...) category = category or "public" module = module or "index" action = action or "index" local pattern = os.getenv("SCRIPT_NAME") .. "/%s/%s/%s" - redirect(pattern:format(category, module, action)) + redirect(pattern:format(category, module, action), ...) end diff --git a/src/ffluci/sys.lua b/src/ffluci/sys.lua index 97a926b0b..532324d4b 100644 --- a/src/ffluci/sys.lua +++ b/src/ffluci/sys.lua @@ -38,6 +38,11 @@ function loadavg() return loadavg:match("^(.-) (.-) (.-) (.-) (.-)$") end +-- Reboots the system +function reboot() + return os.execute("reboot >/dev/null 2>&1") +end + group = {} group.getgroup = posix.getgroup @@ -70,8 +75,16 @@ user = {} user.getuser = posix.getpasswd -- Changes the user password of given user -function user.setpasswd(user, pwd1, pwd2) - local cmd = "(echo '"..pwd1.."';sleep 1;echo '"..pwd2.."')|" - cmd = cmd .. "passwd "..user.." 2>&1" - return ffluci.util.exec(cmd) +function user.setpasswd(user, pwd) + if pwd then + pwd = pwd:gsub("'", "") + end + + if user then + user = user:gsub("'", "") + end + + local cmd = "(echo '"..pwd.."';sleep 1;echo '"..pwd.."')|" + cmd = cmd .. "passwd '"..user.."' >/dev/null 2>&1" + return os.execute(cmd) end
\ No newline at end of file diff --git a/src/ffluci/template.lua b/src/ffluci/template.lua index 2bc015081..52bebbcf4 100644 --- a/src/ffluci/template.lua +++ b/src/ffluci/template.lua @@ -120,10 +120,6 @@ function compile(template) template = string.dump(tf) end - c = c or 1 - ffluci.fs.writefile("/tmp/"..tostring(c), template) - c = c+1 - return template end @@ -179,9 +175,14 @@ function Template.__init__(self, name) -- Build if there is no compiled file or if compiled file is outdated if ((commt == nil) and not (tplmt == nil)) or (not (commt == nil) and not (tplmt == nil) and commt < tplmt) then - local compiled = compile(ffluci.fs.readfile(sourcefile)) - ffluci.fs.writefile(compiledfile, compiled) - self.template, err = loadstring(compiled) + local source + source, err = ffluci.fs.readfile(sourcefile) + + if source then + local compiled = compile(source) + ffluci.fs.writefile(compiledfile, compiled) + self.template, err = loadstring(compiled) + end else self.template, err = loadfile(compiledfile) end @@ -190,7 +191,11 @@ function Template.__init__(self, name) self.template, err = loadfile(self.compiledfile) elseif compiler_mode == "memory" then - self.template, err = loadstring(compile(ffluci.fs.readfile(sourcefile))) + local source + source, err = ffluci.fs.readfile(sourcefile) + if source then + self.template, err = loadstring(compile(source)) + end end diff --git a/src/ffluci/view/admin_system/editor.htm b/src/ffluci/view/admin_system/editor.htm index d4b3302ef..0215c91df 100644 --- a/src/ffluci/view/admin_system/editor.htm +++ b/src/ffluci/view/admin_system/editor.htm @@ -1,7 +1,7 @@ <%+header%> <h1><%:texteditor Texteditor%></h1> <form method="post" action="<%=controller%>/admin/system/editor"> -<div><%:file Datei%>: <input type="text" name="file" size="30" value="<%=fn%>" /> +<div><%:file Datei%>: <input type="text" name="file" size="30" value="<%=(fn or '')%>" /> <% if msg then %><span class="error"><%:error Fehler%>: <%=msg%></span><% end %></div> <br /> <div><textarea style="width: 100%" rows="20" name="data"><%=(cnt or '')%></textarea></div> diff --git a/src/ffluci/view/admin_system/passwd.htm b/src/ffluci/view/admin_system/passwd.htm index 3458fef92..441753d83 100644 --- a/src/ffluci/view/admin_system/passwd.htm +++ b/src/ffluci/view/admin_system/passwd.htm @@ -1,14 +1,33 @@ <%+header%> <h1><%:system System%></h1> -<h2><%:changepw Passwort ändern%></h2> +<h2><%:passwd Passwort ändern%></h2> <div><br /> -<% if msg then %> - <code><%=msg%></code> -<% else %> +<% if stat then %> + <% if stat == 0 then %> + <code><%:password_changed Passwort erfolgreich geändert!%></code> + <% elseif stat == 10 then %> + <code class="error"><%:password_nomatch Passwörter stimmen nicht überein! %></code> + <% else %> + <code class="error"><%:unknown_error Unbekannter Fehler!%></code> + <% end %> +<% end %> +<% if not stat or stat == 10 then %> <form method="post" action="<%=controller%>/admin/system/passwd"> - <input type="password" name="pwd1" /> <%:password Passwort%><br /> - <input type="password" name="pwd2" /> <%:confirmation Bestätigung%><br /> - <input type="submit" value="<%:save Speichern%>" /> + <fieldset class="cbi-section-node"> + <div class="cbi-value clear"> + <div class="cbi-value-title left"><%:password Passwort%></div> + <div class="cbi-value-field"><input type="password" name="pwd1" /></div> + </div> + <div class="cbi-value clear"> + <div class="cbi-value-title left"><%:confirmation Bestätigung%></div> + <div class="cbi-value-field"><input type="password" name="pwd2" /></div> + </div> + <br /> + <div> + <input type="submit" value="<%:save Speichern%>" /> + <input type="reset" value="<%:reset Zurücksetzen%>" /> + </div> + </fieldset> </form> <% end %> </div> diff --git a/src/ffluci/view/admin_system/reboot.htm b/src/ffluci/view/admin_system/reboot.htm new file mode 100644 index 000000000..a81464409 --- /dev/null +++ b/src/ffluci/view/admin_system/reboot.htm @@ -0,0 +1,4 @@ +<%+header%> +<h1><%:system System%></h1> +<h2><%:reboot Neu starten%></h2> +<%+footer%>
\ No newline at end of file diff --git a/src/ffluci/view/admin_system/sshkeys.htm b/src/ffluci/view/admin_system/sshkeys.htm new file mode 100644 index 000000000..1e1cc24ce --- /dev/null +++ b/src/ffluci/view/admin_system/sshkeys.htm @@ -0,0 +1,23 @@ +<%+header%> +<h1><%:system System%></h1> +<h2><%:sshkeys SSH-Schlüssel%></h2> + +<br /> + +<div><%:sshkeys_descr Hier können öffentliche SSH-Schlüssel (einer pro Zeile) + zur Authentifizierung abgelegt werden.%></div> + +<br /> + +<form method="post" action="<%=controller%>/admin/system/sshkeys"> + <fieldset class="cbi-section-node"> + <div><textarea style="width: 100%" rows="10" name="data"><%=(cnt or '')%></textarea></div> + <br /> + <div> + <input type="submit" value="<%:save Speichern%>" /> + <input type="reset" value="<%:reset Zurücksetzen%>" /> + </div> + <% if msg then %><br /><div class="error"><%:error Fehler%>: <%=msg%></div><% end %> + </fieldset> +</form> +<%+footer%>
\ No newline at end of file |