Commit 78195614 authored by Leigh Stoller's avatar Leigh Stoller

Add XMLRPC() routine to demonstrate how to use the xmlrpc backend from

the webserver. This is not being used anyplace, except to test that it
does indeed work. At some point we may want to change how we talk to
the backend, going through the xmlrpc server instead of direct to
scripts. The reason for doing this would be to eventually split the
webserver off from the DB node, but that will take a lot more work
(basically have to xmlrpc the entire backend, and at present the web
interface uses a lot of scripts)!

Note that mysql 4.0 has builtin support for ssl based connections. We
could use that for access to the DB if/when we want to split off the
web server.
parent 25f9bba4
......@@ -280,6 +280,95 @@ function SUEXEC($uid, $gid, $cmdandargs, $action) {
return $suexec_retval;
}
#
# Invoke the XMLRPC backend. We invoke the xmlrpc server, writing the request
# to its stdin. We then wait for the reply to came back on its stdout. We
# decode that reply, and return an error status and output to the caller.
# Note that we run the backend as the uid/gid, much like we do for plain
# scripts. This might change in the future.
#
function XMLRPC($uid, $gid, $method, $arghash)
{
global $TBSUEXEC_PATH;
$xmlcode = xmlrpc_encode_request($method, array(0.1, $arghash));
$descriptorspec = array(0 => array("pipe", "r"),
1 => array("pipe", "w"));
$process = proc_open("$TBSUEXEC_PATH $uid $gid webxmlrpc",
$descriptorspec, $pipes);
if (! is_resource($process)) {
TBERROR("Could not invoke XMLRPC backend!\n".
"$uid $gid $method\n".
print_r($arghash, true), 1);
}
# $pipes now looks like this:
# 0 => writeable handle connected to child stdin
# 1 => readable handle connected to child stdout
#
# Write the request to the process, and then close the pipe so that
# the other side sees the EOF. The sshxmlrpc protocol looks sorta
# like a POST request, so we have to do that.
#
fwrite($pipes[0], "content-length: " . strlen($xmlcode) . "\r\n");
fwrite($pipes[0], "\r\n");
fwrite($pipes[0], "$xmlcode");
fflush($pipes[0]);
fclose($pipes[0]);
#
# Now read back the results into a string. We then convert the string
# back into a PHP datatype. This datatype is defined outside this code
# though.
#
# Skip the headers, but we need the content-length.
#
$content_length = 0;
while (!feof($pipes[1]) && ($foo = trim(fgets($pipes[1], 4096)))) {
if (preg_match("/^content-length: (\d*)/", $foo, $matches)) {
$content_length = $matches[1];
}
}
$output = "";
while(!feof($pipes[1])) {
$output .= fgets($pipes[1], 1024);
}
fclose($pipes[1]);
# It is important that you close any pipes before calling
# proc_close in order to avoid a deadlock.
$return_value = proc_close($process);
if (!$return_value && $content_length) {
$decoded = xmlrpc_decode_request(substr($output, 0, $content_length),
$meth);
}
# On command error or on a "Fault" reply, send email and terminate the
# script; something went really wrong.
if ($return_value || !$content_length ||
(count($decoded) == 2 &&
array_key_exists("faultCode", $decoded) &&
array_key_exists("faultString", $decoded)) ||
!(array_key_exists("code", $decoded) &&
array_key_exists("value", $decoded) &&
array_key_exists("output", $decoded))) {
TBERROR("XMLRPC backend failure!\n".
"$uid $gid $method returned $return_value\n".
"Arg Hash:\n" .
print_r($arghash, true) . "\n\n" .
"XML:\n" .
"$xmlcode\n\n" .
"Output:\n" .
"$output\n", 1);
}
return $decoded;
}
function ADDPUBKEY($uid, $cmdandargs) {
global $TBSUEXEC_PATH;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment