newimageid.php3 23.4 KB
Newer Older
1
<?php
Leigh B. Stoller's avatar
Leigh B. Stoller committed
2 3 4 5 6
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2002 University of Utah and the Flux Group.
# All rights reserved.
#
7 8 9 10 11 12
include("defs.php3");
include("showstuff.php3");

#
# Standard Testbed Header
#
13
PAGEHEADER("Create a new Image Descriptor (long form)");
14 15

#
16
# Only known and logged in users!
17 18 19 20 21 22
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);
$isadmin = ISADMIN($uid);

#
23
# See what projects the uid can do this in.
24
#
25 26 27 28 29
$projlist = TBProjList($uid, $TB_PROJECT_MAKEIMAGEID);

if (! count($projlist)) {
    USERERROR("You do not appear to be a member of any Projects in which ".
	      "you have permission to create new Image descriptors.", 1);
30
}
31 32

#
33 34 35
# Need a list of node types. We join this over the nodes table so that
# we get a list of just the nodes that currently in the testbed, not
# just in the node_types table.
36 37
#
$types_result =
38 39 40
    DBQueryFatal("select distinct n.type from nodes as n ".
		 "left join node_types as nt on n.type=nt.type ".
		 "where nt.imageable=1");
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72

#
# Helper function to write out a menu.
#
function WRITEOSIDMENU($caption, $value, $osid_result, $previous)
{
    echo "<tr>
            <td>*$caption:</td>";
    echo "  <td><select name=\"formfields[$value]\">
                <option value=X>Please Select </option>\n";

    mysql_data_seek($osid_result, 0);

    while ($row = mysql_fetch_array($osid_result)) {
	$osid   = $row[osid];
	$osname = $row[osname];
	$pid    = $row[pid];
	$selected = "";

	if (strcmp($previous, "$osid") == 0)
	    $selected = "selected";

	echo "<option $selected value='$osid'>$pid - $osname</option>\n";
    }
    $selected = "";
    if (strcmp($previous, "none") == 0)
	$selected = "selected";
	
    echo "         <option $selected value=none>No OS</option>\n";
    echo "       </select>";
    echo "    </td>
          </tr>\n";
73
}
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130

