From 56f800deac4c98df6950fe875a79f01a20923f96 Mon Sep 17 00:00:00 2001 From: "Andrey Jr. Melnikov" Date: Sat, 20 Jan 2018 23:03:45 +0300 Subject: [PATCH 1/3] Update class.phpipam-api.php After commit 989c131 debugging is useless due to libcurl internal design. https://bugs.php.net/bug.php?id=65348 So, remove it. --- php-client/class.phpipam-api.php | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/php-client/class.phpipam-api.php b/php-client/class.phpipam-api.php index a668dd2..00179b5 100644 --- a/php-client/class.phpipam-api.php +++ b/php-client/class.phpipam-api.php @@ -8,17 +8,7 @@ */ class phpipam_api_client { - /** - * Debug flag for curl - * - * (default value: false) - * - * @var bool - * @access public - */ - public $debug = false; - - /** + /** * API server URL * * (default value: false) @@ -387,9 +377,7 @@ private function validate_php_extensions () { * @return void */ public function set_debug ($debug = false) { - if(is_bool($debug)) { - $this->debug = $debug; - } + /* Do nothing. */ } /** @@ -656,7 +644,6 @@ private function curl_set_connection ($token_file) { CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $url, CURLOPT_HEADER => 0, - CURLOPT_VERBOSE => $this->debug, CURLOPT_TIMEOUT => 30, CURLOPT_HTTPHEADER => array("Content-Type: application/json"), CURLOPT_USERAGENT => 'phpipam-api php class', @@ -860,7 +847,6 @@ private function curl_authenticate () { CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $this->api_url.$this->api_app_id."/user/", CURLOPT_HEADER => 0, - CURLOPT_VERBOSE => $this->debug, CURLOPT_TIMEOUT => 30, CURLOPT_USERAGENT => 'phpipam-api php class', // ssl From b4daaa916a467f4363cc3417047bdd9ee6d1a78e Mon Sep 17 00:00:00 2001 From: "Andrey Jr. Melnikov" Date: Sat, 20 Jan 2018 23:08:13 +0300 Subject: [PATCH 2/3] Trim newline in token Trim LF in token filed. With LF in token - libcurl generate header with LF (as requested), nginx complain about 'Bad request'. --- php-client/class.phpipam-api.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/php-client/class.phpipam-api.php b/php-client/class.phpipam-api.php index 00179b5..12eb618 100644 --- a/php-client/class.phpipam-api.php +++ b/php-client/class.phpipam-api.php @@ -715,8 +715,8 @@ private function curl_add_token_header ($token_file) { $token = @file($token_file); // save token if(isset($token[0])) { - $this->token = $token[0]; - $this->token_expires = $token[1]; + $this->token = trim($token[0]); + $this->token_expires = trim($token[1]); // is token still valid ? if (strlen($this->token)<2 && $this->token_expires < time()) { From 9163a784aff4e9689dd0e5330a826f70247a2ce2 Mon Sep 17 00:00:00 2001 From: "Andrey Jr. Melnikov" Date: Sat, 20 Jan 2018 23:11:25 +0300 Subject: [PATCH 3/3] Fix missing POST fields Properly push $params to server. --- php-client/class.phpipam-api.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/php-client/class.phpipam-api.php b/php-client/class.phpipam-api.php index 12eb618..6cc9a31 100644 --- a/php-client/class.phpipam-api.php +++ b/php-client/class.phpipam-api.php @@ -668,7 +668,10 @@ private function curl_set_params ($params) { // params set ? if (is_array($params) && !$this->api_encrypt ) { if (sizeof($params)>0) { - curl_setopt($this->Connection, CURLOPT_URL, $this->api_url.$this->api_app_id.str_replace("//", "/", "/".$this->api_server_controller."/".$this->api_server_identifiers."/?".http_build_query($params))); + if ($this->api_server_method === 'GET') + curl_setopt($this->Connection, CURLOPT_URL, $this->api_url.$this->api_app_id.str_replace("//", "/", "/".$this->api_server_controller."/".$this->api_server_identifiers."/?".http_build_query($params))); + else + curl_setopt($this->Connection, CURLOPT_POSTFIELDS, json_encode($params)); } } // encrypt