Ejemplo n.º 1
0
 static function requestPost($action, $params)
 {
     // TODO: error handling when JSON is not returned
     //$authToken = self::authToken();
     $authToken = MonitisConf::$authToken;
     if ($authToken) {
         $params['authToken'] = $authToken;
         $params['validation'] = 'token';
         $params['version'] = MONITIS_API_VERSION;
         $params['action'] = $action;
         $params['apikey'] = MonitisConf::$apiKey;
         $query = http_build_query($params);
         $ch = curl_init(self::$endpoint);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_POST, 1);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
         if (MONITIS_SSL_NOVERIFY) {
             curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
         }
         $result = curl_exec($ch);
         curl_close($ch);
         monitisLog("POST requestPost **** action = <b>{$action}</b><p>{$query}</p><p>{$result}</p>");
         //$json = json_decode($result, true);
         $json = self::jsonDecode($result);
         if ($json && isset($json['errorCode']) && $json['errorCode'] == 4) {
             if (MonitisConf::update_token()) {
                 return self::requestPost($action, $params);
             } else {
                 return array('status' => 'error', 'msg' => 'Monitis server not response');
             }
         }
         return $json;
     } else {
         if (MonitisConf::update_token()) {
             return self::requestPost($action, $params);
         } else {
             return array('status' => 'error', 'msg' => 'Monitis server not response');
         }
     }
 }
Ejemplo n.º 2
0
 static function requestPost($action, $params, $user)
 {
     //$authToken = $user['auth_token'];
     $authToken = MonitisConf::$authToken;
     if ($authToken) {
         $params['validation'] = 'token';
         $params['version'] = MONITIS_API_VERSION;
         $params['action'] = $action;
         $params['timestamp'] = date("Y-m-d H:i:s", time());
         $params['apikey'] = $user['api_key'];
         $params['authToken'] = $authToken;
         $query = http_build_query($params);
         $ch = curl_init(self::$endpoint);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_POST, 1);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
         if (MONITIS_SSL_NOVERIFY) {
             curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
         }
         $result = curl_exec($ch);
         monitisLog("client requestPost **** action = <b>{$action}</b><p>{$query}</p><p>{$result}</p>");
         //$resp = json_decode($result, true);
         $resp = self::jsonDecode($result);
         if (@$resp['error'] && @$resp['errorCode'] && $resp['errorCode'] == 4) {
             if (MonitisConf::update_token()) {
                 return self::requestPost($action, $params);
             } else {
                 return array('status' => 'error', 'msg' => 'Monitis server not response');
             }
         }
         //else
         return $resp;
     } else {
         if (MonitisConf::update_token()) {
             return self::requestPost($action, $params);
         } else {
             return array('status' => 'error', 'msg' => 'Monitis server not response');
         }
     }
 }