use SMD\Api\Api; use SMD\Core\Init; use SMD\Http\Request; use SMD\Http\Response; use SMD\Util\Json; define('APP_ROOT', '.'); require APP_ROOT . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . 'Base.php'; Init::start(); $apiToken = Request::analyze('token'); $action = Request::analyze('action', 0); $Api = new Api(); if (!$Api->checkToken($apiToken)) { Response::printJSON('Token inválido'); } $data = null; switch ($action) { case Api::ACTION_EVENTS: $data = $Api->getEvents(); break; case Api::ACTION_DOWNTIMES: $data = $Api->getDowntimes(); break; case Api::ACTION_CHECK: Response::printJSON('V ' . implode('.', \SMD\Util\Util::getVersion(true)), 0); break; default: Response::printJSON('Petición inválida'); } header('Content-type: application/json'); $json = array('status' => 0, 'data' => $data, 'action' => $action); die(Json::getJson($json));
$ConfigData->setLanguage($siteLanguage); $ConfigData->setPageTitle($siteTitle); $ConfigData->setRefreshValue($eventRefresh); $ConfigData->setNewItemTime($eventNewItemTime); $ConfigData->setMaxDisplayItems($eventMaxItems); $ConfigData->setNewItemAudioEnabled($eventNewItemAudio); $ConfigData->setColLastcheck($showColLastCheck); $ConfigData->setColHost($showColHost); $ConfigData->setColService($showColService); $ConfigData->setColStatusInfo($showColInfo); $ConfigData->setColBackend($showColBackend); $ConfigData->setShowScheduled($showScheduled); $ConfigData->setRegexHostShow($regexHostShow); $ConfigData->setRegexServiceNoShow($regexServicesNoShow); $ConfigData->setCriticalItems(explode(',', $criticalItems)); $ConfigData->setBackend($Backends); $ConfigData->setClientURL($specialClientURL); $ConfigData->setRemoteServer($specialRemoteServerURL); $ConfigData->setMonitorServerUrl($specialMonitorServerUrl); $ConfigData->setAPIToken($specialAPIToken); if (!empty($specialConfigPass) && $specialConfigPass !== (string) Session::getConfig()->getConfigPassword()) { $ConfigData->setConfigPassword(sha1($specialConfigPass)); } else { $ConfigData->setConfigPassword($specialConfigPass); } try { Config::saveConfig(new XmlHandler(XML_CONFIG_FILE), $ConfigData); Response::printJSON('Configuración guardada', 0); } catch (Exception $e) { Response::printJSON('Error al guardar la configuración'); }
Response::printJSON('Petición inválida'); } else { $data = json_decode($data); if (json_last_error() !== 0) { Response::printJSON('Petición inválida'); } } try { switch ($action) { case 'smdBackend': $url = $data->url . '?action=' . $data->action . '&token=' . $data->token; $json = Util::getDataFromUrl($url); break; case 'zabbixBackend': $ZabbixLoader = new ZabbixApiLoader(); $Zabbix = $ZabbixLoader->getAPI($data->version); $Zabbix->setApiUrl($data->url); $Zabbix->userLogin(array('user' => $data->user, 'password' => $data->pass)); $version = $Zabbix->apiinfoVersion(); Response::printJSON('V ' . $version, 0); break; default: Response::printJSON('Petición inválida'); } } catch (Exception $e) { Response::printJSON($e->getMessage()); } if (isset($json) && !empty($json)) { header('Content-type: application/json'); exit($json); }