ea389a65aeee675be6ec2cb571395960aabb5f1c
[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 $preferredEncodings = 'UTF-8, ASCII, ISO-8859-1, UTF-7, EUC-JP, SJIS, eucJP-win, SJIS-win, JIS, ISO-2022-JP';
28 $inputcharset = mb_detect_encoding(urldecode($_SERVER['REQUEST_URI']), $preferredEncodings);
29 if (isset($_GET['usepost']) && $_GET['usepost'] === 'true') {
30     $_GET = $_POST;
31     /// @bug this is not a perfect detection method - it will fail if eg. a latin1 character is in the method name
32     $inputcharset = mb_detect_encoding(urldecode(isset($_GET['methodpayload'])) ? $_GET['methodpayload'] : '', $preferredEncodings);
33 }
34
35 // recover input parameters
36 $debug = false;
37 $protocol = 0;
38 $run = false;
39 $wstype = 0;
40 $id = '';
41 if (isset($_GET['action'])) {
42     if (isset($_GET['wstype']) && $_GET['wstype'] == '1') {
43         $wstype = 1;
44         if (isset($_GET['id'])) {
45             $id = $_GET['id'];
46         }
47     }
48     $host = isset($_GET['host']) ? $_GET['host'] : 'localhost'; // using '' will trigger an xmlrpc error...
49     if (isset($_GET['protocol']) && ($_GET['protocol'] == '1' || $_GET['protocol'] == '2')) {
50         $protocol = $_GET['protocol'];
51     }
52     if (strpos($host, 'http://') === 0) {
53         $host = substr($host, 7);
54     } elseif (strpos($host, 'https://') === 0) {
55         $host = substr($host, 8);
56         $protocol = 2;
57     }
58     $port = isset($_GET['port']) ? $_GET['port'] : '';
59     $path = isset($_GET['path']) ? $_GET['path'] : '';
60     // in case user forgot initial '/' in xmlrpc server path, add it back
61     if ($path && ($path[0]) != '/') {
62         $path = '/' . $path;
63     }
64
65     if (isset($_GET['debug']) && ($_GET['debug'] == '1' || $_GET['debug'] == '2')) {
66         $debug = $_GET['debug'];
67     }
68
69     $verifyhost = (isset($_GET['verifyhost']) && ($_GET['verifyhost'] == '1' || $_GET['verifyhost'] == '2')) ? $_GET['verifyhost'] : 0;
70     if (isset($_GET['verifypeer']) && $_GET['verifypeer'] == '1') {
71         $verifypeer = true;
72     } else {
73         $verifypeer = false;
74     }
75     $cainfo = isset($_GET['cainfo']) ? $_GET['cainfo'] : '';
76     $proxy = isset($_GET['proxy']) ? $_GET['proxy'] : 0;
77     if (strpos($proxy, 'http://') === 0) {
78         $proxy = substr($proxy, 7);
79     }
80     $proxyuser = isset($_GET['proxyuser']) ? $_GET['proxyuser'] : '';
81     $proxypwd = isset($_GET['proxypwd']) ? $_GET['proxypwd'] : '';
82     $timeout = isset($_GET['timeout']) ? $_GET['timeout'] : 0;
83     if (!is_numeric($timeout)) {
84         $timeout = 0;
85     }
86     $action = $_GET['action'];
87
88     $method = isset($_GET['method']) ? $_GET['method'] : '';
89     $methodsig = isset($_GET['methodsig']) ? $_GET['methodsig'] : 0;
90     $payload = isset($_GET['methodpayload']) ? $_GET['methodpayload'] : '';
91     $alt_payload = isset($_GET['altmethodpayload']) ? $_GET['altmethodpayload'] : '';
92
93     if (isset($_GET['run']) && $_GET['run'] == 'now') {
94         $run = true;
95     }
96
97     $username = isset($_GET['username']) ? $_GET['username'] : '';
98     $password = isset($_GET['password']) ? $_GET['password'] : '';
99
100     $authtype = (isset($_GET['authtype']) && ($_GET['authtype'] == '2' || $_GET['authtype'] == '8')) ? $_GET['authtype'] : 1;
101
102     if (isset($_GET['requestcompression']) && ($_GET['requestcompression'] == '1' || $_GET['requestcompression'] == '2')) {
103         $requestcompression = $_GET['requestcompression'];
104     } else {
105         $requestcompression = 0;
106     }
107     if (isset($_GET['responsecompression']) && ($_GET['responsecompression'] == '1' || $_GET['responsecompression'] == '2' || $_GET['responsecompression'] == '3')) {
108         $responsecompression = $_GET['responsecompression'];
109     } else {
110         $responsecompression = 0;
111     }
112
113     $clientcookies = isset($_GET['clientcookies']) ? $_GET['clientcookies'] : '';
114 } else {
115     $host = '';
116     $port = '';
117     $path = '';
118     $action = '';
119     $method = '';
120     $methodsig = 0;
121     $payload = '';
122     $alt_payload = '';
123     $username = '';
124     $password = '';
125     $authtype = 1;
126     $verifyhost = 0;
127     $verifypeer = false;
128     $cainfo = '';
129     $proxy = '';
130     $proxyuser = '';
131     $proxypwd = '';
132     $timeout = 0;
133     $requestcompression = 0;
134     $responsecompression = 0;
135     $clientcookies = '';
136 }
137
138 // check input for known XMLRPC attacks against this or other libs
139 function payload_is_safe($input)
140 {
141     return true;
142 }