plabstats.php3 4.65 KB
Newer Older
1 2 3
<?php
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2003, 2006, 2007 University of Utah and the Flux Group.
5 6 7 8 9
# All rights reserved.
#
include("defs.php3");

#
10
# Standard Testbed Header if not looking for xml returned.
11
#
12 13 14 15
$optargs = OptionalPageArguments("xml",     PAGEARG_STRING,
				 "slice",   PAGEARG_STRING,
				 "records", PAGEARG_INTEGER);

16 17 18 19 20 21 22
if (!isset($xml)) {
    PAGEHEADER("Emulab on Planetlab Stats");
}

#
# Get current user, if any. We return info to logged in admin users,
# or to someone who has the right key.
23 24 25 26 27 28 29
#
$this_user = CheckLogin($check_status);

if ($this_user) {
    CheckLoginOrDie();
    $isadmin = ISADMIN();

30
    if (!$isadmin) {
31 32 33 34 35 36 37 38 39 40
	USERERROR("You do not have permission to view this page!", 1);
    }
}
else {
    #
    # Must be SSL, even though we do not require an account login.
    #
    if (!isset($SSL_PROTOCOL)) {
	USERERROR("Must use https:// to access this page!", 1);
    }
Kirk Webb's avatar
 
Kirk Webb committed
41 42
    $subnet_c = long2ip(ip2long($REMOTE_ADDR) & ip2long("255.255.255.0"));
    $subnet_b = long2ip(ip2long($REMOTE_ADDR) & ip2long("255.255.0.0"));
43
    
Kirk Webb's avatar
 
Kirk Webb committed
44 45 46 47 48
    if (strcmp($subnet_c, "155.98.60.0") &&
	strcmp($subnet_c, "155.98.63.0") &&
	strcmp($subnet_c, "134.134.248.0") &&
	strcmp($subnet_c, "134.134.136.0") &&
        strcmp($subnet_b, "128.112.0.0")) {
49
	USERERROR("You do not have permission to view this page ($REMOTE_ADDR)!",
50 51 52 53 54 55
		  1);
    }
}

# Page args,
if (isset($slice)) {
56 57
    if (preg_match("/^emulab_[-\w]*_([\d]*)$/", $slice, $matches) ||
	preg_match("/^emulab_([\d]*)$/", $slice, $matches)) {
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
	$wclause = "and s.exptidx='$matches[1]'";
    }
    else {
	USERERROR("Invalid 'slice' argument!", 1);
    }
}
else {
    $wclause = "";
}

# Show just the last N records unless request is different.
if (isset($records)) {
    if (!preg_match("/^[\d]*$/", $records)) {
	USERERROR("Invalid 'records' argument!", 1);
    }
    $limit = $records;
}
else {
    $limit = 100;
}

$query_result =
    DBQueryFatal("select s.pid,s.eid,t.uid,r.plabnodes,start_time,t.action, ".
		 "  u.usr_email,u.usr_name,s.exptidx, ".
		 "  UNIX_TIMESTAMP(start_time) as ustart ".
		 " from experiment_resources as r ".
		 "left join experiment_stats as s on r.exptidx=s.exptidx ".
		 "left join testbed_stats as t on t.rsrcidx=r.idx ".
86
		 "left join users as u on u.uid_idx=t.uid_idx ".
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
		 "where r.plabnodes!=0 and t.exitcode=0 and ".
		 "     (t.action='start' or t.action='swapin' or ".
		 "      t.action='swapout') $wclause ".
		 "order by t.end_time desc,t.idx desc limit $limit");

if (!isset($xml)) {
    echo "<table align=center border=1>
          <tr>
            <th>Slice</th>
            <th>Uid</th>
            <th>Pid</th>
            <th>Eid</th>
            <th>Date</th>
            <th>Action (Nodes)</th>
          </tr>\n";
}
else {
    echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" standalone=\"yes\"?>
          <!DOCTYPE EMULABONPLAB_XML [
            <!ELEMENT EMULABONPLAB_XML (EXPERIMENT)*>
              <!ATTLIST EMULABONPLAB_XML VERSION CDATA #REQUIRED>
            <!ELEMENT EXPERIMENT EMPTY>
              <!ATTLIST EXPERIMENT SLICE CDATA #REQUIRED>
              <!ATTLIST EXPERIMENT PID CDATA #REQUIRED>
              <!ATTLIST EXPERIMENT EID CDATA #REQUIRED>
              <!ATTLIST EXPERIMENT UID CDATA #REQUIRED>
              <!ATTLIST EXPERIMENT NAME CDATA #REQUIRED>
              <!ATTLIST EXPERIMENT EMAIL CDATA #REQUIRED>
              <!ATTLIST EXPERIMENT TIMESTAMP CDATA #REQUIRED>
              <!ATTLIST EXPERIMENT NODES CDATA #REQUIRED>
              <!ATTLIST EXPERIMENT ACTION (swapin | swapout) #REQUIRED>
          ]>\n";
    echo "<EMULABONPLAB_XML VERSION=\"0.1\">\n";
}

while ($row = mysql_fetch_assoc($query_result)) {
123 124 125 126 127 128 129 130 131 132
    $pid     = $row["pid"];
    $eid     = $row["eid"];
    $uid     = $row["uid"];
    $name    = $row["usr_name"];
    $email   = $row["usr_email"];
    $start   = $row["start_time"];
    $ustart  = $row["ustart"];
    $action  = $row["action"];
    $pnodes  = $row["plabnodes"];
    $exptidx = $row["exptidx"];
133
    $slice   = "emulab_${exptidx}";
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169

    if (!strcmp($action, "start")) {
	$action = "swapin";
    }

    if (isset($xml)) {
        echo "<EXPERIMENT SLICE=\"$slice\" ";
	echo "PID=\"$pid\" EID=\"$eid\" UID=\"$uid\" ";
	echo "NAME=\"$name\" ";
	echo "EMAIL=\"$email\" TIMESTAMP=\"$ustart\" NODES=\"$pnodes\" ";
	echo "ACTION=\"$action\">\n";
    }
    else {
        echo "<tr>
                <td>$slice</td>
                <td>$uid ($email)</td>
                <td>$pid</td>
                <td>$eid</td>
                <td>$start</td>
                <td>$action ($pnodes)</td>
              </tr>\n";
    }
}

if (isset($xml)) {
    echo "</EMULABONPLAB_XML>\n";
}
else {
    echo "</table>\n";

    #
    # Standard Testbed Footer
    # 
    PAGEFOOTER();
}
?>