#
# Spit the form out using the array of data. 
# 
function SPITFORM($formfields, $errors)
{
    global $uid, $projlist, $isadmin, $types_result;
    global $TBDB_IMAGEID_IMAGENAMELEN, $TBDB_NODEIDLEN;
    
    if ($errors) {
	echo "<table align=center border=0 cellpadding=0 cellspacing=2>
              <tr>
                 <td align=center colspan=3>
                   <font size=+1 color=red>
                      Oops, please fix the following errors!
                   </font>
                 </td>
              </tr>\n";

	while (list ($name, $message) = each ($errors)) {
	    echo "<tr>
                     <td align=right><font color=red>$name:</font></td>
                     <td>&nbsp &nbsp</td>
                     <td align=left><font color=red>$message</font></td>
                  </tr>\n";
	}
	echo "</table><br>\n";
    }

    #
    # Get the OSID list that the user has access to. Do not allow shared OSIDs,
    # since we want to force mere users to create thier own versions.
    #
    if ($isadmin) {
	$osid_result =
	    DBQueryFatal("select * from os_info ".
			 "where (path='' or path is NULL) and ".
			 "      version!='' and version is not NULL ".
			 "order by osid");
    }
    else {
	$osid_result =
	    DBQueryFatal("select distinct o.* from os_info as o ".
			 "left join group_membership as m ".
			 " on m.pid=o.pid ".
			 "where m.uid='$uid' and ".
			 "      (path='' or path is NULL) and ".
			 "      version!='' and version is not NULL ".
			 "order by o.pid,o.osid");
    }
    if (! mysql_num_rows($osid_result)) {
	USERERROR("There are no OS Descriptors that you are able to use!", 1);
    }

    echo "<SCRIPT LANGUAGE=JavaScript>
              function SetPrefix(theform) 
              {
131 132 133 134
                  var idx = theform['formfields[pid]'].selectedIndex;
                  var pid = theform['formfields[pid]'].options[idx].value;

                  if (pid == '') {
135 136 137 138 139
                      theform['formfields[path]'].value = '/proj/';
                  }
                  else if (theform['formfields[imagename]'].value == '') {
		      theform['formfields[imagename]'].defaultValue = '';
  	              theform['formfields[path]'].value =
140
                              '/proj/' + pid + '/images/';
141 142 143
                  }
                  else if (theform['formfields[imagename]'].value != '') {
  	              theform['formfields[path]'].value =
144
                              '/proj/' + pid + '/images/' +
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
                              theform['formfields[imagename]'].value + '.ndz';
                  }
              }
          </SCRIPT>\n";

    echo "<br>
          <table align=center border=1> 
          <tr>
             <td align=center colspan=2>
                 <em>(Fields marked with * are required)</em>
             </td>
          </tr>
          <form action='newimageid.php3' method=post name=idform>\n";

    #
    # Select Project
    #
    echo "<tr>
              <td>*Select Project:</td>
              <td><select name=\"formfields[pid]\"
                          onChange='SetPrefix(idform);'>
                      <option value=''>Please Select &nbsp</option>\n";
    
    while (list($project) = each($projlist)) {
	$selected = "";

	if ($formfields[pid] == $project)
	    $selected = "selected";
	
	echo "        <option $selected value='$project'>$project </option>\n";
    }
    echo "       </select>";
    echo "    </td>
          </tr>\n";

    #
    # Image Name:
    #
    echo "<tr>
              <td>*Descriptor Name (no blanks):</td>
              <td class=left>
                  <input type=text
                         onChange='SetPrefix(idform);'
                         name=\"formfields[imagename]\"
                         value=\"" . $formfields[imagename] . "\"
	                 size=$TBDB_IMAGEID_IMAGENAMELEN
                         maxlength=$TBDB_IMAGEID_IMAGENAMELEN>
              </td>
          </tr>\n";

    #
    # Description
    #
    echo "<tr>
              <td>*Description:<br>
                  (a short pithy sentence)</td>
              <td class=left>
                  <input type=text
                         name=\"formfields[description]\"
                         value=\"" . $formfields[description] . "\"
	                 size=50>
              </td>
          </tr>\n";

    #
    # Load Partition
    #
    echo "<tr>
              <td>*Starting DOS Partition:<br>
                  (1-4, 0 means entire disk)</td>
              <td><select name=\"formfields[loadpart]\">
                          <option value=X>Please Select </option>\n";

    for ($i = 0; $i <= 4; $i++) {
	$selected = "";

	if (strcmp($formfields[loadpart], "$i") == 0)
	    $selected = "selected";
	
	echo "        <option $selected value=$i>$i </option>\n";
    }
    echo "       </select>";
    echo "    </td>
          </tr>\n";

    #
    # Load length
    #
    echo "<tr>
              <td>*Number of DOS Partitions[<b>1</b>]:<br>
                  (1, 2, 3, or 4)</td>
              <td><select name=\"formfields[loadlength]\">
                          <option value=X>Please Select </option>\n";

    for ($i = 0; $i <= 4; $i++) {
	$selected = "";

	if (strcmp($formfields[loadlength], "$i") == 0)
	    $selected = "selected";
	
	echo "        <option $selected value=$i>$i </option>\n";
    }
    echo "       </select>";
    echo "    </td>
          </tr>\n";

    WRITEOSIDMENU("Partition 1 OS[<b>2</b>]",
		  "part1_osid", $osid_result, $formfields[part1_osid]);
    WRITEOSIDMENU("Partition 2 OS",
		  "part2_osid", $osid_result, $formfields[part2_osid]);
    WRITEOSIDMENU("Partition 3 OS",
		  "part3_osid", $osid_result, $formfields[part3_osid]);
    WRITEOSIDMENU("Partition 4 OS",
		  "part4_osid", $osid_result, $formfields[part4_osid]);
    WRITEOSIDMENU("Boot OS[<b>3</b>]",
		  "default_osid", $osid_result, $formfields[default_osid]);

    #
    # Path to image.
    #
    echo "<tr>
              <td>Filename (full path) of Image[<b>4</b>]:<br>
                  (must reside in /proj)</td>
              <td class=left>
                  <input type=text
                         name=\"formfields[path]\"
                         value=\"" . $formfields[path] . "\"
	                 size=50>
              </td>
          </tr>\n";

    #
    # Node Types.
    #
    echo "<tr>
              <td>Node Types[<b>5</b>]:</td>
              <td>\n";

    mysql_data_seek($types_result, 0);
    while ($row = mysql_fetch_array($types_result)) {
        $type    = $row[type];
        $checked = "";

        if (strcmp($formfields["mtype_$type"], "Yep") == 0)
	    $checked = "checked";
    
        echo "<input $checked type=checkbox
                     value=Yep name=\"formfields[mtype_$type]\">
                     $type &nbsp
              </input>\n";
    }
    echo "    </td>
          </tr>\n";

    #
    # Node to Create image from.
    #
    echo "<tr>
              <td>Node to Create Image from[<b>6</b>]:</td>
              <td class=left>
                  <input type=text
                         name=\"formfields[node]\"
                         value=\"" . $formfields[node] . "\"
	                 size=$TBDB_NODEIDLEN maxlength=$TBDB_NODEIDLEN>
              </td>
          </tr>\n";

    if ($isadmin) {
        #
        # Shared?
        #
	echo "<tr>
  	          <td>Shared?:<br>
                      (available to all projects)</td>
                  <td class=left>
                      <input type=checkbox
                             name=\"formfields[shared]\"
                             value=Yep";

	if (isset($formfields[shared]) &&
	    strcmp($formfields[shared], "Yep") == 0)
	    echo "           checked";
	
	echo "                       > Yes
                  </td>
              </tr>\n";

        #
        # Create mapping for this image.
        #
	echo "<tr>
  	          <td>Create Mapping?:<br>
                      (insert osid to imageid mappings)</td>
                  <td class=left>
                      <input type=checkbox
                             name=\"formfields[makedefault]\"
                             value=Yep";

	if (isset($formfields[makedefault]) &&
	    strcmp($formfields[makedefault], "Yep") == 0)
	    echo "           checked";
	
	echo "                       > Yes
                  </td>
              </tr>\n";
    }

    echo "<tr>
              <td align=center colspan=2>
                  <b><input type=submit name=submit value=Submit></b>
              </td>
          </tr>\n";

    echo "</form>
          </table>\n";

    echo "<h4><blockquote><blockquote><blockquote>
          <ol type=1 start=1>
             <li>Only single slices or partial disks are allowed.
  	         If you specify a non-zero starting load partition, the load
	         load length must be one. If you specify zero
	         for the starting load partition, then you can include any or
	         all of the slices (1-4). Note that '0' means to start at the
	         boot sector, while '1' means to start at the beginning of the
	         first partition (typically starting at sector 63).
             <li>If you are using a custom OS, you must
                  <a href='newosid_form.php3'>create the OS Descriptor
                  first!</a>
             <li>The OS (partition) that is active when the node boots up.
             <li>The image file must reside in the project directory.
             <li>Specify the node types that this image will be able
                  to work on (ie: can be loaded on and expected to work).
377 378 379 380 381
                  Typically, images will work on all of the \"pc\" types when
                  you are customizing one of the default images. However,
                  if you are installing your own OS from scratch, or you are
                  using DOS partition four, then this might not be true.
                  Feel free to ask us!
382 383 384 385 386
             <li>If you already have a node customized, enter that node
                 name (pcXXX) and the image will be auto created for you.
                 Notification of completion will be sent to you via email. 
          </ol>
          </blockquote></blockquote></blockquote></h4>\n";
387
}
388 389 390 391 392 393 394 395 396 397 398
    
