newimageid.php3 22.8 KB
Newer Older
1 2 3 4 5 6 7
<?php
include("defs.php3");
include("showstuff.php3");

#
# Standard Testbed Header
#
8
PAGEHEADER("Create a new Image Descriptor (long form)");
9 10

#
11
# Only known and logged in users!
12 13 14 15 16 17
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);
$isadmin = ISADMIN($uid);

#
18
# See what projects the uid can do this in.
19
#
20 21 22 23 24
$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);
25
}
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63

#
# Need a list of node types.
#
$types_result =
    DBQueryFatal("select distinct type from nodes where role='testnode'");

#
# 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";
64
}
65 66 67 68 69 70 71 72 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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 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

#
# 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) 
              {
                  if (theform['formfields[pid]'].value == '') {
                      theform['formfields[path]'].value = '/proj/';
                  }
                  else if (theform['formfields[imagename]'].value == '') {
		      theform['formfields[imagename]'].defaultValue = '';
  	              theform['formfields[path]'].value =
                              '/proj/' +
                              theform['formfields[pid]'].value + '/images/';
                  }
                  else if (theform['formfields[imagename]'].value != '') {
  	              theform['formfields[path]'].value =
                              '/proj/' +
                              theform['formfields[pid]'].value + '/images/' +
                              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).
             <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";
372
}
373 374 375 376 377 378 379 380 381 382 383
    
#
# On first load, display a virgin form and exit.
#
if (! $submit) {
    $defaults = array();
    $defaults[loadpart] = "X";
    $defaults[path]     = "/proj/";
    SPITFORM($defaults, 0);
    PAGEFOOTER();
    return;
384
}
385 386 387 388 389 390 391 392 393

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

if (!isset($formfields[pid]) ||
    strcmp($formfields[pid], "") == 0) {
    $errors["Project"] = "Not Selected";
394
}
395 396
elseif (!TBValidProject($formfields[pid])) {
    $errors["Project"] = "No such project";
397
}
398 399
elseif (!TBProjAccessCheck($uid, $formfields[pid],
			   $formfields[pid], $TB_PROJECT_MAKEIMAGEID)) {
400
    $errors["Project"] = "Not enough permission";
401 402
}

403 404 405
if (!isset($formfields[imagename]) ||
    strcmp($formfields[imagename], "") == 0) {
    $errors["Descriptor Name"] = "Missing Field";
406
}
407 408 409 410 411 412 413 414
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"] =
415 416
	    "Too long! ".
	    "Must be less than or equal to $TBDB_IMAGEID_IMAGENAMELEN";
417
    }
418 419
}

420 421 422
if (!isset($formfields[description]) ||
    strcmp($formfields[description], "") == 0) {
    $errors["Description"] = "Missing Field";
423 424
}

425 426 427 428
if (!isset($formfields[loadpart]) ||
    strcmp($formfields[loadpart], "") == 0 ||
    strcmp($formfields[loadpart], "X") == 0) {
    $errors["Starting Partition"] = "Not Selected";
429
}
430 431 432
elseif (! ereg("^[0-9]+$", $formfields[loadpart]) ||
	$formfields[loadpart] < 0 || $formfields[loadpart] > 4) {
    $errors["Starting Partition"] = "Must be 0,1,2,3, or 4!";
433
}
434 435 436 437 438 439 440 441 442 443 444 445 446

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";
447 448 449 450
}

#
# Check sanity of the OSIDs for each slice. Permission checks not needed.
451 452
# Store the ones we care about and silently forget about the extraneous
# OSIDs by setting the locals to NULL.
453
#
454 455
# XXX This loops creates locals part1_osid, part2_osid, part3_osid, and
#     part4_osid on the fly. Look at $$foo. We use them below.
456
#
457 458
$osid_array = array();

459
for ($i = 1; $i <= 4; $i++) {
460 461
    $foo      = "part${i}_osid";	# Local variable dynamically created.
    $thisosid = $formfields[$foo];
462

463 464
    if (($formfields[loadpart] && $i == $formfields[loadpart]) ||
	(!$formfields[loadpart] && $i <= $formfields[loadlength])) {
465 466

	if (!isset($thisosid) ||
467 468 469
	    strcmp($thisosid, "") == 0 ||
	    strcmp($thisosid, "X") == 0) {
	    $errors["Partition $i OS"] = "Must select an OS";
470
	}
471 472 473 474 475 476 477 478 479 480 481 482 483 484
	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;
485 486 487 488 489 490 491
	}
    }
    else {
	$$foo = "NULL";
    }
}

492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519
#
# 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";
520
}
521 522 523 524 525 526 527 528 529 530 531 532 533
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";
    }
534 535 536
}

#
537 538
# See what node types this image will work on. Must be at least one!
# Store the valid types in a new array for simplicity.
539
#
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555
$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";
556 557 558
}

#
559
# Check sanity of node name and that user can create an image from it.
560
#
561 562 563 564 565 566 567 568 569 570 571 572
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];
573 574 575
}

#
576 577
# If any errors, respit the form with the current values and the
# error messages displayed. Iterate until happy.
578
# 
579 580 581 582 583
if (count($errors)) {
    SPITFORM($formfields, $errors);
    PAGEFOOTER();
    return;
}
584 585

#
586 587
# Only admins have this option. Always on for mereusers, but default off
# for admins. 
588
#
589 590 591 592 593 594
$makedefault = 0;

if (! $isadmin ||
    (isset($formfields[makedefault]) &&
     strcmp($formfields[makedefault], "Yep") == 0)) {
    $makedefault = 1;
595
}
596 597 598 599 600 601 602 603 604 605

#
# 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;
606 607
}

608 609 610 611 612 613 614 615 616 617 618
#
# 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];

619 620 621
#
# And insert the record!
#
622 623 624 625 626 627 628 629 630 631 632 633 634

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;
635
}
636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656

#
# 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]'";
657
}
658 659 660 661 662

$osidclause = "osid=" . "'$osid_array[0]'";
    
for ($i = 1; $i < count($osid_array); $i++) {
    $osidclause = "$osidclause or osid=" . "'$osid_array[$i]'";
663
}
664 665 666 667 668 669 670 671 672 673 674 675 676 677 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
    
$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);
    }
713 714 715 716
}

$query_result =
    DBQueryFatal("INSERT INTO images ".
717
		 "(imagename, imageid, description, loadpart, loadlength, ".
718
		 " part1_osid, part2_osid, part3_osid, part4_osid, ".
719
		 " default_osid, path, pid, shared, creator, created) ".
720
		 "VALUES ".
721 722
		 "  ('$imagename', '$imageid', '$description', $loadpart, ".
		 "   $loadlength, ".
723
		 "   $part1_osid, $part2_osid, $part3_osid, $part4_osid, ".
724 725
		 "   '$default_osid', '$path', '$pid', $shared, ".
	         "   '$uid', now())");
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757

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();
758 759 760 761 762

#
# Dump os_info record.
# 
SHOWIMAGEID($imageid, 0);
763 764 765 766 767 768 769 770 771 772 773 774 775 776
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);
777

778 779 780 781
    echo "<br>
          Creating image using node '$node' ...
          <br><br>\n";
    flush();
782

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

785 786 787 788 789 790
    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
          $node is in. In fact, it is best if you do not mess the with 
          the node at all!<br>\n";
}
791 792 793 794 795 796

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