Commit a0248828 authored by Chad Barb's avatar Chad Barb

Added site variables ('sitevars').
These are stored in the sitevariables database table.
Each one has a name, a description (NOT OPTIONAL!), a
default value, and a current value.
If the current value is NULL, the default value is used.

Soon, a mechanism will be added to the install process to
ensure all needed site variables exist before installing;
more on that when it is committed.

 - Added 'editsitevars.php3' page, accessable to admins
   via the 'Edit Site Variables' menu option.

 - Added 'setsitevar' script,
   an interface for listing, viewing in detail, and setting
   site variables.

 - Web interface now uses 'web/nologins' and 'web/message'
   instead of one-off database tables.

NOTE that setting a variable to the default value and
setting a variable to a value which is string-identical
are NOT the same thing.
(This doesn't matter yet, but when we push default values out to
 remote sites as part of our install, it will.)
parent 87045a9d
......@@ -1345,6 +1345,7 @@ outfiles="$outfiles Makeconf GNUmakefile \
capture/GNUmakefile \
db/GNUmakefile db/nalloc db/nfree db/if2port db/backup \
db/webcontrol db/node_status db/genelists db/genelists.proxy \
db/setsitevar \
db/libdb.pm db/inuse db/avail db/nodeip db/showgraph \
db/dhcpd_makeconf db/nodelog db/webnodelog db/unixgroups \
db/dbcheck db/interswitch db/dbboot db/schemacheck \
......
......@@ -388,6 +388,7 @@ outfiles="$outfiles Makeconf GNUmakefile \
capture/GNUmakefile \
db/GNUmakefile db/nalloc db/nfree db/if2port db/backup \
db/webcontrol db/node_status db/genelists db/genelists.proxy \
db/setsitevar \
db/libdb.pm db/inuse db/avail db/nodeip db/showgraph \
db/dhcpd_makeconf db/nodelog db/webnodelog db/unixgroups \
db/dbcheck db/interswitch db/dbboot db/schemacheck \
......
......@@ -15,7 +15,7 @@ BIN_SCRIPTS = nalloc nfree nodeip readycount
SBIN_SCRIPTS = avail inuse showgraph if2port backup webcontrol node_status \
genelists genelists.proxy dhcpd_makeconf nodelog unixgroups \
dbcheck interswitch dbboot grabron stategraph newwanode \
idletimes idlemail
idletimes idlemail setsitevar
LIBEXEC_SCRIPTS = webnodelog webnfree webnewwanode webidlemail
LIB_SCRIPTS = libdb.pm
......
......@@ -132,6 +132,8 @@ use Exporter;
TBDB_WIDEAREA_LOCALNODE
TBWideareaNodeID TBTipServers
TBSiteVarExists TBGetSiteVar
TBActivityReport
);
......@@ -2129,6 +2131,60 @@ sub TBExptDestroy($$)
return 0;
}
#
# Check if a site-specific variable exists.
#
# usage: TBSiteVarExists($name)
# returns 1 if variable exists;
# returns 0 otherwise.
#
sub TBSiteVarExists($)
{
my($name) = @_;
$name = DBQuoteSpecial( $name );
$query_result =
DBQueryFatal("select name from sitevariables ".
"where name=$name");
if ($query_result->numrows > 0) {
return 1;
} else {
return 0;
}
}
#
# Get site-specific variable.
# Get the value of the variable, or the default value if
# the value is undefined (NULL).
#
# usage: TBGetSiteVar($name)
# returns value if variable is defined;
# dies otherwise.
#
sub TBGetSiteVar($)
{
my($name) = @_;
$name = DBQuoteSpecial( $name );
$query_result =
DBQueryFatal("select value, defaultvalue from sitevariables ".
"where name=$name");
if ($query_result->numrows > 0) {
my($value, $defaultvalue) = $query_result->fetchrow_array;
if (defined $value) { return $value; }
if (defined $defaultvalue) { return $defaultvalue; }
}
die("*** attempted to fetch unknown site variable $name!");
}
#
# List of tables used for experiment removal/backup/restore.
#
......@@ -2148,7 +2204,8 @@ sub TBExptDestroy($$)
"tunnels",
"v2pmap",
"ipport_ranges",
"linkdelays");
"linkdelays",
"portmap");
#
......
#!/usr/bin/perl -wT
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2002 University of Utah and the Flux Group.
# All rights reserved.
#
use English;
use Getopt::Std;
#
# usage: setsitevar
# - displays list of all sitevar names and values
#
# setsitevar <variablename>
# - displays name, description, value, and default for <variablename>
#
# setsitevar <variablename> -
# - sets <variablename> to default value
#
# setsitevar <variablename> <newvalue>
# - sets <variablename> to <newvalue>
#
sub usage()
{
print STDOUT "Usage:\n".
"setsitevar -h\n".
" - displays this usage information.\n".
"\n".
"setsitevar\n".
" - displays list of all sitevar names and values.\n".
"\n".
"setsitevar <variablename>\n".
" - displays name, description, value, \n".
" and default value for <variablename>.\n".
"\n".
"setsitevar <variablename> -\n".
" - sets <variablename> to default value.\n".
"\n".
"setsitevar <variablename> <newvalue>\n".
" - sets <variablename> to <newvalue>.\n";
exit(-1);
}
#
# Configure variables
#
use lib "@prefix@/lib";
use libdb;
#
# Turn off line buffering on output
#
$| = 1;
$name = shift;
if (defined $name && $name eq "-h") {
usage();
}
$value = shift;
shift and usage(); # too many args
if (defined $name) { $qname = DBQuoteSpecial($name); }
if (defined $value) { $qvalue = DBQuoteSpecial($value); }
#
# Only root or admin types!
#
if (($UID != 0) && (!TBAdmin($UID))) {
die("Only root or TB administrators can set site variables.\n");
}
#
# Briefly list all sitevars, a la 'set'.
#
if (! defined $name) {
$result = DBQueryFatal("SELECT name, value, defaultvalue, description ".
"FROM sitevariables ".
"ORDER BY name");
while (($name, $value, $default, $desc) =
$result->fetchrow_array()) {
if (defined $value) {
print "$name\t\"$value\"\n";
} else {
print "$name\t\"$default\"(default)\n";
}
}
exit(0);
}
$result = DBQueryFatal("SELECT value, defaultvalue, description ".
"FROM sitevariables ".
"WHERE name=$qname");
if ($result->numrows == 0) {
print STDERR "No such sitevar $qname!\n";
exit(1);
}
($currentvalue, $default, $desc) = $result->fetchrow_array();
#
# List a specific sitevar in detail
#
if (! defined $value) {
print "sitevar name: $name\n".
"description: $desc\n".
"value: ";
if (defined $currentvalue) {
print "\"$currentvalue\"\n";
} else {
print "<default>\n";
}
print "default value: \"$default\"\n";
exit(0);
}
#
# Set a sitevar
#
#
# Handle '-' argument
#
if ($qvalue eq "'-'") {
$qvalue = "NULL";
}
$result = DBQueryFatal("UPDATE sitevariables ".
"SET value=$qvalue ".
"WHERE name=$qname");
#
# Warn user if operation was redundant.
#
#if ($result->rows == 0) {
# print STDERR "Warning: row value same as before\n";
#}
exit(0);
#!/usr/bin/perl -wT
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
......@@ -24,6 +24,11 @@ my $optlist = "m:l:";
use lib "@prefix@/lib";
use libdb;
my $TBROOT = "@prefix@";
# Untaint the path
$ENV{'PATH'} = "/usr/bin:$TBROOT/libexec:$TBROOT/sbin:$TBROOT/bin";
#
# Turn off line buffering on output
#
......@@ -72,13 +77,15 @@ if ($setmesg) {
if ($message eq "") {
print "Clearing Web Message of the Day\n";
DBQueryFatal("delete from loginmessage");
system("setsitevar web/message -");
}
else {
print "Setting Web Message of the Day to $message\n";
print "Setting Web Message of the Day to \"$message\".\n";
$message =~ s|\&|&amp;|g;
$message =~ s|\<|&lt;|g;
DBQueryFatal("replace into loginmessage (valid, message) ".
"values(1, '$message')");
system("setsitevar","web/message", $message);
}
}
......@@ -86,12 +93,12 @@ if ($setlogin) {
if ($logins) {
print "Enabling Web Interface logins\n";
DBQueryFatal("delete from nologins");
system("setsitevar web/nologins -");
}
else {
print "Disabling Web Interface logins\n";
DBQueryFatal("replace into nologins (nologins) values(1)");
system("setsitevar web/nologins 1");
#
# Find all non admins and log them out.
......@@ -109,3 +116,5 @@ if ($setlogin) {
}
}
......@@ -1593,6 +1593,62 @@ function TBGetExptIdleIgnore($pid,$eid) {
return $row[idle_ignore];
}
#
# Check if a site-specific variable exists.
#
# usage: TBSiteVarExists($name)
# returns 1 if variable exists;
# returns 0 otherwise.
#
function TBSiteVarExists($name)
{
global $lastact_query;
$name = addslashes( $name );
$query_result =
DBQueryFatal("select name from sitevariables ".
"where name='$name'");
if (mysql_num_rows($query_result) > 0) {
return 1;
} else {
return 0;
}
}
#
# Get site-specific variable.
# Get the value of the variable, or the default value if
# the value is undefined (NULL).
#
# usage: TBGetSiteVar($name)
# returns value if variable is defined;
# dies otherwise.
#
function TBGetSiteVar($name)
{
global $lastact_query;
$name = addslashes( $name );
$query_result =
DBQueryFatal("select value, defaultvalue from sitevariables ".
"where name='$name'");
if (mysql_num_rows($query_result) > 0) {
$row = mysql_fetch_array($query_result);
$value = $row[value];
$defaultvalue = $row[defaultvalue];
if (isset($value)) { return $value; }
if (isset($defaultvalue)) { return $defaultvalue; }
}
TBERROR("Attempted to fetch unknown site variable '$name'!");
}
#
# DB Interface.
#
......
<?php
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2003 University of Utah and the Flux Group.
# All rights reserved.
#
include("defs.php3");
#
# Standard Testbed Header
#
PAGEHEADER("Edit Site Variables");
#
# Only known and logged in users can do this.
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);
#
# Of course verify that this uid has admin privs!
#
$isadmin = ISADMIN($uid);
if (! $isadmin) {
USERERROR("You do not have admin privledges to edit site variables!", 1);
}
if (isset($edit)) {
$result = DBQueryFatal("SELECT name, value, defaultvalue, description ".
"FROM sitevariables ".
"WHERE name='$edit'");
if ($row = mysql_fetch_row($result)) {
$name = $row[0];
$value = $row[1];
$defaultvalue = $row[2];
$description = $row[3];
echo "<center>";
echo "<form action='editsitevars.php3' method='post'>";
echo "<input type='hidden' name='name' value='$name'></input>";
echo "<table><tr><th colspan=2>";
echo "Editing site variable '<b>$name</b>':";
echo "</th></tr><tr><td>";
echo "<b>Description:</b></td><td>$description</font>";
echo "</td></tr><tr><td>";
echo "<b>Default value:</b></td><td>";
if (0 != strcmp($defaultvalue,"")) {
echo "<code>$defaultvalue</code>";
} else {
echo "<font color='#00B040'><i>Empty String</i></font>";
}
echo "</td></tr><tr><td>&nbsp;</td><td>";
echo "<input type='submit' name='defaulted' value='Reset to Default Value'></input>";
echo "</td></tr><tr><td>";
echo "<b>New value:</b></td><td>";
echo "<input size='60' type='text' name='value' value='$value'></input>";
echo "</td></tr><tr><td>&nbsp;</td><td>";
echo "<input type='submit' name='edited' value='Change to New Value'></input>";
echo "&nbsp;";
echo "<input type='submit' name='cancelled' value='Cancel'></input>";
echo "</td></tr></table>";
echo "</form>";
echo "</center>";
} else {
TBERROR("Couldn't find variable '$edit'!");
}
PAGEFOOTER();
return;
}
if (isset($edited)) {
DBQueryFatal("UPDATE sitevariables ".
"SET value='$value' ".
"WHERE name='$name'");
echo "<h3>'$name' changed.</h3>";
echo "<form action='editsitevars.php3' method='get'>";
echo "<input type='submit' name='yadda' value='Return to list'></input>";
echo "</form>";
PAGEFOOTER();
return;
}
if (isset($defaulted)) {
DBQueryFatal("UPDATE sitevariables ".
"SET value=NULL ".
"WHERE name='$name'");
echo "<h3>'$name' reset to default.</h3>";
echo "<form action='editsitevars.php3' method='get'>";
echo "<input type='submit' name='yadda' value='Return to list'></input>";
echo "</form>";
PAGEFOOTER();
return;
}
if (isset($cancelled)) {
echo "<h3>Operation cancelled.</h3>";
echo "<form action='editsitevars.php3' method='get'>";
echo "<input type='submit' name='yadda' value='Return to list'></input>";
echo "</form>";
PAGEFOOTER();
return;
}
$result = DBQueryFatal("SELECT name, value, defaultvalue, description ".
"FROM sitevariables ".
"ORDER BY name");
echo "<table>
<tr>
<th>&nbsp;Name&nbsp;</th>
<th>&nbsp;Value&nbsp;</th>
<th><font size='-1'>Edit</font></th>
<th>&nbsp;Default Value&nbsp;</th>
<th>&nbsp;Description&nbsp;</th>
</tr>";
while ($row = mysql_fetch_row($result)) {
$name = $row[0];
$value = $row[1];
$defaultvalue = $row[2];
$description = $row[3];
$cginame = urlencode($name);
echo "<tr><td>&nbsp;<b>$name</b>&nbsp;</td>\n";
echo "<td nowrap='1'>&nbsp;";
if (isset($value)) {
if (0 != strcmp($value, "")) {
echo "<code>$value</code>&nbsp;</td>";
} else {
echo "<font color='#00B040'><i>empty string</i></font>&nbsp;</td>";
}
} else {
echo "<font color='#00B040'><i>default</i></font>&nbsp;</td>";
}
echo "<td align=center>";
echo "&nbsp;<a href='editsitevars.php3?edit=$cginame'>";
echo "<img border='0' src='greenball.gif' /></a>";
echo "&nbsp;</td>";
echo "<td nowrap='1'>&nbsp;";
if (0 != strcmp($defaultvalue, "")) {
echo "<code>$defaultvalue</code>&nbsp;</td>";
} else {
echo "<font color='#00B040'><i>empty string</i></font>&nbsp;</td>";
}
echo "<td>&nbsp;$description&nbsp;</td></tr>\n";
}
echo "</table>";
#
# Standard Testbed Footer
#
PAGEFOOTER();
?>
......@@ -243,6 +243,11 @@ function WRITESIDEBAR() {
$TBBASE, "nodecontrol_list.php3");
WRITESIDEBARBUTTON("Node Up/Down Status",
$TBDOCBASE, "updown.php3");
if (ISADMIN($login_uid)) {
WRITESIDEBARBUTTON("Edit Site Variables",
$TBBASE, "editsitevars.php3");
}
if ($login_status & CHECKLOGIN_CVSWEB) {
WRITESIDEBARBUTTON("CVS Repository",
......@@ -330,20 +335,14 @@ function WRITESIDEBAR() {
echo "</td></tr>\n";
}
#
# MOTD. Set this with the webcontrol script.
# Login message. Set via 'web/message' site variable
#
$query_result =
DBQueryFatal("SELECT message FROM loginmessage");
if (mysql_num_rows($query_result)) {
$row = mysql_fetch_row($query_result);
$message = $row[0];
# XXX: make this red and big (like the old one)?
WRITESIDEBARNOTICE($message);
$message = TBGetSiteVar("web/message");
if (0 != strcmp($message,"")) {
WRITESIDEBARNOTICE($message);
}
echo "</table>\n";
}
......
......@@ -479,28 +479,15 @@ function DOLOGOUT($uid) {
}
#
# Primitive "nologins" support.
# Simple "nologins" support.
#
function NOLOGINS() {
global $CHECKLOGIN_NOLOGINS;
#
# And lastly, check for NOLOGINS!
#
if ($CHECKLOGIN_NOLOGINS >= 0)
return $CHECKLOGIN_NOLOGINS;
$query_result =
DBQueryFatal("SELECT nologins FROM nologins where nologins=1");
# No entry
if (($row = mysql_fetch_array($query_result)) == 0) {
$CHECKLOGIN_NOLOGINS = 0;
}
else {
$CHECKLOGIN_NOLOGINS = $row[nologins];
if ($CHECKLOGIN_NOLOGINS == -1) {
$CHECKLOGIN_NOLOGINS = TBGetSiteVar("web/nologins");
}
return $CHECKLOGIN_NOLOGINS;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment