This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.lua
113 lines (93 loc) · 2.47 KB
/
test.lua
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
local libmonetra = require("libmonetra")
local host = "testbox.monetra.com"
local port = 8665
local user = "test_ecomm:public"
local pass = "publ1ct3st"
local method = libmonetra.CONN_SSL
local cafile = nil
local verifyssl = false
local ret = nil
local err = nil
local tran = nil
local conn = libmonetra.Monetra(host, port, method)
if verifssl then
if cafile then
ret, err = conn:SetSSL_CAfile(cafile)
if not ret then
print(err)
return
end
end
conn:VerifySSLCert(true)
end
-- Set to blocking mode, means we do not have to
-- do a Monitor() loop. TransSend() will do this for us.
conn:SetBlocking(true)
-- Set a timeout to be appended to each transaction
-- sent to Monetra.
conn:SetTimeout(30)
print("Connectiong to " .. host .. ":" .. port .. "using method " .. (method == libmonetra.CONN_IP and "IP" or (method == libmonetra.CONN_SSL and "SSL" or "Unknown")))
ret, err = conn:Connect()
if not ret then
print("connect fail: " .. err)
return
end
print("Connected")
tran = conn:TransNew()
if not tran then
print("Could not create transaction")
conn:Disconnect()
return
end
conn:TransKeyVal(tran, "username", user)
conn:TransKeyVal(tran, "password", pass)
conn:TransKeyVal(tran, "action", "admin")
conn:TransKeyVal(tran, "admin", "gut")
print("Sending Unsettled report request...")
ret, err = conn:TransSend(tran)
if not ret then
print("Communication error: " .. err)
conn:Disconnect()
return
end
print("Response received")
-- We do not have to perform the Monitor() loop
-- because we are in blocking mode.
if conn:ReturnStatus(tran) ~= libmonetra.SUCCESS then
print("Audit failed")
conn:Disconnect()
return
end
if not conn:IsCommaDelimited(tran) then
print("Not a comma delimited response!")
conn:Disconnect()
return
end
-- Print the raw, unparsed data.
--print("Raw Data: " .. conn:GetCommaDelimited(tran))
-- Tell the API to parse the Data.
if not conn:ParseCommaDelimited(tran) then
print("Parsing comma delimited data failed!")
conn:Disconnect()
return
end
-- Retrieve each number of rows/columns.
local rows = conn:NumRows(tran)
local cols = conn:NumColumns(tran)
-- Print all the headers separated by |'s.
local headers = {}
for i=1,cols do
table.insert(headers, conn:GetHeader(tran, i))
end
print(table.concat(headers, "|"))
-- Print one row per line, each cell separated by |'s.
for i=1,rows do
local row = {}
for j=1,cols do
table.insert(row, conn:GetCellByNum(tran, j, i))
end
print(table.concat(row, "|"))
end
conn:DeleteTrans(tran)
conn:Disconnect()
conn = nil