#
# On first load, display a virgin form and exit.
#
if (! $submit) {
    $defaults = array();
    $defaults[loadpart] = "X";
    $defaults[path]     = "/proj/";
    SPITFORM($defaults, 0);
    PAGEFOOTER();
    return;
399
}
400 401 402 403 404 405 406 407 408

#
# Otherwise, must validate and redisplay if errors
#
$errors = array();

if (!isset($formfields[pid]) ||
    strcmp($formfields[pid], "") == 0) {
    $errors["Project"] = "Not Selected";
409
}
410 411
elseif (!TBValidProject($formfields[pid])) {
    $errors["Project"] = "No such project";
412
}
413 414
elseif (!TBProjAccessCheck($uid, $formfields[pid],
			   $formfields[pid], $TB_PROJECT_MAKEIMAGEID)) {
415
    $errors["Project"] = "Not enough permission";
416 417
}

418 419 420
if (!isset($formfields[imagename]) ||
    strcmp($formfields[imagename], "") == 0) {
    $errors["Descriptor Name"] = "Missing Field";
421
}
422 423 424 425 426 427 428 429
else {
    if (! ereg("^[a-zA-Z0-9][-_a-zA-Z0-9\.]+$", $formfields[imagename])) {
	$errors["Descriptor Name"] =
	    "Must be alphanumeric (includes _ and - and .)<br>".
	    "and must begin with an alphanumeric";
    }
    elseif (strlen($formfields[imagename]) > $TBDB_IMAGEID_IMAGENAMELEN) {
	$errors["Descriptor Name"] =
430 431
	    "Too long! ".
	    "Must be less than or equal to $TBDB_IMAGEID_IMAGENAMELEN";
432
    }
433 434
}

