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 -- Returns the hostname
32 return io.lines("/proc/sys/kernel/hostname")()
35 -- Returns the load average
37 local loadavg = io.lines("/proc/loadavg")()
38 return loadavg:match("^(.-) (.-) (.-) (.-) (.-)$")
43 return os.execute("reboot >/dev/null 2>&1")
48 group.getgroup = posix.getgroup
51 -- Returns all available network interfaces
52 function net.devices()
54 for line in io.lines("/proc/net/dev") do
55 table.insert(devices, line:match(" *(.-):"))
61 process.info = posix.getpid
63 -- Sets the gid of a process
64 function process.setgroup(pid, gid)
65 return posix.setpid("g", pid, gid)
68 -- Sets the uid of a process
69 function process.setuser(pid, uid)
70 return posix.setpid("u", pid, uid)
74 -- returns user information to a given uid
75 user.getuser = posix.getpasswd
77 -- Changes the user password of given user
78 function user.setpasswd(user, pwd)
80 pwd = pwd:gsub("'", "")
84 user = user:gsub("'", "")
87 local cmd = "(echo '"..pwd.."';sleep 1;echo '"..pwd.."')|"
88 cmd = cmd .. "passwd '"..user.."' >/dev/null 2>&1"
89 return os.execute(cmd)