1 | <?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? |
---|
9 | |
---|
10 | if(!session_id()) session_start(); |
---|
11 | //$logServer = new logServer(); |
---|
12 | |
---|
13 | |
---|
14 | function writeHeader(){ |
---|
15 | header('Content-type: application/json'); |
---|
16 | header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); |
---|
17 | header("Cache-Control: post-check=0, pre-check=0", false); |
---|
18 | header("Pragma: no-cache"); |
---|
19 | } |
---|
20 | |
---|
21 | function n4d($method, $args){ |
---|
22 | |
---|
23 | writeHeader(); |
---|
24 | $url='https://127.0.0.1:9779'; |
---|
25 | $request=xmlrpc_encode_request($method, $args); |
---|
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 | } |
---|
61 | |
---|
62 | |
---|
63 | function 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 | } |
---|
70 | |
---|
71 | |
---|
72 | |
---|
73 | try{ |
---|
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 | |
---|
89 | } catch(Exception $e){ |
---|
90 | error_log("Exception in n4d.php: ".$e); |
---|
91 | } |
---|
92 | ?> |
---|