435 436 437
if (!isset($formfields[description]) ||
    strcmp($formfields[description], "") == 0) {
    $errors["Description"] = "Missing Field";
438 439
}

440 441 442 443
if (!isset($formfields[loadpart]) ||
    strcmp($formfields[loadpart], "") == 0 ||
    strcmp($formfields[loadpart], "X") == 0) {
    $errors["Starting Partition"] = "Not Selected";
444
}
445 446 447
elseif (! ereg("^[0-9]+$", $formfields[loadpart]) ||
	$formfields[loadpart] < 0 || $formfields[loadpart] > 4) {
    $errors["Starting Partition"] = "Must be 0,1,2,3, or 4!";
448
}
449 450 451 452 453 454 455 456 457 458 459 460 461

if (!isset($formfields[loadlength]) ||
    strcmp($formfields[loadlength], "") == 0 ||
    strcmp($formfields[loadlength], "X") == 0) {
    $errors["#of Partitions"] = "Not Selected";
}
elseif (! ereg("^[0-9]+$", $formfields[loadlength]) ||
	$formfields[loadlength] < 1 || $formfields[loadlength] > 4) {
    $errors["#of Partitions"] = "Must be 1,2,3, or 4!";
}
elseif ($formfields[loadpart] != 0 && $formfields[loadlength] != 1) {
    $errors["#of Partitions"] =
	"Only single slices or<br> partial disks are allowed";
462 463 464 465
}

#
# Check sanity of the OSIDs for each slice. Permission checks not needed.
466 467
# Store the ones we care about and silently forget about the extraneous
# OSIDs by setting the locals to NULL.
468
#
469 470
# XXX This loops creates locals part1_osid, part2_osid, part3_osid, and
#     part4_osid on the fly. Look at $$foo. We use them below.
471
#
472 473
$osid_array = array();

