Newer
Older
include_once("include/ajax/json.php");
include_once("include/ajax/functions/AdminUsers.php");
include_once("include/ajax/functions/AdminGroups.php");
include_once("include/ajax/functions/AdminRealms.php");
include_once("include/ajax/functions/WiSPLocations.php");
define('RES_OK',0);
define('RES_ERR',-1);
/*
* 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);
*/
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
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];
# Initialize array
if (!isset($soapParams[$array_pos])) {
$soapParams[$array_pos] = array();
}
# Check if we have an explicit type
if (isset($items[2])) {
$array_type = $items[2];
# 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]]);
}
}
}
# WiSPLocations.js functions
case "updateWiSPLocation":
$res = updateWiSPLocation($soapParams);
if (isset($res)) {
ajaxException($res);
}
break;
$res = createWiSPLocation($soapParams);
if (isset($res)) {
ajaxException($res);
}
break;
$res = removeWiSPLocation($soapParams);
if (isset($res)) {
ajaxException($res);
}
$res = getWiSPLocations($soapParams);
$rawData = $res[0]; $numResults = $res[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;
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
case "getWiSPLocation":
$rawData = getWiSPLocation($soapParams);
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Name','string');
$res->parseHash($rawData);
echo json_encode($res->export());
break;
# AdminUsers.js functions
case "updateAdminUser":
$res = updateAdminUser($soapParams);
if (isset($res)) {
ajaxException($res);
}
break;
case "createAdminUser":
$res = createAdminUser($soapParams);
if (isset($res)) {
ajaxException($res);
}
break;
case "removeAdminUser":
$res = removeAdminUser($soapParams);
if (isset($res)) {
ajaxException($res);
}
break;
case "getAdminUsers":
$res = getAdminUsers($soapParams);
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Username','string');
$res->addField('Disabled','boolean');
$res->parseArray($rawData);
$res->setDatasetSize($numResults);
echo json_encode($res->export());
break;
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
case "getAdminUser":
$rawData = getAdminUser($soapParams);
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Username','string');
$res->addField('Disabled','boolean');
$res->parseHash($rawData);
echo json_encode($res->export());
break;
# AdminRealms.js functions
case "updateAdminRealm":
$res = updateAdminRealm($soapParams);
if (isset($res)) {
ajaxException($res);
}
break;
case "createAdminRealm":
$res = createAdminRealm($soapParams);
if (isset($res)) {
ajaxException($res);
}
break;
case "removeAdminRealm":
$res = removeAdminRealm($soapParams);
if (isset($res)) {
ajaxException($res);
}
break;
$res = getAdminRealms($soapParams);
$rawData = $res[0]; $numResults = $res[1];
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Name','string');
$res->addField('Disabled','boolean');
$res->parseArray($rawData);
$res->setDatasetSize($numResults);
echo json_encode($res->export());
break;
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
case "getAdminRealm":
$rawData = getAdminRealm($soapParams);
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Name','string');
$res->addField('Disabled','boolean');
$res->parseHash($rawData);
echo json_encode($res->export());
break;
# AdminGroups.js functions
case "updateAdminGroup":
$res = updateAdminGroup($soapParams);
if (isset($res)) {
ajaxException($res);
}
break;
case "createAdminGroup":
$res = createAdminGroup($soapParams);
if (isset($res)) {
ajaxException($res);
}
break;
case "removeAdminGroup":
$res = removeAdminGroup($soapParams);
if (isset($res)) {
ajaxException($res);
}
break;
$res = getAdminGroups($soapParams);
$rawData = $res[0]; $numResults = $res[1];
$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);
$res->setDatasetSize($numResults);
echo json_encode($res->export());
case "getAdminGroup":
$rawData = getAdminGroup($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->parseHash($rawData);
echo json_encode($res->export());
array(
'ID' => 10,
'Name' => 'TestReseller1'
)
);
$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 "getAdminRealms":
$res = getAdminRealms($soapParams);
$rawData = $res[0]; $numResults = $res[1];
$res = new json_response;
$res->setID('ID');
$res->addField('ID','int');
$res->addField('Name','string');
$res->addField('Disabled','boolean');
$res->parseArray($rawData);
$res->setDatasetSize($numResults);
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
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
509
510
511
512
513
514
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;
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
}
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);