This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
/
test.php
168 lines (145 loc) · 4.42 KB
/
test.php
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
error_reporting(E_ALL);
require_once("libmonetra.php");
$MYHOST="testbox.monetra.com";
$MYPORT=8665;
$MYUSER="test_ecomm:public";
$MYPASS="publ1ct3st";
$MYMETHOD="SSL";
$MYCAFILE=NULL;
$MYVERIFYSSL=0;
/* Initialize Engine */
if (!M_InitEngine(NULL)) {
echo "Failed to initialize libmonetra\r\n";
return;
}
/* Initialize Connection */
$conn = M_InitConn();
if ($conn === FALSE) {
echo "Failed to initialize connection resource\r\n";
return;
}
if (strcasecmp($MYMETHOD, "SSL") == 0) {
/* Set up SSL Connection Location */
if (!M_SetSSL($conn, $MYHOST, $MYPORT)) {
echo "Could not set method to SSL\r\n";
/* Free memory associated with conn */
M_DestroyConn($conn);
return;
}
/* Set up information required to verify certificates */
if ($MYVERIFYSSL) {
if (!M_SetSSL_CAfile($conn, $MYCAFILE)) {
echo "Could not set SSL CAFile. " . "Does the file exist?\r\n";
M_DestroyConn($conn);
return;
}
M_VerifySSLCert($conn, 1);
}
} else if (strcasecmp($MYMETHOD, "IP") == 0) {
/* Set up IP Connection Location */
if (!M_SetIP($conn, $MYHOST, $MYPORT)) {
echo "Could not set method to IP\r\n";
/* Free memory associated with conn */
M_DestroyConn($conn);
return;
}
} else {
echo "Invalid method '" . $MYMETHOD . "' specified!\r\n";
/* Free memory associated with conn */
M_DestroyConn($conn);
return;
}
/* Set to blocking mode, means we do not have to
* do a M_Monitor() loop, M_TransSend() will do this for us */
if (!M_SetBlocking($conn, 1)) {
echo "Could not set non-blocking mode\r\n";
/* Free memory associated with conn */
M_DestroyConn($conn);
return;
}
/* Set a timeout to be appended to each transaction
* sent to Monetra */
if (!M_SetTimeout($conn, 30)) {
echo "Could not set timeout\r\n";
/* Free memory associated with conn */
M_DestroyConn($conn);
return;
}
echo "Connecting to $MYHOST:$MYPORT using $MYMETHOD...";
/* Connect to Monetra */
if (!M_Connect($conn)) {
echo "Connection failed: " . M_ConnectionError($conn) . "\r\n";
/* Free memory associated with conn */
M_DestroyConn($conn); // free memory
return;
}
echo "connected\r\n";
/* Allocate new transaction */
$identifier=M_TransNew($conn);
/* User credentials */
M_TransKeyVal($conn, $identifier, "username", $MYUSER);
M_TransKeyVal($conn, $identifier, "password", $MYPASS);
/* Transaction Type */
M_TransKeyVal($conn, $identifier, "action", "admin");
M_TransKeyVal($conn, $identifier, "admin", "GUT");
echo "Sending Unsettled report request...\r\n";
/* Additional Auditing parameters may be specified
* Please consult the Monetra Client Interface Protocol */
if (!M_TransSend($conn, $identifier)) {
echo "Communication Error: " . M_ConnectionError($conn) . "\r\n";
/* Free memory associated with conn */
M_DestroyConn($conn);
return;
}
echo "Response received\r\n";
/* We do not have to perform the M_Monitor() loop
* because we are in blocking mode */
if (M_ReturnStatus($conn, $identifier) != M_SUCCESS) {
echo "Audit failed\r\n";
M_DestroyConn($conn);
return;
}
if (!M_IsCommaDelimited($conn, $identifier)) {
echo "Not a comma delimited response!\r\n";
M_DestroyConn($conn);
return;
}
/* Print the raw, unparsed data */
echo "Raw Data:\r\n" . M_GetCommaDelimited($conn, $identifier) . "\r\n";
/* Tell the API to parse the Data */
if (!M_ParseCommaDelimited($conn, $identifier)) {
echo "Parsing comma delimited data failed";
M_DestroyConn($conn);
return;
}
/* Retrieve each number of rows/columns */
$rows=M_NumRows($conn, $identifier);
$columns=M_NumColumns($conn, $identifier);
/* Print all the headers separated by |'s */
for ($i=0; $i<$columns; $i++) {
if ($i != 0) echo "|";
echo M_GetHeader($conn, $identifier, $i);
}
echo "\r\n";
/* Print one row per line, each cell separated by |'s */
for ($j=0; $j<$rows; $j++) {
for ($i=0; $i<$columns; $i++) {
if ($i != 0) echo "|";
echo M_GetCellByNum($conn, $identifier, $i, $j);
}
echo "\r\n";
}
/*
* Use M_GetCell instead of M_GetCellByNum if you need a
* specific column, as the results will allow for position-
* independent searching of the results. The ordering of
* returned headers may be different between Monetra versions,
* so that is _highly_ recommended */
/* Optionally free transaction, though M_DestroyConn() will
* do this for us */
M_DeleteTrans($conn, $identifier);
/* Clean up and close */
M_DestroyConn($conn);
M_DestroyEngine();
?>