From ae880c99c66509ed24a033f50a32a95b8a72cc58 Mon Sep 17 00:00:00 2001 From: "Leigh B. Stoller" Date: Mon, 28 Feb 2005 19:42:29 +0000 Subject: [PATCH] Trivial little backend script for the web interface to inject setdest events for robots. See www/robotrack/setdest.php3 --- utils/GNUmakefile.in | 6 +- utils/setdest.in | 137 +++++++++++++++++++++++++++++++++++++++++++ utils/websetdest.in | 25 ++++++++ 3 files changed, 166 insertions(+), 2 deletions(-) create mode 100644 utils/setdest.in create mode 100644 utils/websetdest.in diff --git a/utils/GNUmakefile.in b/utils/GNUmakefile.in index 680ab836e..cb4ecb87f 100644 --- a/utils/GNUmakefile.in +++ b/utils/GNUmakefile.in @@ -14,11 +14,13 @@ include $(OBJDIR)/Makeconf SUBDIRS = nsgen -BIN_SCRIPTS = delay_config sshtb create_image node_admin link_config +BIN_SCRIPTS = delay_config sshtb create_image node_admin link_config \ + setdest SBIN_SCRIPTS = vlandiff vlansync withadminprivs export_tables cvsupd.pl \ eventping grantnodetype import_commitlog dhcpd_wrapper \ opsreboot deletenode node_statewait grabwebcams -LIBEXEC_SCRIPTS = webcreateimage newnode webdeletenode spewleds webcopy +LIBEXEC_SCRIPTS = webcreateimage newnode webdeletenode spewleds webcopy \ + websetdest # # Force dependencies on the scripts so that they will be rerun through diff --git a/utils/setdest.in b/utils/setdest.in new file mode 100644 index 000000000..606d8d88b --- /dev/null +++ b/utils/setdest.in @@ -0,0 +1,137 @@ +#!/usr/bin/perl -wT +# +# EMULAB-COPYRIGHT +# Copyright (c) 2005 University of Utah and the Flux Group. +# All rights reserved. +# +use English; +use Getopt::Std; + +# +# Change delay params for a link. +# +sub usage() +{ + print(STDERR + "Usage: setdest -x xpos -y ypos -o orientation node_id\n"); + # Web interface cares about this return value! + exit(-1); +} +my $optlist = "dx:y:o:"; +my $debug = 0; +my $destx; +my $desty; +my $desto; + +# +# Configure variables +# +my $TB = "@prefix@"; +my $TBOPS = "@TBOPSEMAIL@"; +my $TEVC = "$TB/bin/tevc"; +my $nodeid; +my $pid; +my $eid; +my $vname; + +# +# Testbed Support libraries +# +use lib "@prefix@/lib"; +use libdb; +use libtestbed; + +# +# Turn off line buffering on output +# +$| = 1; + +# +# Untaint the path +# +$ENV{'PATH'} = "/bin:/sbin:/usr/bin:/usr/sbin"; +delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; + +# +# Parse command arguments. Once we return from getopts, all that should be +# left are the required arguments. +# +%options = (); +if (! getopts($optlist, \%options)) { + usage(); +} +if (defined($options{"d"})) { + $debug = 1; +} +if (defined($options{"x"})) { + $destx = 1; +} +if (defined($options{"y"})) { + $desty = 1; +} +if (defined($options{"o"})) { + $desto = 1; +} +if (@ARGV != 1) { + usage(); +} +if (! (defined($destx) && defined($desty) && defined($desto))) { + usage(); +} +$nodeid = $ARGV[0]; + +# +# Untaint args. +# +if ($destx =~ /^([\d.]+)$/) { + $destx = $1; +} +else { + die("*** Bad data in pid: $destx.\n"); +} +if ($desty =~ /^([\d.]+)$/) { + $desty = $1; +} +else { + die("*** Bad data in pid: $desty.\n"); +} +if ($desto =~ /^([\d.]+)$/) { + $desto = $1; +} +else { + die("*** Bad data in pid: $desto.\n"); +} + +# +# Check args and permission +# +if (!TBValidNodeName($nodeid)) { + die("*** $0:\n". + " Node does not exist: $nodeid\n"); +} +if (!TBNodeAccessCheck($UID, TB_NODEACCESS_MODIFYINFO(), $nodeid)) { + die("*** $0:\n". + " Not enough permission: $nodeid\n"); + +} +if (!NodeidToExp($nodeid, \$pid, \$eid, \$vname)) { + die("*** $0:\n". + " Could not map nodeid to experiment: $nodeid\n"); +} + +# +# Inject an event. +# +my $inject_string = "$TEVC -e $pid/$eid now $vname SETDEST " . + "X=" . $destx . " Y=" . $desty . " ORIENTATION=" . $desto; + +if ($debug) { + print "$inject_string\n"; +} + +system($inject_string) && + die("*** $0:\n". + " Failed to inject setdest event!\n"); + +exit(0); + diff --git a/utils/websetdest.in b/utils/websetdest.in new file mode 100644 index 000000000..c4304fd32 --- /dev/null +++ b/utils/websetdest.in @@ -0,0 +1,25 @@ +#!/usr/bin/perl -w + +# +# EMULAB-COPYRIGHT +# Copyright (c) 2004, 2005 University of Utah and the Flux Group. +# All rights reserved. +# + +use English; + +# +# This gets invoked from the Web interface. Simply a wrapper ... +# + +# +# Configure variables +# +my $TB = "@prefix@"; + +# +# Run the real thing, and never return. +# +exec "$TB/bin/setdest", @ARGV; + +die("websetdest: Could not exec setdest: $!"); -- GitLab