Newer
Older
# Requires / Includes
include_once("functions/AdminUsers.php");
include_once("functions/AdminGroups.php");
include_once("functions/AdminRealms.php");
include_once("functions/AdminLocations.php");
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
168
169
170
171
172
173
174
define('RES_OK',0);
define('RES_ERR',-1);
class json_response {
private $_fields = array();
private $_id;
private $_results;
private $_datasetSize;
private $_status = RES_OK;
## @method setID($id)
# Set ID column
#
# @param id ID column name
public function setID($id) {
$this->_id = $id;
}
## @method setStatus($status)
# Set response status
#
# @param status Either RES_OK (default) or RES_ERROR
public function setStatus($status) {
$this->_status = $status;
}
## @method addField($name,$type)
# Add a field to our return results
#
# @param name Field name
# @param type Field type, 'int', 'string', 'float', 'boolean', 'date'
public function addField($name,$type) {
# Build field
$field = array(
'name' => $name,
'type' => $type
);
# Set ISO date format
if ($field['type'] == "date") {
$field['dateFormat'] = "Y-m-d";
}
# Add field to list
array_push($this->_fields,$field);
}
## @method setDatasetSize($size)
# Set how many records are returned in the dataset
#
# @param size Dataset size
public function setDatasetSize($size) {
$this->_datasetSize = $size;
}
## @method parseArrayRef($array)
# Parse in the array of results and fix it up
#
# @param arrayref Array ref containing the results
public function parseArray($array) {
$this->_results = array();
# Loop with array items
foreach ($array as $aitem) {
$item = array();
# Loop with fields we want
foreach ($this->_fields as $field) {
# FIXME - typecast?
$item[$field['name']] = $aitem[$field['name']];
}
array_push($this->_results,$item);
}
}
## @method parseHash($hashref)
# Parse in the hash of results and fix it up
#
# @param hashref Hash ref containing the results
public function parseHash($hash) {
$this->_results = array();
foreach ($this->_fields as $field) {
# FIXME - typecast?
$this_results[$field['name']] = $hash[$field['name']];
}
}
## @method export
# Export response into something we return
#
# @return JSON hash
# @li result - Result code/status
# @li data - Ref containing results
# @li metaData - Metadata containing info about the results being returned
# Metadata contains properties..
# - root: root element, which is always 'data'
# - fields: Optional field description, arrayref of hash refs, name = 'name', type 'type' and 'dateFormat' = 'Y-m-d'
# - id: Optional ID field name
# - totalProperty: Optional property name containing the number of records, always 'datasetSize'
# @li datasetSize Optional, number of records we're rturning
public function export() {
# Build result
$ret = array(
'result' => $this->_status,
# Additional stuff for other things to make life easier
'success' => $this->_status == RES_OK ? 1 : 0,
'metaData' => array(
'successProperty' => 'success'
)
);
# If we have results, add them
if (isset($this->_results)) {
$ret['data'] = $this->_results;
$ret['metaData']['root'] = 'data';
# If we have fields, set them up
if (isset($this->_fields)) {
$ret['metaData']['fields'] = $this->_fields;
}
}
# Check if we have an ID set
if (isset($this->_id)) {
$ret['metaData']['totalProperty'] = 'datasetSize';
$ret['datasetSize'] = $this->_datasetSize;
}
return $ret;
}
}
/*
* AJAX Interface to SMEngine SOAP
*/
# Fire an exception off to Ajax
function ajaxException($msg) {
/*
$res = array(
'success' => FALSE,
'errors' => array(
$msg
)
);
echo json_encode($res);
*/
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
exit;
}
# PHP exception handler
function exception_handler($exception) {
ajaxException("Exception: ". $exception->getMessage());
}
# Set PHP exception handler
set_exception_handler('exception_handler');
if (!isset($_REQUEST['SOAPUsername']) || empty($_REQUEST['SOAPUsername'])) {
ajaxException("SOAPUsername undefined");
}
if (!is_string($_REQUEST['SOAPUsername'])) {
ajaxException("SOAPUsername is not a string");
}
$username = $_REQUEST['SOAPUsername'];
if (!isset($_REQUEST['SOAPPassword']) || empty($_REQUEST['SOAPPassword'])) {
ajaxEception("SOAPPassword undefined");
}
if (!is_string($_REQUEST['SOAPPassword'])) {
ajaxException("SOAPPassword is not a string");
}
$password = $_REQUEST['SOAPPassword'];
if (!isset($_REQUEST['SOAPAuthType']) || empty($_REQUEST['SOAPAuthType'])) {
ajaxException("SOAPAuthType undefined");
}
if (!is_string($_REQUEST['SOAPAuthType'])) {
ajaxException("SOAPAuthType is not a string");
}
$authType = $_REQUEST['SOAPAuthType'];
if (!isset($_REQUEST['SOAPModule']) || empty($_REQUEST['SOAPModule'])) {
ajaxException("SOAPModule undefined");
}
if (!is_string($_REQUEST['SOAPModule'])) {
ajaxException("SOAPModule is not a string");
}
$module = $_REQUEST['SOAPModule'];
if (!isset($_REQUEST['SOAPFunction']) || empty($_REQUEST['SOAPFunction'])) {
ajaxException("SOAPFunction undefined");
}
if (!is_string($_REQUEST['SOAPFunction'])) {
ajaxException("SOAPFunction is not a string");
}
$function = $_REQUEST['SOAPFunction'];
/*
__search
ID,__search
1:Name,1:Contact,1:Telephone,1:Email
*/
$soapParamTemplate = explode(',',$_REQUEST['SOAPParams']);
$soapParams = array();
foreach ($soapParamTemplate as $param) {
# Special case '__search'
if ($param == "__search") {
# Build hash and push into param list
$search = array(
'Filter' => isset($_REQUEST['filter']) ? $_REQUEST['filter'] : '',
'Start' => $_REQUEST['start'],
'Limit' => $_REQUEST['limit'],
'Sort' => isset($_REQUEST['sort']) ? $_REQUEST['sort'] : '',
'SortDirection' => isset($_REQUEST['dir']) ? $_REQUEST['dir'] : '',
);
array_push($soapParams,$search);
# Special case '__null'
} elseif ($param == "__null") {
array_push($soapParams,NULL);
# Everything else
} else {
# Split off param number if we're using it
$items = explode(':',$param);
# We have a parameter number
if (count($items) > 1) {
$array_pos = $items[0];
$array_item = $items[1];
$array_type = $items[2];
# Initialize array
if (!isset($soapParams[$array_pos])) {
$soapParams[$array_pos] = array();
}
# Check if we have an explicit type
if (isset($array_type)) {
# Check type
if ($array_type == "boolean") {
# Checkboxes/booleans are undefined if false
if (isset($_REQUEST[$array_item])) {
$item_value = 'true';
} else {
$item_value = 'false';
}
# And bitch if we invalid
} else {
ajaxException("Unknown AJAX=>SOAP type: '$array_type'");
}
} else {
$item_value = $_REQUEST[$array_item];
}
# Set item
$soapParams[$array_pos][$array_item] = $item_value;
} else {
array_push($soapParams,$_REQUEST[$items[0]]);
}
}
}
switch ($function) {
case "getWiSPResellers":
array(
'ID' => 10,
'Name' => 'TestReseller1'
)
);
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
$numResults = 1;
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Name','string');
$res->parseArray($rawData);
$res->setDatasetSize($numResults);
echo json_encode($res->export());
break;
case "getLocations":
$rawData = getAdminLocations($soapParams);
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Name','string');
$res->parseArray($rawData[1]);
$res->setDatasetSize($rawData[0]);
echo json_encode($res->export());
break;
case "getAdminRealms":
$rawData = getAdminRealms($soapParams);
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Name','string');
$res->addField('Disabled','boolean');
$res->parseArray($rawData[1]);
$res->setDatasetSize($rawData[0]);
echo json_encode($res->export());
break;
case "getAdminGroups":
$rawData = getAdminGroups($soapParams);
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Name','string');
$res->addField('Priority','int');
$res->addField('Disabled','boolean');
$res->addField('Comment','string');
$res->parseArray($rawData[1]);
$res->setDatasetSize($rawData[0]);
echo json_encode($res->export());
break;
case "getAdminUsers":
$rawData = getAdminUsers($soapParams);
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Username','string');
$res->addField('Disabled','boolean');
$res->parseArray($rawData[1]);
$res->setDatasetSize($rawData[0]);
echo json_encode($res->export());
break;
case "getWiSPUsers":
$rawData = array (
array(
'ID' => 10,
'AgentID' => 5,
'AgentName' => 'joe agent',
'Username' => 'johnsmith',
'UsageCap' => 1000,
'ClassID' => 7,
'ClassDesc' => 'ClassTest',
'RealmDesc' => 'My Realm',
'Service' => 'My Service',
'AgentDisabled' => FALSE,
'Disabled' => FALSE,
'AgentRef' => 'Reseller ref'
)
);
$numResults = 1;
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('AgentID','int');
$res->addField('AgentName','string');
$res->addField('Username','string');
$res->addField('UsageCap','int');
$res->addField('ClassID','int');
$res->addField('ClassDesc','string');
$res->addField('RealmDesc','string');
$res->addField('Service','string');
$res->addField('AgentDisabled','boolean');
$res->addField('Disabled','boolean');
$res->addField('AgentRef','string');
$res->parseArray($rawData);
$res->setDatasetSize($numResults);
echo json_encode($res->export());
break;
case "getWiSPUserLogs":
$rawData = array (
array(
'ID' => 10,
'Username' => 'johnsmith',
'Status' => 1,
'Timestamp' => '10/03/2009',
'AcctSessionID' => '24234',
'AcctSessionTime' => '10:30',
'NASIPAddress' => '192.168.1.254',
'NASPortType' => '2',
'NASPort' => '3128',
'CalledStationID' => '282282',
'CallingStationID' => '2782872',
'NASTransmitRate' => '2000',
'NASReceiveRate' => '4000',
'FramedIPAddress' => '192.168.1.30',
'AcctInputMbyte' => '1241',
'AcctOutputMbyte' => '229',
'LastAcctUpdate' => '1282893',
'ConnectTermReason' => 'Failboat'
)
);
$numResults = 1;
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Username','int');
$res->addField('Status','string');
$res->addField('Timestamp','string');
$res->addField('AcctSessionID','int');
$res->addField('AcctSessionTime','int');
$res->addField('NASIPAddress','string');
$res->addField('NASPortType','string');
$res->addField('NASPort','string');
$res->addField('CalledStationID','boolean');
$res->addField('CallingStationID','boolean');
$res->addField('NASTransmitRate','string');
$res->addField('NASReceiveRate','string');
$res->addField('FramedIPAddress','string');
$res->addField('AcctInputMbyte','string');
$res->addField('AcctOutputMbyte','string');
$res->addField('LastAcctUpdate','string');
$res->addField('ConnectTermReason','string');
$res->parseArray($rawData);
$res->setDatasetSize($numResults);
echo json_encode($res->export());
break;
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
}
exit;
# Connect via soap
$soap = new SoapClient(null,
array(
'location' => "http://localhost:1080/?Auth=$authType",
'uri' => $module,
'login' => $username,
'password' => $password
)
);
# Try soap call
try {
$soapRes = $soap->__call($function,$soapParams);
} catch (Exception $e) {
# Build msg string
if (is_soap_fault($e)) {
header("$SERVER_PROTOCOL 500 Internal Server Error");
$msg = "SOAP Fault: ".$e->faultstring;
if (!empty($e->detail)) {
$msg .= " (".$e->detail.")";
}
} else {
header("$SERVER_PROTOCOL 400 Bad Request");
$msg = "Fault: ".$e->getMessage();
}
ajaxException($msg);
}
echo json_encode($soapRes);