* but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ define('_HOMEREXEC', "1"); /* MAIN CLASS modules */ include "class/index.php"; // register the DataTable autoloader include 'DataTable/Autoloader.php'; spl_autoload_register(array('DataTable_Autoloader', 'autoload')); // include the Demo DataTable class include_once 'SipDataTable.php'; // build a Browser Service object based on the type that was selected include_once 'SipSearchService.php'; $sipService = new SipSearchService($db->hostname_homer); // instatiate new DataTable $table = new SipDataTable(); $table->setBrowserService($sipService); $tmpdata = json_decode($_REQUEST['data'], true); $data = array(); foreach ($tmpdata as $k => $v) { $data[$v['name']] = $v['value']; } $request = new DataTable_Request(); $request->fromPhpRequest($data); // render the JSON data string echo $table->renderJson($request);
function basicFeautures($type, $data) { global $obj, $auth, $search, $db; $answer = array(); switch ($type) { case 'session': if (!isset($data->username) || !isset($data->password)) { if ($auth->checkSession()) { $answer['auth'] = 'true'; $answer['status'] = 'ok'; $answer['sid'] = session_id(); } else { $answer['sid'] = session_id(); $answer['auth'] = 'false'; $answer['status'] = 'wrong-session'; } } else { $answer['user'] = $auth->logIn($data); if (empty($answer['user'])) { $answer['message'] = 'bad password or username'; $answer['status'] = 'wrong-credentials'; } else { $answer['status'] = 'ok'; } } break; case 'user': $answer['user'] = $auth->getUser(); if (count($answer['user'])) { $answer['status'] = 'ok'; } else { $answer['status'] = 'no-auth'; } break; /* SEARCH CALLS */ /* SEARCH CALLS */ case 'search/messages/all': include 'DataTable/Autoloader.php'; spl_autoload_register(array('DataTable_Autoloader', 'autoload')); include_once 'DataTable/sip/SipDataTable.php'; include_once 'DataTable/sip/SipSearchService.php'; $sipService = new SipSearchService($db->hostname_homer); $table = new SipDataTable(); $table->setBrowserService($sipService); $tmpdata = array(); foreach ($data as $k => $v) { $tmpdata[$v->name] = $v->value; } $dt_request = new DataTable_Request(); $dt_request->fromPhpRequest($tmpdata); echo $table->renderJson($dt_request); exit; break; /* messages */ /* messages */ case 'message/all/last': if ($resp = $search->showMessageAll($data, 0)) { $answer['status'] = 'ok'; $answer['data'] = $resp; } else { $answer['status'] = 'not good'; $answer['data'] = array(); } break; case 'rtcp/report/all': if ($resp = $search->showRtcpAll($data, 0)) { $answer['status'] = 'ok'; $answer['data'] = $resp; } else { //$answer['status'] = 'not good'; $answer['status'] = 'not good'; $answer['data'] = array(); } break; case 'cdr/report/all': if ($resp = $search->showCdrAll($data, 0)) { $answer['status'] = 'ok'; $answer['data'] = $resp; } else { $answer['status'] = 'not good'; $answer['data'] = array(); } break; /* statistic */ /* statistic */ case 'statistic/method/all': case 'statistic/method/total': $reqkey = preg_replace('/statistic\\/method\\//', '', $obj->getRURI()); if ($reqkey == "all") { $total = 0; } else { $total = 1; } if ($resp = $search->statisticMethod($data, $total)) { $answer['status'] = 'ok'; $answer['data'] = $resp; } else { $answer['status'] = 'not good'; $answer['data'] = array(); } break; case 'statistic/data/all': case 'statistic/data/total': $reqkey = preg_replace('/statistic\\/data\\//', '', $obj->getRURI()); if ($reqkey == "all") { $total = 0; } else { $total = 1; } if ($resp = $search->statisticData($data, $total)) { $answer['status'] = 'ok'; $answer['data'] = $resp; } else { $answer['status'] = 'not good'; $answer['data'] = array(); } break; case 'statistic/ip/all': case 'statistic/ip/total': $reqkey = preg_replace('/statistic\\/ip\\//', '', $obj->getRURI()); if ($reqkey == "all") { $total = 0; } else { $total = 1; } if ($resp = $search->statisticIP($data, $total)) { $answer['status'] = 'ok'; $answer['data'] = $resp; } else { $answer['status'] = 'not good'; $answer['data'] = array(); } break; case 'statistic/useragent/all': case 'statistic/useragent/total': $reqkey = preg_replace('/statistic\\/useragent\\//', '', $obj->getRURI()); if ($reqkey == "all") { $total = 0; } else { $total = 1; } if ($resp = $search->statisticUserAgent($data, $total)) { $answer['status'] = 'ok'; $answer['data'] = $resp; } else { $answer['status'] = 'not good'; $answer['data'] = array(); } break; case 'alarm/data/all': case 'alarm/data/total': case 'alarm/data/short': $reqkey = preg_replace('/alarm\\/data\\//', '', $obj->getRURI()); if ($reqkey == "all") { $total = 0; } else { if ($reqkey == "short") { $total = 2; } else { $total = 1; } } if ($resp = $search->alarmData($data, $total)) { $answer['status'] = 'ok'; $answer['data'] = $resp; } else { $answer['status'] = 'not good'; $answer['data'] = array(); } break; case 'alarm/update': if ($resp = $search->replaceAlarm($data)) { $answer['status'] = 'ok'; $answer['data'] = $resp; } else { $answer['status'] = 'not good'; $answer['data'] = array(); } break; case 'alarm/delete': if ($resp = $search->deleteAlarm($data)) { $answer['status'] = 'ok'; $answer['data'] = $resp; } else { $answer['status'] = 'not good'; $answer['data'] = array(); } break; case 'alarm/delete/all': if ($resp = $search->deleteAllAlarms()) { $answer['status'] = 'ok'; $answer['data'] = $resp; } else { $answer['status'] = 'not good'; $answer['data'] = array(); } break; case 'alarm/ack/all': console . log("Want to ACK all alarms"); if ($resp = $search->ackAllAlarms()) { $answer['status'] = 'ok'; $answer['data'] = $resp; } else { $answer['status'] = 'not good'; $answer['data'] = array(); } break; case 'export/pcap/callid': case 'export/text/callid': include_once "class/pcap.php"; /* Call Search */ $export = new Export(); $export->setDB($db); $text = 0; if ($obj->getRURI() == "export/text/callid") { $text = 1; } $resp = $export->generatePcap($data, $text); if (!empty($resp)) { sendFile(200, $resp[0], $resp[1], $resp[2]); exit; } else { $answer['status'] = 'ok'; $answer['data'] = array(); exit; } break; /* ALARMS */ /* ALARMS */ default: $answer['status'] = 'not good'; $answer['message'] = 'Unknown get call: [' . $request . ']'; $answer['data'] = array(); break; } return $answer; }