Jsonapi impossible à relier à un CMS

Miidash

Architecte en herbe
14 Avril 2014
87
29
66
28
Bonsoir , voila mon probleme , j'ai absolument correctement bien entrer les bonnes informations sur les dossiers config.yml+user.yml de JSONAPI + La configuration sur le CMS voici les fichiers (logins fictifs , essayez toujours de hack ^^) mais le serveur ne reçoit aucune requete du CMS , je précise que le serveur est en 1.6.4 et le CMS utilisé est SamantCMS mais c'est de ma faute j'ai du modifier une ligne sans le faire expres pouvez vous m'aider?

Voici les fichiers:

Sur le config.yml (serveur) :

Code:
# API methods on the method-whitelist will be
# able to called without any sort of authentication
method-whitelist:
- getPlayerLimit
- dynmap.getPort
options:
  stream_pusher:
    max_queue_age: 30
    max_queue_length: 500
  startup-delay: 2000
  port: 39393
  ip-whitelist: []
  log-to-console: true
  log-to-file: 'false'
  anyone-can-use-calladmin: true
  use-new-api: true

Sur le user.yml (serveur) :

Code:
users:
- username: useradmin
  password: 1234
  logging: true
  groups:
  - full_control
- username: user
  password: 12345
  logging: true
  groups:
  - chat_only

Sur le jsonapi_configuration.php (site CMS) :


Code:
  <?php
                    // Ajout du fichier JSONAPI
                    require_once ("JSONAPI.php");
                      
                    ####### A CONFIGURER CMS
                    $var_salt_1 = ""; // cryptage
                    $var_ip_1 = "62.4.13.166";          <!-- Sachant que le port est celui par défaut (25565)  -->
                    $var_user_1 = "useradmin";
                    $var_mdp_1 = "1234";
                    $var_port_1 = "39393";
                    ####### A CONFIGURER
                      
                    $connexion_1 = new JSONAPI($var_ip_1, $var_port_1, $var_user_1, $var_mdp_1, $var_salt_1);
                      
                    $server1 = $connexion_1->call("getPlayerCount"); 
                    $server1_limit = $connexion_1->call("getPlayerLimit"); 
            ?>

Sur le JSONAPI.php :

Code:
<?php
 
/**
 * A PHP class for access Minecraft servers that have Bukkit with the {@link http://github.com/alecgorge/JSONAPI JSONAPI} plugin installed.
 * 
 * This class handles everything from key creation to URL creation to actually returning the decoded JSON as an associative array.
 * 
 * @author Alec Gorge <[email protected]>
 * @version Alpha 5
 * @link http://github.com/alecgorge/JSONAPI
 * @package JSONAPI
 * @since Alpha 5
 */
