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