Fix: make debugger work correctly when any field value is LATIN-1
[plcapi.git] / debugger / common.php
1 <?php
2 /**
3  * @author Gaetano Giunta
4  * @copyright (C) 2005-2014 G. Giunta
5  * @license code licensed under the BSD License: http://phpxmlrpc.sourceforge.net/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   {
14     function stripslashes_deep($value)
15     {
16         $value = is_array($value) ?
17                     array_map('stripslashes_deep', $value) :
18                     stripslashes($value);
19
20         return $value;
21     }
22     $_GET = array_map('stripslashes_deep', $_GET);
23   }
24
25   $preferredEncodings = 'UTF-8, ASCII, ISO-8859-1, UTF-7, EUC-JP, SJIS, eucJP-win, SJIS-win, JIS, ISO-2022-JP';
26   $inputcharset = mb_detect_encoding(urldecode($_SERVER['REQUEST_URI']), $preferredEncodings);
27
28   if ( isset( $_GET['usepost'] ) && $_GET['usepost'] === 'true' )
29   {
30       $_GET = $_POST;
31       $inputcharset = mb_detect_encoding(implode('', $_GET), $preferredEncodings);
32   }
33
34 // recover input parameters
35   $debug = false;
36   $protocol = 0;
37   $run = false;
38   $wstype = 0;
39   $id = '';
40   if (isset($_GET['action']))
41   {
42     if (isset($_GET['wstype']) && $_GET['wstype'] == '1')
43     {
44       $wstype = 1;
45       if (isset($_GET['id']))
46         $id = $_GET['id'];
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     if (strpos($host, 'http://') === 0)
52       $host = substr($host, 7);
53     else if (strpos($host, 'https://') === 0)
54     {
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     if (isset($_GET['debug']) && ($_GET['debug'] == '1' || $_GET['debug'] == '2'))
65       $debug = $_GET['debug'];
66
67     $verifyhost = (isset($_GET['verifyhost']) && ($_GET['verifyhost'] == '1' || $_GET['verifyhost'] == '2')) ? $_GET['verifyhost'] : 0;
68     if (isset($_GET['verifypeer']) && $_GET['verifypeer'] == '1')
69       $verifypeer = true;
70     else
71       $verifypeer = false;
72     $cainfo= isset($_GET['cainfo']) ? $_GET['cainfo'] : '';
73     $proxy = isset($_GET['proxy']) ? $_GET['proxy'] : 0;
74     if (strpos($proxy, 'http://') === 0)
75       $proxy = substr($proxy, 7);
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     $action = $_GET['action'];
82
83     $method = isset($_GET['method']) ? $_GET['method'] : '';
84     $methodsig = isset($_GET['methodsig']) ? $_GET['methodsig'] : 0;
85     $payload = isset($_GET['methodpayload']) ? $_GET['methodpayload'] : '';
86     $alt_payload = isset($_GET['altmethodpayload']) ? $_GET['altmethodpayload'] : '';
87
88     if (isset($_GET['run']) && $_GET['run'] == 'now')
89       $run = true;
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     if (isset($_GET['responsecompression']) && ($_GET['responsecompression'] == '1' || $_GET['responsecompression'] == '2' || $_GET['responsecompression'] == '3'))
101       $responsecompression = $_GET['responsecompression'];
102     else
103       $responsecompression = 0;
104
105     $clientcookies = isset($_GET['clientcookies']) ? $_GET['clientcookies'] : '';
106   }
107   else
108   {
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   }
137 ?>