summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorScott Ullrich <sullrich@pfsense.org>2010-08-19 12:25:56 -0400
committerScott Ullrich <sullrich@pfsense.org>2010-08-19 12:26:08 -0400
commit2445e8515882368b5d8335409c50abeb9653b1e1 (patch)
treeaa4eabcb1cba59b4d253ec032c8b56b7656efded
parent1e1dd1f590db2470bae56583ec18603567469726 (diff)
downloadpfsense-2445e8515882368b5d8335409c50abeb9653b1e1.zip
pfsense-2445e8515882368b5d8335409c50abeb9653b1e1.tar.gz
Misc fixes
-rw-r--r--etc/inc/zeromq.inc93
1 files changed, 58 insertions, 35 deletions
diff --git a/etc/inc/zeromq.inc b/etc/inc/zeromq.inc
index 27ffc4f..9e7c825 100644
--- a/etc/inc/zeromq.inc
+++ b/etc/inc/zeromq.inc
@@ -35,93 +35,115 @@ $do_not_include_config_gui_inc = true;
require("auth.inc");
/* zeromq_send: Send a message to a member node */
-function zeromq_send($protocol = "tcp", $ipaddress, $port, $method, $params, $username, $password) {
+function zeromq_send($protocol = "tcp", $ipaddress = "127.0.0.1", $port = "8888",
+ $method, $params, $username, $password) {
if(!$ipaddress || !$port || !$message || !$username || !$password)
return;
-
+ if(!is_array($params))
+ return;
+
/* Set calling function and auth information */
- $params['username'] = $username;
- $params['password'] = $password;
- $params['function'] = $method;
+ $xmlparams = array(
+ XML_RPC_encode($username),
+ XML_RPC_encode($password),
+ XML_RPC_encode($params)
+ );
- /* Serialize the data we are going to send over */
- $serialized = serialize($params);
+ /* Create the XML message with params and credentials */
+ $msg = new XML_RPC_Message($method, $xmlparams);
/* Create new queue object */
$queue = new ZMQSocket(new ZMQContext(), ZMQ::SOCKET_REQ, "MySock1");
$queue->connect("{$protocol}://{$ipaddress}:{$port}");
/* Assign socket 1 to the queue, send and receive */
- $result = $queue->send($serialized)->recv();
+ $result = $queue->send($msg)->recv();
- /* Unserialize the return and return */
- $unserializedresult = unserialize($result);
+ /* xmlrpc_params_to_php() the result and return */
+ $unserializedresult = xmlrpc_params_to_php($result);
/* Return the result to the caller */
return $unserializedresult;
}
-function zeromq_server($protocol = "tcp", $ipaddress, $port) {
- if(!$ipaddress || !$port)
+function zeromq_server($protocol = "tcp", $ipaddress = "127.0.0.1", $port = "8888") {
+ global $debug;
+ if(!$ipaddress || !$port) {
+ if($debug)
+ echo "ERROR: You must pass, proto, ipaddress and port\n";
return;
+ }
+ if($debug)
+ echo "Creating ZMQSocket()\n";
$server = new ZMQSocket(new ZMQContext(), ZMQ::SOCKET_REP);
+ if($debug)
+ echo "Binding to {$protocol}://{$ipaddress}:{$port}\n";
$server->bind("{$protocol}://{$ipaddress}:{$port}");
- /* Loop receiving and echoing back */
+ if($debug)
+ echo "Entering while() loop\n";
while ($msg = $server->recv()) {
- $message = unserialize($msg);
- switch ($message['function']) {
+ //$message = unserialize($msg);
+ // Convert the XML to a PHP array
+ $message = xmlrpc_params_to_php($msg);
+ switch ($message[3]) {
case "pfsense.exec_shell":
$function_to_call = "exec_shell_zeromq";
- break;
+ break;
case "pfsense.exec_php":
$function_to_call = "exec_php_zeromq";
- break;
+ break;
case "pfsense.filter_configure":
$function_to_call = "filter_configure_zeromq";
- break;
+ break;
case "pfsense.interfaces_carp_configure":
$function_to_call = "interfaces_carp_configure_zeromq";
- break;
+ break;
case "pfsense.backup_config_section":
$function_to_call = "backup_config_section_zeromq";
- break;
+ break;
case "pfsense.restore_config_section":
$function_to_call = "restore_config_section_zeromq";
- break;
+ break;
case "pfsense.merge_config_section":
$function_to_call = "merge_config_section_zeromq";
- break;
+ break;
case "pfsense.merge_installedpackages_section_zeromq":
$function_to_call = "merge_installedpackages_section_zeromq";
- break;
+ break;
case "pfsense.check_firmware_version":
$function_to_call = "check_firmware_version_zeromq";
- break;
+ break;
case "pfsense.reboot":
$function_to_call = "reboot_zeromq";
- break;
+ break;
case "pfsense.get_notices":
$function_to_call = "get_notices_zeromq";
- break;
+ break;
}
- if(!$function_to_call)
+ if(!$function_to_call) {
+ if($debug)
+ echo "ERROR: Could not find a function to call";
return;
- // Call function that is being invoked
+ }
+ /* Call function that is being invoked */
$result = $function_to_call($message);
- /* echo back the result */
- $server->send($result);
+ /* echo back the result */
+ $server->send($result);
}
}
function zeromq_auth($params) {
- global $config, $g;
+ global $config, $g, $debug;
- $username = $params['username'];
- $password = $params['password'];
+ $username = $params[0];
+ $password = $params[1];
$user = getUserEntry($username);
- if (!$user)
+ if (!$user) {
+ if($debug)
+ echo "Could not locate user $username with getUserEntry()\n";
return false;
+ }
if (is_account_disabled($username) || is_account_expired($username))
return false;
@@ -237,7 +259,8 @@ function interfaces_carp_configure_zeromq($raw_params) {
function check_firmware_version_zeromq($raw_params) {
global $XML_RPC_String;
$params = xmlrpc_params_to_php($raw_params);
- if(!zeromq_auth($params)) return ZEROMQ_AUTH_FAIL;
+ if(!zeromq_auth($params))
+ return ZEROMQ_AUTH_FAIL;
return new XML_RPC_Response(new XML_RPC_Value(check_firmware_version(false), $XML_RPC_String));
}
OpenPOWER on IntegriCloud