Example #1
0
# of the node running the checkin. We could return an http error, but
# that would be of no help to the user on the other side.
#
function SPITSTATUS($code, $msg)
{
    header("HTTP/1.0 {$code} {$msg}");
    exit;
}
# Required arguments
$reqargs = RequiredPageArguments("xmlstuff", PAGEARG_ANYTHING);
$xmlname = tempnam("/tmp", "sitecheckin");
if (!$xmlname) {
    TBERROR("Could not create temporary filename", 0);
    SPITSTATUS(404, "Could not create temporary file!");
}
if (!($fp = fopen($xmlname, "w"))) {
    TBERROR("Could not open temp file {$xmlname}", 0);
    SPITSTATUS(404, "Could not open temporary file!");
}
fwrite($fp, $xmlstuff);
fclose($fp);
chmod($xmlname, 0666);
#
# Invoke the backend and return the status.
#
$retval = SUEXEC("elabman", $TBADMINGROUP, "websitecheckin {$xmlname}", SUEXEC_ACTION_IGNORE);
if ($retval) {
    SUEXECERROR(SUEXEC_ACTION_CONTINUE);
    SPITSTATUS(404, "Could not do a site checkin!");
}
unlink($xmlname);
}
# Required arguments
$reqargs = RequiredPageArguments("IP", PAGEARG_STRING, "privkey", PAGEARG_STRING);
$optargs = OptionalPageArguments("hostname", PAGEARG_STRING);
# Must use https,
if (!isset($_SERVER["SSL_PROTOCOL"])) {
    SPITSTATUS(WASTATUS_MUSTUSESSL);
    return;
}
if (!preg_match('/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/', $IP) || !preg_match('/^[\\w]+$/', $privkey) || isset($hostname) && !preg_match('/^[-\\w\\.]+$/', $hostname)) {
    SPITSTATUS(WASTATUS_INVALIDARGS);
    return;
}
#
# Make sure this is a valid privkey before we invoke the backend.
#
$query_result = DBQueryFatal("select IP from widearea_nodeinfo where privkey='{$privkey}'");
if (!mysql_num_rows($query_result)) {
    SPITSTATUS(WASTATUS_BADPRIVKEY);
    return;
}
#
# Invoke the backend and return the status. We send the IP since cause we
# have to deal with nodes with dynamic IP addresses.
#
$retval = SUEXEC("nobody", $TBADMINGROUP, "webwanodecheckin " . (isset($hostname) ? "-h {$hostname} " : "") . "{$privkey} {$IP}", SUEXEC_ACTION_IGNORE);
if ($retval) {
    SUEXECERROR(SUEXEC_ACTION_CONTINUE);
}
SPITSTATUS($retval);