Project

General

Profile

Download (6.66 KB) Statistics
| Branch: | Tag: | Revision:
1 50d49018 Colin Smith
#!/usr/local/bin/php
2
<?php
3
/*
4 81d8a9ad Colin Smith
	$Id$
5
	
6 50d49018 Colin Smith
        xmlrpc.php
7
        Copyright (C) 2005 Colin Smith
8
        All rights reserved.
9
10
        Redistribution and use in source and binary forms, with or without
11
        modification, are permitted provided that the following conditions are met:
12
13
        1. Redistributions of source code must retain the above copyright notice,
14
           this list of conditions and the following disclaimer.
15
16
        2. Redistributions in binary form must reproduce the above copyright
17
           notice, this list of conditions and the following disclaimer in the
18
           documentation and/or other materials provided with the distribution.
19
20
        THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
        INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
        AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
        AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
        OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
        SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
        INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
        CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
        ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
        POSSIBILITY OF SUCH DAMAGE.
30 780dbd56 Colin Smith
31
	TODO:
32
		* Expose more functions.
33 97bde338 Colin Smith
		* Add syslog handling of errors.
34
		* Define XML_RPC_erruser.
35
		* Write handlers for PHP -> XML_RPC_Value.
36 780dbd56 Colin Smith
		* xmlrpc_params_to_php currently does *not* handle structs.
37 50d49018 Colin Smith
*/
38
39 f977ac60 Bill Marquette
include("guiconfig.inc");
40 50d49018 Colin Smith
require_once("xmlrpc_server.inc");
41 6fe6b916 Colin Smith
require_once("xmlrpc.inc");
42 50d49018 Colin Smith
require_once("config.inc");
43
require_once("functions.inc");
44
45 21dc3a7d Colin Smith
// Exposed functions.
46
47 0148e152 Colin Smith
$backup_config_section_doc = 'XMLRPC wrapper for backup_config_section. This method must be called with two parameters: a string containing the local system\'s password followed by a string containing the section to be backed up.';
48
$backup_config_section_sig = array(array(string, string, string));
49 21dc3a7d Colin Smith
50 57e6d4c9 Colin Smith
function backup_config_section_xmlrpc($raw_params) {
51
	$params = xmlrpc_params_to_php($raw_params); // Convert XML_RPC_Value objects to a PHP array of values.
52 97bde338 Colin Smith
	if(!xmlrpc_auth($params)) return new XML_RPC_Response(new XML_RPC_Value("auth_failure", 'string'));
53 62918596 Colin Smith
	$val = new XML_RPC_Value(backup_config_section($params[0]), 'string'); 
54 50d49018 Colin Smith
	return new XML_RPC_Response($val);
55
}
56
57 0148e152 Colin Smith
$restore_config_section_doc = 'XMLRPC wrapper for restore_config_section. This method must be called with three parameters: a string containing the local system\'s password, a string containing the section to be restored, and a string containing the returned value of backup_config_section() for that section. This function returns true upon completion.';
58 af2ecddf Colin Smith
$restore_config_section_sig = array(array(boolean, string, array(), array()));
59 21dc3a7d Colin Smith
60 57e6d4c9 Colin Smith
function restore_config_section_xmlrpc($raw_params) {
61
	$params = xmlrpc_params_to_php($raw_params);
62 a52c8ce2 Colin Smith
	$i = 0;
63 97bde338 Colin Smith
	if(!xmlrpc_auth($params)) return new XML_RPC_Response(new XML_RPC_Value("auth_failure", 'string'));
64 a52c8ce2 Colin Smith
	foreach($params[0] as $section) {
65
		restore_config_section($section, $params[1][$i]);
66 99bc7cc2 Colin Smith
		$i++;
67 a52c8ce2 Colin Smith
	}
68 50d49018 Colin Smith
	return new XML_RPC_Response(new XML_RPC_Value(true, 'boolean'));
69
}
70
71 07a7b08f Colin Smith
$filter_configure_doc = 'Basic XMLRPC wrapper for filter_configure. This method must be called with one paramater: a string containing the local system\'s password. This function returns true upon completion.';
72
$filter_configure_sig = array(array(boolean, string));
73
74
function filter_configure_xmlrpc($raw_params) {
75
	$params = xmlrpc_params_to_php($raw_params);
76 97bde338 Colin Smith
	if(!xmlrpc_auth($params)) return new XML_RPC_Response(new XML_RPC_Value("auth_failure", 'string'));
77 07a7b08f Colin Smith
	filter_configure();
78 af2ecddf Colin Smith
	return new XML_RPC_Response(new XML_RPC_Value(true, 'boolean'));
79 07a7b08f Colin Smith
}
80
81 186359bf Colin Smith
$check_firmware_version_doc = 'Basic XMLRPC wrapper for filter_configure. This function will return the output of check_firmware_version upon completion.';
82 44488c3c Colin Smith
$check_firmware_version_sig = array(array(string, string));
83
84
function check_firmware_version_xmlrpc($raw_params) {
85 186359bf Colin Smith
	return new XML_RPC_Response(new XML_RPC_Value(check_firmware_version(false), 'string'));
86 44488c3c Colin Smith
}
87
88
89 186359bf Colin Smith
$auto_update_doc = 'Basic XMLRPC wrapper for auto_update. This method must be called with one paramater: a string containing the local system\'s password. This function will return true upon completion.';
90 44488c3c Colin Smith
$auto_update_sig = array(array(boolean, string));
91
92
function auto_update_xmlrpc($raw_params) {
93
	$params = xmlrpc_params_to_php($raw_params);
94 186359bf Colin Smith
        if(!xmlrpc_auth($params)) return new XML_RPC_Response(new XML_RPC_Value("auth_failure", 'string'));
95 44488c3c Colin Smith
	auto_update();
96
	return new XML_RPC_Response(new XML_RPC_Value(true, 'boolean'));
97
}
98
99 bd0fe65b Colin Smith
$reboot_doc = 'Basic XMLRPC wrapper for rc.reboot.';
100
$reboot_sig = array(array(boolean, string));
101
102
function reboot_xmlrpc($raw_params) {
103 53cf5533 Colin Smith
	require_once("util.inc");
104 bd0fe65b Colin Smith
	$params = xmlrpc_params_to_php($raw_params);
105
	if(!xmlrpc_auth($params)) return new XML_RPC_Response(new XML_RPC_Value("auth_failure", 'string'));
106 53cf5533 Colin Smith
	mwexec_bg("/etc/rc.reboot");
107 bd0fe65b Colin Smith
	return new XML_RPC_Response(new XML_RPC_Value(true, 'boolean'));
108
}
109
110 d9064267 Colin Smith
$get_notices_sig = array(array(array(), string), array(array()));
111
function get_notices_xmlrpc($raw_params) {
112
	global $g;
113
	require_once("notices.inc");
114
	$params = xmlrpc_params_to_php($raw_params);
115
	if(!$params[0]) {
116
		$toreturn = get_notices();
117
	} else {
118
		$toreturn = get_notices($params[0]);
119
	}
120
	$response = new XML_RPC_Response(XML_RPC_encode($toreturn));
121
	print $response->serialize();
122
	return $response;
123
}
124
125 21dc3a7d Colin Smith
$server = new XML_RPC_Server(
126
        array(
127 07a7b08f Colin Smith
            'pfsense.backup_config_section' => 	array('function' => 'backup_config_section_xmlrpc',
128 21dc3a7d Colin Smith
							'signature' => $backup_config_section_sig,
129
							'docstring' => $backup_config_section_doc),
130
	    'pfsense.restore_config_section' => array('function' => 'restore_config_section_xmlrpc',
131
							'signature' => $restore_config_section_sig,
132 07a7b08f Colin Smith
							'docstring' => $restore_config_section_doc),
133
	    'pfsense.filter_configure' => 	array('function' => 'filter_configure_xmlrpc',
134
							'signature' => $filter_configure_sig,
135 44488c3c Colin Smith
							'docstring' => $filter_configure_doc),
136
	    'pfsense.check_firmware_version' =>	array('function' => 'check_firmware_version_xmlrpc',
137
							'signature' => $check_firmware_version_sig,
138 bd0fe65b Colin Smith
							'docstring' => $check_firmware_version_doc),
139 186359bf Colin Smith
//	    'pfsense.auto_update' =>		array('function' => 'auto_update_xmlrpc',
140
//							'signature' => $auto_update_sig,
141 bd0fe65b Colin Smith
//							'docstring' => $auto_update_doc),
142
	    'pfsense.reboot' =>			array('function' => 'reboot_xmlrpc',
143
							'signature' => $reboot_sig,
144 d9064267 Colin Smith
							'docstring' => $reboot_doc),
145
	    'pfsense.get_notices' =>		array('function' => 'get_notices_xmlrpc',
146
							'signature' => $get_notices_sig)
147 50d49018 Colin Smith
        )
148
);
149 a3539850 Colin Smith
?>