2 FFLuCI - System library
5 Utilities for interaction with the Linux system
11 Copyright 2008 Steven Barth <steven@midlink.org>
13 Licensed under the Apache License, Version 2.0 (the "License");
14 you may not use this file except in compliance with the License.
15 You may obtain a copy of the License at
17 http://www.apache.org/licenses/LICENSE-2.0
19 Unless required by applicable law or agreed to in writing, software
20 distributed under the License is distributed on an "AS IS" BASIS,
21 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 See the License for the specific language governing permissions and
23 limitations under the License.
27 module("ffluci.sys", package.seeall)
30 -- Runs "command" and returns its output
31 function exec(command)
32 local pp = io.popen(command)
33 local data = pp:read("*a")
39 -- Runs "command" and returns its output as a array of lines
40 function execl(command)
41 local pp = io.popen(command)
47 if (line == nil) then break end
48 table.insert(data, line)
55 -- Uses "ffluci-flash" to flash a new image file to the system
56 function flash(image, kpattern)
57 local cmd = "ffluci-flash "
59 cmd = cmd .. "-k '" .. kapttern:gsub("'", "") .. "' "
61 cmd = cmd .. "'" .. image:gsub("'", "") .. "'"
63 return os.execute(cmd)
66 -- Returns the hostname
68 return io.lines("/proc/sys/kernel/hostname")()
71 -- Returns the load average
73 local loadavg = io.lines("/proc/loadavg")()
74 return loadavg:match("^(.-) (.-) (.-) (.-) (.-)$")
79 return os.execute("reboot >/dev/null 2>&1")
84 group.getgroup = posix.getgroup
87 -- Returns all available network interfaces
88 function net.devices()
90 for line in io.lines("/proc/net/dev") do
91 table.insert(devices, line:match(" *(.-):"))
97 process.info = posix.getpid
99 -- Sets the gid of a process
100 function process.setgroup(pid, gid)
101 return posix.setpid("g", pid, gid)
104 -- Sets the uid of a process
105 function process.setuser(pid, uid)
106 return posix.setpid("u", pid, uid)
110 -- returns user information to a given uid
111 user.getuser = posix.getpasswd
113 -- Changes the user password of given user
114 function user.setpasswd(user, pwd)
116 pwd = pwd:gsub("'", "")
120 user = user:gsub("'", "")
123 local cmd = "(echo '"..pwd.."';sleep 1;echo '"..pwd.."')|"
124 cmd = cmd .. "passwd '"..user.."' >/dev/null 2>&1"
125 return os.execute(cmd)