Commit f57631d1 authored by Mike Hibler's avatar Mike Hibler

Add some more sitevar manipulation routines.

parent e155d15d
#!/usr/bin/perl -w
#
# Copyright (c) 2000-2010 University of Utah and the Flux Group.
# Copyright (c) 2000-2012 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -26,7 +26,8 @@ use strict;
use Exporter;
use vars qw(@ISA @EXPORT);
@ISA = qw(Exporter);
@EXPORT = qw(SiteVarExists GetSiteVar SetSiteVar NoLogins IsShutDown);
@EXPORT = qw(SiteVarExists CreateSiteVar GetSiteVar SetSiteVar
GetSiteVarDesc SetSiteVarDesc NoLogins IsShutDown);
use emdb;
......@@ -52,6 +53,48 @@ sub SiteVarExists($)
return $query_result->numrows;
}
#
# Create a new site variable.
#
# usage: CreateSiteVar($name, $desc, $defvalue, $value, $nsinclude)
# All but $name and $desc are optional.
# Returns 1 on success, 0 if sitevar exists or on failure.
#
sub CreateSiteVar($$;$$$)
{
my ($name,$desc,$defval,$val,$nsinc) = @_;
return 0
if (SiteVarExists($name));
return 0
if (!defined($desc));
$name = DBQuoteSpecial($name);
$desc = DBQuoteSpecial($desc);
if (defined($defval)) {
$defval = DBQuoteSpecial($defval);
} else {
$defval = "NULL";
}
if (defined($val)) {
$val = DBQuoteSpecial($val);
} else {
$val = "NULL";
}
if (defined($nsinc)) {
$nsinc = ($nsinc != 0);
} else {
$nsinc = 0;
}
my $query_result =
DBQueryWarn("insert into sitevariables ".
"(name,value,defaultvalue,description,ns_include) ".
"values ($name,$val,$defval,$desc,$nsinc)");
return $query_result ? 1 : 0;
}
#
# Get site-specific variable.
# Get the value of the variable, or the default value if
......@@ -133,6 +176,48 @@ sub SetSiteVar($$)
return 1;
}
# usage: GetSiteVarDesc($name)
# Returns description if variable is defined; dies otherwise.
#
sub GetSiteVarDesc($)
{
my ($name) = @_;
my $value;
$name = DBQuoteSpecial( $name );
my $query_string =
"select description from sitevariables where name=$name";
my $query_result = DBQueryFatal($query_string);
if ($query_result->numrows > 0) {
my ($desc) = $query_result->fetchrow_array();
return $desc;
}
die("*** $0:\n".
" Attempted to fetch description of unknown site variable $name\n");
}
#
# Set a sitevar description. Assumed to be a real sitevar.
#
# usage: SetSiteVarDesc($name, $desc)
#
sub SetSiteVarDesc($$)
{
my ($name, $desc) = @_;
$name = DBQuoteSpecial($name);
$desc = DBQuoteSpecial($desc);
my $query_result =
DBQueryWarn("update sitevariables set description=$desc where name=$name");
return 0
if (!$query_result);
return 1;
}
#
# Check for nologins; web interface disabled means other interfaces
# should be disabled. Not using libdb:GetSiteVar cause do not want to
......
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