Remove $id$ tag now that we are on git; update copyright notice to year 2013
[plcapi.git] / debugger / common.php
1 <?php
2 /**
3  * @author Gaetano Giunta
4  * @copyright (C) 2005-2013 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
26   if ( isset( $_GET['usepost'] ) && $_GET['usepost'] === 'true' )
27   {
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   {
39     if (isset($_GET['wstype']) && $_GET['wstype'] == '1')
40     {
41       $wstype = 1;
42       if (isset($_GET['id']))
43         $id = $_GET['id'];
44     }
45     $host = isset($_GET['host']) ? $_GET['host'] : 'localhost'; // using '' will trigger an xmlrpc error...
46     if (isset($_GET['protocol']) && ($_GET['protocol'] == '1' || $_GET['protocol'] == '2'))
47       $protocol = $_GET['protocol'];
48     if (strpos($host, 'http://') === 0)
49       $host = substr($host, 7);
50     else if (strpos($host, 'https://') === 0)
51     {
52       $host = substr($host, 8);
53       $protocol = 2;
54     }
55     $port = isset($_GET['port']) ? $_GET['port'] : '';
56     $path = isset($_GET['path']) ? $_GET['path'] : '';
57     // in case user forgot initial '/' in xmlrpc server path, add it back
58     if ($path && ($path[0]) != '/')
59       $path = '/'.$path;
60
61     if (isset($_GET['debug']) && ($_GET['debug'] == '1' || $_GET['debug'] == '2'))
62       $debug = $_GET['debug'];
63
64     $verifyhost = (isset($_GET['verifyhost']) && ($_GET['verifyhost'] == '1' || $_GET['verifyhost'] == '2')) ? $_GET['verifyhost'] : 0;
65     if (isset($_GET['verifypeer']) && $_GET['verifypeer'] == '1')
66       $verifypeer = true;
67     else
68       $verifypeer = false;
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     $proxyuser= isset($_GET['proxyuser']) ? $_GET['proxyuser'] : '';
74     $proxypwd = isset($_GET['proxypwd']) ? $_GET['proxypwd'] : '';
75     $timeout = isset($_GET['timeout']) ? $_GET['timeout'] : 0;
76     if (!is_numeric($timeout))
77       $timeout = 0;
78     $action = $_GET['action'];
79
80     $method = isset($_GET['method']) ? $_GET['method'] : '';
81     $methodsig = isset($_GET['methodsig']) ? $_GET['methodsig'] : 0;
82     $payload = isset($_GET['methodpayload']) ? $_GET['methodpayload'] : '';
83     $alt_payload = isset($_GET['altmethodpayload']) ? $_GET['altmethodpayload'] : '';
84
85     if (isset($_GET['run']) && $_GET['run'] == 'now')
86       $run = true;
87
88     $username = isset($_GET['username']) ? $_GET['username'] : '';
89     $password = isset($_GET['password']) ? $_GET['password'] : '';
90
91     $authtype = (isset($_GET['authtype']) && ($_GET['authtype'] == '2' || $_GET['authtype'] == '8')) ? $_GET['authtype'] : 1;
92
93     if (isset($_GET['requestcompression']) && ($_GET['requestcompression'] == '1' || $_GET['requestcompression'] == '2'))
94       $requestcompression = $_GET['requestcompression'];
95     else
96       $requestcompression = 0;
97     if (isset($_GET['responsecompression']) && ($_GET['responsecompression'] == '1' || $_GET['responsecompression'] == '2' || $_GET['responsecompression'] == '3'))
98       $responsecompression = $_GET['responsecompression'];
99     else
100       $responsecompression = 0;
101
102     $clientcookies = isset($_GET['clientcookies']) ? $_GET['clientcookies'] : '';
103   }
104   else
105   {
106     $host = '';
107     $port = '';
108     $path = '';
109     $action = '';
110     $method = '';
111     $methodsig = 0;
112     $payload = '';
113     $alt_payload = '';
114     $username = '';
115     $password = '';
116     $authtype = 1;
117     $verifyhost = 0;
118     $verifypeer = false;
119     $cainfo = '';
120     $proxy = '';
121     $proxyuser = '';
122     $proxypwd = '';
123     $timeout = 0;
124     $requestcompression = 0;
125     $responsecompression = 0;
126     $clientcookies = '';
127   }
128
129   // check input for known XMLRPC attacks against this or other libs
130   function payload_is_safe($input)
131   {
132       return true;
133   }
134 ?>