* Added reboot page
authorSteven Barth <steven@midlink.org>
Sun, 30 Mar 2008 19:12:16 +0000 (19:12 +0000)
committerSteven Barth <steven@midlink.org>
Sun, 30 Mar 2008 19:12:16 +0000 (19:12 +0000)
* Added SSH-Keys page
* ffluci.template: Removed a debugging statement

src/ffluci/controller/admin/system.lua
src/ffluci/fs.lua
src/ffluci/http.lua
src/ffluci/sys.lua
src/ffluci/template.lua
src/ffluci/view/admin_system/editor.htm
src/ffluci/view/admin_system/passwd.htm
src/ffluci/view/admin_system/reboot.htm [new file with mode: 0644]
src/ffluci/view/admin_system/sshkeys.htm [new file with mode: 0644]

index 5e32041538af2bfc428e7c5971045f99343d6498..455424eb8af7c9ae0943a7ae0994538f393c82cc 100644 (file)
@@ -9,19 +9,21 @@ menu = {
        descr   = "System",
        order   = 20,
        entries = {
        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()
        }
 }
 
 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 data = ffluci.http.formvalue("data")
        local err  = nil
        local msg  = nil
-       local stat = nil
+       local stat = true
        
        if file and data then
        
        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
        end
        
        if not stat then
@@ -30,11 +32,9 @@ function action_editor()
                msg = table.concat(err, " ")
        end
        
                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)
                cnt = ffluci.util.pcdata(cnt)
-       else
-               cnt = nil
        end
        ffluci.template.render("admin_system/editor", {fn=file, cnt=cnt, msg=msg})      
 end
        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")
 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
        
        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
        
        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
 end
\ No newline at end of file
index e262caa3c3fd3bc4d9bf39a86c1d704577cd1a0c..897308c105428d8ea139c4ae1973fe6f8db948d3 100644 (file)
@@ -40,7 +40,7 @@ function readfile(filename)
        local fp, err = io.open(filename)
        
        if fp == nil then
        local fp, err = io.open(filename)
        
        if fp == nil then
-               error(err)
+               return nil, err
        end
        
        local data = fp:read("*a")
        end
        
        local data = fp:read("*a")
@@ -55,7 +55,7 @@ function readfilel(filename)
        local data = {}
                
        if fp == nil then
        local data = {}
                
        if fp == nil then
-               error(err)
+               return nil, err
        end
        
        while true do
        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")
 -- Writes given data to a file
 function writefile(filename, data)
        local fp, err = io.open(filename, "w")
+       
        if fp == nil then
        if fp == nil then
-               error(err)
+               return nil, err
        end
        end
+       
        fp:write(data)
        fp:close()
        fp:write(data)
        fp:close()
+       
+       return true
 end
 
 -- Returns the file modification date/time of "path"
 end
 
 -- Returns the file modification date/time of "path"
index 81076233b9967044dc45c4d4b22c74e16d40ed37..b7ce92ffab2a79249445a1b408045a242bfb799f 100644 (file)
@@ -38,20 +38,24 @@ end
 
 
 -- Asks the browser to redirect to "url"
 
 
 -- 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
        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"
        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
 
 
 end
 
 
index 97a926b0b1bc2320e35b2bc8782b3781d2fd8347..532324d4bd05354154a518d92d6bb795a4ed91d7 100644 (file)
@@ -38,6 +38,11 @@ function loadavg()
        return loadavg:match("^(.-) (.-) (.-) (.-) (.-)$")
 end
 
        return loadavg:match("^(.-) (.-) (.-) (.-) (.-)$")
 end
 
+-- Reboots the system
+function reboot()
+       return os.execute("reboot >/dev/null 2>&1")
+end
+
 
 group = {}
 group.getgroup = posix.getgroup
 
 group = {}
 group.getgroup = posix.getgroup
@@ -70,8 +75,16 @@ user = {}
 user.getuser = posix.getpasswd
        
 -- Changes the user password of given 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
 end
\ No newline at end of file
index 2bc0150812e8f6a612e5bdaf4a1889ea0bbae04a..52bebbcf4a69e6ba0ca6d4a7cc649b3c07551ffe 100644 (file)
@@ -120,10 +120,6 @@ function compile(template)
                template = string.dump(tf)
        end
        
                template = string.dump(tf)
        end
        
-       c = c or 1
-       ffluci.fs.writefile("/tmp/"..tostring(c), template)
-       c = c+1
-       
        return template
 end
 
        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
                -- 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
                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 = 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
        
                        
        end
        
index d4b3302efa692ea1a5f83193ae0aa77eeede9407..0215c91dff9aeab1d34f846dd753c74069e3311a 100644 (file)
@@ -1,7 +1,7 @@
 <%+header%>
 <h1><%:texteditor Texteditor%></h1>
 <form method="post" action="<%=controller%>/admin/system/editor">
 <%+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>
 <% 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>
index 3458fef92473a8e6a3bf2ac51f3c322e9f5e8e3d..441753d8393c2145d1f48cf2e3615606bb4d5064 100644 (file)
@@ -1,14 +1,33 @@
 <%+header%>
 <h1><%:system System%></h1>
 <%+header%>
 <h1><%:system System%></h1>
-<h2><%:changepw Passwort ändern%></h2>
+<h2><%:passwd Passwort ändern%></h2>
 <div><br />
 <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">
        <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>
        </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 (file)
index 0000000..a814644
--- /dev/null
@@ -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 (file)
index 0000000..1e1cc24
--- /dev/null
@@ -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