All new accounts created on Gitlab now require administrator approval. If you invite any collaborators, please let Flux staff know so they can approve the accounts.

Commit 9a586d0b authored by Russ Fish's avatar Russ Fish

Move newimageid_ez page form logic to a backend Perl script.

     www/newimageid_ez.php3 - The reworked PHP page.  Calls Image::NewImageId with ez=1.
     www/newimageid.php3 - Call Image::NewImageId with ez=0.
     www/imageid_defs.php - Re-use the Image::NewImageId class method, adding an 'ez' arg.
     backend/{newimageid_ez,GNUmakefile}.in configure configure.in - New backend script.
         After checks, calls OSinfo->Create and Image->Create with the same XML args array.
     db/Image.pm.in - Re-use the Image->Create method, adding an imageid over-ride arg.
     db/OSinfo.pm.in - Filter out extraneous db slot args from XML in the Create method.
     db/libdb.pm.in - Add TB_{OS,IMAGE}ID_* constants from dbdefs.php3 .
     sql/database-fill.sql - Add OS entries to the table_regex 'images' pattern set.
parent 38bc8fa1
......@@ -13,9 +13,11 @@ UNIFIED = @UNIFIED_BOSS_AND_OPS@
include $(OBJDIR)/Makeconf
BIN_SCRIPTS = moduserinfo newgroup newmmlist editexp editimageid \
editnodetype editsitevars newimageid editgroup
editnodetype editsitevars newimageid editgroup \
newimageid_ez
WEB_BIN_SCRIPTS = webmoduserinfo webnewgroup webnewmmlist webeditimageid \
webeditnodetype webeditsitevars webnewimageid webeditgroup
webeditnodetype webeditsitevars webnewimageid webeditgroup \
webnewimageid_ez
WEB_SBIN_SCRIPTS=
LIBEXEC_SCRIPTS = $(WEB_BIN_SCRIPTS) $(WEB_SBIN_SCRIPTS)
......
This diff is collapsed.
......@@ -2428,8 +2428,9 @@ outfiles="$outfiles Makeconf GNUmakefile \
account/addpubkey account/addsfskey account/genpubkeys \
account/quotamail account/mkusercert account/newproj account/newuser \
backend/GNUmakefile backend/moduserinfo backend/newgroup \
backend/newmmlist backend/editexp backend/editimageid backend/editnodetype \
backend/editsitevars backend/newimageid backend/editgroup \
backend/newmmlist backend/editexp backend/editimageid \
backend/editnodetype backend/editsitevars backend/newimageid \
backend/editgroup backend/newimageid_ez \
tbsetup/GNUmakefile tbsetup/console_setup tbsetup/spewlogfile \
tbsetup/spewrpmtar tbsetup/gentopofile tbsetup/power_sgmote.pm \
tbsetup/console_reset tbsetup/bwconfig tbsetup/power_rpc27.pm \
......
......@@ -808,8 +808,9 @@ outfiles="$outfiles Makeconf GNUmakefile \
account/addpubkey account/addsfskey account/genpubkeys \
account/quotamail account/mkusercert account/newproj account/newuser \
backend/GNUmakefile backend/moduserinfo backend/newgroup \
backend/newmmlist backend/editexp backend/editimageid backend/editnodetype \
backend/editsitevars backend/newimageid backend/editgroup \
backend/newmmlist backend/editexp backend/editimageid \
backend/editnodetype backend/editsitevars backend/newimageid \
backend/editgroup backend/newimageid_ez \
tbsetup/GNUmakefile tbsetup/console_setup tbsetup/spewlogfile \
tbsetup/spewrpmtar tbsetup/gentopofile tbsetup/power_sgmote.pm \
tbsetup/console_reset tbsetup/bwconfig tbsetup/power_rpc27.pm \
......
......@@ -20,6 +20,7 @@ use libtestbed;
use Project;
use Group;
use User;
use OSinfo;
use English;
use Data::Dumper;
use overload ('""' => 'Stringify');
......@@ -168,11 +169,10 @@ sub Refresh($)
# Create a new os_info. This installs the new record in the DB,
# and returns an instance. There is some bookkeeping along the way.
#
sub Create($$$$)
sub Create($$$$$$$$)
{
my ($class, $project, $group, $creator, $imagename, $argref, $usrerr_ref) = @_;
my $idx;
my $now = time();
my ($class, $project, $group, $creator,
$imagename, $imageid, $argref, $usrerr_ref) = @_;
return undef
if (ref($class) || !ref($project));
......@@ -221,15 +221,26 @@ sub Create($$$$)
return undef;
}
#
# Grab unique ID. Table already locked.
#
my $imageid = TBGetUniqueIndex("next_imageid", undef, 1);
# We allow providing an image descriptor index, so newimageid_ez can use
# the same name, description, and index for both the OS and Image it makes.
if ($imageid > 0 ) {
# Make sure the OS descriptor for it already exists.
if (!OSinfo->Lookup($imageid)) {
DBQueryWarn("unlock tables");
$$usrerr_ref = "Error: Missing OSinfo $imagename/$imageid in $pid!";
return undef;
}
} else {
#
# Grab unique ID. Table already locked.
#
$imageid = TBGetUniqueIndex("next_imageid", undef, 1);
}
my $uuid = NewUUID();
my $desc = "''";
# Some fields special cause of quoting.
#
my $desc = "''";
if (exists($argref->{'description'})) {
$desc = DBQuoteSpecial($argref->{'description'});
}
......
......@@ -177,7 +177,7 @@ sub reboot_waittime($) { return field($_[0], "reboot_waittime"); }
# Create a new os_info. This installs the new record in the DB,
# and returns an instance. There is some bookkeeping along the way.
#
sub Create($$$$)
sub Create($$$$$$)
{
my ($class, $project, $creator, $osname, $argref, $usrerr_ref) = @_;
my $idx;
......@@ -215,19 +215,29 @@ sub Create($$$$)
my $desc = "''";
my $magic = "''";
# Some fields special cause of quoting.
#
if (exists($argref->{'description'})) {
$desc = DBQuoteSpecial($argref->{'description'});
delete($argref->{'description'});
}
if (exists($argref->{'magic'})) {
$magic = DBQuoteSpecial($argref->{'magic'});
delete($argref->{'magic'});
}
# Filter arg array to just valid slots that we don't explicitly set below.
my @arg_slots;
foreach my $key ("old_osid", "OS", "version", "path", "machinetype",
"osfeatures", "ezid", "shared", "mustclean",
"op_mode", "nextosid", "old_nextosid",
"max_concurrent", "mfs", "reboot_waittime") {
if (exists($argref->{$key})) {
push(@arg_slots, $key);
}
}
my $query = "insert into os_info set ".
join(",", map("$_='" . $argref->{$_} . "'", keys(%{$argref})));
join(",", map("$_='" . $argref->{$_} . "'", @arg_slots));
# Append the rest
$query .= ",osname='$osname'";
......
......@@ -62,10 +62,12 @@ use vars qw(@ISA @EXPORT);
TB_OSID_READINFO TB_OSID_CREATE
TB_OSID_DESTROY TB_OSID_MIN TB_OSID_MAX
TB_OSID_OSIDLEN TB_OSID_OSNAMELEN TB_OSID_VERSLEN
TB_IMAGEID_READINFO TB_IMAGEID_MODIFYINFO
TB_IMAGEID_CREATE TB_IMAGEID_DESTROY
TB_IMAGEID_ACCESS TB_IMAGEID_MIN TB_IMAGEID_MAX
TB_IMAGEID_IMAGEIDLEN TB_IMAGEID_IMAGENAMELEN
DBLIMIT_NSFILESIZE NODERELOADPENDING_EID
......@@ -566,6 +568,9 @@ sub TB_OSID_CREATE() { 2; }
sub TB_OSID_DESTROY() { 3; }
sub TB_OSID_MIN() { TB_OSID_READINFO; }
sub TB_OSID_MAX() { TB_OSID_DESTROY; }
sub TB_OSID_OSIDLEN() { 35; }
sub TB_OSID_OSNAMELEN() { 20; }
sub TB_OSID_VERSLEN() { 12; }
# Magic OSID constants
sub TB_OSID_MBKERNEL() { "_KERNEL_"; } # multiboot kernel OSID
......@@ -587,6 +592,8 @@ sub TB_IMAGEID_DESTROY() { 4; }
sub TB_IMAGEID_ACCESS() { 5; }
sub TB_IMAGEID_MIN() { TB_IMAGEID_READINFO; }
sub TB_IMAGEID_MAX() { TB_IMAGEID_ACCESS; }
sub TB_IMAGEID_IMAGEIDLEN() { 45; }
sub TB_IMAGEID_IMAGENAMELEN() { 30; }
# Node Log Types
sub TB_NODELOGTYPE_MISC { "misc"; }
......
......@@ -811,6 +811,15 @@ REPLACE INTO table_regex VALUES ('images','node_id','text','redirect','nodes:nod
REPLACE INTO table_regex VALUES ('images','load_address','text','redirect','default:text',0,0,NULL);
REPLACE INTO table_regex VALUES ('images','frisbee_pid','text','redirect','default:int',0,0,NULL);
REPLACE INTO table_regex VALUES ('images','nodetype','text','redirect','node_types:node_type',0,0,NULL);
REPLACE INTO table_regex VALUES ('images','OS','text','redirect','os_info:OS',0,0,NULL);
REPLACE INTO table_regex VALUES ('images','version','text','redirect','os_info:version',0,0,NULL);
REPLACE INTO table_regex VALUES ('images','osfeatures','text','redirect','os_info:osfeatures',0,0,NULL);
REPLACE INTO table_regex VALUES ('images','op_mode','text','redirect','os_info:op_mode',0,0,NULL);
REPLACE INTO table_regex VALUES ('images','wholedisk','text','redirect','default:boolean',0,0,NULL);
REPLACE INTO table_regex VALUES ('images','max_concurrent','text','redirect','default:int',0,0,NULL);
REPLACE INTO table_regex VALUES ('images','reboot_waittime','text','redirect','default:int',0,0,NULL);
REPLACE INTO table_regex VALUES ('node_types','new_type','text','redirect','default:tinytext',0,0,NULL);
REPLACE INTO table_regex VALUES ('node_types','node_type','text','regex','^[-\\w]+$',1,30,NULL);
REPLACE INTO table_regex VALUES ('node_types','class','text','regex','^[\\w]+$',1,30,NULL);
......
......@@ -117,7 +117,7 @@ class Image
#
# Class function to create a new image descriptor.
#
function NewImageId($imagename, $args, &$errors) {
function NewImageId($ez, $imagename, $args, &$errors) {
global $suexec_output, $suexec_output_array;
#
......@@ -148,7 +148,8 @@ class Image
fclose($fp);
chmod($xmlname, 0666);
$retval = SUEXEC("nobody", "nobody", "webnewimageid $xmlname",
$script = "webnewimageid" . ($ez ? "_ez" : "");
$retval = SUEXEC("nobody", "nobody", "$script $xmlname",
SUEXEC_ACTION_IGNORE);
if ($retval) {
......
......@@ -503,7 +503,7 @@ if (!isset($submit)) {
}
reset($projlist);
}
SPITFORM($defaults, 0);
PAGEFOOTER();
return;
......@@ -514,7 +514,7 @@ if (!isset($submit)) {
#
$errors = array();
# Be friendly about the form field names.
# Be friendly about the required form field names.
if (!isset($formfields["pid"]) ||
strcmp($formfields["pid"], "") == 0) {
$errors["Project"] = "Missing Field";
......@@ -747,7 +747,7 @@ if (mysql_num_rows($query_result)) {
# Send to the backend for more checking, and eventually, to update the DB.
$imagename = $args["imagename"];
if (! ($image = Image::NewImageId($imagename, $args, $errors))) {
if (! ($image = Image::NewImageId(0, $imagename, $args, $errors))) {
# Always respit the form so that the form fields are not lost.
# I just hate it when that happens so lets not be guilty of it ourselves.
SPITFORM($formfields, $errors);
......
This diff is collapsed.
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