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/AdminLocations.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
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
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]]);
}
}
}
case "removeAdminGroup":
print_r($soapParams);
$res = removeAdminGroup($soapParams);
if (isset($res)) {
ajaxException($res);
}
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 "getLocations":
$res = getAdminLocations($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;
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);
echo json_encode($res->export());
break;
case "getAdminGroups":
$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());
break;
case "getAdminUsers":
$res = getAdminUsers($soapParams);
$rawData = $res[0]; $numResults = $res[1];
# Check we have data returned
if (!isset($rawData)) {
# $numResults in this case is actually $msg, which is the errorm essage
ajaxException($numResults);
}
$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);
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
294
295
296
297
298
299
300
301
302
303
304
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
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;
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
}
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);