/** * Obtener los datos remotos desde la API de sysMonDash con CURL * * Devuelve los datos deserializados * * @param $url * @return mixed * @throws \Exception */ protected function getRemoteData($url) { $data = json_decode(Util::getDataFromUrl($url)); if (is_object($data) && isset($data->status) && $data->status === 1) { $msg = sprintf('%s (%s): %s', $this->getBackend()->getAlias(), 'SMD', $data->description); error_log($msg); throw new BackendException($msg); } elseif (!is_object($data)) { $msg = sprintf('%s (%s): %s', $this->getBackend()->getAlias(), 'SMD', Language::t('Error al acceder a la API')); error_log($msg); throw new BackendException($msg); } return unserialize(base64_decode($data->data)); }
Init::start(); $action = Request::analyze('action'); $data = Request::analyze('data'); if (!$action || !$data) { 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()); }