* Rewritten menu builder
[project/luci.git] / src / ffluci / sys.lua
index 97a926b..367d41e 100644 (file)
@@ -27,6 +27,31 @@ limitations under the License.
 module("ffluci.sys", package.seeall)
 require("posix")
 
+-- Runs "command" and returns its output
+function exec(command)
+       local pp   = io.popen(command)
+       local data = pp:read("*a")
+       pp:close()
+       
+       return data
+end
+
+-- Runs "command" and returns its output as a array of lines
+function execl(command)
+       local pp   = io.popen(command)  
+       local line = ""
+       local data = {}
+       
+       while true do
+               line = pp:read()
+               if (line == nil) then break end
+               table.insert(data, line)
+       end 
+       pp:close()      
+       
+       return data
+end
+
 -- Returns the hostname
 function hostname()
        return io.lines("/proc/sys/kernel/hostname")()
@@ -38,6 +63,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 +100,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