class JSONAPI {
public $host;
public $port;
public $salt;
public $username;
public $password;
private $urlFormats = array(
"call" => "http://%s:%s/api/call?method=%s&args=%s&key=%s",
"callMultiple" => "http://%s:%s/api/call-multiple?method=%s&args=%s&key=%s"
);
 
/**
* Creates a new JSONAPI instance.
*/
public function __construct ($host, $port, $uname, $pword, $salt) {
$this->host = $host;
$this->port = $port;
$this->username = $uname;
$this->password = $pword;
$this->salt = $salt;
 
if(!extension_loaded("cURL")) {
throw new Exception("JSONAPI requires cURL extension in order to work.");
}
}
 
/**
* Generates the proper SHA256 based key from the given method suitable for use as the key GET parameter in a JSONAPI API call.
* 
* @param string $method The name of the JSONAPI API method to generate the key for.
* @return string The SHA256 key suitable for use as the key GET parameter in a JSONAPI API call.
*/
public function createKey($method) {
if(is_array($method)) {
$method = json_encode($method);
}
return hash('sha256', $this->username . $method . $this->password . $this->salt);
}
 
/**
* Generates the proper URL for a standard API call the given method and arguments.
* 
* @param string $method The name of the JSONAPI API method to generate the URL for.
* @param array $args An array of arguments that are to be passed in the URL.
* @return string A proper standard JSONAPI API call URL. Example: "http://localhost:20059/api/call?method=methodName&args=jsonEncodedArgsArray&key=validKey".
*/
public function makeURL($method, array $args) {
return sprintf($this->urlFormats["call"], $this->host, $this->port, rawurlencode($method), rawurlencode(json_encode($args)), $this->createKey($method));
}
 
/**
* Generates the proper URL for a multiple API call the given method and arguments.
* 
* @param array $methods An array of strings, where each string is the name of the JSONAPI API method to generate the URL for.
* @param array $args An array of arrays, where each array contains the arguments that are to be passed in the URL.
* @return string A proper multiple JSONAPI API call URL. Example: "http://localhost:20059/api/call-multiple?method=[methodName,methodName2]&args=jsonEncodedArrayOfArgsArrays&key=validKey".
*/
public function makeURLMultiple(array $methods, array $args) {
return sprintf($this->urlFormats["callMultiple"], $this->host, $this->port, rawurlencode(json_encode($methods)), rawurlencode(json_encode($args)), $this->createKey($methods));
}
 
/**
* Calls the single given JSONAPI API method with the given args.
* 
* @param string $method The name of the JSONAPI API method to call.
* @param array $args An array of arguments that are to be passed.
* @return array An associative array representing the JSON that was returned.
*/
public function call($method, array $args = array()) {
if(is_array($method)) {
return $this->callMultiple($method, $args);
}
 
$url = $this->makeURL($method, $args);
 
return json_decode($this->curl($url), true);
}
 
private function curl($url) {
$c = curl_init($url);
curl_setopt($c, CURLOPT_PORT, $this->port);
curl_setopt($c, CURLOPT_HEADER, false);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_TIMEOUT, 10);
$result = curl_exec($c);
curl_close($c);
return $result;
}
 
/**
* Calls the given JSONAPI API methods with the given args.
* 
* @param array $methods An array strings, where each string is the name of a JSONAPI API method to call.
* @param array $args An array of arrays of arguments that are to be passed.
* @throws Exception When the length of the $methods array and the $args array are different, an exception is thrown.
* @return array An array of associative arrays representing the JSON that was returned.
*/
public function callMultiple(array $methods, array $args = array()) {
if(count($methods) !== count($args)) {
throw new Exception("The length of the arrays \$methods and \$args are different! You need an array of arguments for each method!");
}
 
$url = $this->makeURLMultiple($methods, $args);
 
return json_decode($this->curl($url), true);
}
/**
* The default function called if no one matched for JSONAPI.
* 
* @param string $method The name of the JSONAPI API method to call.
* @param array $params An array of arguments that are to be passed.
* @return array An associative array representing the JSON that was returned.
*/
function __call($method, $params) {
                if(is_array($params)) {
                    return $this->call($method, $params);
                } else {
                    return $this->call($method, array($params));
                }
}
}


En espèrent que vous trouviez le problème.

PS : j'ai bien installé protocolLib+Vault à la bonne version sur le serveur ainsi que JSONAPI. (le fichier de config s'est crée avec ces fichiers si dessus)

Cordialement , Sébastien
 
  • J'aime
Reactions: stargate83

Miidash

Architecte en herbe
14 Avril 2014
87
29
66
28
Non je ne pense pas que cela viendrait de l’hébergeur puisque comme je l'ai dit dans mon sujet , c'est moi qui a du sans doute toucher à quelque chose mais je ne sais pas quoi car quelques jour avant, la boutique et le système de vote marchaient correctement .

PS : Mon hébergeur Web est EasyHebergement et mon hébergeur Minecraft : Dedishops

Cordialement , Sébastien
 
  • J'aime
Reactions: stargate83

Flud_Ice

Architecte en herbe
28 Mars 2013
107
7
75
26
Le port est ouvert sur tes deux hébergeurs ? Si tu ne sais pas, poste un message sur leur support !
 

Valtureyn

Développeur
28 Février 2014
243
45
67
31
Pourquoi t’embête tu avec JsonApi ? Fait une boutique qui marche avec des requêtes Sql et crée par la suite un plugin qui va s'occuper de traiter les commandes sur le serveur.

Cordialement.