474
for ($i = 1; $i <= 4; $i++) {
475 476
    $foo      = "part${i}_osid";	# Local variable dynamically created.
    $thisosid = $formfields[$foo];
477

478 479
    if (($formfields[loadpart] && $i == $formfields[loadpart]) ||
	(!$formfields[loadpart] && $i <= $formfields[loadlength])) {
480 481

	if (!isset($thisosid) ||
482 483 484
	    strcmp($thisosid, "") == 0 ||
	    strcmp($thisosid, "X") == 0) {
	    $errors["Partition $i OS"] = "Must select an OS";
485
	}
486 487 488 489 490 491 492 493 494 495 496 497 498 499
	elseif (strcmp($thisosid, "none") == 0) {
	    #
	    # Allow admins to specify no OS for a partition.
	    # 
	    if (!$isadmin)	    
		$errors["Partition $i OS"] = "Must select an OS";
	    $$foo = "NULL";	    
	}
	elseif (!TBValidOSID($thisosid)) {
	    $errors["Partition $i OS"] = "No such OS defined";
	}
	else {
	    $$foo = "'$thisosid'";
	    $osid_array[] = $thisosid;
500 501 502 503 504 505 506
	}
    }
    else {
	$$foo = "NULL";
    }
}

507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534
#
# Check the boot OS. Must be one of the OSes selected for a partition.
# 
if (!isset($formfields[default_osid]) ||
    strcmp($formfields[default_osid], "") == 0 ||
    strcmp($formfields[default_osid], "none") == 0) {
    $errors["Boot OS"] = "Not Selected";
}
elseif (!TBValidOSID($formfields[default_osid])) {
    $errors["Boot OS"] = "No such OS defined";
}
else {
    for ($i = 0; $i < count($osid_array); $i++) {
	if (strcmp($osid_array[$i], $formfields[default_osid]) == 0)
	    break;
    }
    if ($i == count($osid_array)) 
	$errors["Boot OS"] = "Invalid; Must be one of the partitions";
}

#
# The path must not contain illegal chars and it must be more than
# the original /proj/$pid we gave the user. We allow admins to specify
# a path outside of /proj though.
# 
if (!isset($formfields[path]) ||
    strcmp($formfields[path], "") == 0) {
    $errors["Path"] = "Missing Field";
535
}
536 537 538 539 540 541 542 543 544 545 546 547 548
elseif (! ereg("^[-_a-zA-Z0-9\/\.+]+$", $formfields[path])) {
    $errors["Path"] = "Contains invalid characters";
}
else {
    $pdef = "/proj/$formfields[pid]/";

    if (strcmp($formfields[path], "$pdef") == 0) {
	$errors["Path"] = "Incomplete Path";
    }
    elseif (!$isadmin &&
	    strcmp(substr($formfields[path], 0, strlen($pdef)), $pdef)) {
	$errors["Path"] = "Invalid Path";
    }
549 550 551
}

#
552 553
# See what node types this image will work on. Must be at least one!
# Store the valid types in a new array for simplicity.
554
#
555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570
$mtypes_array = array();

while ($row = mysql_fetch_array($types_result)) {
    $type = $row[type];
    $foo  = $formfields["mtype_$type"];

    #
    # Look for a post variable with name.
    # 
    if (isset($foo) &&
	strcmp($foo, "Yep") == 0) {
	$mtypes_array[] = $type;
    }
}
if (! count($mtypes_array)) {
    $errors["Node Types"] = "Must select at least one type";
571 572 573
}

#
574
# Check sanity of node name and that user can create an image from it.
575
#
576 577 578 579 580 581 582 583 584 585 586 587
if (isset($formfields[node]) &&
    strcmp($formfields[node], "")) {

    if (! TBValidNodeName($formfields[node])) {
	$errors["Node"] = "Invalid node name";
    }
    
    if (! TBNodeAccessCheck($uid, $formfields[node],
			    $TB_NODEACCESS_LOADIMAGE)) {
	$errors["Node"] = "Not enough permission";
    }
    $node = $formfields[node];
588 589 590
}

