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 9dcf6297 authored by Russ Fish's avatar Russ Fish

Move editimageid page form logic to a backend Perl script.

     www/editimageid.php3 - The reworked PHP page.
     www/imageid_defs.php - Add an Experiment::EditImageid class method
                            bridging to the script via XML.
     backend/{editimageid,GNUmakefile}.in configure configure.in - New backend script.
     db/Image.pm.in - Add an EditImageid worker class method for script arg checking.
     sql/database-fill.sql - Add to the table_regex 'images' checking patterns.
parent a35e40cb
......@@ -12,8 +12,8 @@ UNIFIED = @UNIFIED_BOSS_AND_OPS@
include $(OBJDIR)/Makeconf
BIN_SCRIPTS = moduserinfo newgroup newmmlist editexp
WEB_BIN_SCRIPTS = webmoduserinfo webnewgroup webnewmmlist webeditexp
BIN_SCRIPTS = moduserinfo newgroup newmmlist editexp editimageid
WEB_BIN_SCRIPTS = webmoduserinfo webnewgroup webnewmmlist webeditimageid
WEB_SBIN_SCRIPTS=
LIBEXEC_SCRIPTS = $(WEB_BIN_SCRIPTS) $(WEB_SBIN_SCRIPTS)
......
This diff is collapsed.
......@@ -2428,7 +2428,7 @@ 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/newmmlist backend/editexp backend/editimageid \
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,7 +808,7 @@ 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/newmmlist backend/editexp backend/editimageid \
tbsetup/GNUmakefile tbsetup/console_setup tbsetup/spewlogfile \
tbsetup/spewrpmtar tbsetup/gentopofile tbsetup/power_sgmote.pm \
tbsetup/console_reset tbsetup/bwconfig tbsetup/power_rpc27.pm \
......
......@@ -164,6 +164,116 @@ sub Refresh($)
return 0;
}
#
# Worker class method to edit image descriptor.
# Assumes most argument checking was done elsewhere.
#
sub EditImageid($$$$)
{
my ($class, $image, $argref, $usrerr_ref) = @_;
my %mods;
my $noreport;
my $imageid = $image->imageid();
#
# Now update the rest of the information in the DB.
# (Others above already did their own updates.)
#
my %updates;
foreach my $col ("description", "path", "load_address", "frisbee_pid" ) {
# Copy args we want so that others can't get through.
if (exists($argref->{$col})) {
$updates{$col} = $mods{$col} = $argref->{$col};
}
}
# See mtype_$type args below.
#
# Need a list of node types. We join this over the nodes table so that
# we get a list of just the nodes that are currently in the testbed, not
# just in the node_types table.
#
my $types_result =
DBQueryFatal("select distinct n.type from nodes as n ".
"left join node_type_attributes as a on a.type=n.type ".
"where a.attrkey='imageable' and ".
" a.attrvalue!='0'");
my @mtypes_array;
my @map_updates;
my $redo_map = 0;
while (my ($type) = $types_result->fetchrow_array()) {
push(@mtypes_array, $type);
# Remember when we get one of the mtype_$type args. These aren't DB
# columns to update, but instead control re-creating the rows in the
# osidtoimageid table for this imageid, below.
my $mtype = "mtype_$type";
if (exists($argref->{$mtype})) {
my $value = $argref->{$mtype};
##printf "argref->{$mtype} %s\n", $value;
$mods{$mtype} = $value;
if ($value eq "1") {
push(@map_updates, $type);
$redo_map = 1;
}
}
}
if (!keys %mods) {
if (!$noreport) {
# Warn the user that the submit button was pressed with no effect.
$$usrerr_ref = "Submit: Nothing changed";
return undef;
}
}
if (keys %updates || $redo_map) {
DBQueryFatal("lock tables images write, os_info write, ".
"osidtoimageid write");
}
if (keys %updates) {
if ($image->Update(\%updates)) {
$$usrerr_ref = "DB: Error updating the images table";
DBQueryFatal("unlock tables");
return undef;
}
}
if ($redo_map) {
#
# Update the osidtoimageid table too.
#
# Must delete old entries first.
DBQueryFatal("delete from osidtoimageid ".
"where imageid='$imageid'");
my @osid_array;
for (my $i = 1; $i <= 4; $i++) {
my $foo = $image->field("part${i}_osid");
if (defined($foo)) {
push(@osid_array, $foo);
}
}
for (my $i = 0; $i <= $#map_updates; $i++) {
for (my $j = 0; $j <= $#osid_array; $j++) {
my $query = "REPLACE INTO osidtoimageid ".
" (osid, type, imageid) ".
"VALUES ('$osid_array[$j]', ".
" '$map_updates[$i]', ".
" '$imageid')";
##print "$query\n";
DBQueryFatal($query);
}
}
}
if (keys %updates || $redo_map) {
DBQueryFatal("unlock tables");
}
return 1;
}
#
# Stringify for output.
#
......
......@@ -788,8 +788,16 @@ REPLACE INTO table_regex VALUES ('virt_nodes','plab_role','text','regex','^(plc|
REPLACE INTO table_regex VALUES ('experiments','elab_in_elab','int','redirect','default:boolean',0,0,NULL);
REPLACE INTO table_regex VALUES ('experiments','elabinelab_singlenet','int','redirect','default:boolean',0,0,NULL);
REPLACE INTO table_regex VALUES ('experiments','elabinelab_cvstag','text','regex','^[-\\w\\@\\/\\.]+$',0,0,NULL);
REPLACE INTO table_regex VALUES ('images','imageid','text','regex','^[a-zA-Z0-9][-\\w\\.+]+$',0,45,NULL);
REPLACE INTO table_regex VALUES ('images','imageid','text','redirect','default:int',0,100000000,NULL);
REPLACE INTO table_regex VALUES ('images','imagename','text','regex','^[a-zA-Z0-9][-\\w\\.+]+$',2,30,NULL);
REPLACE INTO table_regex VALUES ('images','description','text','regex','^[\\040-\\176\\012\\015\\011]*$',1,256,NULL);
REPLACE INTO table_regex VALUES ('images','path','text','regex','^[-_\\w\\.\\/:+]*$',1,256,NULL);
REPLACE INTO table_regex VALUES ('images','mtype','text','redirect','default:boolean',0,0,NULL);
REPLACE INTO table_regex VALUES ('images','osid','text','redirect','os_info:osid',0,0,NULL);
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 ('experiments','security_level','int','redirect','default:tinyuint',0,4,NULL);
REPLACE INTO table_regex VALUES ('experiments','elabinelab_eid','text','redirect','experiments:eid',0,0,NULL);
REPLACE INTO table_regex VALUES ('virt_node_startloc','pid','text','redirect','projects:pid',0,0,NULL);
......
This diff is collapsed.
......@@ -114,6 +114,75 @@ class Image
return 0;
}
#
# Class function to edit image descriptor.
#
function EditImageid($image, $args, &$errors) {
global $suexec_output, $suexec_output_array;
#
# Generate a temporary file and write in the XML goo.
#
$xmlname = tempnam("/tmp", "editimageid");
if (! $xmlname) {
TBERROR("Could not create temporary filename", 0);
$errors[] = "Transient error; please try again later.";
return null;
}
if (! ($fp = fopen($xmlname, "w"))) {
TBERROR("Could not open temp file $xmlname", 0);
$errors[] = "Transient error; please try again later.";
return null;
}
# Add these. Maybe caller should do this?
$args["imageid"] = $image->imageid();
fwrite($fp, "<image>\n");
foreach ($args as $name => $value) {
fwrite($fp, "<attribute name=\"$name\">");
fwrite($fp, " <value>" . htmlspecialchars($value) . "</value>");
fwrite($fp, "</attribute>\n");
}
fwrite($fp, "</image>\n");
fclose($fp);
chmod($xmlname, 0666);
$retval = SUEXEC("nobody", "nobody", "webeditimageid $xmlname",
SUEXEC_ACTION_IGNORE);
if ($retval) {
if ($retval < 0) {
$errors[] = "Transient error; please try again later.";
SUEXECERROR(SUEXEC_ACTION_CONTINUE);
}
else {
# unlink($xmlname);
if (count($suexec_output_array)) {
for ($i = 0; $i < count($suexec_output_array); $i++) {
$line = $suexec_output_array[$i];
if (preg_match("/^([-\w]+):\s*(.*)$/",
$line, $matches)) {
$errors[$matches[1]] = $matches[2];
}
else
$errors[] = $line;
}
}
else
$errors[] = "Transient error; please try again later.";
}
return null;
}
# There are no return value(s) to parse at the end of the output.
# Unlink this here, so that the file is left behind in case of error.
# We can then create the image by hand from the xmlfile, if desired.
unlink($xmlname);
return true;
}
#
# Equality test.
#
......
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