- Initial import of the mob, reorganizing dirs to match packaged version
[plcapi.git] / debugger / common.php
1 <?php
2 /**
3  * @version $Id$
4  * @author Gaetano Giunta
5  * @copyright (C) 2005-2008 G. Giunta
6  * @license code licensed under the BSD License: http://phpxmlrpc.sourceforge.net/license.txt
7  *
8  * @todo switch params for http compression from 0,1,2 to values to be used directly
9  * @todo do some more sanitization of received parameters
10  */
11
12 // work around magic quotes
13   if (get_magic_quotes_gpc())
14   {
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     $_GET = array_map('stripslashes_deep', $_GET);
24   }
25
26
27   if ( isset( $_GET['usepost'] ) && $_GET['usepost'] === 'true' )
28   {
29       $_GET = $_POST;
30   }
31
32 // recover input parameters
33   $debug = false;
34   $protocol = 0;
35   $run = false;
36   $wstype = 0;
37   $id = '';
38   if (isset($_GET['action']))
39   {
40     if (isset($_GET['wstype']) && $_GET['wstype'] == '1')
41     {
42       $wstype = 1;
43       if (isset($_GET['id']))
44         $id = $_GET['id'];
45     }
46     $host = isset($_GET['host']) ? $_GET['host'] : 'localhost'; // using '' will trigger an xmlrpc error...
47     if (isset($_GET['protocol']) && ($_GET['protocol'] == '1' || $_GET['protocol'] == '2'))
48       $protocol = $_GET['protocol'];
49     if (strpos($host, 'http://') === 0)
50       $host = substr($host, 7);
51     else if (strpos($host, 'https://') === 0)
52     {
53       $host = substr($host, 8);
54       $protocol = 2;
55     }
56     $port = isset($_GET['port']) ? $_GET['port'] : '';
57     $path = isset($_GET['path']) ? $_GET['path'] : '';
58     // in case user forgot initial '/' in xmlrpc server path, add it back
59     if ($path && ($path[0]) != '/')
60       $path = '/'.$path;
61
62     if (isset($_GET['debug']) && ($_GET['debug'] == '1' || $_GET['debug'] == '2'))
63       $debug = $_GET['debug'];
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     $cainfo= isset($_GET['cainfo']) ? $_GET['cainfo'] : '';
71     $proxy = isset($_GET['proxy']) ? $_GET['proxy'] : 0;
72     if (strpos($proxy, 'http://') === 0)
73       $proxy = substr($proxy, 7);
74     $proxyuser= isset($_GET['proxyuser']) ? $_GET['proxyuser'] : '';
75     $proxypwd = isset($_GET['proxypwd']) ? $_GET['proxypwd'] : '';
76     $timeout = isset($_GET['timeout']) ? $_GET['timeout'] : 0;
77     if (!is_numeric($timeout))
78       $timeout = 0;
79     $action = $_GET['action'];
80
81     $method = isset($_GET['method']) ? $_GET['method'] : '';
82     $methodsig = isset($_GET['methodsig']) ? $_GET['methodsig'] : 0;
83     $payload = isset($_GET['methodpayload']) ? $_GET['methodpayload'] : '';
84     $alt_payload = isset($_GET['altmethodpayload']) ? $_GET['altmethodpayload'] : '';
85
86     if (isset($_GET['run']) && $_GET['run'] == 'now')
87       $run = true;
88
89     $username = isset($_GET['username']) ? $_GET['username'] : '';
90     $password = isset($_GET['password']) ? $_GET['password'] : '';
91
92     $authtype = (isset($_GET['authtype']) && ($_GET['authtype'] == '2' || $_GET['authtype'] == '8')) ? $_GET['authtype'] : 1;
93
94     if (isset($_GET['requestcompression']) && ($_GET['requestcompression'] == '1' || $_GET['requestcompression'] == '2'))
95       $requestcompression = $_GET['requestcompression'];
96     else
97       $requestcompression = 0;
98     if (isset($_GET['responsecompression']) && ($_GET['responsecompression'] == '1' || $_GET['responsecompression'] == '2' || $_GET['responsecompression'] == '3'))
99       $responsecompression = $_GET['responsecompression'];
100     else
101       $responsecompression = 0;
102
103     $clientcookies = isset($_GET['clientcookies']) ? $_GET['clientcookies'] : '';
104   }
105   else
106   {
107     $host = '';
108     $port = '';
109     $path = '';
110     $action = '';
111     $method = '';
112     $methodsig = 0;
113     $payload = '';
114     $alt_payload = '';
115     $username = '';
116     $password = '';
117     $authtype = 1;
118     $verifyhost = 0;
119     $verifypeer = false;
120     $cainfo = '';
121     $proxy = '';
122     $proxyuser = '';
123     $proxypwd = '';
124     $timeout = 0;
125     $requestcompression = 0;
126     $responsecompression = 0;
127     $clientcookies = '';
128   }
129
130   // check input for known XMLRPC attacks against this or other libs
131   function payload_is_safe($input)
132   {
133       return true;
134   }
135 ?>