#
591 592
# If any errors, respit the form with the current values and the
# error messages displayed. Iterate until happy.
593
# 
594 595 596 597 598
if (count($errors)) {
    SPITFORM($formfields, $errors);
    PAGEFOOTER();
    return;
}
599 600

#
601 602
# Only admins have this option. Always on for mereusers, but default off
# for admins. 
603
#
604 605 606 607 608 609
$makedefault = 0;

if (! $isadmin ||
    (isset($formfields[makedefault]) &&
     strcmp($formfields[makedefault], "Yep") == 0)) {
    $makedefault = 1;
610
}
611 612 613 614 615 616 617 618 619 620

#
# Only admin types can set the shared bit for an image. Ignore silently.
#
$shared = 0;

if ($isadmin &&
    isset($formfields[shared]) &&
    strcmp($formfields[shared], "Yep") == 0) {
    $shared = 1;
621 622
}

623 624 625 626 627 628 629 630 631 632 633
#
# For the rest, sanitize and convert to locals to make life easier.
# 
$description = addslashes($formfields[description]);
$pid         = $formfields[pid];
$imagename   = $formfields[imagename];
$loadpart    = $formfields[loadpart];
$loadlength  = $formfields[loadlength];
$default_osid= $formfields[default_osid];
$path        = $formfields[path];

634 635 636
#
# And insert the record!
#
637 638 639 640 641 642 643 644 645 646 647 648 649

DBQueryFatal("lock tables images write, osidtoimageid write");

#
# Of course, the Image record may not already exist in the DB.
#
if (TBValidImage($pid, $imagename)) {
    DBQueryFatal("unlock tables");

    $errors["Descriptor Name"] = "Already in use in selected project";
    SPITFORM($formfields, $errors);
    PAGEFOOTER();
    return;
650
}
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671

#
# Just concat them to form a unique imageid. 
# 
$imageid = "$pid-$imagename";
if (TBValidImageID($imageid)) {
    DBQueryFatal("unlock tables");
    TBERROR("Could not form a unique imageid for $pid/$imagename!", 1);
}

#
# Mereusers are not allowed to create more than one osid/imageid mapping
# for each machinetype. They cannot actually do that through the EZ form
# since the osid/imageid has to be unique, but it can happen by mixed
# use of the long form and the short form, or with multiple uses of the
# long form. 
#
$typeclause = "type=" . "'$mtypes_array[0]'";

for ($i = 1; $i < count($mtypes_array); $i++) {
    $typeclause = "$typeclause or type=" . "'$mtypes_array[$i]'";
672
}
673 674 675 676 677

$osidclause = "osid=" . "'$osid_array[0]'";
    
for ($i = 1; $i < count($osid_array); $i++) {
    $osidclause = "$osidclause or osid=" . "'$osid_array[$i]'";
678
}
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727
    
$query_result =
    DBQueryFatal("select osidtoimageid.*,images.pid,images.imagename ".
		 " from osidtoimageid ".
		 "left join images on ".
		 " images.imageid=osidtoimageid.imageid ".
		 "where ($osidclause) and ($typeclause)");

