Newer
Older
#!/usr/bin/perl -wT
use English;
use Getopt::Std;
#
# Turn on/off admin mode for a node.
#
sub usage()
{
print STDOUT "Usage: nodeadmin [-h] [-n] <on | off> <node>\n";
print STDOUT "-h This message\n";
print STDOUT "-n Don't reboot nodes\n";
exit(-1);
}
my $optlist = "hn";
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#
# Configure variables
#
my $TB = "@prefix@";
my $TBOPS = "@TBOPSEMAIL@";
my $BOSSADDR = "@BOSSNODE@";
my $TFTPDIR = "/tftpboot";
#
# 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:";
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
#
#
#
my $freebsd = "$BOSSADDR:$TFTPDIR/pxeboot.freebsd";
my $nodereboot = "$TB/bin/node_reboot";
my $pxebootpath;
my $dbuid;
#
# Parse command arguments. Once we return from getopts, all that should be
# left are the required arguments.
#
%options = ();
if (! getopts($optlist, \%options)) {
usage();
}
if ($options{h}) {
usage();
}
62
63
64
65
66
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
if (@ARGV != 2) {
usage();
}
my $onoff = $ARGV[0];
my $node = $ARGV[1];
if ($onoff ne "on" && $onoff ne "off") {
usage();
}
#
# Untaint the arguments.
#
if ($node =~ /^([-\w]+)$/) {
$node = $1;
}
else {
die("Tainted node name: $node");
}
#
# Verify user and get his DB uid.
#
if (! UNIX2DBUID($UID, \$dbuid)) {
die("*** $0:\n".
" You do not exist in the Emulab Database.\n");
}
#
# Root and admin types can do whatever they want. Normal users can only
# run this on nodes in their own experiments.
#
if ($UID && !TBAdmin($UID)) {
if (! TBNodeAccessCheck($UID, TB_NODEACCESS_LOADIMAGE, $node)) {
die("*** $0:\n".
" You are not allowed to boot the FreeBSD MFS on $node!\n");
}
}
if ($onoff eq "on") {
$pxebootpath = $freebsd;
}
else {
my $query_result =
DBQueryFatal("select node_types.pxe_boot_path from node_types " .
"left join nodes on nodes.type=node_types.type " .
"where node_id='$node'");
my @row = $query_result->fetchrow_array();
$pxebootpath = $row[0];
}
DBQueryFatal("update nodes set pxe_boot_path='$pxebootpath', ".
"startupcmd='', startstatus='none' ".
"where node_id='$node'");
#
# Reboot node
#
if (!$options{n}) {
if (system("$nodereboot", "$node")) {
die("*** $0:\n".
" WARNING: Could not reboot $node.\n");
}
exit(0);