2

I'm trying to communicate with the Kodi JSONRPC api and I keep getting a permission denied.

I have looked everywhere, I've tried all the curl options I can find, and none of them seem to be doing a thing.

$options = array(
        CURLOPT_VERBOSE => 1,
        CURLOPT_RETURNTRANSFER      => true,
        CURLOPT_HEADER              => true,
        CURLOPT_HTTPHEADER          => array(                                                                          
        'Content-Type: application/json',                                                                                
        'Content-Length: ' . strlen($data_string)),
        CURLOPT_ENCODING            => "",       
        CURLOPT_USERAGENT           => "curl/7.65.1", 
        CURLOPT_POSTFIELDS          => $data_string,
    );

$ch = curl_init( $url );
curl_setopt_array( $ch, $options );
$info = curl_getinfo($ch);
$content = curl_exec( $ch );

print_r($info);
echo $content;

There are a couple of troubling responses I get, my curl request looks like this:

Array
(
    [url] => http://10.1.1.214:8080/jsonrpc
    [content_type] => 
    [http_code] => 0
    [header_size] => 0
    [request_size] => 0
    [filetime] => 0
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 0
    [namelookup_time] => 0
    [connect_time] => 0
    [pretransfer_time] => 0
    [size_upload] => 0
    [size_download] => 0
    [speed_download] => 0
    [speed_upload] => 0
    [download_content_length] => -1
    [upload_content_length] => -1
    [starttransfer_time] => 0
    [redirect_time] => 0
    [certinfo] => Array
        (
        )

    [primary_ip] => 
    [primary_port] => 0
    [local_ip] => 
    [local_port] => 0
    [redirect_url] => 
)

my error_log looks like this:

* About to connect() to 10.1.1.214 port 8080 (#69)
*   Trying 10.1.1.214...
* Failed to connect to 10.1.1.214: Permission denied
* couldn't connect to host at 10.1.1.214:8080
* Closing connection 69

Successful commands from the commandline look like this:

curl -v --data-binary '{"jsonrpc": "2.0", "method": "Application.GetProperties", "params": {"properties": ["version"]}, "id": 1}' -H 'content-type: application/json'  http://10.1.1.214:8080/jsonrpc
*   Trying 10.1.1.214:8080...
* TCP_NODELAY set
* Connected to 10.1.1.214 (10.1.1.214) port 8080 (#0)
> POST /jsonrpc HTTP/1.1
> Host: 10.1.1.214:8080
> User-Agent: curl/7.65.1
> Accept: */*
> content-type: application/json
> Content-Length: 105
>
* upload completely sent off: 105 out of 105 bytes
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Connection: Keep-Alive
< Content-Length: 116
< Content-Type: application/json
< Cache-Control: private, max-age=0, no-cache
< Accept-Ranges: none
< Date: Fri, 30 Aug 2019 02:02:17 GMT
<
* Connection #0 to host 10.1.1.214 left intact
{"id":1,"jsonrpc":"2.0","result":{"version":{"major":18,"minor":3,"revision":"newclock5_18.3-Leia","tag":"stable"}}}

1 Answers1

1

As it turns out, the issue was an SELINUX policy.

by running the following, it will fix the issue

#setsebool -P httpd_can_network_connect=1
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149