wanodecheckin.php 1.96 KB
Newer Older
1 2 3
<?php
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2007, 2010 University of Utah and the Flux Group.
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
# All rights reserved.
#
require("defs.php3");

# These error codes must match whats in the client, but of course.
define("WASTATUS_OKAY"	,		0);
define("WASTATUS_MISSINGARGS",		100);
define("WASTATUS_INVALIDARGS",		101);
define("WASTATUS_BADPRIVKEY",		102);
define("WASTATUS_BADIPADDR",		103);
define("WASTATUS_BADREMOTEIP",		104);
define("WASTATUS_IPADDRINUSE",		105);
define("WASTATUS_MUSTUSESSL",		106);
define("WASTATUS_OTHER",		199);

#
# Spit back a text message we can display to the user on the console
# 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($status)
{
    header("Content-Type: text/plain");
    echo "emulab_status=$status\n";
}

# 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) &&
Leigh B. Stoller's avatar
Leigh B. Stoller committed
45
     !preg_match('/^[-\w\.]+$/', $hostname))) {
46 47 48 49 50 51 52 53 54 55
    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)) {
56
    SPITSTATUS(WASTATUS_BADPRIVKEY);
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
    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);
73 74

?>