if (mysql_num_rows($query_result)) {
    if (!$isadmin || $makedefault) {
	DBQueryFatal("unlock tables");

	echo "<center>
              There are other image descriptors that specify the 
	      same OS descriptors for the same node types.<br>
              There must be a
	      unique mapping of OS descriptor to Image descriptor for
              each node type! Perhaps you need to delete one of the
              images below, or create a new OS descriptor to use in
              this new Image descriptor.
              </center><br>\n";

	echo "<table border=1 cellpadding=2 cellspacing=2 align='center'>\n";

	echo "<tr>
                  <td align=center>OSID</td>
                  <td align=center>Type</td>
                  <td align=center>ImageID</td>
             </tr>\n";

	while ($row = mysql_fetch_array($query_result)) {
	    $imageid   = $row['imageid'];
	    $url       = rawurlencode($imageid);
	    $osid      = $row[osid];
	    $type      = $row[type];
	    $imagename = $row[imagename];
	    
	    echo "<tr>
                      <td>$osid</td>
	              <td>$type</td>
                      <td><A href='showimageid.php3?&imageid=$url'>
                             $imagename</A></td>
	          </tr>\n";
	}
	echo "</table><br><br>\n";
    
	USERERROR("Please check the other Image descriptors and make the ".
		  "necessary changes!", 1);
    }
728 729 730 731
}

$query_result =
    DBQueryFatal("INSERT INTO images ".
732
		 "(imagename, imageid, description, loadpart, loadlength, ".
733
		 " part1_osid, part2_osid, part3_osid, part4_osid, ".
734
		 " default_osid, path, pid, shared, creator, created) ".
735
		 "VALUES ".
736 737
		 "  ('$imagename', '$imageid', '$description', $loadpart, ".
		 "   $loadlength, ".
738
		 "   $part1_osid, $part2_osid, $part3_osid, $part4_osid, ".
739 740
		 "   '$default_osid', '$path', '$pid', $shared, ".
	         "   '$uid', now())");
741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772

if (!$isadmin || $makedefault) {
    for ($i = 0; $i < count($mtypes_array); $i++) {
	for ($j = 0; $j < count($osid_array); $j++) {
	    DBQueryFatal("REPLACE INTO osidtoimageid ".
			 "(osid, type, imageid) ".
			 "VALUES ('$osid_array[$j]', '$mtypes_array[$i]', ".
			 "        '$imageid')");
	}
    }
}

DBQueryFatal("unlock tables");

SUBPAGESTART();
SUBMENUSTART("More Options");
if (! isset($node)) {
    $fooid = rawurlencode($imageid);
    WRITESUBMENUBUTTON("Edit this Image Descriptor",
		       "editimageid_form.php3?imageid=$fooid");
    WRITESUBMENUBUTTON("Delete this Image Descriptor",
		       "deleteimageid.php3?imageid=$fooid");
}
WRITESUBMENUBUTTON("Create a new Image Descriptor",
		   "newimageid_explain.php3");
WRITESUBMENUBUTTON("Create a new OS Descriptor",
		   "newosid_form.php3");
WRITESUBMENUBUTTON("Back to Image Descriptor list",
		   "showimageid_list.php3");
WRITESUBMENUBUTTON("Back to OS Descriptor list",
		   "showosid_list.php3");
SUBMENUEND();
773 774 775 776 777

#
# Dump os_info record.
# 
SHOWIMAGEID($imageid, 0);
778 779 780 781 782 783 784 785 786 787 788 789 790 791
SUBPAGEEND();

if (isset($node)) {
    #
    # Create the image.
    #
    # XXX There is no locking of the descriptor or the node. Not really a
    # problem for the descriptor; the script is done with it by the time
    # it returns. However, if the node is freed up, things are going to go
    # awry. 
    #
    # Grab the unix GID for running script.
    #
    TBGroupUnixInfo($pid, $pid, $unix_gid, $unix_name);
792

793 794 795 796
    echo "<br>
          Creating image using node '$node' ...
          <br><br>\n";
    flush();
797

798
    SUEXEC($uid, $unix_gid, "webcreateimage -p $pid $imagename $node", 1);
799

800 801 802
    echo "This will take 10 minutes or more; you will receive email
          notification when the image is complete. In the meantime,
          <b>PLEASE DO NOT</b> delete the imageid or the experiment
803
          $node is in. In fact, it is best if you do not mess with 
804 805
          the node at all!<br>\n";
}
806 807 808 809 810 811

#
# Standard Testbed Footer
# 
PAGEFOOTER();
?>