This repository has been archived by the owner on Jan 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
xmlrpc.php
executable file
·215 lines (185 loc) · 7.45 KB
/
xmlrpc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<?php
/*
$Id: xmlrpc.php,v 1.3 2008/07/06 01:30:33 sullrich Exp $
xmlrpc_pfsense_com.php
Copyright (C) 2005 Colin Smith
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
require_once("xmlrpc_server.inc");
require_once("xmlparse.inc");
require_once("xmlrpc.inc");
include_once("array_intersect_key.php");
$XML_RPC_erruser = 200;
//$get_firmware_version_sig = array(array($XML_RPC_Array, $XML_RPC_Array));
$get_firmware_version_doc = 'Method used to get the current firmware, kernel, and base system versions. This must be called with an array. This method returns an array.';
function get_firmware_version($raw_params) {
global $branch;
// Variables.
$path_to_files = './xmlrpc/';
$toreturn = array();
$working = array();
$toparse = array();
$params = array_shift(xmlrpc_params_to_php($raw_params));
// Branches to track
$branches = array(
'stable' => array('stable'),
'beta' => array('stable', 'beta'),
'alpha' => array('stable', 'beta', 'alpha')
);
$platforms = array(
'pfSense',
'embedded'
);
// Version manifest filenames.
if(!$platforms[$params['platform']]) $params['platform'] = "pfSense";
$versions = array(
'firmware' => 'version',
'base' => 'version_base',
'kernel' => 'version_' . $params['platform']
);
// Categories we know about.
$categories = array(
'firmware',
'base',
'kernel'
);
// Load the version manifests into the versions array and initialize our returned struct.
foreach($params as $key => $value) {
if(isset($versions[$key])) { // Filter out other params like "platform"
$versions[$key] = parse_xml_config($path_to_files . $versions[$key], "pfsenseupdates", $categories);
$versions[$key] = $versions[$key][$key];
if(is_array($versions[$key])) { // If we successfully parsed the XML, start processing versions
for($i = 0; $i < count($versions[$key]); $i++) {
if(version_compare($params[$key]['version'], $versions[$key][$i]['version'], "=")) {
$toreturn[$key] = array_slice($versions[$key], $i + 1);
}
}
if(count($toreturn[$key]) < 1) {
$toreturn[$key] = $versions[$key];
}
// Now that we have the versions we need, find the newest full update.
$latestfull = 0;
foreach($toreturn[$key] as $index => $version) {
if(array_key_exists('full', $version)) {
$latestfull = $index;
}
}
$toreturn[$key] = array_slice($toreturn[$key], $latestfull);
// For the client's convenience toss the latest version of this type into an array.
$toreturn['latest'][$key] = $toreturn[$key][count($toreturn[$key]) - 1]['version'];
// Now that we have our base array, process branches.
$branch = $params['branch'] ? $branches[$params['branch']] : $branches['stable'];
$toreturn[$key] = array_filter($toreturn[$key], "filter_versions");
if(count($toreturn[$key]) < 1) {
$toreturn[$key] = "latest_in_branch";
}
} else {
$toreturn[$key] = "xml_error";
}
}
}
$response = XML_RPC_encode($toreturn);
return new XML_RPC_Response($response);
}
function filter_versions($value) {
global $branch;
return in_array($value['branch'], $branch);
}
function get_pkgs($raw_params) {
$path_to_files = '../packages/';
$pkg_rootobj = 'pfsensepkgs';
$apkgs = array();
$toreturn = array();
$params = array_shift(xmlrpc_params_to_php($raw_params));
if($params['freebsd_version'])
$freebsd_version = "." . $params['freebsd_version'];
else
$freebsd_version = "";
if(!empty($params['freebsd_machine']))
$freebsd_machine = $params['freebsd_machine'];
else
$freebsd_machine = "i386";
$xml_config_file = $path_to_files . 'pkg_config' . $freebsd_version . '.xml';
if (file_exists($xml_config_file . '.' . $freebsd_machine))
$xml_config_file .= '.' . $freebsd_machine;
$pkg_config = parse_xml_config_pkg($xml_config_file, $pkg_rootobj);
foreach($pkg_config['packages']['package'] as $pkg) {
if(($params['pkg'] != 'all') and (!in_array($pkg['name'], $params['pkg'])))
continue;
if (!empty($pkg['only_for_archs'])) {
$allowed_archs = explode(' ', preg_replace('/\s+/', ' ', trim($pkg['only_for_archs'])));
if (!in_array($freebsd_machine, $allowed_archs))
continue;
}
if (isset($pkg['depends_on_package_pbi']) &&
preg_match('/##ARCH##/', $pkg['depends_on_package_pbi']))
$pkg['depends_on_package_pbi'] = preg_replace('/##ARCH##/',
$freebsd_machine, $pkg['depends_on_package_pbi']);
// On pkg_config.10.xml and later, depends_on_package_base_url is global
if (!empty($pkg_config['depends_on_package_base_url']))
$pkg['depends_on_package_base_url'] = $pkg_config['depends_on_package_base_url'];
if($params['info'] == 'all') {
$apkgs[$pkg['name']] = $pkg;
} else {
$apkgs[$pkg['name']] = array_intersect_key($pkg, array_flip($params['info']));
}
}
$response = XML_RPC_encode($apkgs);
return new XML_RPC_Response($response);
}
function report_bug($raw_params) {
/* give us access to XML listtags */
global $listtags;
$listtags = array(
'bug'
);
/* where do we stuff the bug reports? */
$path_to_bugfile = '../bugreports/reports.xml';
/* get our params */
$params = array_shift(xmlrpc_params_to_php($raw_params));
$bugfile = parse_xml_config_raw($path_to_bugfile, 'bugfile');
if($params['desc']) {
if($params['name'])
$toput['name'] = $params['name'];
if($params['email'])
$toput['email'] = $params['email'];
$toput['desc'] = $params['desc'];
$toput['config'] = base64_encode($params['config']);
$toput['rules'] = base64_encode($params['rules']);
$toput['time'] = time();
$bugfile['bugs']['bug'][] = $toput;
$xmlout = dump_xml_config_raw($bugfile, 'bugfile');
$fout = fopen($path_to_bugfile, "w");
fwrite($fout, $xmlout);
fclose($fout);
return new XML_RPC_Response(XML_RPC_encode(true));
} else {
return new XML_RPC_Response(XML_RPC_encode(false));
}
return new XML_RPC_Response(XML_RPC_encode(false));
}
$methodMap = array(
'pfsense.get_firmware_version' => array('function' => 'get_firmware_version'),
'pfsense.get_pkgs' => array('function' => 'get_pkgs'),
'pfsense.report_bug' => array('function' => 'report_bug')
);
$server = new XML_RPC_Server($methodMap, 0);
$server->service();
?>