linkmon_ctl.php3 3.49 KB
Newer Older
1 2
<?php
#
3
# Copyright (c) 2005-2011 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
23 24 25 26 27 28
#
include("defs.php3");

#
# Only known and logged in users.
#
29 30 31
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
32 33

#
34
# Verify page arguments.
35
#
36 37 38 39 40 41 42 43 44
$reqargs = RequiredPageArguments("experiment", PAGEARG_EXPERIMENT,
				 "linklan",    PAGEARG_STRING,
				 "action",     PAGEARG_STRING);
$optargs = OptionalPageArguments("vnode",      PAGEARG_STRING);

# Need these below.
$pid = $experiment->pid();
$eid = $experiment->eid();
$unix_gid = $experiment->UnixGID();
45 46
$project  = $experiment->Project();
$unix_pid = $project->unix_gid();
47 48 49

if (!$experiment->AccessCheck($this_user, $TB_EXPT_MODIFY)) {
    USERERROR("You do not have permission to run linktest on $pid/$eid!", 1);
50 51 52
}

#
53 54 55
# Must be active. The backend can deal with changing the base experiment
# when the experiment is swapped out, but we need to generate a form based
# on virt_lans instead of delays/linkdelays. Thats harder to do. 
56
#
57 58
if ($experiment->state() != $TB_EXPTSTATE_ACTIVE) {
    USERERROR("Experiment $eid must be active to monitor its links!", 1);
59
}
60

61 62 63 64 65
if (! TBvalid_linklanname($linklan)) {
    PAGEARGERROR("$linklan contains invalid characters!");
}

#
66
# Optional vnode on the link.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
#
if (isset($vnode) && $vnode != "") {
    if (! TBvalid_node_id($vnode)) {
	PAGEARGERROR("$vnode contains invalid characters!");
    }
}
else {
    unset($vnode);
}

#
# And we need the action to apply. 
# 
if ($action != "pause" && $action != "restart" &&
    $action != "kill" && $action != "snapshot") {
    USERERROR("Invalid action to apply", 1);
}

$query_result =
    DBQueryFatal("select * from traces ".
		 "where eid='$eid' AND pid='$pid' and ".
		 "      linkvname='$linklan' ".
		 (isset($vnode) ? "and vnode='$vnode'" : ""));

if (mysql_num_rows($query_result) == 0) {
    USERERROR("No such link being traced/monitored in $eid/$pid!", 1);
}

#
# Build up a command; basically the backend is going to do nothing except
# call tevc, but we indirect through a script.
#
$cmd = "weblinkmon_ctl " .
       ((isset($vnode) ? "-s $vnode " : "")) .
       "$pid $eid $linklan $action";

103
$retval = SUEXEC($uid, "$unix_pid,$unix_gid", $cmd, SUEXEC_ACTION_IGNORE);
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
if ($retval) {
    # Ug, I know this hardwired return value is bad! 
    if ($retval == 2) {
        # A usage error, reported to user. At some point the
        # approach is to do all the argument checking first.
	SUEXECERROR(SUEXEC_ACTION_USERERROR);
    }
    else {
         # All other errors reported to tbops since they are bad!
	SUEXECERROR(SUEXEC_ACTION_DIE);
    }
}

#
# Otherwise, return the user to the list page.
#
120 121 122
header("Location: ". CreateURL("linkmon_list", $experiment,
			       "linklan", $linklan, "action", $action,
			       "vnode", (isset($vnode) ? $vnode : "")));
123 124

?>