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.

editnodetype.php3 18.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
<?php
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2004 University of Utah and the Flux Group.
# All rights reserved.
#
include("defs.php3");
include("osiddefs.php3");

#
# No PAGEHEADER since we spit out a Location header later. See below.
#

#
# Only known and logged in users can end experiments.
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);

#
# Admin users only
#
$isadmin = ISADMIN($uid);

if (! $isadmin) {
    USERERROR("You do not have permission to edit node types!", 1);
}

29 30
if (!$new_type && (!isset($node_type) || !strcmp($node_type,""))) {
    USERERROR("No type given!", 1);
31 32 33 34 35 36 37
}

#
# Spit the form out using the array of data.
#
function SPITFORM($node_type, $formfields, $errors)
{
38
    global $osid_result, $imageid_result, $new_type;
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 64 65 66 67 68 69 70 71

    #
    # Standard Testbed Header
    #
    PAGEHEADER("Edit Node Type");

    echo "<font size=+2>Node Type <b>".
         "<a href='shownodetype.php3?node_type=$node_type'>$node_type</a></b>\n".
         "</font>\n";
    echo "<br><br>\n";

    if ($errors) {
	echo "<table class=nogrid
                     align=center border=0 cellpadding=6 cellspacing=0>
              <tr>
                 <th align=center colspan=2>
                   <font size=+1 color=red>
                      &nbsp;Oops, please fix the following errors!&nbsp;
                   </font>
                 </td>
              </tr>\n";

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

72 73 74 75 76 77

    $formargs = "node_type=$node_type";
    if ($new_type) {
	$formargs .= "&new_type=1";
    }

78
    echo "<table align=center border=1>
79 80
          <form action=editnodetype.php3?$formargs method=post " .
	  " name=typeform>\n";
81 82

    echo "<tr>
83 84 85 86 87 88 89 90 91 92
              <td>Type:</td>\n";
    if ($new_type) {
        echo "<td class=left>
                 <input type=text
                        name=\"node_type\"
                        value=\"" . $node_type . "\"
	                size=10>
             </td>\n";
    } else {
         echo "<td class=left>$node_type</td>
93
          </tr>\n";
94
    }
95 96

    echo "<tr>
97 98 99 100 101 102 103 104 105 106
              <td>Class:</td>\n";
    if ($new_type) {
        echo "<td class=left>
                 <input type=text
                        name=\"formfields[class]\"
                        value=\"" . $formfields['class'] . "\"
	                size=10>
             </td>\n";
    } else {
	echo "<td class=left>$formfields[class]</td>
107
          </tr>\n";
108
    }
109 110

    echo "<tr>
111
             <td>Processor (eg. 'Pentium IV'):</td>
112 113 114 115 116 117 118 119 120 121 122 123 124 125
             <td class=left>
                 <input type=text
                        name=\"formfields[proc]\"
                        value=\"" . $formfields[proc] . "\"
	                size=10>
             </td>
          </tr>\n";

    echo "<tr>
             <td>Speed:</td>
             <td class=left>
                 <input type=text
                        name=\"formfields[speed]\"
                        value=\"" . $formfields[speed] . "\"
126
	                size=5> MHz
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
             </td>
          </tr>\n";

    echo "<tr>
             <td>RAM:</td>
             <td class=left>
                 <input type=text
                        name=\"formfields[RAM]\"
                        value=\"" . $formfields[RAM] . "\"
	                size=5> MB
             </td>
          </tr>\n";

    echo "<tr>
             <td>Disk Size:</td>
             <td class=left>
                 <input type=text
                        name=\"formfields[HD]\"
                        value=\"" . $formfields[HD] . "\"
	                size=10> GB
             </td>
          </tr>\n";

    echo "<tr>
             <td>Max Interfaces:</td>
             <td class=left>
                 <input type=text
                        name=\"formfields[max_interfaces]\"
                        value=\"" . $formfields[max_interfaces] . "\"
	                size=3>
             </td>
          </tr>\n";

160 161 162 163 164 165 166 167 168 169 170 171
    #
    # Function to set iface based on the control net
    #
    echo "<SCRIPT LANGUAGE=JavaScript>
              function SetIface(theform) 
              {
                  var control_net = theform['formfields[control_net]'].value;
		  theform['formfields[control_iface]'].value =
			  'eth' + control_net;
	      }
	  </SCRIPT>\n";

172 173

    echo "<tr>
174
             <td>*Control Network:</td>
175 176 177 178
             <td class=left>
                 <input type=text
                        name=\"formfields[control_net]\"
                        value=\"" . $formfields[control_net] . "\"
179 180 181 182 183 184 185 186 187 188 189
	                size=3 onChange='SetIface(typeform);'>
             </td>
          </tr>\n";

    echo "<tr>
             <td>*Control Network Iface (eg. 'eth0'):</td>
             <td class=left>
                 <input type=text
                        name=\"formfields[control_iface]\"
                        value=\"" . $formfields[control_iface] . "\"
	                size=6>
190
             </td>
191 192
          </tr>\n";

193 194 195 196 197 198 199 200 201 202 203 204 205 206

    WRITEOSIDMENU("Default OSID", "formfields[osid]",
		  $osid_result, $formfields[osid]);

    WRITEIMAGEIDMENU("Default ImageID", "formfields[imageid]",
		  $imageid_result, $formfields[imageid]);

    WRITEOSIDMENU("Delay OSID", "formfields[delay_osid]",
		  $osid_result, $formfields[delay_osid]);

    WRITEOSIDMENU("Jailbird OSID", "formfields[jail_osid]",
		  $osid_result, $formfields[jail_osid]);


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
    echo "<tr>
             <td>Power Cycle Time:</td>
             <td class=left>
                 <input type=text
                        name=\"formfields[power_time]\"
                        value=\"" . $formfields[power_time] . "\"
	                size=5> Seconds
             </td>
          </tr>\n";


    echo "<tr>
             <td>Imageable?:</td>
             <td class=left>
                 <input type=text
                        name=\"formfields[imageable]\"
                        value=\"" . $formfields[imageable] . "\"
	                size=2>
             </td>
          </tr>\n";

    echo "<tr>
             <td>Delay Capacity:</td>
             <td class=left>
                 <input type=text
                        name=\"formfields[delay_capacity]\"
                        value=\"" . $formfields[delay_capacity] . "\"
	                size=2>
             </td>
          </tr>\n";

    echo "<tr>
             <td>Disktype (ad,da,ar):</td>
             <td class=left>
                 <input type=text
                        name=\"formfields[disktype]\"
                        value=\"" . $formfields[disktype] . "\"
	                size=6>
             </td>
          </tr>\n";

248 249 250 251 252 253 254 255 256 257
    echo "<tr>
             <td>Boot Disk Unit (0-255):</td>
             <td class=left>
                 <input type=text
                        name=\"formfields[bootdisk_unit]\"
                        value=\"" . $formfields[bootdisk_unit] . "\"
	                size=6>
             </td>
          </tr>\n";

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
    echo "<tr>
             <td>isvirtnode:</td>
             <td class=left>
                 <input type=text
                        name=\"formfields[isvirtnode]\"
                        value=\"" . $formfields[isvirtnode] . "\"
	                size=2>
             </td>
          </tr>\n";

    echo "<tr>
             <td>isremotenode:</td>
             <td class=left>
                 <input type=text
                        name=\"formfields[isremotenode]\"
                        value=\"" . $formfields[isremotenode] . "\"
	                size=2>
             </td>
          </tr>\n";

    echo "<tr>
             <td>issubnode:</td>
             <td class=left>
                 <input type=text
                        name=\"formfields[issubnode]\"
                        value=\"" . $formfields[issubnode] . "\"
	                size=2>
             </td>
          </tr>\n";

    echo "<tr>
             <td>isplabdslice:</td>
             <td class=left>
                 <input type=text
                        name=\"formfields[isplabdslice]\"
                        value=\"" . $formfields[isplabdslice] . "\"
	                size=2>
             </td>
          </tr>\n";

    echo "<tr>
             <td>issimnode:</td>
             <td class=left>
                 <input type=text
                        name=\"formfields[issimnode]\"
                        value=\"" . $formfields[issimnode] . "\"
	                size=2>
             </td>
          </tr>\n";

    echo "<tr>
             <td>Simnode Capacity:</td>
             <td class=left>
                 <input type=text
                        name=\"formfields[simnode_capacity]\"
                        value=\"" . $formfields[simnode_capacity] . "\"
	                size=3>
             </td>
          </tr>\n";

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

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

328 329
if ($new_type) {
    #
330
    # Starting a new node type - let's give some reasonable defaults
331 332 333 334
    #
    $defaults = array("class" => "pc", "power_time" => 60, "imageable" => 1,
	"delay_capacity" => 2, "disktype" => "ad", "isvirtnode" => 0,
	"isremotenode" => 0, "issubnode" => 0, "isplabdslice" => 0,
335
	"issimnode" => 0, "simnode_capacity" => 20, "bootdisk_unit" => 0);
336 337 338 339 340 341 342 343 344 345
} else {
    #
    # We're editing an existing type - suck the current info out of the
    # database.
    #
    if (!preg_match("/^[-\w]+$/", $node_type)) {
	USERERROR("$node_type contains illegal characters!", 1);    
    }
    $query_result =
	DBQueryFatal("select * from node_types where type='$node_type'");
346

347 348 349
    if (($defaults = mysql_fetch_array($query_result)) == 0) {
	USERERROR("$node_type is not a valid node type!", 1);
    }
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 377
#
# We need a list of osids and imageids.
#
$osid_result =
    DBQueryFatal("select osid,osname,pid from os_info ".
		 "where (path='' or path is NULL) ".
		 "order by pid,osid");

$imageid_result =
    DBQueryFatal("select imageid,imagename,pid from images ".
		 "order by pid,imageid");

#
# On first load, display initial values.
#
if (! isset($submit)) {
    SPITFORM($node_type, $defaults, 0);
    PAGEFOOTER();
    return;
}

#
# We do not allow these to be changed.
#
378 379 380
if (!$new_type) {
    $formfields["class"] = $defaults["class"];
}
381 382 383 384 385 386 387 388

#
# Otherwise, must validate and redisplay if errors. Build up a DB insert
# string as we go. 
#
$errors  = array();
$inserts = array();

389 390 391 392 393 394 395 396 397 398
# Class (only for new types)
if ($new_type && isset($formfields['class']) && $formfields['class'] != "") {
    if (! TBvalid_description($formfields['class'])) {
	$errors["Class"] = TBFieldErrorString();
    }
    else {
	$inserts["class"] = addslashes($formfields["class"]);
    }
}

399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448
# Processor
if (isset($formfields[proc]) && $formfields[proc] != "") {
    if (! TBvalid_description($formfields[proc])) {
	$errors["Processor"] = TBFieldErrorString();
    }
    else {
	$inserts["proc"] = addslashes($formfields[proc]);
    }
}

# Speed
if (isset($formfields[speed]) && $formfields[speed] != "") {
    if (! TBvalid_integer($formfields[speed])) {
	$errors["speed"] = TBFieldErrorString();
    }
    else {
	$inserts["speed"] = $formfields[speed];
    }
}

# RAM
if (isset($formfields[RAM]) && $formfields[RAM] != "") {
    if (! TBvalid_integer($formfields[RAM])) {
	$errors["RAM"] = TBFieldErrorString();
    }
    else {
	$inserts["RAM"] = $formfields[RAM];
    }
}

# HD
if (isset($formfields[HD]) && $formfields[HD] != "") {
    if (! TBvalid_float($formfields[HD])) {
	$errors["HD"] = TBFieldErrorString();
    }
    else {
	$inserts["HD"] = $formfields[HD];
    }
}

# max_interfaces
if (isset($formfields[max_interfaces]) && $formfields[max_interfaces] != "") {
    if (! TBvalid_tinyint($formfields[max_interfaces])) {
	$errors["max_interfaces"] = TBFieldErrorString();
    }
    else {
	$inserts["max_interfaces"] = $formfields[max_interfaces];
    }
}

449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
# control_net
if (isset($formfields[control_net]) && $formfields[control_net] != "") {
    if (! TBvalid_tinyint($formfields[control_net])) {
	$errors["control_net"] = TBFieldErrorString();
    }
    else {
	$inserts["control_net"] = $formfields[control_net];
    }
} else {
    $errors["control_net"] = "Field is required";
}

# control_iface
if (isset($formfields[control_iface]) && $formfields[control_iface] != "") {
    if (! TBvalid_userdata($formfields[control_iface])) {
	$errors["control_iface"] = TBFieldErrorString();
    }
    else {
	$inserts["control_iface"] = addslashes($formfields[control_iface]);
    }
} else {
    $errors["control_iface"] = "Field is required";
}

473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
# OSID
if (isset($formfields[osid]) && $formfields[osid] != "") {
    if ($formfields[osid] == "none") {
	$inserts["osid"] = "";
    }
    elseif (! TBvalid_osid($formfields[osid])) {
	$errors["osid"] = TBFieldErrorString();
    }
    elseif (! TBValidOSID($formfields[osid])) {
	$errors["osid"] = "No such OSID";
    }
    else {
	$inserts["osid"] = $formfields[osid];
    }
}

489 490 491 492 493 494 495 496 497 498
# ImageID
if (isset($formfields[imageid]) && $formfields[imageid] != "") {
    if ($formfields[imageid] == "none") {
	$inserts["imageid"] = "";
    }
    elseif (! TBvalid_osid($formfields[imageid])) {
	$errors["imageid"] = TBFieldErrorString();
    }
    elseif (! TBValidImageID($formfields[imageid])) {
	$errors["imageid"] = "No such ImageID";
499 500
    }
    else {
501
	$inserts["imageid"] = $formfields[imageid];
502 503 504
    }
}

505 506 507 508 509 510 511 512 513 514
# delay_osid
if (isset($formfields[delay_osid]) && $formfields[delay_osid] != "") {
    if ($formfields[delay_osid] == "none") {
	$inserts["delay_osid"] = "";
    }
    elseif (! TBvalid_osid($formfields[delay_osid])) {
	$errors["delay_osid"] = TBFieldErrorString();
    }
    elseif (! TBValidOSID($formfields[delay_osid])) {
	$errors["delay_osid"] = "No such osid";
515 516
    }
    else {
517
	$inserts["delay_osid"] = $formfields[delay_osid];
518 519 520
    }
}

521 522 523 524
# jail_osid
if (isset($formfields[jail_osid]) && $formfields[jail_osid] != "") {
    if ($formfields[jail_osid] == "none") {
	$inserts["jail_osid"] = "";
525
    }
526 527
    elseif (! TBvalid_osid($formfields[jail_osid])) {
	$errors["jail_osid"] = TBFieldErrorString();
528
    }
529 530
    elseif (! TBValidOSID($formfields[jail_osid])) {
	$errors["jail_osid"] = "No such osid";
531 532
    }
    else {
533 534 535 536 537 538 539 540 541 542 543
	$inserts["jail_osid"] = $formfields[jail_osid];
    }
}

# power_time
if (isset($formfields[power_time]) && $formfields[power_time] != "") {
    if (! TBvalid_tinyint($formfields[power_time])) {
	$errors["power_time"] = TBFieldErrorString();
    }
    else {
	$inserts["power_time"] = $formfields[power_time];
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578
    }
}

# imageable
if (isset($formfields[imageable]) && $formfields[imageable] != "") {
    if (! TBvalid_boolean($formfields[imageable])) {
	$errors["imageable"] = TBFieldErrorString();
    }
    else {
	$inserts["imageable"] = $formfields[imageable];
    }
}

# delay_capacity
if (isset($formfields[delay_capacity]) && $formfields[delay_capacity] != "") {
    if (! TBvalid_tinyint($formfields[delay_capacity])) {
	$errors["delay_capacity"] = TBFieldErrorString();
    }
    else {
	$inserts["delay_capacity"] = $formfields[delay_capacity];
    }
}

# disktype
if (isset($formfields[disktype]) && $formfields[disktype] != "") {
    if ($formfields[disktype] != "ad" &&
	$formfields[disktype] != "da" &&
	$formfields[disktype] != "ar") {
	$errors["disktype"] = "Must be one of ad, da, ar";
    }
    else {
	$inserts["disktype"] = $formfields[disktype];
    }
}

579 580 581 582 583 584 585 586 587 588
# bootdisk_unit
if (isset($formfields[bootdisk_unit]) && $formfields[bootdisk_unit] != "") {
    if (! TBvalid_tinyint($formfields[bootdisk_unit])) {
	$errors["bootdisk_unit"] = TBFieldErrorString();
    }
    else {
	$inserts["bootdisk_unit"] = $formfields[bootdisk_unit];
    }
}

589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666
# isvirtnode
if (isset($formfields[isvirtnode]) && $formfields[isvirtnode] != "") {
    if (! TBvalid_boolean($formfields[isvirtnode])) {
	$errors["isvirtnode"] = TBFieldErrorString();
    }
    else {
	$inserts["isvirtnode"] = $formfields[isvirtnode];
    }
}

# isremotenode
if (isset($formfields[isremotenode]) && $formfields[isremotenode] != "") {
    if (! TBvalid_boolean($formfields[isremotenode])) {
	$errors["isremotenode"] = TBFieldErrorString();
    }
    else {
	$inserts["isremotenode"] = $formfields[isremotenode];
    }
}

# issubnode
if (isset($formfields[issubnode]) && $formfields[issubnode] != "") {
    if (! TBvalid_boolean($formfields[issubnode])) {
	$errors["issubnode"] = TBFieldErrorString();
    }
    else {
	$inserts["issubnode"] = $formfields[issubnode];
    }
}

# isplabdslice
if (isset($formfields[isplabdslice]) && $formfields[isplabdslice] != "") {
    if (! TBvalid_boolean($formfields[isplabdslice])) {
	$errors["isplabdslice"] = TBFieldErrorString();
    }
    else {
	$inserts["isplabdslice"] = $formfields[isplabdslice];
    }
}

# issimnode
if (isset($formfields[issimnode]) && $formfields[issimnode] != "") {
    if (! TBvalid_boolean($formfields[issimnode])) {
	$errors["issimnode"] = TBFieldErrorString();
    }
    else {
	$inserts["issimnode"] = $formfields[issimnode];
    }
}

# simnode_capacity
if (isset($formfields[simnode_capacity]) &&
    $formfields[simnode_capacity] != "") {
    if (! TBvalid_tinyint($formfields[simnode_capacity])) {
	$errors["simnode_capacity"] = TBFieldErrorString();
    }
    else {
	$inserts["simnode_capacity"] = $formfields[simnode_capacity];
    }
}

#
# Spit any errors now.
#
if (count($errors)) {
    SPITFORM($node_type, $formfields, $errors);
    PAGEFOOTER();
    return;
}

#
# Otherwise, do the inserts.
#
$insert_data = array();
foreach ($inserts as $name => $value) {
    $insert_data[] = "$name='$value'";
}

667 668 669
if ($new_type) {
    DBQueryFatal("insert into node_types set type='$node_type', ".
		 implode(",", $insert_data));
670 671 672 673 674 675 676 677 678
    if ($formfields["class"] == "pc") {
	$vnode_type = $node_type;
	$vnode_type = preg_replace("/pc/","pcvm",$vnode_type);
	if ($vnode_type == $node_type) {
	    $vnode_type = "$vnode_type-vm";
	}
	DBQueryFatal("insert into node_types_auxtypes set " .
	    "auxtype='$vnode_type' type='pcvm'");
    }
679 680 681 682 683
} else {
    DBQueryFatal("update node_types set ".
		 implode(",", $insert_data) . " ".
		 "where type='$node_type'");
}
684 685 686 687 688 689 690 691

#
# Spit out a redirect so that the history does not include a post
# in it. The back button skips over the post and to the form.
#
header("Location: editnodetype.php3?node_type=$node_type");

?>