Ignore:
Timestamp:
Apr 29, 2016, 1:40:19 PM (5 years ago)
Author:
joamuran
Message:

wip

File:
1 edited

Legend:

Unmodified
Added
Removed
  • admin-center/trunk/fuentes/admin-center.install/usr/share/admin-center/n4d.php

    r1055 r1312  
    11<?php
     2//require_once("logServer.php"); -> No s'usa!
     3//require_once('php_lib/wsclient/vendor/autoload.php'); -> No s'usa !
     4//use WebSocket\Client; -> No s'usa!
     5
     6
     7// require_once('php_lib/logListener.php');  -> S'utilitza?
     8// use logListener;  -> S'utilitza?
    29
    310if(!session_id()) session_start();
     11//$logServer = new logServer();
    412
    5 try{
    613
    7   //$credentials=$_POST["creds"];
    8   //$class=$_POST["class"];
    9   $method=$_POST["method"];
    10   $args=json_decode($_POST["args"]);
    11   //$args=$_POST["args"];
    12   error_log("!!!!!!!!!!!!!!!".print_r($args, true)."****************");
    13   error_log($method);
    14   //$args=["lliurex", "lliurex"];
    15   //error_log(print_r($args, true));
    16 
    17   //error_log("method:$method\n args:$args\n");
    18 
     14function writeHeader(){
    1915  header('Content-type: application/json');
    2016  header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
    2117  header("Cache-Control: post-check=0, pre-check=0", false);
    2218  header("Pragma: no-cache");
     19}
    2320
    24   //$args=array("", "VariablesManager");
    25 
     21function n4d($method, $args){
     22 
     23  writeHeader();
    2624  $url='https://127.0.0.1:9779';
    2725  $request=xmlrpc_encode_request($method, $args);
    28   error_log($request);
    29   $header[] = "Content-type: text/xml";
    30   $header[] = "Content-length: ".strlen($request);
    31 
    32   $ch = curl_init();
    33   curl_setopt($ch, CURLOPT_URL, $url);
    34   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    35   curl_setopt($ch, CURLOPT_TIMEOUT, 10000);
    36   curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    37   curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
    38 
    39   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
    40   curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    41   curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "/n4dcert.pem");
     26  //error_log($request);
     27    $header[] = "Content-type: text/xml";
     28    $header[] = "Content-length: ".strlen($request);
     29 
     30    $ch = curl_init();
     31    curl_setopt($ch, CURLOPT_URL, $url);
     32    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     33    curl_setopt($ch, CURLOPT_TIMEOUT, 10000);
     34    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
     35    curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
     36 
     37    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
     38    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
     39    curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "/n4dcert.pem");
     40 
     41 
     42    $data = curl_exec($ch);
     43    error_log(curl_errno($ch));
     44    if (curl_errno($ch)) {
     45      $xml_snippet=simplexml_load_string($data);
     46      $json=json_encode($xml_snippet);
     47      echo ($json);
     48    } else {
     49        $xmlobj=xmlrpc_decode($data);
     50        $json=json_encode($xmlobj);
     51        var_error_log($data);
     52        var_error_log($xmlobj);
     53        var_error_log($json);
     54        if ($json=="") {
     55          $json=$xmlobj;}
     56          var_error_log($json);
     57        echo ($json);
     58    }
     59 
     60}
    4261
    4362
    44   $data = curl_exec($ch);
    45   if (curl_errno($ch)) {
    46     error_log("111111111111111111111111111111");
    47     $xml_snippet=simplexml_load_string($data);
    48     $json=json_encode($xml_snippet);
    49     echo ($json);
     63function var_error_log( $object=null ){
     64    ob_start();                    // start buffer capture
     65    var_dump( $object );           // dump the values
     66    $contents = ob_get_contents(); // put the buffer into a variable
     67    ob_end_clean();                // end capture
     68    error_log( $contents );        // log contents of the result of var_dump( $object )
     69}
    5070
    51     } else {
    52       error_log("2222222222222222222222222222222222");
    53       $xmlobj=xmlrpc_decode($data);
    54       $json=json_encode($xmlobj);
    55       error_log($json);
    56       echo ($json);
    57     }
    5871
     72
     73try{
     74// Getting $_POST parameters
     75  $method=$_POST["method"];
     76  $args=json_decode($_POST["args"]);
     77  $myfile = fopen("/tmp/n4dlog","a");
     78  fwrite($myfile,$method);
     79  fwrite($myfile,$_POST["args"]);
     80  fwrite($myfile,"******\n");
     81  fclose($myfile);
     82  error_log($method);
     83 
     84  if (isset($_POST['log'])) $log=$_POST["log"];
     85    else $log="false";
     86   
     87  n4d($method, $args);
     88 
    5989} catch(Exception $e){
    60   error_log("Exception!!!!!!!!!!!!!!: ".$e);
     90  error_log("Exception in n4d.php: ".$e);
    6191}
    6292?>
Note: See TracChangeset for help on using the changeset viewer.