blob: a1e835272fe1bffa922ed2304bc4d8c3c923601c (
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
#!/usr/bin/lua5.2
local posix = require 'posix'
local json = require 'cjson'
local aac = require 'aaudit.common'
local function usage()
print([[
Usage: aaudit [create|commit] [OPTIONS...]
Valid options for create:
-s SERV Use server SERV
-d DESC Description for repository (default: hostname)
-t ADDR Specify ADDR as target device (default: local source IP)
-m MSG Specify message for the initial commit
-g GRP Add in group GRP
Valid options for commit:
-m MSG Specify message for the commit
-r RT Related to ticket RT
-c RT Closes ticket RT
]])
os.exit(1)
end
local conf = aac.readconfig() or {}
local req = {}
for ret, optval in posix.getopt(arg, 's:d:t:m:g:r:c:') do
if ret == 's' then
conf.server = optval
elseif ret == 'd' then
conf.description = optval
elseif ret == 't' then
conf.target_address = optval
elseif ret == 'm' then
req.message = optval
elseif ret == 'g' then
req.groups = req.groups or {}
table.insert(req.groups, optval)
elseif ret == 'r' then
req.ticket = optval
elseif ret == 'c' then
req.ticket = optval
req.ticket_action = "close"
else
usage()
end
end
if conf.server == nil then
print("Error: No server configured.")
usage()
end
req.command = arg[1]
if arg[1] == "create" then
req.description = conf.description or aac.readfile("/etc/hostname"):gsub("\n","")
req.ssh_host_key = aac.readfile("/etc/ssh/ssh_host_ecdsa_key.pub")
or aac.readfile("/etc/ssh/ssh_host_dsa_key.pub")
or aac.readfile("/etc/ssh/ssh_host_rsa_key.pub")
aac.writeconfig(conf)
elseif arg[1] == "commit" then
else
usage()
end
local F = io.popen(("ssh -T %s@%s "):format(conf.user or "aaudit", conf.server), "w")
F:write(json.encode(req))
F:close()
|