comments
[plcapi.git] / debugger / common.php
1 <?php
2 /**
3  * @author Gaetano Giunta
4  * @copyright (C) 2005-2020 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  * @todo move parameters away from global namespace
12  */
13
14 // work around magic quotes
15 if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
16     function stripslashes_deep($value)
17     {
18         $value = is_array($value) ?
19             array_map('stripslashes_deep', $value) :
20             stripslashes($value);
21
22         return $value;
23     }
24
25     $_GET = array_map('stripslashes_deep', $_GET);
26 }
27
28 $preferredEncodings = 'UTF-8, ASCII, ISO-8859-1, UTF-7, EUC-JP, SJIS, eucJP-win, SJIS-win, JIS, ISO-2022-JP';
29 $inputcharset = mb_detect_encoding(urldecode($_SERVER['REQUEST_URI']), $preferredEncodings);
30 if (isset($_GET['usepost']) && $_GET['usepost'] === 'true') {
31     $_GET = $_POST;
32     $inputcharset = mb_detect_encoding(implode('', $_GET), $preferredEncodings);
33 }
34
35 /// @todo if $inputcharset is not UTF8, we should probably re-encode $_GET to make it UTF-8
36
37 // recover input parameters
38 $debug = false;
39 $protocol = 0;
40 $run = false;
41 $wstype = 0;
42 $id = '';
43 if (isset($_GET['action'])) {
44     if (isset($_GET['wstype']) && $_GET['wstype'] == '1') {
45         $wstype = 1;
46         if (isset($_GET['id'])) {
47             $id = $_GET['id'];
48         }
49     }
50     $host = isset($_GET['host']) ? $_GET['host'] : 'localhost'; // using '' will trigger an xmlrpc error...
51     if (isset($_GET['protocol']) && ($_GET['protocol'] == '1' || $_GET['protocol'] == '2')) {
52         $protocol = $_GET['protocol'];
53     }
54     if (strpos($host, 'http://') === 0) {
55         $host = substr($host, 7);
56     } elseif (strpos($host, 'https://') === 0) {
57         $host = substr($host, 8);
58         $protocol = 2;
59     }
60     $port = isset($_GET['port']) ? $_GET['port'] : '';
61     $path = isset($_GET['path']) ? $_GET['path'] : '';
62     // in case user forgot initial '/' in xmlrpc server path, add it back
63     if ($path && ($path[0]) != '/') {
64         $path = '/' . $path;
65     }
66
67     if (isset($_GET['debug']) && ($_GET['debug'] == '1' || $_GET['debug'] == '2')) {
68         $debug = $_GET['debug'];
69     }
70
71     $verifyhost = (isset($_GET['verifyhost']) && ($_GET['verifyhost'] == '1' || $_GET['verifyhost'] == '2')) ? $_GET['verifyhost'] : 0;
72     if (isset($_GET['verifypeer']) && $_GET['verifypeer'] == '1') {
73         $verifypeer = true;
74     } else {
75         $verifypeer = false;
76     }
77     $cainfo = isset($_GET['cainfo']) ? $_GET['cainfo'] : '';
78     $proxy = isset($_GET['proxy']) ? $_GET['proxy'] : 0;
79     if (strpos($proxy, 'http://') === 0) {
80         $proxy = substr($proxy, 7);
81     }
82     $proxyuser = isset($_GET['proxyuser']) ? $_GET['proxyuser'] : '';
83     $proxypwd = isset($_GET['proxypwd']) ? $_GET['proxypwd'] : '';
84     $timeout = isset($_GET['timeout']) ? $_GET['timeout'] : 0;
85     if (!is_numeric($timeout)) {
86         $timeout = 0;
87     }
88     $action = $_GET['action'];
89
90     $method = isset($_GET['method']) ? $_GET['method'] : '';
91     $methodsig = isset($_GET['methodsig']) ? $_GET['methodsig'] : 0;
92     $payload = isset($_GET['methodpayload']) ? $_GET['methodpayload'] : '';
93     $alt_payload = isset($_GET['altmethodpayload']) ? $_GET['altmethodpayload'] : '';
94
95     if (isset($_GET['run']) && $_GET['run'] == 'now') {
96         $run = true;
97     }
98
99     $username = isset($_GET['username']) ? $_GET['username'] : '';
100     $password = isset($_GET['password']) ? $_GET['password'] : '';
101
102     $authtype = (isset($_GET['authtype']) && ($_GET['authtype'] == '2' || $_GET['authtype'] == '8')) ? $_GET['authtype'] : 1;
103
104     if (isset($_GET['requestcompression']) && ($_GET['requestcompression'] == '1' || $_GET['requestcompression'] == '2')) {
105         $requestcompression = $_GET['requestcompression'];
106     } else {
107         $requestcompression = 0;
108     }
109     if (isset($_GET['responsecompression']) && ($_GET['responsecompression'] == '1' || $_GET['responsecompression'] == '2' || $_GET['responsecompression'] == '3')) {
110         $responsecompression = $_GET['responsecompression'];
111     } else {
112         $responsecompression = 0;
113     }
114
115     $clientcookies = isset($_GET['clientcookies']) ? $_GET['clientcookies'] : '';
116 } else {
117     $host = '';
118     $port = '';
119     $path = '';
120     $action = '';
121     $method = '';
122     $methodsig = 0;
123     $payload = '';
124     $alt_payload = '';
125     $username = '';
126     $password = '';
127     $authtype = 1;
128     $verifyhost = 0;
129     $verifypeer = false;
130     $cainfo = '';
131     $proxy = '';
132     $proxyuser = '';
133     $proxypwd = '';
134     $timeout = 0;
135     $requestcompression = 0;
136     $responsecompression = 0;
137     $clientcookies = '';
138 }
139
140 // check input for known XMLRPC attacks against this or other libs
141 function payload_is_safe($input)
142 {
143     return true;
144 }