public function response($status, $txt) { switch ($this->handler) { case 'json': $resp = msAPI::encode(array('status' => $status, 'message' => $txt)); break; case 'xml': $resp = '<?xml version="1.0" encoding="' . $this->xml_charset . '"?><msapi><status>' . $status . '</status><message>' . $txt . '</message></msapi>'; break; } switch ($status) { case 'OK': msAPI::log($resp); break; default: msAPI::log('[' . strtoupper($this->handler) . '] ' . $txt); break; } echo $resp; exit; }
if ($SETTINGS->apiKey == '' || !in_array('xml', $apiOpts) && !in_array('json', $apiOpts)) { die('API not enabled. Enable JSON and/or XML handlers in settings and set API Key.'); } // Load API files.. include PATH . 'control/classes/class.api.php'; $MSAPI = new msAPI(); $MSAPI->settings = $SETTINGS; $MSAPI->datetime = $MSDT; // Incoming data.. // Determine handler.. // Read data.. include PATH . 'control/system/api/lib.php'; if (!isset($data)) { $HEADERS->err403(); } $MSAPI->log('Incoming data received:{nl}{nl}' . $data); $MSAPI->handler = $MSAPI->getHandler($data); $MSAPI->allowed = $apiOpts; $read = $MSAPI->read($data); if (!empty($read)) { // Determine ops.. $ops = $MSAPI->ops($read); // Check key.. if (isset($ops['key']) && $ops['key'] == $SETTINGS->apiKey) { $MSAPI->log('[' . strtoupper($MSAPI->handler) . '] Key successfully checked and authenticated'); // Run operation... switch ($ops['op']) { // Create ticket.. case 'ticket': $MSAPI->log('[' . strtoupper($MSAPI->handler) . '] Preparing to add new tickets'); include PATH . 'control/system/api/create-tickets.php';