webcontrol.in 2.58 KB
Newer Older
1
#!/usr/bin/perl -w
Leigh Stoller's avatar
Leigh Stoller committed
2 3

#
4
# Copyright (c) 2000-2003, 2007 University of Utah and the Flux Group.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
# 
# {{{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/>.
# 
# }}}
Leigh Stoller's avatar
Leigh Stoller committed
24
#
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
use English;
use Getopt::Std;

#
# usage: webcontrol [-m message] [-l login | nologin]
#
sub usage()
{
    print STDOUT "Usage: webcontrol [-m message] [-l login | nologin]\n";
    exit(-1);
}
my  $optlist = "m:l:";

#
# Configure variables
#
41 42
use lib "@prefix@/lib";
use libdb;
43

44 45 46 47 48
my $TBROOT         = "@prefix@";

# Untaint the path
$ENV{'PATH'} = "/usr/bin:$TBROOT/libexec:$TBROOT/sbin:$TBROOT/bin";

49 50 51 52 53 54 55 56 57 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 86 87 88
#
# Turn off line buffering on output
#
$| = 1;

#
# Parse command arguments. Once we return from getopts, all that should
# left are the required arguments.
#
%options = ();
if (! getopts($optlist, \%options)) {
    usage();
}
if (@ARGV != 0) {
    usage();
}
my $setmesg = 0;
my $message = "";
if (defined($options{"m"})) {
    $setmesg = 1;
    $message = $options{"m"};
}
my $setlogin = 0;
my $logins   = 1;
if (defined($options{"l"})) {
    $setlogin = 1;
    if ($options{"l"} eq "login") {
	$logins = 1;
    }
    elsif ($options{"l"} eq "nologin") {
	$logins = 0;
    }
    else {
	usage();
    }
}

#
# Only root or admin types!
# 
89
if (($UID != 0) && (!TBAdmin($UID))) {
90 91 92 93 94 95 96
	die("Only root or TB administrators can control the web interface.\n");
}

if ($setmesg) {
    if ($message eq "") {
	print "Clearing Web Message of the Day\n";

97
	system("setsitevar web/message -");
98 99
    }
    else {
100 101 102 103
	print "Setting Web Message of the Day to \"$message\".\n";

	$message =~ s|\&|&amp;|g;
	$message =~ s|\<|&lt;|g;
104

105
	system("setsitevar","web/message", $message);
106 107 108 109 110 111 112
    }
}

if ($setlogin) {
    if ($logins) {
	print "Enabling Web Interface logins\n";

113
	system("setsitevar web/nologins -");
114 115 116 117
    }
    else {
	print "Disabling Web Interface logins\n";

118
	system("setsitevar web/nologins 1");
119 120 121 122

	#
	# Find all non admins and log them out.
	# 
123
	DBQueryFatal("delete from login where adminon=0");
124 125 126
    }
}

127 128