phpipam icon indicating copy to clipboard operation
phpipam copied to clipboard

API-Call via curl: Invalid content type

Open sven76 opened this issue 6 months ago • 2 comments

Describe the bug

curl https://myipamserver.domain/api/dns/subnets/22/ --header 'token: xxxmytokenxxx' -i 

HTTP/1.1 415 Unsupported Media Type
Server: nginx/1.22.1
Date: Mon, 12 Aug 2024 12:57:48 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Set-Cookie: phpipam=mqh14rsee1gm1piqr7lekie0g0; expires=Tue, 13 Aug 2024 12:57:48 +0000; Max-Age=86400; path=/; SameSite=Lax; HttpOnly;
Cache-Control: no-cache
Pragma: no-cache
Vary: Accept-Encoding

{"code":415,"success":false,"message":"Invalid Content type ","time":0.001}

Environment

  • phpIPAM: 1.6.0 release
  • OS: Debian 12.6
  • PHP-Version: php8.2-fpm (8.2.20-1~deb12u1)
  • Webserver: nginx-1.22.1-9
  • Database: mariadb-server-1:10.11.6-0+deb12u1

Steps To Reproduce

  1. Install nginx, mariadb, phpipam according to https://phpipam.net/news/phpipam-on-nginx/
  2. Include line "fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;" in php section.
  3. start nginx, import the old database
  4. call curl from above.

Additional Info If I the file: controllers/Responses.php

    public function validate_content_type () {
        // remove charset if provided
/*                                                                                                                                                
        if(isset($_SERVER['CONTENT_TYPE']))
        $_SERVER['CONTENT_TYPE'] = array_shift(pf_explode(";", $_SERVER['CONTENT_TYPE']));
        // not set, presume json
        if( !isset($_SERVER['CONTENT_TYPE']) || strlen(@$_SERVER['CONTENT_TYPE']==0) ) {}
        // post
        elseif($_SERVER['CONTENT_TYPE']=="application/x-www-form-urlencoded") {}
        // set, verify
        elseif (!($_SERVER['CONTENT_TYPE']=="application/xml" || $_SERVER['CONTENT_TYPE']=="application/json")) {
            $this->throw_exception (415, "Invalid Content type ".$_SERVER['CONTENT_TYPE']);
        }
*/ 
        $_SERVER['CONTENT_TYPE'] = "application/json";

I get a working result as expected. Something seems to be broken in the split function of the content type.

If I call: curl -H 'Content-Type: application/json' https://myipamserver.domain/api/dns/subnets/22/ --header 'token: xxxmytokenxxx' -i It's also working.

sven76 avatar Aug 12 '24 13:08 sven76