642326ab63fb0f98cece70b7dbf490de81407f55
[plcapi.git] / debugger / common.php
1 <?php
2 /**
3  * @author Gaetano Giunta
4  * @copyright (C) 2005-2015 G. Giunta
5  * @license code licensed under the BSD License: see file license.txt
6  *
7  * @todo switch params for http compression from 0,1,2 to values to be used directly
8  * @todo do some more sanitization of received parameters
9  */
10
11 // work around magic quotes
12 if (get_magic_quotes_gpc()) {
13     function stripslashes_deep($value)
14     {
15         $value = is_array($value) ?
16             array_map('stripslashes_deep', $value) :
17             stripslashes($value);
18
19         return $value;
20     }
21
22     $_GET = array_map('stripslashes_deep', $_GET);
23 }
24
25 if (isset($_GET['usepost']) && $_GET['usepost'] === 'true') {
26     $_GET = $_POST;
27 }
28
29 // recover input parameters
30 $debug = false;
31 $protocol = 0;
32 $run = false;
33 $wstype = 0;
34 $id = '';
35 if (isset($_GET['action'])) {
36     if (isset($_GET['wstype']) && $_GET['wstype'] == '1') {
37         $wstype = 1;
38         if (isset($_GET['id'])) {
39             $id = $_GET['id'];
40         }
41     }
42     $host = isset($_GET['host']) ? $_GET['host'] : 'localhost'; // using '' will trigger an xmlrpc error...
43     if (isset($_GET['protocol']) && ($_GET['protocol'] == '1' || $_GET['protocol'] == '2')) {
44         $protocol = $_GET['protocol'];
45     }
46     if (strpos($host, 'http://') === 0) {
47         $host = substr($host, 7);
48     } elseif (strpos($host, 'https://') === 0) {
49         $host = substr($host, 8);
50         $protocol = 2;
51     }
52     $port = isset($_GET['port']) ? $_GET['port'] : '';
53     $path = isset($_GET['path']) ? $_GET['path'] : '';
54     // in case user forgot initial '/' in xmlrpc server path, add it back
55     if ($path && ($path[0]) != '/') {
56         $path = '/' . $path;
57     }
58
59     if (isset($_GET['debug']) && ($_GET['debug'] == '1' || $_GET['debug'] == '2')) {
60         $debug = $_GET['debug'];
61     }
62
63     $verifyhost = (isset($_GET['verifyhost']) && ($_GET['verifyhost'] == '1' || $_GET['verifyhost'] == '2')) ? $_GET['verifyhost'] : 0;
64     if (isset($_GET['verifypeer']) && $_GET['verifypeer'] == '1') {
65         $verifypeer = true;
66     } else {
67         $verifypeer = false;
68     }
69     $cainfo = isset($_GET['cainfo']) ? $_GET['cainfo'] : '';
70     $proxy = isset($_GET['proxy']) ? $_GET['proxy'] : 0;
71     if (strpos($proxy, 'http://') === 0) {
72         $proxy = substr($proxy, 7);
73     }
74     $proxyuser = isset($_GET['proxyuser']) ? $_GET['proxyuser'] : '';
75     $proxypwd = isset($_GET['proxypwd']) ? $_GET['proxypwd'] : '';
76     $timeout = isset($_GET['timeout']) ? $_GET['timeout'] : 0;
77     if (!is_numeric($timeout)) {
78         $timeout = 0;
79     }
80     $action = $_GET['action'];
81
82     $method = isset($_GET['method']) ? $_GET['method'] : '';
83     $methodsig = isset($_GET['methodsig']) ? $_GET['methodsig'] : 0;
84     $payload = isset($_GET['methodpayload']) ? $_GET['methodpayload'] : '';
85     $alt_payload = isset($_GET['altmethodpayload']) ? $_GET['altmethodpayload'] : '';
86
87     if (isset($_GET['run']) && $_GET['run'] == 'now') {
88         $run = true;
89     }
90
91     $username = isset($_GET['username']) ? $_GET['username'] : '';
92     $password = isset($_GET['password']) ? $_GET['password'] : '';
93
94     $authtype = (isset($_GET['authtype']) && ($_GET['authtype'] == '2' || $_GET['authtype'] == '8')) ? $_GET['authtype'] : 1;
95
96     if (isset($_GET['requestcompression']) && ($_GET['requestcompression'] == '1' || $_GET['requestcompression'] == '2')) {
97         $requestcompression = $_GET['requestcompression'];
98     } else {
99         $requestcompression = 0;
100     }
101     if (isset($_GET['responsecompression']) && ($_GET['responsecompression'] == '1' || $_GET['responsecompression'] == '2' || $_GET['responsecompression'] == '3')) {
102         $responsecompression = $_GET['responsecompression'];
103     } else {
104         $responsecompression = 0;
105     }
106
107     $clientcookies = isset($_GET['clientcookies']) ? $_GET['clientcookies'] : '';
108 } else {
109     $host = '';
110     $port = '';
111     $path = '';
112     $action = '';
113     $method = '';
114     $methodsig = 0;
115     $payload = '';
116     $alt_payload = '';
117     $username = '';
118     $password = '';
119     $authtype = 1;
120     $verifyhost = 0;
121     $verifypeer = false;
122     $cainfo = '';
123     $proxy = '';
124     $proxyuser = '';
125     $proxypwd = '';
126     $timeout = 0;
127     $requestcompression = 0;
128     $responsecompression = 0;
129     $clientcookies = '';
130 }
131
132 // check input for known XMLRPC attacks against this or other libs
133 function payload_is_safe($input)
134 {
135     return true;
136 }