summaryrefslogtreecommitdiffstats
path: root/syslog-model.lua
blob: 7391cfe79ffed599aa0769af3dce89e5bfe7dd5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
module(..., package.seeall)

require("pidof")
require("split")

-- we actually need root permissions to get the process list
priv = {}
function priv.is_enabled()
	return (pidof.pidof("syslogd"))
end

function priv.enable(opts)
	if opts and opts.remote then
		local f = io.open("/etc/conf.d/syslog", "w")
		if f == nil then
			return nil
		end
		f:write("# this file was written by and will be overwritten by acf\n")
		f:write("SYSLOGD_OPTS=\"-R "..opts.remote.."\"")
		f:close()
	end
	os.system("/etc/init.d/syslogd restart; rc_add -k -s 20 syslog")
end


-- this func does not need privileges
function readopts()
	local opts = {}
	local line
	local f = io.open("/etc/conf.d/syslog", "r")
	if f == nil then
		return nil
	end
	for line in f:lines() do
		local optstr = string.match(line, "^SYSLOGD_OPTS=\"?(.*)\"?")
		if optstr then
			opts.remote = string.match(optstr, "-R%s*(.*)%s*.*$")
			opts.optstr = optstr
		end
	end
	return opts
end