Kodi Community Forum

Full Version: Kodi JSON RPC and PHP
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi All,

I'm trying to setup a PHP script to interact with IFTTT.  I found that there is one github but wasn't able to make it work.  in my investigation I'm finding that I'm getting a "permission denied".  I've got some code snippets below, wondering if anyone here is able to help me figure this out.  ITS DRIVING ME NUTS!

Thank you,

PHP code:

$url='http://10.1.1.214:8080/jsonrpc';
$myvars = array(
    'jsonrpc'=>'2.0', 'id'=>'1', 'method'=>'Application.GetProperties', 'params'=>array('properties'=>array('properties'=>array('volume'))))
;

$jsonvars = json_encode($myvars);

echo $jsonvars;
echo "\n\n";

$data = array("name" => "Hagrid", "age" => "36");
$data_string = json_encode($myvars);

    $options = array(
        CURLOPT_VERBOSE => 1,
        CURLOPT_RETURNTRANSFER        => true,     // return web page
        CURLOPT_HEADER                => true,    // don't return headers
        CURLOPT_HTTPHEADER            => array(                                                                          
        'Content-Type: application/json',                                                                                
        'Content-Length: ' . strlen($data_string)),

        CURLOPT_ENCODING            => "",       // handle all encodings
        CURLOPT_USERAGENT            => "curl/7.65.1", // who am i
        CURLOPT_POSTFIELDS            => $data_string,
        
    );
    
$ch = curl_init( $url );
curl_setopt_array( $ch, $options );
$info = curl_getinfo($ch);
$content = curl_exec( $ch );
$error_msg = curl_error($ch);
curl_close($ch);

print_r($info);
echo "\n response content: \n";
echo $content;
echo "\n error message\n";
echo $error_msg;

what I get out of the above is as follows:
Quote:{"jsonrpc":"2.0","id":"1","method":"Application.GetProperties","params":{"properties":{"properties":["volume"]}}} 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] => ) response content: error message Failed to connect to 10.1.1.214: Permission denied




what I have in the error log looks like this:
Quote:* About to connect() to 10.1.1.214 port 8080 (#78)
*   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 78
For anyone interested, I was able to get the issue solved.  it was an SELINUX policy, by running the command below, it fixed the issue
Quote:#setsebool -P httpd_can_network_connect=1