dbvistopology.in 2.67 KB
Newer Older
Chad Barb's avatar
Chad Barb committed
1
#!/usr/bin/perl -wT
Leigh Stoller's avatar
Leigh Stoller committed
2 3 4

#
# EMULAB-COPYRIGHT
5
# Copyright (c) 2000-2003 University of Utah and the Flux Group.
Leigh Stoller's avatar
Leigh Stoller committed
6 7 8
# All rights reserved.
#

Chad Barb's avatar
Chad Barb committed
9 10 11 12 13 14 15 16 17
use English;
use Getopt::Std;

#
# Generate a PNG image of the topology for an experiment.
#
sub usage()
{
    print STDOUT
18
	"Usage: dbvistoplogy [-o <outputfile>] [-t <thumbsize> ] [-z <zoomfactor>] [-d <detaillevel>] <pid> <eid>\n";
Chad Barb's avatar
Chad Barb committed
19 20
    exit(-1);
}
21
my  $optlist = "o:z:d:t:";
Chad Barb's avatar
Chad Barb committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35

#
# Configure variables
#
my $TB       = "@prefix@";

#
# Testbed Support libraries
#
use lib "/usr/testbed/lib";
use libdb;
use libtestbed;

my $render   = "$TB/libexec/vis/render";
36
# my $tbdata   = "tbdata";
Chad Barb's avatar
Chad Barb committed
37 38 39
my $output;
my $zoom;
my $detail;
40
my $thumb;
Chad Barb's avatar
Chad Barb committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66

#
# Turn off line buffering on output
#
$| = 1;

#
# Untaint the path
# 
$ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin';
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 (@ARGV != 2) {
    usage();
}
my $pid   = $ARGV[0];
my $eid   = $ARGV[1];

67 68 69 70 71 72 73 74 75 76 77
if (defined($options{"t"})) {
    $thumb = $options{"t"};
    
    if ($thumb =~ /^([0-9]+)$/) {
	$thumb = $1;
    }
    else {
	die("Bad data in thumbnail size: $thumb");
    } 
}

Chad Barb's avatar
Chad Barb committed
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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
if (defined($options{"o"})) {
    $output = $options{"o"};

    if ($output =~ /^([-\@\w.\/]+)$/) {
	$output = $1;
    }
    else {
	die("Bad data in output name: $output");
    }
}

if (defined($options{"z"})) {
    $zoom = $options{"z"};
    if ($zoom =~ /^([\.0-9]+)$/) {
	$zoom = $1;
    }
    else {
	die("Bad data in zoom factor: $zoom");
    }
}

if (defined($options{"d"})) {
    $detail = $options{"d"};
    if ($detail =~ /^([0-9]+)$/) {
	$detail = $1;
    }
    else {
	die("Bad data in detail level: $detail");
    }
}

#
# Untaint the arguments.
#
if ($pid =~ /^([-\@\w]+)$/) {
    $pid = $1;
}
else {
    die("Tainted argument $pid!\n");
}
if ($eid =~ /^([-\@\w]+)$/) {
    $eid = $1;
}
else {
    die("Tainted argument $eid!\n");
}

#
# Verify existing experiment.
#
if (! ExpState($pid, $eid)) {
    die("*** $0:\n".
	"    No such experiment $pid/$eid\n");
}

#
# Verify that this person is allowed to look at experiment.
#

if (! TBExptAccessCheck($UID, $pid, $eid, TB_EXPT_READINFO)) {
    die("*** $0:\n".
	"    You do not have permission to view experiment $pid/$eid\n");
}

142
my $args = "";
Chad Barb's avatar
Chad Barb committed
143 144 145


if (defined($zoom)) {
146
    $args .= "-z $zoom ";
Chad Barb's avatar
Chad Barb committed
147 148 149
} 

if (defined($detail)) {
150 151 152
    $args .= "-d $detail ";
}

153 154 155 156
if (defined($thumb)) {
    $args .= "-t $thumb ";
}

157 158 159 160
$args .= "$pid $eid ";

if (defined($output)) {
    $args .= "> $output";
Chad Barb's avatar
Chad Barb committed
161
} else {
162
    $args .= "2> /dev/null";
Chad Barb's avatar
Chad Barb committed
163 164
}

165
if (system("nice $render $args") != 0) { 
Chad Barb's avatar
Chad Barb committed
166 167 168 169
    exit(1);
}

exit(0);