Computers\n"; print "You do not have access to manage any computers.
\n"; return; } $platform_cnt = count($data["platforms"]); $schedule_cnt = count($data["schedules"]); # get a count of schedules user can manage $tmp = getUserResources(array("scheduleAdmin"), array("manageGroup")); $scheduleAdminCnt = count($tmp['schedule']); # get a list of computers user can manage $tmp = getUserResources(array("computerAdmin"), array("administer")); $computers = $tmp["computer"]; print "

Computers

\n"; print "
\n"; $cdata = array(); if($platform_cnt > 1 || $schedule_cnt > 1) { print "Select the criteria for the computers you want to view:\n"; print "
\n"; # by groups $size = count($computergroups); if($size > 13) $size = 13; print "
\n"; printSelectInput("groups[]", $computergroups, -1, 0, 1, '', "size=$size"); print "
\n"; # by platform/schedule print "
\n"; print "\n"; print " \n"; if($platform_cnt > 1) print " \n"; if($schedule_cnt > 1) print " \n"; print " \n"; print " \n"; if($platform_cnt > 1) { print " \n"; } else { $tmp = array_keys($data["platforms"]); $platform_key = $tmp[0]; $cdata['platforms'] = array($platform_key); } if($schedule_cnt > 1) { print " \n"; } else { $tmp = array_keys($data["schedules"]); $schedule_key = $tmp[0]; $cdata['schedules'] = array($schedule_key); } print " \n"; print "
Platforms:Schedules:
\n"; printSelectInput("platforms[]", $data["platforms"], -1, 0, 1); print " \n"; printSelectInput("schedules[]", $data["schedules"], -1, 0, 1, '', 'size=11'); print "
\n"; print "
\n"; print "

\n"; } else { $size = count($computergroups); if($size > 1) { if($size > 13) $size = 13; print "Select the computer groups you want to view:
\n"; print "(do not select any to view all computers to which you have access)
\n"; printSelectInput("groups[]", $computergroups, -1, 0, 1, '', "size=$size"); print "

\n"; } $tmp = array_keys($data["platforms"]); $platform_key = $tmp[0]; $cdata['platforms'] = array($platform_key); $tmp = array_keys($data["schedules"]); $schedule_key = $tmp[0]; $cdata['schedules'] = array($schedule_key); } if(count($computergroups)) { $cont = addContinuationsEntry('viewComputerGroups', $cdata); print "\n"; print "

\n"; } if(count($computers)) { $cont = addContinuationsEntry('computerUtilities', $cdata); print "\n"; print "

\n"; } if($scheduleAdminCnt) { $cont = addContinuationsEntry('viewComputers', $cdata); print ""; print "\n"; print "\n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print "
"; print "
"; print "
"; print "
"; print ""; print "
"; print "
\n"; } print "\n"; print "
\n"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn viewComputers($showall) /// /// \param $showall - (optional) show all computer columns reguardless of what /// was checked /// /// \brief prints out information about the computers in the db /// //////////////////////////////////////////////////////////////////////////////// function viewComputers($showall=0) { global $user, $mode; $data = processComputerInput(); if(empty($data['groups'])) $bygroups = 0; else { $bygroups = 1; $compidlist = getCompIdList($data['groups']); } if($data["showdeleted"]) { $computers = getComputers(1, 1); $resources = getUserResources(array("computerAdmin"), array("administer"), 0, 1); } else { $computers = getComputers(1); $resources = getUserResources(array("computerAdmin"), array("administer")); } if($data["showcounts"]) getComputerCounts($computers); $userCompIDs = array_keys($resources["computer"]); $states = array("2" => "available", "10" => "maintenance", "20" => "vmhostinuse"); $platforms = getPlatforms(); $tmp = getUserResources(array("scheduleAdmin"), array("manageGroup")); $schedules = $tmp["schedule"]; $allschedules = getSchedules(); $images = getImages(1); $provisioning = getProvisioning(); if($mode == "viewComputers") print "

Computers

\n"; elseif($mode == "submitEditComputer" || $mode == "computerAddedMaintenceNote") { print "

Edit Computer

\n"; print "computer successfully updated

\n"; } elseif($mode == "submitDeleteComputer") { print "

Delete Computer

\n"; $deleted = getContinuationVar("deleted"); if($deleted) { print "computer successfully restored to the normal "; print "state

\n"; } else { print "computer successfully set to the deleted "; print "state

\n"; } } elseif($mode == "submitAddComputer") { print "

Add Computer

\n"; print "computer successfully added

\n"; } if(! count($schedules)) { print "You don't have access to manage any schedules. You must be able "; print "to manage at least one schedule before you can manage computers."; print "
\n"; return; } print "
\n"; print "\n"; $cdata = getComputerSelection($data); $cdata['states'] = $states; $cont = addContinuationsEntry('addComputer', $cdata); print "\n"; print "
\n"; print "
\n"; print "\n"; $cdata = getComputerSelection($data); $cdata['states'] = $states; $cont = addContinuationsEntry('bulkAddComputer', $cdata); print "\n"; print "


\n"; print "\n"; print " \n"; print " \n"; print " \n"; if($data["showhostname"] || $showall) print " \n"; if($data["showipaddress"] || $showall) print " \n"; if($data["showstate"] || $showall) print " \n"; if($data["showowner"] || $showall) print " \n"; if($data["showplatform"] || $showall) print " \n"; if($data["showschedule"] || $showall) print " \n"; if($data["showcurrentimage"] || $showall) print " \n"; if($data["shownextimage"] || $showall) print " \n"; if($data["showram"] || $showall) print " \n"; if($data["showprocnumber"] || $showall) print " \n"; if($data["showprocspeed"] || $showall) print " \n"; if($data["shownetwork"] || $showall) print " \n"; if($data["showcomputerid"] || $showall) print " \n"; if($data["showtype"] || $showall) print " \n"; if($data["showprovisioning"] || $showall) print " \n"; if($data["showdeleted"]) print " \n"; if($data["shownotes"] || $showall) print " \n"; if($data["showcounts"] || $showall) print " \n"; if($data["showlocation"] || $showall) print " \n"; print " \n"; $count = 0; foreach(array_keys($computers) as $id) { if($bygroups) { if(! array_key_exists($id, $compidlist)) continue; } elseif(! in_array($computers[$id]["platformid"], $data["platforms"]) || ! in_array($computers[$id]["scheduleid"], $data["schedules"])) continue; if(! in_array($id, $userCompIDs)) { continue; } print " \n"; print " \n"; print " \n"; if($data["showhostname"]) print " \n"; if($data["showipaddress"]) print " \n"; if($data["showstate"]) print " \n"; if($data["showowner"]) print " \n"; if($data["showplatform"]) { print " \n"; } if($data["showschedule"]) { print " \n"; } if($data["showcurrentimage"]) { print " \n"; } if($data["shownextimage"]) { if($computers[$id]['nextimgid']) $next = $images[$computers[$id]["nextimgid"]]["prettyname"]; else $next = "(selected by system)"; print " \n"; } if($data["showram"]) print " \n"; if($data["showprocnumber"]) print " \n"; if($data["showprocspeed"]) print " \n"; if($data["shownetwork"]) print " \n"; if($data["showcomputerid"]) print " \n"; if($data["showtype"]) print " \n"; if($data["showprovisioning"]) print " \n"; if($data["showdeleted"]) { if($computers[$id]["deleted"]) print " \n"; else print " \n"; } if($data["shownotes"]) if(empty($computers[$id]["notes"])) print " \n"; else { print " \n"; } if($data["showcounts"]) print " \n"; if($data["showlocation"]) print " \n"; print " \n"; $count++; } print "
HostnameIP AddressStateOwnerPlatformScheduleCurrent ImageNext ImageRAM(MB)No. CoresProcessor Speed(MHz)Network Speed(Mbps)Computer IDTypeProvisioning EngineDeletedNotesNo. of ReservationsLocation
\n"; print "
\n"; $cdata = $data; $cdata['compid'] = $id; $cont = addContinuationsEntry('confirmDeleteComputer', $cdata); print " \n"; if($data["showdeleted"] && $computers[$id]["deleted"]) print " \n"; else print " \n"; print "
\n"; print "
\n"; print "
\n"; $cdata = $data; $cdata['compid'] = $id; $cont = addContinuationsEntry('editComputer', $cdata); print " \n"; if($computers[$id]["deleted"] == 0) print " \n"; print "
\n"; print "
" . $computers[$id]["hostname"] . "" . $computers[$id]["IPaddress"] . "" . $computers[$id]["state"] . "" . $computers[$id]["owner"] . "" . $platforms[$computers[$id]["platformid"]]; print "" . $allschedules[$computers[$id]["scheduleid"]]["name"]; print "" . $images[$computers[$id]["currentimgid"]]["prettyname"]; print "$next" . $computers[$id]["ram"] . "" . $computers[$id]["procnumber"] . "" . $computers[$id]["procspeed"] . "" . $computers[$id]["network"] . "$id" . $computers[$id]["type"] . "" . $computers[$id]["provisioning"] . "yesno " . str_replace('@', '
', $computers[$id]["notes"]); print "
{$computers[$id]["counts"]}{$computers[$id]["location"]}
\n"; print "
\n"; $cdata = processComputerInput2(); if($data["showdeleted"]) { $cdata['showdeleted'] = 0; print "\n"; } else { $cdata['showdeleted'] = 1; print "\n"; } $cont = addContinuationsEntry('viewComputers', $cdata); print "\n"; print "
\n"; print "
$count computers found
\n"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn addComputerPrompt() /// /// \brief prints a page to add computers when there are none in the db /// //////////////////////////////////////////////////////////////////////////////// function addComputerPrompt() { print "

Add Computers

\n"; print "There are currently no computers in the VCL database. Would you like "; print "to add a single computer or add multiple computers in bulk? To add "; print "them in bulk, they'll need to have contiguous IP addresses and have "; print "hostnames that only differ by a number in the hostname with those "; print "numbers being contiguous.

\n"; print "
\n"; $cdata = array('nocomps' => 1); $cont = addContinuationsEntry('addComputer', $cdata); print "\n"; print "
\n"; $cont = addContinuationsEntry('bulkAddComputer'); print "\n"; print "

\n"; print "\n"; print "
\n"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn editOrAddComputer($state) /// /// \param $state - 0 for edit, 1 for add /// /// \brief prints a page to edit a given comptuer /// //////////////////////////////////////////////////////////////////////////////// function editOrAddComputer($state) { global $submitErr, $submitErrMsg; $data2 = processComputerInput2(); $computers = getComputers(); $nocomps = getContinuationVar('nocomps', 0); if($submitErr) { $data = processComputerInput(); } elseif($nocomps || $state == 1) { $data = array(); $data["ipaddress"] = ''; $data["pripaddress"] = ''; $data["eth0macaddress"] = ''; $data["eth1macaddress"] = ''; $data["stateid"] = ''; $data["owner"] = ''; $data["platformid"] = ''; $data["scheduleid"] = ''; $data["currentimgid"] = ''; $data["ram"] = ''; $data["numprocs"] = '1'; $data["procspeed"] = ''; $data["network"] = '1000'; $data["hostname"] = ''; $data["type"] = 'blade'; $data["notes"] = ''; $data["computergroup"] = array(); $data["provisioningid"] = ''; $data["location"] = ''; $data["vmprofileid"] = ''; } else { $data["compid"] = getContinuationVar("compid"); $id = $data["compid"]; $data["ipaddress"] = $computers[$id]["IPaddress"]; $data["pripaddress"] = $computers[$id]["privateIPaddress"]; $data["eth0macaddress"] = $computers[$id]["eth0macaddress"]; $data["eth1macaddress"] = $computers[$id]["eth1macaddress"]; $data["stateid"] = $computers[$id]["stateid"]; $data["owner"] = $computers[$id]["owner"]; $data["platformid"] = $computers[$id]["platformid"]; $data["scheduleid"] = $computers[$id]["scheduleid"]; $data["currentimgid"] = $computers[$id]["currentimgid"]; $data["ram"] = $computers[$id]["ram"]; $data["numprocs"] = $computers[$id]["procnumber"]; $data["procspeed"] = $computers[$id]["procspeed"]; $data["network"] = $computers[$id]["network"]; $data["hostname"] = $computers[$id]["hostname"]; $data["type"] = $computers[$id]["type"]; $data["notes"] = $computers[$id]["notes"]; $data["provisioningid"] = $computers[$id]["provisioningid"]; $data["location"] = $computers[$id]["location"]; $data["vmprofileid"] = $computers[$id]['vmprofileid']; } $tmpstates = getStates(); if($data["stateid"] && array_key_exists($data['stateid'], $tmpstates)) { $states = array($data["stateid"] => $tmpstates[$data["stateid"]], 2 => "available", 10 => "maintenance", 20 => "vmhostinuse"); } else $states = array(2 => "available", 10 => "maintenance", 20 => "vmhostinuse"); # check for reservation to move computer to vmhostinuse $tovmhostinuse = 0; if($state == 0 && $computers[$data['compid']]['stateid'] != 20) { $query = "SELECT UNIX_TIMESTAMP(rq.start) AS start " . "FROM request rq, " . "reservation rs, " . "state ls, " . "state cs " . "WHERE rs.requestid = rq.id AND " . "rs.computerid = {$data['compid']} AND " . "rq.laststateid = ls.id AND " . "rq.stateid = cs.id AND " . "ls.name = 'tovmhostinuse' AND " . "cs.name NOT IN ('failed', 'maintenance', 'complete', 'deleted') AND " . "rq.end > NOW() " . "ORDER BY rq.start " . "LIMIT 1"; $qh = doQuery($query); if($row = mysql_fetch_assoc($qh)) $tovmhostinuse = $row['start']; } print "\n"; if($state) { print "

Add Computer

\n"; } else { print "

Edit Computer

\n"; if($tovmhostinuse) { print "
\n"; $nicestart = date('g:i A \o\n l, F jS, Y', $tovmhostinuse); if($tovmhostinuse > time()) print "NOTICE: This computer is scheduled to start being reloaded as a vmhost at $nicestart. You may cancel this scheduled reload by clicking the button below.

\n"; else print "NOTICE: This computer is currently being reloaded as a vmhost. You may cancel this process by clicking on the button below. After canceling the reload, it may take several minutes for the cancellation process to complete.

\n"; print "\n"; print "
\n"; } } if($submitErr & VMHOSTINUSEERR) { print "
\n"; print $submitErrMsg[VMHOSTINUSEERR]; print "
\n"; } print "
\n"; print "\n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; if($data['stateid'] == 20) print " \n"; else print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; if(! $state) { print " \n"; print " \n"; print " \n"; print " \n"; } print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; if(! $state) { print " \n"; print " \n"; print " \n"; print " \n"; } print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print "
Hostname*:"; printSubmitErr(HOSTNAMEERR); print "
Type:\n"; $tmpArr = array("blade" => "blade", "lab" => "lab", "virtualmachine" => "virtualmachine"); printSelectInput('type', $tmpArr, $data['type'], 0, 0, 'type', 'dojoType="dijit.form.Select" onChange="editComputerSelectType(0);"'); print "
Public IP Address*:"; printSubmitErr(IPADDRERR); print "
Private IP Address:"; printSubmitErr(IPADDRERR2); print "
Public MAC Address:"; printSubmitErr(MACADDRERR); print "
Private MAC Address:"; printSubmitErr(MACADDRERR2); print "
Provisioning Engine:\n"; printSelectInput("provisioningid", $showprovisioning, $data["provisioningid"], 0, 0, 'provisioningid', 'dojoType="dijit.form.Select" onChange="editComputerSelectType(1);"'); print "
State:\n"; if(($state == 1 && ($data['provisioningid'] == '' || $provisioning[$data['provisioningid']]['name'] == 'none')) || ($state == 0 && ($computers[$data['compid']]['provisioning'] == 'None' || ($data['type'] == 'virtualmachine' && $data['stateid'] != 2)) || ($data['type'] == 'virtualmachine' && $computers[$data['compid']]['vmhostid'] == ''))) unset_by_val('available', $states); if($state == 0 && $computers[$data['compid']]['type'] == 'virtualmachine') unset_by_val('vmhostinuse', $states); printSelectInput('stateid', $states, $data['stateid'], 0, 0, 'stateid', 'dojoType="dijit.form.Select" onChange="editComputerSelectState();"'); print " "; printSubmitErr(VMAVAILERR); print "
VM Host Profile:\n"; printSelectInput("vmprofileid", $profiles, $data["vmprofileid"], 0, 0, 'vmprofileid', 'dojoType="dijit.form.Select"'); print "
Owner*:"; printSubmitErr(OWNERERR); print "
Platform:\n"; printSelectInput("platformid", $platforms, $data["platformid"], 0, 0, 'platformid', 'dojoType="dijit.form.Select"'); print "
Schedule:\n"; if($data["scheduleid"] != "") { if(! array_key_exists($data["scheduleid"], $schedules)) { $schedules[$data["scheduleid"]] = $allschedules[$data["scheduleid"]]["name"]; uasort($schedules, "sortKeepIndex"); } printSelectInput("scheduleid", $schedules, $data["scheduleid"], 0, 0, 'scheduleid', 'dojoType="dijit.form.Select"'); } else printSelectInput("scheduleid", $schedules, '', 0, 0, 'scheduleid', 'dojoType="dijit.form.Select"'); print "
Current Image:" . $images[$data["currentimgid"]]["prettyname"] . "
RAM (MB)*:"; printSubmitErr(RAMERR); print "
No. Cores:\n"; print " \n"; print "
Processor Speed (MHz)*:"; printSubmitErr(PROCSPEEDERR); print "
Network Speed (Mbps):\n"; $tmpArr = array("10" => "10", "100" => "100", "1000" => "1000", "10000" => "10000"); printSelectInput("network", $tmpArr, $data["network"], 0, 0, 'network', 'dojoType="dijit.form.Select"'); print "
Compter ID:" . $data["compid"] . "
Physical Location:
\n"; if($state) { $tmp = getUserResources(array("computerAdmin"), array("manageGroup"), 1); $computergroups = $tmp["computer"]; uasort($computergroups, "sortKeepIndex"); print "

Computer Groups

"; print "\n"; print " \n"; foreach($computergroups as $group) { print " \n"; } print " \n"; print " \n"; foreach(array_keys($computergroups) as $groupid) { $name = "computergroup[$groupid]"; if(array_key_exists($groupid, $data["computergroup"])) $checked = "checked"; else $checked = ""; print " \n"; } print " \n"; print "
$group
\n"; print " \n"; print "
\n"; } print "\n"; print " \n"; print " \n"; print " \n"; print " \n"; print "
\n"; $data2['provisioning'] = $provisioning; if($state) { $cont = addContinuationsEntry('confirmAddComputer', $data2, SECINDAY, 0, 1, 1); print " \n"; } else { $data2['currentimgid'] = $data['currentimgid']; $data2['compid'] = $data['compid']; if($submitErr & VMHOSTINUSEERR) $data2['allowvmhostinuse'] = 1; else $data2['allowvmhostinuse'] = 0; $cont = addContinuationsEntry('confirmEditComputer', $data2, SECINDAY, 0); print " \n"; } print " \n"; print " \n"; print " \n"; print "
\n"; $cont = addContinuationsEntry('viewComputers', $data2); print " \n"; print " \n"; print "
\n"; print "
\n"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn confirmEditOrAddComputer($state) /// /// \param $state - 0 for edit, 1 for add /// /// \brief checks for valid input and allows user to confirm the edit/add /// //////////////////////////////////////////////////////////////////////////////// function confirmEditOrAddComputer($state) { global $submitErr, $submitErrMsg; $data = processComputerInput(); if($submitErr) { editOrAddComputer($state); return; } $warnend = ''; if($state == 0) { $data['reloadstart'] = 0; $compdata = getComputers(0, 0, $data['compid']); if($data['stateid'] == 20 && $compdata[$data['compid']]['stateid'] != 20) { $compid = $data['compid']; $end = 0; moveReservationsOffComputer($compid); # get end time of last reservation $end = getCompFinalReservationTime($compid); $data['reloadstart'] = $end; $allowvmhostinuse = getContinuationVar('allowvmhostinuse', 0); if($end && ! $allowvmhostinuse) { $submitErr |= VMHOSTINUSEERR; $end = date('n/j/y g:i a', $end); if($data['deploymode'] == 1) $submitErrMsg[VMHOSTINUSEERR] = "This node currently has reservations that will not end until $end. Clicking Confirm Changes again will cause this node to be reloaded as a vmhost at $end."; else $submitErrMsg[VMHOSTINUSEERR] = "This computer is currently allocated until $end and cannot be converted to a VM host until then. Clicking Confirm Changes again will cause the computer to be placed into the maintenance state at $end. VCL will then prevent it from being used beyond $end. Confirming changes will do that now, or you can simply try this process again after $end. If you schedule it to be placed into maintenance, you will still need to edit this computer again to change it to the vmhostinuse state sometime after $end.
\n"; editOrAddComputer(0); return; } if($end) $warnend = date('n/j/y g:i a', $end); } } if($state) { $data["currentimgid"] = ""; $data["compid"] = ""; $nextmode = "submitAddComputer"; $title = "Add Computer"; $question = "Submit the following new computer?"; if($data['stateid'] != '20') $data['vmprofileid'] = ''; } else { if($data['type'] == 'virtualmachine') $data['location'] = ''; $nextmode = "submitEditComputer"; $title = "Edit Computer"; $question = "Submit the following changes?"; } print "

$title

\n"; print "

$question

\n"; if(! $state && ! empty($warnend)) { print "
\n"; if($data['deploymode'] == 1) print "Clicking Submit will cause a reservation to be created to deploy this node as a VM Host at $warnend. It will remain in the current state until that time.\n"; else print "Clicking Submit will cause a reservation to be created to place this node in the maintenance state at $warnend. It will remain in the current state until that time.\n"; print "
\n"; } printComputerInfo($data["pripaddress"], $data["ipaddress"], $data["eth0macaddress"], $data["eth1macaddress"], $data["stateid"], $data["owner"], $data["platformid"], $data["scheduleid"], $data["currentimgid"], $data["ram"], $data["numprocs"], $data["procspeed"], $data["network"], $data["hostname"], $data["compid"], $data["type"], $data["provisioningid"], $data["location"], $data["vmprofileid"], $data["deploymode"]); if($state) { $tmp = getUserResources(array("computerAdmin"), array("manageGroup"), 1); $computergroups = $tmp["computer"]; uasort($computergroups, "sortKeepIndex"); print "

Computer Groups

"; print "\n"; print " \n"; foreach($computergroups as $group) { print " \n"; } print " \n"; print " \n"; foreach(array_keys($computergroups) as $groupid) { if(array_key_exists($groupid, $data["computergroup"])) $checked = "src=images/x.png alt=selected"; else $checked = "src=images/blank.gif alt=unselected"; print " \n"; } print " \n"; print "
$group
\n"; print " \n"; print "
\n"; } print "\n"; print " \n"; print " \n"; print " \n"; print " \n"; print "
\n"; print "
\n"; if(! $state && $data['stateid'] == 10) $cont = addContinuationsEntry('computerAddMaintenanceNote', $data, SECINDAY, 0); else { $data['provisioning'] = getContinuationVar('provisioning'); $cont = addContinuationsEntry($nextmode, $data, SECINDAY, 0, 0); } print " \n"; print " \n"; print "
\n"; print "
\n"; print "
\n"; $cont = addContinuationsEntry('viewComputers', $data); print " \n"; print " \n"; print "
\n"; print "
\n"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn submitEditComputer() /// /// \brief updates submitted information for specified computer /// //////////////////////////////////////////////////////////////////////////////// function submitEditComputer() { global $mode, $user; $data = processComputerInput(); $compdata = getComputers(0, 0, $data["compid"]); $compid = $data['compid']; $profileid = $data['vmprofileid']; # maintenance to maintenance if($compdata[$compid]["stateid"] == 10 && $data["stateid"] == 10) { // possibly update notes with new text $testdata = explode('@', $compdata[$compid]["notes"]); if(count($testdata) != 2) $testdata[1] = ""; if($testdata[1] == $data["notes"]) // don't update the notes field $data["notes"] = $compdata[$compid]["notes"]; else { if(get_magic_quotes_gpc()) $data['notes'] = stripslashes($data['notes']); $data['notes'] = mysql_real_escape_string($data['notes']); // update user, timestamp, and text $data["notes"] = $user["unityid"] . " " . unixToDatetime(time()) . "@" . $data["notes"]; } } # available or failed to maintenance elseif(($compdata[$compid]["stateid"] == 2 || $compdata[$compid]["stateid"] == 5) && $data["stateid"] == 10) { // set notes to new data if(get_magic_quotes_gpc()) $data['notes'] = stripslashes($data['notes']); $data['notes'] = mysql_real_escape_string($data['notes']); $data["notes"] = $user["unityid"] . " " . unixToDatetime(time()) . "@" . $data["notes"]; } # maintenance or failed to available elseif(($compdata[$compid]["stateid"] == 10 || $compdata[$compid]["stateid"] == 5) && $data["stateid"] == 2) { $data["notes"] = ""; } # anything to vmhostinuse elseif($compdata[$compid]["stateid"] != 20 && $data["stateid"] == 20) { $data["notes"] = ""; moveReservationsOffComputer($compid); $knownreloadstart = getContinuationVar('reloadstart'); $delayed = 0; # get end time of last reservation $reloadstart = getCompFinalReservationTime($compid); if($data['deploymode'] == 1) { # VCL deployed if($reloadstart > 0 && $knownreloadstart == 0) { print "

Edit Computer

\n"; $end = date('n/j/y g:i a', $reloadstart); unset($data['stateid']); $cnt = updateComputer($data); if($cnt) { print "Changes to this computer's information were successfully "; print "saved. However, this "; } else print "This "; print "computer is currently allocated until $end. So, it cannot "; print "be converted to a VM host server until then. Do you "; print "want to schedule VCL to convert it to a VM host server at "; print "$end, or wait and initiate this process again later?

\n"; print "\n"; print " \n"; print " \n"; print " \n"; print " \n"; print "
\n"; print "
\n"; $cdata = $data; $cdata['maintenanceonly'] = 0; $cdata['scheduletime'] = $reloadstart; $cont = addContinuationsEntry('submitComputerVMHostLater', $cdata, SECINDAY, 1, 0); print " \n"; print " \n"; print "
\n"; print "
\n"; print "
\n"; $cont = addContinuationsEntry('viewComputers', $data); print " \n"; print " \n"; print "
\n"; print "
\n"; return; } else { # change to vmhostinuse state # create a reload reservation to load machine with image # corresponding to selected vm profile $vclreloadid = getUserlistID('vclreload@Local'); $profiles = getVMProfiles(); $imagerevisionid = getProductionRevisionid($profiles[$profileid]['imageid']); if($reloadstart) $start = $reloadstart; else $start = getReloadStartTime(); $end = $start + SECINYEAR; # don't want anyone making a future reservation for this machine $start = unixToDatetime($start); $end = unixToDatetime($end); unset($data['stateid']); if(! (simpleAddRequest($compid, $profiles[$profileid]['imageid'], $imagerevisionid, $start, $end, 21, $vclreloadid))) { $cnt = updateComputer($data); print "

Edit Computer

\n"; print "An error was encountered while trying to convert this "; print "computer to a VM host server.

\n"; if($cnt) { print "Other changes you made to this computer's information "; print "were saved successfully.
\n"; } return; } # check for existing vmhost entry $query = "SELECT id, " . "vmprofileid " . "FROM vmhost " . "WHERE computerid = $compid"; $qh = doQuery($query, 101); if($row = mysql_fetch_assoc($qh)) { if($row['vmprofileid'] != $profileid) { # update vmprofile $query = "UPDATE vmhost " . "SET vmprofileid = $profileid " . "WHERE id = {$row['id']}"; doQuery($query, 101); } } else { # create vmhost entry $query = "INSERT INTO vmhost " . "(computerid, " . "vmlimit, " . "vmprofileid) " . "VALUES ($compid, " . "2, " . "$profileid)"; doQuery($query, 101); } if($knownreloadstart > 0 && $reloadstart > $knownreloadstart) { print "

Edit Computer

\n"; $end = date('n/j/y g:i a', $reloadstart); unset($data['stateid']); $cnt = updateComputer($data); if($cnt) { print "Changes to this computer's information were successfully "; print "saved.

\n"; } print "Reload reservation successfully created.

\n"; print "NOTE: The end of the last reservation for the computer changed "; print "from the previous page. The computer will now be "; print "reloaded at $end."; return; } } } else { # manually installed if($reloadstart > 0 && $knownreloadstart == 0) { # notify that need to try after $reloadstart $end = date('n/j/y g:i a', $reloadstart); print "

Edit Computer

\n"; unset($data['stateid']); $cnt = updateComputer($data); if($cnt) { print "Changes to this computer's information were successfully "; print "saved. However, this "; } else print "This "; print "computer is currently allocated until $end and cannot "; print "be converted to a VM host until then. If you schedule the "; print "computer to be placed into the maintenance state at $end, "; print "VCL will prevent it from being used beyond $end. You can "; print "select to do that now, or you can simply try this process "; print "again after $end. If you schedule it to be placed into "; print "maintenance, you will still need to edit this computer again "; print "to change it to the vmhostinuse state sometime after $end.

\n"; print "\n"; print " \n"; print " \n"; print " \n"; print " \n"; print "
\n"; print "
\n"; $cdata = $data; $cdata['maintenanceonly'] = 1; $cdata['scheduletime'] = $reloadstart; $cont = addContinuationsEntry('submitComputerVMHostLater', $cdata, SECINDAY, 1, 0); print " \n"; print " \n"; print "
\n"; print "
\n"; print "
\n"; $cont = addContinuationsEntry('viewComputers', $data); print " \n"; print " \n"; print "
\n"; print "
\n"; return; } elseif($reloadstart > 0) { $vclreloadid = getUserlistID('vclreload@Local'); $end = $reloadstart + SECINYEAR; # don't want anyone making a future reservation for this machine $startdt = unixToDatetime($reloadstart); $enddt = unixToDatetime($end); $imageid = getImageId('noimage'); $imagerevisionid = getProductionRevisionid($imageid); if(! (simpleAddRequest($compid, $imageid, $imagerevisionid, $startdt, $enddt, 18, $vclreloadid))) { unset($data['stateid']); $cnt = updateComputer($data); print "

Edit Computer

\n"; print "An error was encountered while trying to convert this "; print "computer to a VM host server.

\n"; if($cnt) { print "Other changes you made to this computer's information "; print "were saved successfully.
\n"; } return; } print "

Edit Computer

\n"; $end = date('n/j/y g:i a', $reloadstart); unset($data['stateid']); $cnt = updateComputer($data); if($cnt) { print "Changes to this computer's information were successfully "; print "saved.

\n"; } print "Maintenance reservation successfully created.

\n"; if($reloadstart > $knownreloadstart) { print "NOTE: The end of the last reservation for the computer changed "; print "from the previous page. The computer will now be "; print "placed into the maintenance state at $end."; } return; } else { # set to vmhostinuse # check for existing vmhost entry $query = "SELECT id, " . "vmprofileid " . "FROM vmhost " . "WHERE computerid = $compid"; $qh = doQuery($query, 101); if($row = mysql_fetch_assoc($qh)) { if($row['vmprofileid'] != $profileid) { # update vmprofile $query = "UPDATE vmhost " . "SET vmprofileid = $profileid " . "WHERE id = {$row['id']}"; doQuery($query, 101); } } else { # create vmhost entry $query = "INSERT INTO vmhost " . "(computerid, " . "vmlimit, " . "vmprofileid) " . "VALUES ($compid, " . "2, " . "$profileid)"; doQuery($query, 101); } if($reloadstart == 0 && $knownreloadstart > 0) { print "

Edit Computer

\n"; $cnt = updateComputer($data); if($cnt) { print "Changes to this computer's information were successfully "; print "saved.

\n"; } print "NOTE: Reservations for this computer completed since the previous page. The computer has now been placed into the vmhostinuse state.\n"; return; } } } } elseif($compdata[$compid]["stateid"] == 20 && $data["stateid"] == 20 && ($profileid != $compdata[$compid]['vmprofileid'])) { # check for assigned VMs $query = "SELECT COUNT(c.id) AS cnt " . "FROM computer c, " . "vmhost v " . "WHERE v.computerid = $compid AND " . "c.vmhostid = v.id"; $qh = doQuery($query); $row = mysql_fetch_assoc($qh); if($row['cnt'] > 0) { print "

Edit Computer

\n"; unset($data['stateid']); $cnt = updateComputer($data); if($cnt) { print "Changes to this computer's information were successfully "; print "saved. However, there "; } else print "There "; print "are currently VMs assigned to this VM host. You must remove "; print "all VMs from the host before changing it to a different VM Host "; print "Profile.\n"; return; } if($data['deploymode'] == 1) { # reload with new profile $vclreloadid = getUserlistID('vclreload@Local'); $profiles = getVMProfiles(); $imagerevisionid = getProductionRevisionid($profiles[$profileid]['imageid']); $start = getReloadStartTime(); $end = $start + SECINYEAR; # don't want anyone making a future reservation for this machine $start = unixToDatetime($start); $end = unixToDatetime($end); if(! (simpleAddRequest($compid, $profiles[$profileid]['imageid'], $imagerevisionid, $start, $end, 21, $vclreloadid))) { unset($data['stateid']); $cnt = updateComputer($data); print "

Edit Computer

\n"; print "An error was encountered while trying to convert this "; print "computer to the new VM Host Profile.

\n"; if($cnt) { print "Other changes you made to this computer's information "; print "were saved successfully.
\n"; } return; } # set computer to reserved state $query = "UPDATE computer " . "SET stateid = (SELECT id " . "FROM state " . "WHERE name = 'reserved') " . "WHERE id = $compid"; doQuery($query); } # update vmprofile $query = "SELECT id " . "FROM vmhost " . "WHERE computerid = $compid"; $qh = doQuery($query, 101); if($row = mysql_fetch_assoc($qh)) { $query = "UPDATE vmhost " . "SET vmprofileid = $profileid " . "WHERE id = {$row['id']}"; doQuery($query, 101); } } updateComputer($data); viewComputers(); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn computerAddMaintenanceNote($data) /// /// \param $data - array returned from processComputerInput /// /// \brief prints a page asking user to enter a reason for placing a computer /// in maintenance state /// //////////////////////////////////////////////////////////////////////////////// function computerAddMaintenanceNote() { $data = processComputerInput(); unset($data['notes']); $compdata = getComputers(0, 0, $data["compid"]); $notes = explode('@', $compdata[$data["compid"]]["notes"]); if(count($notes) != 2) $notes[1] = ""; print "
\n"; print "

Edit Computer

\n"; print "Why are you placing this computer in the maintenance state?\n"; print "
\n"; print "\n"; print "\n"; print " \n"; print " \n"; $cont = addContinuationsEntry('submitEditComputer', $data, SECINDAY, 0, 0); print " \n"; print " \n"; print " \n"; print " \n"; $cont = addContinuationsEntry('viewComputers', $data); print " \n"; print " \n"; print " \n"; print "
\n"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn AJcanceltovmhostinuse() /// /// \brief cancels any reservations to place the computer in the vmhostinuse /// state /// //////////////////////////////////////////////////////////////////////////////// function AJcanceltovmhostinuse() { global $mysql_link_vcl; $compid = getContinuationVar('compid'); $type = 'none'; $query = "DELETE FROM request " . "WHERE start > NOW() AND " . "stateid = 21 AND " . "id IN (SELECT requestid " . "FROM reservation " . "WHERE computerid = $compid)"; doQuery($query); if(mysql_affected_rows($mysql_link_vcl)) $type = 'future'; $query = "UPDATE request rq, " . "reservation rs, " . "state ls " . "SET rq.stateid = 1 " . "WHERE rs.requestid = rq.id AND " . "rs.computerid = $compid AND " . "rq.start <= NOW() AND " . "rq.laststateid = ls.id AND " . "ls.name = 'tovmhostinuse'"; doQuery($query); if(mysql_affected_rows($mysql_link_vcl)) $type = 'current'; $query = "SELECT rq.start " . "FROM request rq, " . "reservation rs, " . "state ls, " . "state cs " . "WHERE rs.requestid = rq.id AND " . "rs.computerid = $compid AND " . "rq.laststateid = ls.id AND " . "rq.stateid = cs.id AND " . "ls.name = 'tovmhostinuse' AND " . "cs.name NOT IN ('failed', 'maintenance', 'complete', 'deleted') AND " . "rq.end > NOW() " . "ORDER BY rq.start"; $qh = doQuery($query); if(mysql_num_rows($qh)) $arr = array('status' => 'failed'); else { if($type == 'now') $msg = "The reservation currently being processed to place this " . "computer in the vmhostinuse state has been flagged for " . "deletion. As soon as the deletion can be processed, the " . "computer will be set to the available state."; else $msg = "The reservation scheduled to place this computer in the " . "vmhostinuse state has been deleted."; $arr = array('status' => 'success', 'msg' => $msg); } sendJSON($arr); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn submitAddComputer() /// /// \brief adds a new computer with the submitted information /// //////////////////////////////////////////////////////////////////////////////// function submitAddComputer() { $data = processComputerInput(); addComputer($data); clearPrivCache(); viewComputers(); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn submitComputerVMHostLater() /// /// \brief schedules a computer to be converted to vmhostinuse state at a future /// time /// //////////////////////////////////////////////////////////////////////////////// function submitComputerVMHostLater() { $data = getContinuationVar(); $delayed = 0; $compid = $data['compid']; $start = $data['scheduletime']; moveReservationsOffComputer($compid); $tmp = getCompFinalReservationTime($compid); if($tmp > $data['scheduletime']) { $delayed = 1; $start = $tmp; } # create a reload reservation to load machine with image # corresponding to selected vm profile $vclreloadid = getUserlistID('vclreload@Local'); $end = $start + SECINYEAR; # don't want anyone making a future reservation for this machine $startdt = unixToDatetime($start); $end = unixToDatetime($end); if($data['maintenanceonly']) { $imageid = getImageId('noimage'); $imagerevisionid = getProductionRevisionid($imageid); if(! (simpleAddRequest($compid, $imageid, $imagerevisionid, $startdt, $end, 18, $vclreloadid))) { print "

Edit Computer

\n"; print "An error was encountered while trying to schedule this "; print "computer for the maintenance state. Please try again later.\n"; return; } } else { $profiles = getVMProfiles(); $imagerevisionid = getProductionRevisionid($profiles[$data['vmprofileid']]['imageid']); if(! (simpleAddRequest($compid, $profiles[$data['vmprofileid']]['imageid'], $imagerevisionid, $startdt, $end, 21, $vclreloadid))) { print "

Edit Computer

\n"; print "An error was encountered while trying to convert this "; print "computer to a VM host server. Please try again later.\n"; return; } # check for existing vmhost entry $query = "SELECT id, " . "vmprofileid " . "FROM vmhost " . "WHERE computerid = $compid"; $qh = doQuery($query, 101); if($row = mysql_fetch_assoc($qh)) { if($row['vmprofileid'] != $data['vmprofileid']) { # update vmprofile $query = "UPDATE vmhost " . "SET vmprofileid = $profileid " . "WHERE id = {$row['id']}"; doQuery($query, 101); } } else { # create vmhost entry $query = "INSERT INTO vmhost " . "(computerid, " . "vmlimit, " . "vmprofileid) " . "VALUES ($compid, " . "2, " . "$profileid)"; doQuery($query, 101); } } print "

Edit Computer

\n"; $schtime = date('n/j/y g:i a', $start); if($delayed) { print "NOTE: The end time for the final reservation for this "; print "computer changed from what was previously reported."; print "

\n"; } if($data['maintenanceonly']) { print "The computer has been scheduled to be placed into the maintenance "; print "state at $schtime."; } else { print "The computer has been scheduled to be converted to a VM host at "; print "$schtime."; } } //////////////////////////////////////////////////////////////////////////////// /// /// \fn confirmDeleteComputer() /// /// \brief prints a confirmation page about deleteing a computer /// //////////////////////////////////////////////////////////////////////////////// function confirmDeleteComputer() { $data = processComputerInput(0); $computers = getComputers(0, 1); $compid = $data["compid"]; if($computers[$compid]["deleted"]) { $deleted = 1; $title = "Undelete Computer"; $question = "Undelete the following computer?"; $button = "Undelete"; } else { $deleted = 0; $title = "Delete Computer"; $question = "Delete the following computer?"; $button = "Delete"; } print "
\n"; print "

$title

\n"; print "

$question

\n"; printComputerInfo($computers[$compid]["privateIPaddress"], $computers[$compid]["IPaddress"], $computers[$compid]["eth0macaddress"], $computers[$compid]["eth1macaddress"], $computers[$compid]["stateid"], $computers[$compid]["owner"], $computers[$compid]["platformid"], $computers[$compid]["scheduleid"], $computers[$compid]["currentimgid"], $computers[$compid]["ram"], $computers[$compid]["procnumber"], $computers[$compid]["procspeed"], $computers[$compid]["network"], $computers[$compid]["hostname"], $compid, $computers[$compid]["type"], $computers[$compid]["provisioningid"], $computers[$compid]["location"]); print "\n"; print " \n"; print " \n"; print " \n"; print " \n"; print "
\n"; print "
\n"; $cdata = $data; $cdata['deleted'] = $deleted; $cdata['compid'] = $compid; $cont = addContinuationsEntry('submitDeleteComputer', $cdata, SECINDAY, 0, 0); print " \n"; print " \n"; print "
\n"; print "
\n"; print "
\n"; $cont = addContinuationsEntry('viewComputers', $data); print " \n"; print " \n"; print "
\n"; print "
\n"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn submitDeleteComputer() /// /// \brief deletes a computer from the database and notifies the user /// //////////////////////////////////////////////////////////////////////////////// function submitDeleteComputer() { $compid = getContinuationVar("compid"); $deleted = getContinuationVar("deleted"); if($deleted) { $query = "UPDATE computer " . "SET deleted = 0 " . "WHERE id = $compid"; $qh = doQuery($query, 190); } else { $query = "UPDATE computer " . "SET deleted = 1, " . "vmhostid = NULL " . "WHERE id = $compid"; $qh = doQuery($query, 191); } $_SESSION['userresources'] = array(); viewComputers(); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn bulkAddComputer() /// /// \brief prints a form for adding a block of computers /// //////////////////////////////////////////////////////////////////////////////// function bulkAddComputer() { global $submitErr; $data = processBulkComputerInput(0); $data2 = processComputerInput2(); //yes, this is somewhat redundant, but it // makes things easier later $states = array("2" => "available", "10" => "maintenance", "20" => "vmhostinuse"); print "\n"; print "

Add Multiple Computers

\n"; print "
\n"; print "
\n"; print "NOTE: 'Start IP' and 'End IP' can only differ in the number "; print "after the last '.'. The hostnames will be generated from the "; print "'Hostname' field. The hostnames for each computer can only differ "; print "by the value of a number in the first part of the hostname. Place "; print "a '%' character in the 'Hostname' field where that number will be. "; print "Then fill in 'Start value' and 'End value' with the first and last "; print "values to be used in the hostname.

"; print "Required text fields are noted with *

\n"; print "
\n"; print "
\n"; print "\n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print "
Hostname*:"; printSubmitErr(HOSTNAMEERR); print "
Start value*:"; printSubmitErr(STARTHOSTVALERR); print "
End value*:"; printSubmitErr(ENDHOSTVALERR); print "
Type:\n"; $tmpArr = array("blade" => "blade", "lab" => "lab", "virtualmachine" => "virtualmachine"); printSelectInput('type', $tmpArr, $data['type'], 0, 0, 'type', 'dojoType="dijit.form.Select" onChange="editComputerSelectType(0);"'); print "
Start Public IP Address*:"; printSubmitErr(IPADDRERR); print "
End Public IP Address*:"; printSubmitErr(IPADDRERR2); print "
Start Private IP Address:"; printSubmitErr(IPADDRERR3); print "
End Private IP Address:"; printSubmitErr(IPADDRERR4); print "
Start MAC Address:"; printSubmitErr(MACADDRERR); print "
Provisioning Engine:\n"; printSelectInput("provisioningid", $showprovisioning, $data["provisioningid"], 0, 0, 'provisioningid', 'dojoType="dijit.form.Select" onChange="editComputerSelectType(1);"'); print "
State:\n"; if($submitErr && $data['type'] == 'virtualmachine') $states = array('10' => 'maintenance'); if($data['provisioningid'] == '' || $provisioning[$data['provisioningid']]['name'] == 'none') unset_by_val('available', $states); printSelectInput('stateid', $states, $data['stateid'], 0, 0, 'stateid', 'dojoType="dijit.form.Select" onChange="editComputerSelectState();"'); print "
VM Host Profile:\n"; printSelectInput("vmprofileid", $profiles, $data["vmprofileid"], 0, 0, 'vmprofileid', 'dojoType="dijit.form.Select"'); print "
Owner*:"; printSubmitErr(OWNERERR); print "
Platform:\n"; printSelectInput("platformid", $platforms, $data["platformid"], 0, 0, 'platformid', 'dojoType="dijit.form.Select"'); print "
Schedule:\n"; printSelectInput("scheduleid", $schedules, $data["scheduleid"], 0, 0, 'scheduleid', 'dojoType="dijit.form.Select"'); print "
RAM (MB)*:"; printSubmitErr(RAMERR); print "
No. Cores:\n"; print " \n"; print "
Processor Speed (MHz)*:"; printSubmitErr(PROCSPEEDERR); print "
Network Speed (Mbps):\n"; $tmpArr = array("10" => "10", "100" => "100", "1000" => "1000", "10000" => "10000"); printSelectInput("network", $tmpArr, $data["network"], 0, 0, 'network', 'dojoType="dijit.form.Select"'); print "
Physical Location:
\n"; $tmp = getUserResources(array("computerAdmin"), array("manageGroup"), 1); $computergroups = $tmp["computer"]; print "

Computer Groups

"; print "\n"; print " \n"; foreach($computergroups as $group) { print " \n"; } print " \n"; print " \n"; foreach(array_keys($computergroups) as $groupid) { $name = "computergroup[$groupid]"; if(array_key_exists($groupid, $data["computergroup"])) $checked = "checked"; else $checked = ""; print " \n"; } print " \n"; print "
$group
\n"; print " \n"; print "
\n"; print "\n"; print " \n"; print " \n"; print " \n"; print " \n"; print "
\n"; $cont = addContinuationsEntry('confirmAddBulkComputers', $data2, SECINDAY, 0, 1, 1); print " \n"; print " \n"; print " \n"; print " \n"; print "
\n"; $cont = addContinuationsEntry('viewComputers', $data2); print " \n"; print " \n"; print "
\n"; print "
\n"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn confirmAddBulkComputers() /// /// \brief checks for valid input and allows user to confirm the bulk add /// //////////////////////////////////////////////////////////////////////////////// function confirmAddBulkComputers() { global $submitErr; $data = processBulkComputerInput(); if($submitErr) { bulkAddComputer(); return; } print "

Add Multiple Computers

\n"; print "

Add the following comptuers?

\n"; $states = getStates(); $platforms = getPlatforms(); $schedules = getSchedules(); $images = getImages(); $provisioning = getProvisioning(); print "\n"; print " \n"; print " \n"; $first = str_replace('%', $data["starthostval"], $data["hostname"]); $last = str_replace('%', $data["endhostval"], $data["hostname"]); print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; if(! empty($data['startpripaddress'])) { print " \n"; print " \n"; print " \n"; print " \n"; } if(! empty($data['macs'])) { $end = $data['count'] * 2 - 1; print " \n"; print " \n"; print " \n"; print " \n"; } print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; if(! empty($data['vmprofileid'])) { print " \n"; print " \n"; print " \n"; print " \n"; } print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print "
Hostnames:$first - $last
Type:" . $data["type"] . "
IP Addresses:" . $data["startipaddress"] . " - "; print $data["endipaddress"] . "
Private IP Addresses:" . $data["startpripaddress"] . " - "; print $data["endpripaddress"] . "
MAC Addresses:{$data['macs'][0]} - {$data['macs'][$end]} (2 for each machine)
Provisioning Engine:" . $provisioning[$data["provisioningid"]]['prettyname'] . "
State:" . $states[$data["stateid"]] . "
VM Host Profile:{$data['profiles'][$data['vmprofileid']]['profilename']}
Owner:" . $data["owner"] . "
Platform:" . $platforms[$data["platformid"]] . "
Schedule:" . $schedules[$data["scheduleid"]]["name"] . "
RAM (MB):" . $data["ram"] . "
No. Cores:" . $data["numprocs"] . "
Processor Speed (MHz):" . $data["procspeed"] . "
Network Speed (Mbps):" . $data["network"] . "
Location:{$data['location']}
\n"; $tmp = getUserResources(array("computerAdmin"), array("manageGroup"), 1); $computergroups = $tmp["computer"]; print "

Computer Groups

"; print "\n"; print " \n"; foreach($computergroups as $group) { print " \n"; } print " \n"; print " \n"; foreach(array_keys($computergroups) as $groupid) { if(array_key_exists($groupid, $data["computergroup"])) $checked = "src=images/x.png alt=selected"; else $checked = "src=images/blank.gif alt=unselected"; print " \n"; } print " \n"; print "
$group
\n"; print " \n"; print "
\n"; print "\n"; print " \n"; print " \n"; print " \n"; print " \n"; print "
\n"; print "
\n"; $cont = addContinuationsEntry('submitAddBulkComputers', $data, SECINDAY, 0, 0); print " \n"; print " \n"; print "
\n"; print "
\n"; print "
\n"; $cont = addContinuationsEntry('viewComputers', $data); print " \n"; print " \n"; print "
\n"; print "
\n"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn submitAddBulkComputers() /// /// \brief submits the computers and notifies the user /// //////////////////////////////////////////////////////////////////////////////// function submitAddBulkComputers() { global $mysql_link_vcl; $data = processBulkComputerInput(0); $ownerid = getUserlistID($data["owner"]); $tmpArr = explode('.', $data["startipaddress"]); $startip = $tmpArr[3]; $tmpArr = explode('.', $data["endipaddress"]); $endip = $tmpArr[3]; array_pop($tmpArr); $baseaddr = implode('.', $tmpArr); $dopr = 0; if(! empty($data['startpripaddress'])) { $dopr = 1; $tmpArr = explode('.', $data["startpripaddress"]); $startprip = $tmpArr[3]; $tmpArr = explode('.', $data["endpripaddress"]); $endprip = $tmpArr[3]; array_pop($tmpArr); $basepraddr = implode('.', $tmpArr); } $domacs = 0; if(! empty($data['macs'])) { $domacs = 1; $maccnt = 0; } $doloc = 0; if($data['location'] != '') { $doloc = 1; $location = $data['location']; if(get_magic_quotes_gpc()) $location = stripslashes($location); $location = mysql_real_escape_string($location); } $dhcpdata = array(); $count = 0; $addedrows = 0; $noimageid = getImageId('noimage'); $noimagerevisionid = getProductionRevisionid($noimageid); for($i = $startip, $j = $data["starthostval"]; $i <= $endip; $i++, $j++, $count++) { $hostname = str_replace('%', $j, $data["hostname"]); $ipaddress = $baseaddr . ".$i"; $dhcpdata[$count] = array('hostname' => $hostname); if($dopr) { $pripaddress = $basepraddr . '.' . $startprip++; $dhcpdata[$count]['prip'] = $pripaddress; } if($domacs) { $eth0 = $data['macs'][$maccnt++]; $eth1 = $data['macs'][$maccnt++]; $dhcpdata[$count]['eth0mac'] = $eth0; } $query = "INSERT INTO computer " . "(stateid, " . "ownerid, " . "platformid, " . "provisioningid, " . "scheduleid, " . "currentimageid, " . "imagerevisionid, " . "RAM, " . "procnumber, " . "procspeed, " . "network, " . "hostname, " . "IPaddress, "; if($dopr) $query .= "privateIPaddress, "; if($domacs) $query .= "eth0macaddress, " . "eth1macaddress, "; if($doloc) $query .= "location, "; $query .= "type) " . "VALUES ({$data['stateid']}, " . "$ownerid, " . "{$data['platformid']}, " . "{$data['provisioningid']}, " . "{$data['scheduleid']}, " . "$noimageid, " . "$noimagerevisionid, " . "{$data['ram']}, " . "{$data['numprocs']}, " . "{$data['procspeed']}, " . "{$data['network']}, " . "'$hostname', " . "'$ipaddress', "; if($dopr) $query .= "'$pripaddress', "; if($domacs) $query .= "'$eth0', " . "'$eth1', "; if($doloc) $query .= "'$location', "; $query .= "'{$data['type']}')"; $qh = doQuery($query, 235); $addedrows += mysql_affected_rows($mysql_link_vcl); $compid = dbLastInsertID(); $query = "INSERT INTO resource " . "(resourcetypeid, " . "subid) " . "VALUES (12, " . "$compid)"; doQuery($query, 238); $resid = dbLastInsertID(); // add computer into selected groups if(! empty($data['computergroup'])) { $vals = array(); foreach(array_keys($data["computergroup"]) as $groupid) $vals[] = "($resid, $groupid)"; $allvals = implode(',', $vals); $query = "INSERT INTO resourcegroupmembers " . "(resourceid, " . "resourcegroupid) " . "VALUES $allvals"; doQuery($query, 101); } if($data['stateid'] == 20) { # create vmhost entry $query = "INSERT INTO vmhost " . "(computerid, " . "vmlimit, " . "vmprofileid) " . "VALUES ($compid, " . "2, " . "{$data['vmprofileid']})"; doQuery($query, 101); } } print "
\n"; print "

Add Multiple Computers

\n"; if($count == $addedrows) print "The computers were added successfully.

\n"; else print $count - $addedrows . " computers failed to get added

\n"; print "
\n"; print "You can download data for /etc/hosts and dhcpd.conf or dhcpd.leases from the Computer Utilities page.\n"; clearPrivCache(); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn viewComputerGroups() /// /// \brief prints a form for editing computer groups /// //////////////////////////////////////////////////////////////////////////////// function viewComputerGroups() { global $mode; $platforminput = getContinuationVar('platforms', processInputVar("platforms", ARG_MULTINUMERIC)); $scheduleinput = getContinuationVar("schedules", processInputVar("schedules", ARG_MULTINUMERIC)); $groups = processInputVar('groups', ARG_MULTINUMERIC); $computers = getComputers(1); $tmp = getUserResources(array("computerAdmin"), array("manageGroup"), 1); $computergroups = $tmp["computer"]; $computermembership = getResourceGroupMemberships("computer"); $resources = getUserResources(array("computerAdmin"), array("manageGroup")); uasort($resources["computer"], "sortKeepIndex"); if($mode == 'submitComputerGroups') $gridSelected = "selected=\"true\""; else $gridSelected = ""; print "

Computer Groups

\n"; print "
\n"; # by computer tab print "
\n"; print "Select a computer and click \"Get Groups\" to see all of the groups "; print "it is in. Then,
select a group it is in and click the Remove "; print "button to remove it from that group,
or select a group it is not "; print "in and click the Add button to add it to that group.

\n"; print "Computer:\n"; print "\n"; print "\n"; # select for groups image is in print "\n"; # transfer buttons print "\n"; # select for groups computer is not in print "\n"; print "
\n"; print "Groups is in:
\n"; print "\n"; print "
\n"; print "\n"; print "
\n"; print "
\n"; print "
\n"; print "\n"; print "
\n"; print "Groups is not in:
\n"; print "\n"; print "
\n"; print "
\n"; # by group tab print "
\n"; print "Select a group and click \"Get Computers\" to see all of the computers "; print "in it. Then,
select a computer in it and click the Remove "; print "button to remove it from the group,
or select a computer that is not "; print "in it and click the Add button to add it to the group.

\n"; print "Group:\n"; print "\n"; print "\n"; # select for images in group print "\n"; # transfer buttons print "\n"; # computers not in group select print "\n"; print "
\n"; print "Computers in :
\n"; print "\n"; print "
\n"; print "\n"; print "
\n"; print "
\n"; print "
\n"; print "\n"; print "
\n"; print "Computers not in :
\n"; print "\n"; print "
\n"; print "
\n"; # grid tab if(empty($gridSelected)) { $cdata = array('platforms' => $platforminput, 'schedules' => $scheduleinput, 'groups' => $groups); } else { $cdata = array('platforms' => getContinuationVar("platforms"), 'schedules' => getContinuationVar("schedules"), 'groups' => getContinuationVar("groups")); } $cont = addContinuationsEntry('compGroupingGrid', $cdata); $loadingmsg = "Loading page (this may take a really long time)"; print "\n"; print " Checkbox Grid\n"; print "
\n"; # end of main tab container $cont = addContinuationsEntry('jsonCompGroupingComps'); print "\n"; $cont = addContinuationsEntry('jsonCompGroupingGroups'); print "\n"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn compGroupingGrid() /// /// \brief prints a page to view and modify computer grouping /// //////////////////////////////////////////////////////////////////////////////// function compGroupingGrid() { global $mode; $platforminput = getContinuationVar('platforms'); $scheduleinput = getContinuationVar('schedules'); $groups = getContinuationVar('groups'); if(empty($groups)) { if(empty($platforminput) && empty($scheduleinput)) { print "No criteria selected to determine which computers to display. Please go back
\n"; print "to the Manage Computers page and select either a set of platforms
\n"; print "and schedules or at least one computer group.
\n"; return; } $bygroups = 0; $compidlist = array(); } else { $bygroups = 1; $compidlist = getCompIdList($groups); } $computers = getComputers(1); $tmp = getUserResources(array("computerAdmin"), array("manageGroup"), 1); $computergroups = $tmp["computer"]; $computermembership = getResourceGroupMemberships("computer"); $resources = getUserResources(array("computerAdmin"), array("manageGroup")); uasort($resources["computer"], "sortKeepIndex"); if($mode == "submitComputerGroups") { print "Computer groups successfully updated"; print "

\n"; } print "
\n"; print "\n"; print " \n"; if($bygroups) { foreach($groups as $id) { print " \n"; } } else { foreach(array_keys($computergroups) as $id) { print " \n"; } } print " \n"; print " \n"; if($bygroups) print " \n"; else print " \n"; print " \n"; print " \n"; if($bygroups) { foreach($groups as $id) { print " \n"; } } else { foreach($computergroups as $id => $group) { print " \n"; } } print " \n"; $count = 1; foreach($resources["computer"] as $compid => $computer) { if($bygroups) { if(! array_key_exists($compid, $compidlist)) continue; } else { if(! in_array($computers[$compid]["platformid"], $platforminput) || ! in_array($computers[$compid]["scheduleid"], $scheduleinput)) { continue; } } if($bygroups) $items = $groups; else $items = array_keys($computergroups); if($count % 20 == 0) { print " \n"; print " \n"; foreach($items as $id) { print " \n"; } print " \n"; } print " \n"; print " \n"; foreach($items as $groupid) { $name = "computergroup[" . $compid . ":" . $groupid . "]"; if(array_key_exists($compid, $computermembership["computer"]) && in_array($groupid, $computermembership["computer"][$compid])) { $checked = "checked"; $value = 1; } else { $checked = ""; $value = 2; } print " \n"; } print " \n"; $count++; } print "
HostnameGroupsGroups
{$computergroups[$id]}$group
{$computergroups[$id]}
$computer\n"; print " \n"; print "
\n"; if($count > 1) { print "\n"; print "\n"; $cdata = array('platforms' => $platforminput, 'schedules' => $scheduleinput, 'groups' => $groups, 'compidlist' => $compidlist); # set a short timeout because this is a "last one in wins" page $cont = addContinuationsEntry('submitComputerGroups', $cdata, 300, 0, 0, 1); print "\n"; } print "
\n"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn submitComputerGroups() /// /// \brief updates computer groupings and notifies user /// //////////////////////////////////////////////////////////////////////////////// function submitComputerGroups() { $platforminput = getContinuationVar("platforms"); $scheduleinput = getContinuationVar("schedules"); $groups = getContinuationVar("groups"); $compidlist = getContinuationVar('compidlist'); $groupinput = processInputVar("computergroup", ARG_MULTINUMERIC); if(empty($groups)) $bygroups = 0; else $bygroups = 1; $computers = getComputers(); # build an array of memberships currently in the db $tmp = getUserResources(array("groupAdmin"), array("manageGroup"), 1); $computergroupsIDs = array_keys($tmp["computer"]); // ids of groups that user can manage $resources = getUserResources(array("computerAdmin"), array("manageGroup")); $userCompIDs = array_keys($resources["computer"]); // ids of computers that user can manage $computermembership = getResourceGroupMemberships("computer"); $basecomputergroups = $computermembership["computer"]; // all computer group memberships $computergroups = array(); foreach(array_keys($basecomputergroups) as $compid) { if(in_array($compid, $userCompIDs)) { foreach($basecomputergroups[$compid] as $grpid) { if($bygroups && ! in_array($grpid, $groups)) continue; if(in_array($grpid, $computergroupsIDs)) { if(array_key_exists($compid, $computergroups)) array_push($computergroups[$compid], $grpid); else $computergroups[$compid] = array($grpid); } } } } $newmembers = array(); foreach(array_keys($groupinput) as $key) { list($compid, $grpid) = explode(':', $key); if(array_key_exists($compid, $newmembers)) { array_push($newmembers[$compid], $grpid); } else { $newmembers[$compid] = array($grpid); } } $adds = array(); $removes = array(); foreach(array_keys($computers) as $compid) { if($bygroups) { if(! array_key_exists($compid, $compidlist)) continue; } else { if(! in_array($computers[$compid]["platformid"], $platforminput) || ! in_array($computers[$compid]["scheduleid"], $scheduleinput)) continue; } if(! array_key_exists($compid, $newmembers) && ! array_key_exists($compid, $computergroups)) { continue; } $id = $computers[$compid]["resourceid"]; // check that $compid is in $newmembers, if not, remove it from all groups if(! array_key_exists($compid, $newmembers)) { $removes[$id] = $computergroups[$compid]; continue; } // check that $compid is in $computergroups, if not, add all groups // in $newmembers if(! array_key_exists($compid, $computergroups)) { $adds[$id] = $newmembers[$compid]; continue; } // adds are groupids that are in $newmembers, but not in $computergroups $adds[$id] = array_diff($newmembers[$compid], $computergroups[$compid]); if(count($adds[$id]) == 0) { unset($adds[$id]); } // removes are groupids that are in $computergroups, but not in // $newmembers $removes[$id] = array_diff($computergroups[$compid], $newmembers[$compid]); if(count($removes[$id]) == 0) { unset($removes[$id]); } } foreach(array_keys($adds) as $compid) { foreach($adds[$compid] as $grpid) { $query = "INSERT INTO resourcegroupmembers " . "(resourceid, resourcegroupid) " . "VALUES ($compid, $grpid)"; doQuery($query, 285); } } foreach(array_keys($removes) as $compid) { foreach($removes[$compid] as $grpid) { $query = "DELETE FROM resourcegroupmembers " . "WHERE resourceid = $compid AND " . "resourcegroupid = $grpid"; doQuery($query, 286); } } viewComputerGroups(); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn computerUtilities() /// /// \brief prints a page for selecting multiple computers and then choosing from /// a few utility type functions to operate on the selected computers /// //////////////////////////////////////////////////////////////////////////////// function computerUtilities() { global $user, $mode, $skin; $data = processComputerInput(0); if(empty($data['groups'])) $bygroups = 0; else { $bygroups = 1; $compidlist = getCompIdList($data['groups']); } $computers = getComputers(1); $resources = getUserResources(array("computerAdmin"), array("administer")); $userCompIDs = array_keys($resources["computer"]); $resources = getUserResources(array("imageAdmin", "imageCheckOut")); $platforms = getPlatforms(); $tmp = getUserResources(array("scheduleAdmin"), array("manageGroup")); $schedules = $tmp["schedule"]; $allschedules = getSchedules(); $images = getImages(1); print "

Computer Utilities

\n"; print "
\n"; print "\n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; #print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; /*print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n";*/ print " \n"; print " \n"; $count = 0; $statecolor = array( 'available' => '#008000', 'reloading' => '#e58304', 'failed' => 'red' ); $dispcompids = array(); foreach(array_keys($computers) as $id) { if($bygroups) { if(! array_key_exists($id, $compidlist)) continue; } elseif(! in_array($computers[$id]["platformid"], $data["platforms"]) || ! in_array($computers[$id]["scheduleid"], $data["schedules"])) continue; if(! in_array($id, $userCompIDs)) { continue; } $dispcompids[] = $id; print " \n"; print " \n"; print " \n"; print " \n"; if(isset($statecolor[$computers[$id]['state']])) print " \n"; else print " \n"; print " \n"; #print " \n"; print " \n"; print " \n"; if($computers[$id]["nextimgid"]) print " \n"; else print " \n"; if(is_null($computers[$id]['vmhost'])) print " \n"; else print " \n"; /*print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n";*/ if(empty($computers[$id]["notes"])) print " \n"; else { print " \n"; } print " \n"; $count++; } print "
HostnameIP AddressStateOwnerPlatformScheduleCurrent ImageNext ImageVM HostRAM(MB)No. CoresProcessor Speed(MHz)Network Speed(Mbps)Computer IDTypeNo. of ReservationsNotes
" . $computers[$id]["hostname"] . "" . $computers[$id]["IPaddress"] . "{$computers[$id]["state"]}" . $computers[$id]["state"] . "" . $computers[$id]["owner"] . "{$platforms[$computers[$id]["platformid"]]}{$allschedules[$computers[$id]["scheduleid"]]["name"]}{$images[$computers[$id]["currentimgid"]]["prettyname"]}{$images[$computers[$id]["nextimgid"]]["prettyname"]}(selected by system)N/A" . $computers[$id]["vmhost"] . "" . $computers[$id]["ram"] . "" . $computers[$id]["procnumber"] . "" . $computers[$id]["procspeed"] . "" . $computers[$id]["network"] . "$id" . $computers[$id]["type"] . " " . str_replace('@', '
', $computers[$id]["notes"]); print "
\n"; if($count == 0) { print "
0 computers found
\n"; return; } print "Check All / \n"; print "Uncheck All
\n"; print "\n"; if(count($resources['image'])) { print " \n"; print " "; print " \n"; print " "; $cont = addContinuationsEntry('reloadComputers', array(), SECINDAY, 0); print " \n"; print " \n"; } print " \n"; print " "; $states = array("2" => "available", "23" => "hpc", "10" => "maintenance", "20" => "convert to vmhostinuse", "999" => "DELETE"); print " \n"; $cont = addContinuationsEntry('compStateChange', array(), SECINDAY, 0); print " \n"; print " \n"; if(count($schedules)) { print " \n"; print " "; uasort($schedules, "sortKeepIndex"); print " \n"; $cont = addContinuationsEntry('compScheduleChange', array(), SECINDAY, 0); print " \n"; print " \n"; } print " \n"; print " "; print " \n"; print " \n"; print "
Reload selected computers with this image:\n"; printSelectInput("imageid", $resources["image"], -1, 1); print "
Change state of or delete selected computers:\n"; printSelectInput("stateid", $states); print " "; print "
Change schedule of selected computers to:\n"; printSelectInput("scheduleid", $schedules); print " "; print "
For selected computers, generate computer data for:\n"; $tmp = array('dhcpd' => 'dhcpd', 'hosts' => '/etc/hosts'); printSelectInput('generatetype', $tmp, -1, 0, 0, 'generatetype'); print " "; print "
\n"; print "\n"; print "
\n"; print "
$count computers found
\n"; print "
\n"; print "
\n"; print "
\n"; print " Enter Management Node Private IP Address:
\n"; print " \n"; print " \n"; print "
\n"; print "
"; print " Loading...
\n"; print "
\n"; $cdata = array('dispcompids' => $dispcompids); $cont = addContinuationsEntry('AJgenerateUtilData', $cdata, SECINDAY); print " \n"; print "
\n"; print " \n"; print "
\n"; print "
\n"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn reloadComputers() /// /// \brief confirms reloading submitted computers with the selected image /// //////////////////////////////////////////////////////////////////////////////// function reloadComputers() { global $user; $data = processComputerInput3(); $computers = getComputers(1); $imagedata = getImages(0, $data['imageid']); $reloadnow = array(); $reloadasap = array(); $noreload = array(); foreach($data['computerids'] as $compid) { switch($computers[$compid]['state']) { case "available": case "failed": case "reloading": array_push($reloadnow, $compid); break; case "inuse": case "timeout": case "reserved": array_push($reloadasap, $compid); break; case "maintenance": array_push($noreload, $compid); break; default: array_push($noreload, $compid); break; } } print "

Reload Computers

\n"; if(count($reloadnow)) { print "The following computers will be immediately reloaded with "; print "{$imagedata[$data['imageid']]['prettyname']}:
\n"; print "\n"; foreach($reloadnow as $compid) { print " \n"; print " \n"; print " \n"; } print "
{$computers[$compid]['hostname']}
\n"; print "
\n"; } if(count($reloadasap)) { print "The following computers are currently in use and will be "; print "reloaded with {$imagedata[$data['imageid']]['prettyname']} at the end "; print "of the user's reservation:
\n"; print "\n"; foreach($reloadasap as $compid) { print " \n"; print " \n"; print " \n"; } print "
{$computers[$compid]['hostname']}
\n"; print "
\n"; } print "
\n"; print "
\n"; $data['imagename'] = $imagedata[$data['imageid']]['prettyname']; $cont = addContinuationsEntry('submitReloadComputers', $data, SECINDAY, 0, 0); print "\n"; print "
\n"; if(count($noreload)) { print "The following computers are currently in the maintenance "; print "state and therefore will have nothing done to them:
\n"; print "\n"; foreach($noreload as $compid) { print " \n"; print " \n"; print " \n"; } print "
{$computers[$compid]['hostname']}
\n"; print "
\n"; } } //////////////////////////////////////////////////////////////////////////////// /// /// \fn submitReloadComputers() /// /// \brief configures system to reloaded submitted computers with submitted /// image /// //////////////////////////////////////////////////////////////////////////////// function submitReloadComputers() { $data = getContinuationVar(); $start = getReloadStartTime(); $end = $start + 1200; // + 20 minutes $startstamp = unixToDatetime($start); $endstamp = unixToDatetime($end); $imagerevisionid = getProductionRevisionid($data['imageid']); // get semaphore lock if(! semLock()) abort(3); $computers = getComputers(1); $reloadnow = array(); $reloadasap = array(); foreach($data['computerids'] as $compid) { switch($computers[$compid]['state']) { case "available": case "failed": array_push($reloadnow, $compid); break; case "reload": case "reloading": case "inuse": case "timeout": case "reserved": array_push($reloadasap, $compid); break; } } $vclreloadid = getUserlistID('vclreload@Local'); $fails = array(); $passes = array(); foreach($reloadnow as $compid) { if(simpleAddRequest($compid, $data['imageid'], $imagerevisionid, $startstamp, $endstamp, 19, $vclreloadid)) $passes[] = $compid; else $fails[] = $compid; } // release semaphore lock semUnlock(); if(count($reloadasap)) { $compids = implode(',', $reloadasap); $query = "UPDATE computer " . "SET nextimageid = {$data['imageid']} " . "WHERE id IN ($compids)"; doQuery($query, 101); } print "

Reload Computers

\n"; if(count($passes)) { print "The following computers are being immediately reloaded with "; print "{$data['imagename']}:
\n"; foreach($passes as $compid) print "{$computers[$compid]['hostname']}
\n"; } if(count($reloadasap)) { if(count($passes)) print "
"; print "The following computers will be reloaded with "; print "{$data['imagename']} after their current reservations are over:
\n"; foreach($reloadasap as $compid) print "{$computers[$compid]['hostname']}
\n"; } if(count($fails)) { if(count($passes) || count($reloadasap)) print "
"; print "No functional management node was found for the following "; print "computers. They could not be reloaded at this time:
\n"; foreach($fails as $compid) print "{$computers[$compid]['hostname']}
\n"; } } //////////////////////////////////////////////////////////////////////////////// /// /// \fn compStateChange() /// /// \brief confirms changing computers to selected state, and if new state is /// maintenance, asks for reason /// //////////////////////////////////////////////////////////////////////////////// function compStateChange() { global $submitErr; print "

Change State of Computers

\n"; $data = processComputerInput3(); $computers = getComputers(1); if($data['stateid'] == 10) { $notes = explode('@', $data['notes']); if(count($notes) != 2) $notes[1] = ""; } if($data['stateid'] == 2) { print "You are about to place the following computers into the "; print "available state:\n"; print "
\n"; } elseif($data['stateid'] == 10) { print "Please enter a reason you are changing the following computers to "; print "the maintenance state:

\n"; print "\n"; print "
\n"; print "
Selected computers:\n"; } elseif($data['stateid'] == 20) { $profiles = getVMProfiles(); $data['profiles'] = $profiles; print "Select a VM Host Profile and then click Submit\n"; print "to place the computers into the vmhostinuse state:

\n"; print "\n"; print "

\n"; print "

\n"; } elseif($data['stateid'] == 23) { print "You are about to place the following computers into the "; print "hpc state:\n"; print "\n"; } elseif($data['stateid'] == 999) { print "You are about to DELETE the following computers"; print "\n"; } $cont = addContinuationsEntry('submitCompStateChange', $data, SECINDAY, 0, 0); print " \n"; print "\n"; foreach($data['computerids'] as $compid) { print " \n"; #print " \n"; print " \n"; print " \n"; } print "
{$computers[$compid]['hostname']}{$computers[$compid]['hostname']}
\n"; print "
\n"; print "\n"; print "
\n"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn submitCompStateChange() /// /// \brief configures system to put submitted computers in submitted state /// //////////////////////////////////////////////////////////////////////////////// function submitCompStateChange() { global $user; print "

Change State of Computers

\n"; $data = getContinuationVar(); $computers = getComputers(1); # switching to available if($data['stateid'] == 2) { $compids = implode(',', $data['computerids']); $query = "UPDATE computer " . "SET stateid = 2, " . "notes = '' " . "WHERE id IN ($compids)"; doQuery($query, 101); print "The following computers were changed to the available state:\n"; print "\n"; foreach($data['computerids'] as $compid) { print " \n"; print " \n"; print " \n"; } print "
{$computers[$compid]['hostname']}
\n"; } # switching to maintenance elseif($data['stateid'] == 10) { $data['notes'] = processInputVar('notes', ARG_STRING); if(get_magic_quotes_gpc()) $data['notes'] = stripslashes($data['notes']); $data['notes'] = mysql_real_escape_string($data['notes']); $data["notes"] = $user["unityid"] . " " . unixToDatetime(time()) . "@" . $data["notes"]; $vclreloadid = getUserlistID('vclreload@Local'); $imageid = getImageId('noimage'); $imagerevisionid = getProductionRevisionid($imageid); $noaction = array(); $changenow = array(); $changeasap = array(); $changetimes = array(); $changetimes2 = array(); foreach($data['computerids'] as $compid) { if($computers[$compid]['state'] == 'maintenance') array_push($noaction, $compid); else array_push($changeasap, $compid); } $passes = array(); $fails = array(); $blockallocs = array(); $blockfails = array(); // get semaphore lock if(! semLock()) abort(3); foreach($changeasap as $compid) { # try to move future reservations off of computer moveReservationsOffComputer($compid); # get end time of last reservation $query = "SELECT rq.end " . "FROM request rq, " . "reservation rs " . "WHERE rs.requestid = rq.id AND " . "rs.computerid = $compid AND " . "rq.stateid NOT IN (1,5,12) " . "ORDER BY end DESC " . "LIMIT 1"; $qh = doQuery($query, 101); $query2 = "SELECT t.end " . "FROM blockComputers c, " . "blockTimes t " . "WHERE c.computerid = $compid AND " . "c.blockTimeid = t.id AND " . "t.end > NOW() " . "ORDER BY t.end DESC " . "LIMIT 1"; $qh2 = doQuery($query2, 101); # create a really long reservation starting at that time in state tomaintenance if($row = mysql_fetch_assoc($qh)) { $start = $row['end']; $changetimes[$compid] = $start; $end = datetimeToUnix($start) + SECINWEEK; // hopefully keep future reservations off of it $end = unixToDatetime($end); if(simpleAddRequest($compid, $imageid, $imagerevisionid, $start, $end, 18, $vclreloadid)) $passes[] = $compid; else $fails[] = $compid; } // if part of a block allocation, create a really long reservation # starting at the block allocation end time in state tomaintenance elseif($row = mysql_fetch_assoc($qh2)) { $start = $row['end']; $changetimes2[$compid] = $start; $end = datetimeToUnix($start) + SECINWEEK; // hopefully keep future reservations off of it $end = unixToDatetime($end); if(simpleAddRequest($compid, $imageid, $imagerevisionid, $start, $end, 18, $vclreloadid)) $blockallocs[] = $compid; else $blockfails[] = $compid; } # change to maintenance state and save in $changenow // if we wait and put them all in maintenance at the same time, # we may end up moving reservations to the computer later in the # loop else { $query = "UPDATE computer " . "SET stateid = 10, " . "notes = '{$data['notes']}' " . "WHERE id = $compid"; doQuery($query, 101); unset_by_val($compid, $changeasap); array_push($changenow, $compid); } } // release semaphore lock semUnlock(); if(count($noaction) || count($changeasap)) { $comparr = array_merge($noaction, $changeasap); $compids = implode(',', $comparr); $query = "UPDATE computer " . "SET notes = '{$data['notes']}' " . "WHERE id IN ($compids)"; doQuery($query, 101); } if(count($changenow)) { print "The following computers were immediately placed into the "; print "maintenance state:\n"; print "\n"; foreach($changenow as $compid) { print " \n"; print " \n"; print " \n"; } print "
{$computers[$compid]['hostname']}
\n"; print "
\n"; } if(count($passes)) { print "The following computers currently have reservations on them "; print "and will be placed in the maintenance state at the time listed "; print "for each computer:\n"; print "\n"; print " \n"; print " \n"; print " \n"; print " \n"; foreach($passes as $compid) { print " \n"; print " \n"; $time = date('n/j/y g:i a', datetimeToUnix($changetimes[$compid])); print " \n"; print " \n"; } print "
ComputerMaintenance time
{$computers[$compid]['hostname']}$time
\n"; print "
\n"; } if(count($fails)) { print "The following computers currently have reservations on them "; print "but no functional management node was found for them. Nothing will "; print "be done with them at this time:\n"; print "\n"; foreach($fails as $compid) { print " \n"; print " \n"; print " \n"; } print "
{$computers[$compid]['hostname']}
\n"; print "
\n"; } if(count($blockallocs)) { print "The following computers are part of an upcoming block allocation "; print "and will be placed in the maintenance state at the time listed "; print "for each computer:\n"; print "\n"; print " \n"; print " \n"; print " \n"; print " \n"; foreach($blockallocs as $compid) { print " \n"; print " \n"; $time = date('n/j/y g:i a', datetimeToUnix($changetimes2[$compid])); print " \n"; print " \n"; } print "
ComputerMaintenance time
{$computers[$compid]['hostname']}$time
\n"; print "
\n"; } if(count($blockfails)) { print "The following computers currently have reservations on them "; print "but no functional management node was found for them. Nothing will "; print "be done with them at this time:\n"; print "\n"; foreach($blockfails as $compid) { print " \n"; print " \n"; print " \n"; } print "
{$computers[$compid]['hostname']}
\n"; print "
\n"; } if(count($noaction)) { print "The following computers were already in the maintenance "; print "state and had their notes on being in the maintenance state "; print "updated:\n"; print "\n"; foreach($noaction as $compid) { print " \n"; print " \n"; print " \n"; } print "
{$computers[$compid]['hostname']}
\n"; print "
\n"; } } # switching to vmhostinuse elseif($data['stateid'] == 20) { $profileid = processInputVar('profileid', ARG_NUMERIC); if(! array_key_exists($profileid, $data['profiles'])) { $keys = array_keys($data['profiles']); $profileid = $keys[0]; } $vclreloadid = getUserlistID('vclreload@Local'); $imagerevisionid = getProductionRevisionid($data['profiles'][$profileid]['imageid']); $noaction = array(); $changenow = array(); $changeasap = array(); $blockalloc = array(); $changetimes = array(); $fails = array(); foreach($data['computerids'] as $compid) { if($computers[$compid]['state'] == 'vmhostinuse') array_push($noaction, $compid); else array_push($changeasap, $compid); } // get semaphore lock if(! semLock()) abort(3); foreach($changeasap as $compid) { moveReservationsOffComputer($compid); # get end time of last reservation $query = "SELECT rq.end " . "FROM request rq, " . "reservation rs " . "WHERE rs.requestid = rq.id AND " . "rs.computerid = $compid AND " . "rq.stateid NOT IN (1,5,12) " . "ORDER BY end DESC " . "LIMIT 1"; $qh = doQuery($query, 101); $query2 = "SELECT c.computerid " . "FROM blockComputers c, " . "blockTimes t " . "WHERE c.computerid = $compid AND " . "c.blockTimeid = t.id AND " . "t.end > NOW()"; $qh2 = doQuery($query2, 101); if($row = mysql_fetch_assoc($qh)) { // if there is a reservation, leave in $changeasap so we can # notify that we can't change this one } // if computer allocated to block allocation remove from $changeasap # and add to $blockalloc elseif($row = mysql_fetch_assoc($qh2)) { unset_by_val($compid, $changeasap); $blockalloc[] = $compid; } # change to vmhostinuse state and save in $changenow // if we wait and put them all in vmhostinuse at the same time, # we may end up moving reservations to the computer later in the # loop else { # create a reload reservation to load machine with image # corresponding to selected vm profile $start = getReloadStartTime(); $end = $start + SECINYEAR; # don't want anyone making a future reservation for this machine $start = unixToDatetime($start); $end = unixToDatetime($end); if(simpleAddRequest($compid, $data['profiles'][$profileid]['imageid'], $imagerevisionid, $start, $end, 21, $vclreloadid)) { $changenow[] = $compid; } else $fails[] = $compid; unset_by_val($compid, $changeasap); # check for existing vmhost entry $query = "SELECT id, " . "vmprofileid " . "FROM vmhost " . "WHERE computerid = $compid"; $qh = doQuery($query, 101); if($row = mysql_fetch_assoc($qh)) { if($row['vmprofileid'] != $profileid) { # update vmprofile $query = "UPDATE vmhost " . "SET vmprofileid = $profileid " . "WHERE id = {$row['id']}"; doQuery($query, 101); } } else { # create vmhost entry $query = "INSERT INTO vmhost " . "(computerid, " . "vmlimit, " . "vmprofileid) " . "VALUES ($compid, " . "2, " . "$profileid)"; doQuery($query, 101); } } } // release semaphore lock semUnlock(); if(count($changenow)) { print "The following computers were placed into the "; print "vmhostinuse state:\n"; print "\n"; foreach($changenow as $compid) { print " \n"; print " \n"; print " \n"; } print "
{$computers[$compid]['hostname']}
\n"; print "
\n"; } if(count($fails)) { print "The following computers had no reservations on them but no "; print "functional management node was found to reload them with the "; print "VM host image. Nothing will be done with them at this time:\n"; print "\n"; foreach($fails as $compid) { print " \n"; print " \n"; print " \n"; } print "
{$computers[$compid]['hostname']}
\n"; print "
\n"; } if(count($changeasap)) { print "The following computers currently have reservations on them "; print "and cannot be placed in the vmhostinuse state at this time:\n"; print "\n"; foreach($changeasap as $compid) { print " \n"; print " \n"; print " \n"; } print "
{$computers[$compid]['hostname']}
\n"; print "
\n"; } if(count($blockalloc)) { print "The following computers are part of an upcoming block allocation "; print "and cannot be placed in the vmhostinuse state at this time:\n"; print "\n"; foreach($blockalloc as $compid) { print " \n"; print " \n"; print " \n"; } print "
{$computers[$compid]['hostname']}
\n"; print "
\n"; } if(count($noaction)) { print "The following computers were already in the vmhostinuse "; print "state:\n"; print "\n"; foreach($noaction as $compid) { print " \n"; print " \n"; print " \n"; } print "
{$computers[$compid]['hostname']}
\n"; print "
\n"; } } # switching to hpc elseif($data['stateid'] == 23) { $noaction = array(); $changenow = array(); $changeasap = array(); $blockalloc = array(); $changetimes = array(); foreach($data['computerids'] as $compid) { if($computers[$compid]['state'] == 'hpc') array_push($noaction, $compid); else array_push($changeasap, $compid); } if(! semLock()) abort(3); foreach($changeasap as $compid) { moveReservationsOffComputer($compid); # get end time of last reservation $query = "SELECT rq.end " . "FROM request rq, " . "reservation rs " . "WHERE rs.requestid = rq.id AND " . "rs.computerid = $compid AND " . "rq.stateid NOT IN (1,5,12) " . "ORDER BY end DESC " . "LIMIT 1"; $qh = doQuery($query, 101); $query2 = "SELECT c.computerid " . "FROM blockComputers c, " . "blockTimes t " . "WHERE c.computerid = $compid AND " . "c.blockTimeid = t.id AND " . "t.end > NOW()"; $qh2 = doQuery($query2, 101); if($row = mysql_fetch_assoc($qh)) { // if there is a reservation, leave in $changeasap so we can # notify that we can't change this one } // if computer allocated to block allocation remove from $changeasap # and add to $blockalloc elseif($row = mysql_fetch_assoc($qh2)) { unset_by_val($compid, $changeasap); $blockalloc[] = $compid; } # change to hpc state and save in $changenow // if we wait and put them all in hpc at the same time, # we may end up moving reservations to the computer later in the # loop else { $query = "UPDATE computer " . "SET stateid = 23 " . "WHERE id = $compid"; doQuery($query, 101); unset_by_val($compid, $changeasap); array_push($changenow, $compid); } } // release semaphore lock semUnlock(); if(count($changenow)) { print "The following computers were placed into the "; print "hpc state:\n"; print "\n"; foreach($changenow as $compid) { print " \n"; print " \n"; print " \n"; } print "
{$computers[$compid]['hostname']}
\n"; print "
\n"; } if(count($changeasap)) { print "The following computers currently have reservations on them "; print "and cannot be placed in the hpc state at this time:\n"; print "\n"; foreach($changeasap as $compid) { print " \n"; print " \n"; print " \n"; } print "
{$computers[$compid]['hostname']}
\n"; print "
\n"; } if(count($blockalloc)) { print "The following computers are part of an upcoming block allocation "; print "and cannot be placed in the hpc state at this time:\n"; print "\n"; foreach($blockalloc as $compid) { print " \n"; print " \n"; print " \n"; } print "
{$computers[$compid]['hostname']}
\n"; print "
\n"; } if(count($noaction)) { print "The following computers were already in the hpc "; print "state:\n"; print "\n"; foreach($noaction as $compid) { print " \n"; print " \n"; print " \n"; } print "
{$computers[$compid]['hostname']}
\n"; print "
\n"; } } # set to deleted elseif($data['stateid'] == 999) { $compids = implode(',', $data['computerids']); $query = "UPDATE computer " . "SET deleted = 1, " . "notes = '', " . "vmhostid = NULL " . "WHERE id IN ($compids)"; doQuery($query, 999); print "The following computers were deleted:\n"; print "\n"; foreach($data['computerids'] as $compid) { print " \n"; print " \n"; print " \n"; } print "
{$computers[$compid]['hostname']}
\n"; } else abort(50); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn compScheduleChange() /// /// \brief confirms changing computers to selected schedule /// //////////////////////////////////////////////////////////////////////////////// function compScheduleChange() { global $submitErr; print "

Change Schedule of Computers

\n"; $data = processComputerInput3(); $computers = getComputers(1); $schedules = getSchedules(); print "You are about to place the following computer(s) into schedule "; print "{$schedules[$data['scheduleid']]['name']}"; print ".
Note: "; print "This will not affect reservations currently on the computer(s). It "; print "will only affect new reservations made on the computer(s).
\n"; print "
\n"; $cdata = array('scheduleid' => $data['scheduleid'], 'schedule' => $schedules[$data['scheduleid']]['name'], 'computerids' => $data['computerids']); $cont = addContinuationsEntry('submitCompScheduleChange', $cdata, SECINDAY, 1, 0); print "\n"; print "\n"; foreach($data['computerids'] as $compid) { print " \n"; print " \n"; print " \n"; } print "
{$computers[$compid]['hostname']}
\n"; print "\n"; print "
\n"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn submitCompScheduleChange() /// /// \brief configures system to put submitted computers in submitted state /// //////////////////////////////////////////////////////////////////////////////// function submitCompScheduleChange() { global $user; print "

Change Schedule of Computers

\n"; $data = getContinuationVar(); $computers = getComputers(1); $compids = implode(',', $data['computerids']); $query = "UPDATE computer " . "SET scheduleid = {$data['scheduleid']} " . "WHERE id IN ($compids)"; doQuery($query, 101); print "The schedule for the following computer(s) was set to "; print "{$data['schedule']}:
\n"; print "\n"; foreach($data['computerids'] as $compid) { print " \n"; print " \n"; print " \n"; } print "
{$computers[$compid]['hostname']}
\n"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn processComputerInput($checks) /// /// \param $checks - (optional) 1 to perform validation, 0 not to /// /// \return an array with the following keys:\n /// bulk, ipaddress, stateid, platformid, scheduleid, currentimgid, /// ram, numprocs, procspeed, network, hostname, compid, type /// /// \brief validates input from the previous form; if anything was improperly /// submitted, sets submitErr and submitErrMsg /// //////////////////////////////////////////////////////////////////////////////// function processComputerInput($checks=1) { global $submitErr, $submitErrMsg, $mode; $return = processComputerInput2(); $return["bulk"] = getContinuationVar("bulk", processInputVar("bulk", ARG_NUMERIC)); $return["ipaddress"] = getContinuationVar("ipaddress", processInputVar("ipaddress", ARG_STRING, NULL, 1)); $return["pripaddress"] = getContinuationVar("pripaddress", processInputVar("pripaddress", ARG_STRING, NULL, 1)); $return["eth0macaddress"] = getContinuationVar("eth0macaddress", processInputVar("eth0macaddress", ARG_STRING, NULL, 1)); $return["eth1macaddress"] = getContinuationVar("eth1macaddress", processInputVar("eth1macaddress", ARG_STRING, NULL, 1)); $return["stateid"] = getContinuationVar("stateid", processInputVar("stateid", ARG_NUMERIC)); $return["owner"] = getContinuationVar("owner", processInputVar("owner", ARG_STRING, NULL, 1)); $return["platformid"] = getContinuationVar("platformid", processInputVar("platformid", ARG_NUMERIC)); $return["scheduleid"] = getContinuationVar("scheduleid", processInputVar("scheduleid", ARG_NUMERIC)); $return["currentimgid"] = getContinuationVar("currentimgid", processInputVar("currentimgid", ARG_NUMERIC)); $return["ram"] = getContinuationVar("ram", processInputVar("ram", ARG_NUMERIC, NULL, 1)); $return["numprocs"] = getContinuationVar("numprocs", processInputVar("numprocs", ARG_NUMERIC, 1)); $return["procspeed"] = getContinuationVar("procspeed", processInputVar("procspeed", ARG_NUMERIC, NULL, 1)); $return["network"] = getContinuationVar("network", processInputVar("network", ARG_NUMERIC)); $return["hostname"] = getContinuationVar("hostname", processInputVar("hostname", ARG_STRING, NULL, 1)); $return["compid"] = getContinuationVar("compid", processInputVar("compid", ARG_NUMERIC)); $return["type"] = getContinuationVar("type", processInputVar("type", ARG_STRING, "blade")); $return["provisioningid"] = getContinuationVar("provisioningid", processInputVar("provisioningid", ARG_NUMERIC)); $return["notes"] = getContinuationVar("notes", processInputVar("notes", ARG_STRING)); $return["computergroup"] = getContinuationVar("computergroup", processInputVar("computergroup", ARG_MULTINUMERIC)); $return["showcounts"] = getContinuationVar("showcounts", processInputVar("showcounts", ARG_NUMERIC)); $return["location"] = getContinuationVar('location', processInputVar('location', ARG_STRING)); $return["vmprofileid"] = getContinuationVar('vmprofileid', processInputVar('vmprofileid', ARG_NUMERIC)); $return["showdeleted"] = getContinuationVar('showdeleted', 0); $return['states'] = getContinuationVar('states'); $return['profiles'] = getContinuationVar('profiles', array()); if(! $checks) { return $return; } $ipaddressArr = explode('.', $return["ipaddress"]); if(! preg_match('/^(([0-9]){1,3}\.){3}([0-9]){1,3}$/', $return["ipaddress"]) || $ipaddressArr[0] < 1 || $ipaddressArr[0] > 255 || $ipaddressArr[1] < 0 || $ipaddressArr[1] > 255 || $ipaddressArr[2] < 0 || $ipaddressArr[2] > 255 || $ipaddressArr[3] < 0 || $ipaddressArr[3] > 255) { $submitErr |= IPADDRERR; $submitErrMsg[IPADDRERR] = "Invalid IP address. Must be w.x.y.z with each of " . "w, x, y, and z being between 1 and 255 (inclusive)"; } $pripaddressArr = explode('.', $return["pripaddress"]); if(strlen($return['pripaddress']) && (! preg_match('/^(([0-9]){1,3}\.){3}([0-9]){1,3}$/', $return["pripaddress"]) || $pripaddressArr[0] < 1 || $pripaddressArr[0] > 255 || $pripaddressArr[1] < 0 || $pripaddressArr[1] > 255 || $pripaddressArr[2] < 0 || $pripaddressArr[2] > 255 || $pripaddressArr[3] < 0 || $pripaddressArr[3] > 255)) { $submitErr |= IPADDRERR2; $submitErrMsg[IPADDRERR2] = "Invalid IP address. Must be w.x.y.z with each of " . "w, x, y, and z being between 1 and 255 (inclusive)"; } if(strlen($return['eth0macaddress']) && ! preg_match('/^(([A-Fa-f0-9]){2}:){5}([A-Fa-f0-9]){2}$/', $return["eth0macaddress"])) { $submitErr |= MACADDRERR2; $submitErrMsg[MACADDRERR2] = "Invalid MAC address. Must be XX:XX:XX:XX:XX:XX " . "with each pair of XX being from 00 to FF (inclusive)"; } if(strlen($return['eth1macaddress']) && ! preg_match('/^(([A-Fa-f0-9]){2}:){5}([A-Fa-f0-9]){2}$/', $return["eth1macaddress"])) { $submitErr |= MACADDRERR; $submitErrMsg[MACADDRERR] = "Invalid MAC address. Must be XX:XX:XX:XX:XX:XX " . "with each pair of XX being from 00 to FF (inclusive)"; } /*if(! ($submitErr & IPADDRERR) && checkForIPaddress($return["ipaddress"], $return["compid"])) { $submitErr |= IPADDRERR; $submitErrMsg[IPADDRERR] = "There is already a computer with this IP address."; }*/ if($return["ram"] < 32 || $return["ram"] > 8388607) { $submitErr |= RAMERR; $submitErrMsg[RAMERR] = "RAM must be between 32 and 8388607"; } if($return["procspeed"] < 500 || $return["procspeed"] > 20000) { $submitErr |= PROCSPEEDERR; $submitErrMsg[PROCSPEEDERR] = "Processor Speed must be between 500 and 20000"; } if(! preg_match('/^[a-zA-Z0-9_][-a-zA-Z0-9_.]{1,35}$/', $return["hostname"])) { $submitErr |= HOSTNAMEERR; $submitErrMsg[HOSTNAMEERR] = "Hostname must be <= 36 characters"; } if(! ($submitErr & HOSTNAMEERR) && checkForHostname($return["hostname"], $return["compid"])) { $submitErr |= HOSTNAMEERR; $submitErrMsg[HOSTNAMEERR] = "There is already a computer with this hostname."; } if($mode != 'viewComputers' && ! validateUserid($return["owner"])) { $submitErr |= OWNERERR; $submitErrMsg[OWNERERR] = "Submitted ID is not valid"; } if($return['type'] != 'blade' && $return['type'] != 'lab' && $return['type'] != 'virtualmachine') $return['type'] = 'blade'; if($return['stateid'] != '' && ! array_key_exists($return['stateid'], $return['states'])) $submitErr |= 1 << 15; if($mode == 'confirmAddComputer' && $return['type'] == 'virtualmachine' && $return['stateid'] != 10) { $submitErr |= VMAVAILERR; $submitErrMsg[VMAVAILERR] = "Virtual machines can only be added in the maintenance state."; } if(! empty($return['vmprofileid']) && ! array_key_exists($return['vmprofileid'], $return['profiles'])) { $keys = array_keys($return['profiles']); $return['vmprofileid'] = array_shift($keys); } $provs = getContinuationVar('provisioning'); if(is_array($provs) && array_key_exists($return['provisioningid'], $provs) && $provs[$return['provisioningid']]['name'] == 'none') $return['deploymode'] = 0; else $return['deploymode'] = 1; return $return; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn processComputerInput2() /// /// \return an array with the following keys:\n /// platforms, schedules, showhostname, shownextimage, showipaddress, showram, /// showstate, showprocnumber, showdepartment, showprocspeed, showplatform, /// shownetwork, showschedule, showcomputerid, showcurrentimage, showtype, /// showprovisioning /// /// \brief processes platforms, schedules, and all of the flags for /// what data to show /// //////////////////////////////////////////////////////////////////////////////// function processComputerInput2() { $return = array(); $return["platforms"] = getContinuationVar('platforms', processInputVar("platforms", ARG_MULTINUMERIC)); $return["schedules"] = getContinuationVar('schedules', processInputVar("schedules", ARG_MULTINUMERIC)); $return["groups"] = getContinuationVar('groups', processInputVar("groups", ARG_MULTINUMERIC)); $return["showhostname"] = getContinuationVar('showhostname', processInputVar("showhostname", ARG_NUMERIC, 0)); $return["shownextimage"] = getContinuationVar('shownextimage', processInputVar("shownextimage", ARG_NUMERIC, 0)); $return["showipaddress"] = getContinuationVar('showipaddress', processInputVar("showipaddress", ARG_NUMERIC, 0)); $return["showram"] = getContinuationVar('showram', processInputVar("showram", ARG_NUMERIC, 0)); $return["showstate"] = getContinuationVar('showstate', processInputVar("showstate", ARG_NUMERIC, 0)); $return["showprocnumber"] = getContinuationVar('showprocnumber', processInputVar("showprocnumber", ARG_NUMERIC, 0)); $return["showdepartment"] = getContinuationVar('showdepartment', processInputVar("showdepartment", ARG_NUMERIC, 0)); $return["showowner"] = getContinuationVar('showowner', processInputVar("showowner", ARG_NUMERIC, 0)); $return["showprocspeed"] = getContinuationVar('showprocspeed', processInputVar("showprocspeed", ARG_NUMERIC, 0)); $return["showplatform"] = getContinuationVar('showplatform', processInputVar("showplatform", ARG_NUMERIC, 0)); $return["shownetwork"] = getContinuationVar('shownetwork', processInputVar("shownetwork", ARG_NUMERIC, 0)); $return["showschedule"] = getContinuationVar('showschedule', processInputVar("showschedule", ARG_NUMERIC, 0)); $return["showcomputerid"] = getContinuationVar('showcomputerid', processInputVar("showcomputerid", ARG_NUMERIC, 0)); $return["showcurrentimage"] = getContinuationVar('showcurrentimage', processInputVar("showcurrentimage", ARG_NUMERIC, 0)); $return["showtype"] = getContinuationVar('showtype', processInputVar("showtype", ARG_NUMERIC, 0)); $return["showprovisioning"] = getContinuationVar('showprovisioning', processInputVar("showprovisioning", ARG_NUMERIC, 0)); $return["shownotes"] = getContinuationVar('shownotes', processInputVar("shownotes", ARG_NUMERIC, 0)); $return["showcounts"] = getContinuationVar('showcounts', processInputVar("showcounts", ARG_NUMERIC, 0)); $return["showlocation"] = getContinuationVar('showlocation', processInputVar("showlocation", ARG_NUMERIC, 0)); return $return; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn processComputerInput3() /// /// \return an array with the following indexes:\n /// notes, imageid, stateid, computerids /// /// \brief processes input for computer utilities pages /// //////////////////////////////////////////////////////////////////////////////// function processComputerInput3() { global $submitErr, $submitErrMsg; $compids = getContinuationVar("computerids", processInputVar('computerids', ARG_MULTINUMERIC)); $return['notes'] = getContinuationVar("notes", processInputVar('notes', ARG_STRING)); $return['imageid'] = getContinuationVar("imageid", processInputVar('imageid', ARG_NUMERIC)); $return['stateid'] = getContinuationVar("stateid", processInputVar('stateid', ARG_NUMERIC)); $return['scheduleid'] = getContinuationVar("scheduleid", processInputVar('scheduleid', ARG_NUMERIC)); $resources = getUserResources(array("computerAdmin"), array("administer")); $userCompIDs = array_keys($resources["computer"]); $remove = array_diff($compids, $userCompIDs); $return['computerids'] = array_diff($compids, $remove); return $return; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn processBulkComputerInput($checks) /// /// \param $checks - (optional) 1 to perform validation, 0 not to /// /// \return an array with the following indexes:\n /// startipaddress, endipaddress, starthostval, endhostval, stateid, /// platformid, scheduleid, ram, numprocs, procspeed, network, /// hostname, type, count (0 if any errors found) /// /// \brief validates input from the previous form; if anything was improperly /// submitted, sets submitErr and submitErrMsg /// //////////////////////////////////////////////////////////////////////////////// function processBulkComputerInput($checks=1) { global $submitErr, $submitErrMsg; $return = processComputerInput2(); $ipaddress = getContinuationVar("ipaddress", processInputVar("ipaddress", ARG_STRING, NULL, 1)); if(! empty($ipaddress)) { $return["startipaddress"] = $ipaddress; $tmp = $ipaddress; $tmpArr = explode('.', $tmp); array_pop($tmpArr); $return["endipaddress"] = implode('.', $tmpArr); $return["starthostval"] = ""; $return["endhostval"] = ""; } else { $return["startipaddress"] = getContinuationVar("startipaddress", processInputVar("startipaddress", ARG_STRING, NULL, 1)); $return["endipaddress"] = getContinuationVar("endipaddress", processInputVar("endipaddress", ARG_STRING, NULL, 1)); $return["starthostval"] = getContinuationVar("starthostval", processInputVar("starthostval", ARG_NUMERIC, NULL, 1)); $return["endhostval"] = getContinuationVar("endhostval", processInputVar("endhostval", ARG_NUMERIC, NULL, 1)); } $return["startpripaddress"] = getContinuationVar("startpripaddress", processInputVar("startpripaddress", ARG_STRING, NULL, 1)); $return["endpripaddress"] = getContinuationVar("endpripaddress", processInputVar("endpripaddress", ARG_STRING, NULL, 1)); $return["startmac"] = getContinuationVar("startmac", processInputVar("startmac", ARG_STRING, NULL, 1)); $return["stateid"] = getContinuationVar("stateid", processInputVar("stateid", ARG_NUMERIC)); $return["owner"] = getContinuationVar("owner", processInputVar("owner", ARG_STRING, NULL, 1)); $return["platformid"] = getContinuationVar("platformid", processInputVar("platformid", ARG_NUMERIC)); $return["scheduleid"] = getContinuationVar("scheduleid", processInputVar("scheduleid", ARG_NUMERIC)); $return["ram"] = getContinuationVar("ram", processInputVar("ram", ARG_NUMERIC, NULL, 1)); $return["numprocs"] = getContinuationVar("numprocs", processInputVar("numprocs", ARG_NUMERIC, 1)); $return["procspeed"] = getContinuationVar("procspeed", processInputVar("procspeed", ARG_NUMERIC, NULL, 1)); $return["network"] = getContinuationVar("network", processInputVar("network", ARG_NUMERIC, 1000)); $return["hostname"] = getContinuationVar("hostname", processInputVar("hostname", ARG_STRING, NULL, 1)); $return["type"] = getContinuationVar("type", processInputVar("type", ARG_STRING, 'blade')); $return["provisioningid"] = getContinuationVar("provisioningid", processInputVar("provisioningid", ARG_NUMERIC)); $return["location"] = getContinuationVar("location", processInputVar("location", ARG_STRING)); $return["computergroup"] = getContinuationVar("computergroup", processInputVar("computergroup", ARG_MULTINUMERIC)); $return['macs'] = getContinuationVar('macs', array()); $return["vmprofileid"] = getContinuationVar("vmprofileid", processInputVar("vmprofileid", ARG_NUMERIC)); $return["profiles"] = getContinuationVar("profiles", array()); if(! $checks) { return $return; } $startaddrArr = explode('.', $return["startipaddress"]); if(! preg_match('/^(([0-9]){1,3}\.){3}([0-9]){1,3}$/', $return["startipaddress"]) || $startaddrArr[0] < 1 || $startaddrArr[0] > 255 || $startaddrArr[1] < 0 || $startaddrArr[1] > 255 || $startaddrArr[2] < 0 || $startaddrArr[2] > 255 || $startaddrArr[3] < 1 || $startaddrArr[3] > 255) { $submitErr |= IPADDRERR; $submitErrMsg[IPADDRERR] = "Invalid IP address. Must be w.x.y.z with each of " . "w, x, y, and z being between 1 and 255 (inclusive)"; } $endaddrArr = explode('.', $return["endipaddress"]); if(! preg_match('/^(([0-9]){1,3}\.){3}([0-9]){1,3}$/', $return["endipaddress"]) || $endaddrArr[0] < 1 || $endaddrArr[0] > 255 || $endaddrArr[1] < 0 || $endaddrArr[1] > 255 || $endaddrArr[2] < 0 || $endaddrArr[2] > 255 || $endaddrArr[3] < 1 || $endaddrArr[3] > 255) { $submitErr |= IPADDRERR2; $submitErrMsg[IPADDRERR2] = "Invalid IP address. Must be w.x.y.z with each of " . "w, x, y, and z being between 1 and 255 (inclusive)"; } $endpraddrArr = array(); if(! empty($return['startpripaddress']) || ! empty($return['endpripaddress'])) { $startpraddrArr = explode('.', $return["startpripaddress"]); if(! preg_match('/^(([0-9]){1,3}\.){3}([0-9]){1,3}$/', $return["startpripaddress"]) || $startpraddrArr[0] < 1 || $startpraddrArr[0] > 255 || $startpraddrArr[1] < 0 || $startpraddrArr[1] > 255 || $startpraddrArr[2] < 0 || $startpraddrArr[2] > 255 || $startpraddrArr[3] < 1 || $startpraddrArr[3] > 255) { $submitErr |= IPADDRERR3; $submitErrMsg[IPADDRERR3] = "Invalid IP address. Must be w.x.y.z with each of " . "w, x, y, and z being between 1 and 255 (inclusive)"; } $endpraddrArr = explode('.', $return["endpripaddress"]); if(! preg_match('/^(([0-9]){1,3}\.){3}([0-9]){1,3}$/', $return["endpripaddress"]) || $endpraddrArr[0] < 1 || $endpraddrArr[0] > 255 || $endpraddrArr[1] < 0 || $endpraddrArr[1] > 255 || $endpraddrArr[2] < 0 || $endpraddrArr[2] > 255 || $endpraddrArr[3] < 1 || $endpraddrArr[3] > 255) { $submitErr |= IPADDRERR4; $submitErrMsg[IPADDRERR4] = "Invalid IP address. Must be w.x.y.z with each of " . "w, x, y, and z being between 1 and 255 (inclusive)"; } } if(! empty($return['startmac'])) { if(! preg_match('/^(([A-Fa-f0-9]){2}:){5}([A-Fa-f0-9]){2}$/', $return["startmac"])) { $submitErr |= MACADDRERR; $submitErrMsg[MACADDRERR] = "Invalid MAC address. Must be XX:XX:XX:XX:XX:XX " . "with each pair of XX being from 00 to FF (inclusive)"; } elseif(! $submitErr) { $tmp = explode(':', $return['startmac']); $topdec = hexdec($tmp[0] . $tmp[1] . $tmp[2]); $botdec = hexdec($tmp[3] . $tmp[4] . $tmp[5]); $topmac = "{$tmp[0]}:{$tmp[1]}:{$tmp[2]}"; $topplus = implode(':', str_split(dechex($topdec + 1), 2)); $start = $botdec; $return['macs'] = array(); $eth0macs = array(); $eth1macs = array(); $toggle = 0; $end = $start + (($endaddrArr[3] - $startaddrArr[3] + 1) * 2); for($i = $start; $i < $end; $i++) { if($i > 16777215) { $val = $i - 16777216; $tmp = sprintf('%06x', $val); $tmp2 = str_split($tmp, 2); $return['macs'][] = $topplus . ':' . implode(':', $tmp2); } else { $tmp = sprintf('%06x', $i); $tmp2 = str_split($tmp, 2); $return['macs'][] = $topmac . ':' . implode(':', $tmp2); } if($toggle % 2) $eth1macs[] = $topmac . ':' . implode(':', $tmp2); else $eth0macs[] = $topmac . ':' . implode(':', $tmp2); $toggle++; } $ineth0s = implode("','", $eth0macs); $ineth1s = implode("','", $eth1macs); $query = "SELECT id " . "FROM computer " . "WHERE eth0macaddress IN ('$ineth0s') OR " . "eth1macaddress IN ('$ineth1s')"; $qh = doQuery($query); if(mysql_num_rows($qh)) { $submitErr |= MACADDRERR; $submitErrMsg[MACADDRERR] = "The specified starting MAC address " . "combined with the number of computers " . "entered will result in a MAC address " . "already assigned to another computer."; } elseif($i > 16777215 && $topdec == 16777215) { $submitErr |= MACADDRERR; $submitErrMsg[MACADDRERR] = "Starting MAC address too large for given " . "given number of machines"; } } } if($return["ram"] < 32 || $return["ram"] > 512000) { $submitErr |= RAMERR; $submitErrMsg[RAMERR] = "RAM must be between 32 and 512000"; } if($return["procspeed"] < 500 || $return["procspeed"] > 20000) { $submitErr |= PROCSPEEDERR; $submitErrMsg[PROCSPEEDERR] = "Processor Speed must be between 500 and 20000"; } if(! preg_match('/^[a-zA-Z0-9_%][-a-zA-Z0-9_.%]{1,35}$/', $return["hostname"])) { $submitErr |= HOSTNAMEERR; $submitErrMsg[HOSTNAMEERR] = "Hostname must be <= 36 characters"; } if(! ($submitErr & HOSTNAMEERR)) { $checkhosts = array(); for($i = $return["starthostval"]; $i <= $return["endhostval"]; $i++) { $checkhosts[] = str_replace('%', $i, $return["hostname"]); } $allhosts = implode("','", $checkhosts); $query = "SELECT hostname FROM computer " . "WHERE hostname IN ('$allhosts')"; $qh = doQuery($query); $exists = array(); while($row = mysql_fetch_assoc($qh)) $exists[] = $row['hostname']; if(count($exists)) { $hosts = implode(', ', $exists); $submitErr |= HOSTNAMEERR; $submitErrMsg[HOSTNAMEERR] = "There are already computers with these hostnames: $hosts"; } } if(empty($return["starthostval"]) && $return["starthostval"] != 0) { $submitErr |= STARTHOSTVALERR; $submitErrMsg[STARTHOSTVALERR] = "Start value can only be numeric."; } if(empty($return["endhostval"]) && $return["endhostval"] != 0) { $submitErr |= ENDHOSTVALERR; $submitErrMsg[ENDHOSTVALERR] = "End value can only be numeric."; } if(! ($submitErr & IPADDRERR2 || $submitErr & ENDHOSTVALERR) && ($endaddrArr[3] - $startaddrArr[3] != $return["endhostval"] - $return["starthostval"])) { $numipaddrs = $endaddrArr[3] - $startaddrArr[3] + 1; $numhostnames = $return["endhostval"] - $return["starthostval"] + 1; $submitErr |= IPADDRERR2; $submitErrMsg[IPADDRERR2] = "The number of IP addresses ($numipaddrs) " . "does not match the number of hostnames ($numhostnames)."; $submitErr |= ENDHOSTVALERR; $submitErrMsg[ENDHOSTVALERR] = $submitErrMsg[IPADDRERR2]; } if(! empty($return['startpripaddress']) && ! empty($return['endpripaddress']) && (! ($submitErr & IPADDRERR4) && ! empty($endpraddrArr) && ($return["endhostval"] - $return["starthostval"] != $endpraddrArr[3] - $startpraddrArr[3]))) { $numpraddrs = $endpraddrArr[3] - $startpraddrArr[3] + 1; $numhostnames = $return["endhostval"] - $return["starthostval"] + 1; $submitErr |= IPADDRERR4; $submitErrMsg[IPADDRERR4] = "The number of private IP addresses ($numpraddrs) " . "does not match the number of hostnames ($numhostnames)."; if(! ($submitErr & ENDHOSTVALERR)) { $submitErr |= ENDHOSTVALERR; $submitErrMsg[ENDHOSTVALERR] = $submitErrMsg[IPADDRERR4]; } } if(! empty($return['vmprofileid']) && ! array_key_exists($return['vmprofileid'], $return['profiles'])) { $keys = array_keys($return['profiles']); $return['vmprofileid'] = array_shift($keys); } if(! validateUserid($return["owner"])) { $submitErr |= OWNERERR; $submitErrMsg[OWNERERR] = "Submitted ID is not valid"; } $return['count'] = 0; if(! $submitErr) $return['count'] = $endaddrArr[3] - $startaddrArr[3] + 1; return $return; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn checkForHostname($hostname, $compid) /// /// \param $hostname - a computer hostname /// \param $compid - a computer id to ignore /// /// \return 1 if $hostname is already in the computer table, 0 if not /// /// \brief checks for $hostname being somewhere in the computer table except /// for $compid /// //////////////////////////////////////////////////////////////////////////////// function checkForHostname($hostname, $compid) { $query = "SELECT id FROM computer " . "WHERE hostname = '$hostname'"; if(! empty($compid)) $query .= " AND id != $compid"; $qh = doQuery($query, 101); if(mysql_num_rows($qh)) return 1; return 0; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn checkForIPaddress($ipaddress, $compid) /// /// \param $ipaddress - a computer ip address /// \param $compid - a computer id to ignore /// /// \return 1 if $ipaddress is already in the computer table, 0 if not /// /// \brief checks for $ipaddress being somewhere in the computer table except /// for $compid /// //////////////////////////////////////////////////////////////////////////////// function checkForIPaddress($ipaddress, $compid) { $query = "SELECT id FROM computer " . "WHERE IPaddress = '$ipaddress'"; if(! empty($compid)) $query .= " AND id != $compid"; $qh = doQuery($query, 101); if(mysql_num_rows($qh)) return 1; return 0; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn getCompIdList($groups) /// /// \param $groups - an array of computer group ids /// /// \return an array where each key is a computer id and each value is 1 /// /// \brief builds a list of computer ids that are either in $groups or are not /// in any groups but owned by the logged in user /// //////////////////////////////////////////////////////////////////////////////// function getCompIdList($groups) { global $user; $inlist = implode(',', $groups); $query = "SELECT DISTINCT r.subid as compid " . "FROM resource r, " . "resourcegroupmembers rgm " . "WHERE r.id = rgm.resourceid AND " . "rgm.resourcegroupid IN ($inlist)"; $qh = doQuery($query, 101); $compidlist = array(); while($row = mysql_fetch_assoc($qh)) $compidlist[$row['compid']] = 1; $query = "SELECT id " . "FROM computer " . "WHERE ownerid = {$user['id']} AND " . "id NOT IN (SELECT r.subid " . "FROM resource r, " . "resourcegroupmembers rgm " . "WHERE r.id = rgm.resourceid AND " . "r.resourcetypeid = 12)"; $qh = doQuery($query, 101); while($row = mysql_fetch_assoc($qh)) $compidlist[$row['id']] = 1; return $compidlist; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn updateComputer($data) /// /// \param $data - an array with the following indexes:\n /// ipaddress, stateid, platformid, scheduleid, /// ram, numprocs, procspeed, network, hostname, compid, type /// /// \return number of rows affected by the update\n /// \b NOTE: mysql reports that no rows were affected if none of the fields /// were actually changed even if the update matched a row /// /// \brief performs a query to update the computer with data from $data /// //////////////////////////////////////////////////////////////////////////////// function updateComputer($data) { $ownerid = getUserlistID($data['owner']); if($data['eth0macaddress'] == '') $eth0 = 'NULL'; else $eth0 = "'{$data['eth0macaddress']}'"; if($data['eth1macaddress'] == '') $eth1 = 'NULL'; else $eth1 = "'{$data['eth1macaddress']}'"; if($data['pripaddress'] == '') $privateip = 'NULL'; else $privateip = "'{$data['pripaddress']}'"; if($data['location'] == '') $location = 'NULL'; else { $location = $data['location']; if(get_magic_quotes_gpc()) $location = stripslashes($location); $location = mysql_real_escape_string($location); $location = "'$location'"; } $query = "UPDATE computer " . "SET ownerid = $ownerid, "; if(array_key_exists('stateid', $data)) $query .= "stateid = {$data['stateid']}, "; $query .= "platformid = {$data['platformid']}, " . "scheduleid = {$data['scheduleid']}, " . "RAM = {$data['ram']}, " . "procnumber = {$data['numprocs']}, " . "procspeed = {$data['procspeed']}, " . "network = {$data['network']}, " . "hostname = '{$data['hostname']}', " . "IPaddress = '{$data['ipaddress']}', " . "privateIPaddress = $privateip, " . "eth0macaddress = $eth0, " . "eth1macaddress = $eth1, " . "type = '{$data['type']}', " . "provisioningid = {$data['provisioningid']}, " . "notes = '{$data['notes']}', " . "location = $location " . "WHERE id = {$data['compid']}"; $qh = doQuery($query, 185); return mysql_affected_rows($GLOBALS['mysql_link_vcl']); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn addComputer($data) /// /// \param $data - an array with the following indexes:\n /// ipaddress, stateid, platformid, scheduleid, /// ram, numprocs, procspeed, network, hostname, type /// /// \brief adds a computer to the computer table /// //////////////////////////////////////////////////////////////////////////////// function addComputer($data) { global $user; $ownerid = getUserlistID($data['owner']); if($data['stateid'] == 10) { $now = unixToDatetime(time()); $notes = "'{$user['unityid']} $now@in maintenance state when added to database'"; } else $notes = 'NULL'; if($data['eth0macaddress'] == '') $eth0 = 'NULL'; else $eth0 = "'{$data['eth0macaddress']}'"; if($data['eth1macaddress'] == '') $eth1 = 'NULL'; else $eth1 = "'{$data['eth1macaddress']}'"; if($data['pripaddress'] == '') $privateip = 'NULL'; else $privateip = "'{$data['pripaddress']}'"; if($data['location'] == '') $location = 'NULL'; else { $location = $data['location']; if(get_magic_quotes_gpc()) $location = stripslashes($location); $location = mysql_real_escape_string($location); $location = "'$location'"; } $noimageid = getImageId('noimage'); $noimagerevisionid = getProductionRevisionid($noimageid); $query = "INSERT INTO computer " . "(stateid, " . "ownerid, " . "platformid, " . "scheduleid, " . "currentimageid, " . "imagerevisionid, " . "RAM, " . "procnumber, " . "procspeed, " . "network, " . "hostname, " . "IPaddress, " . "privateIPaddress, " . "eth0macaddress, " . "eth1macaddress, " . "type, " . "notes, " . "provisioningid, " . "location) " . "VALUES ({$data['stateid']}, " . "$ownerid, " . "{$data['platformid']}, " . "{$data['scheduleid']}, " . "$noimageid, " . "$noimagerevisionid, " . "{$data['ram']}, " . "{$data['numprocs']}, " . "{$data['procspeed']}, " . "{$data['network']}, " . "'{$data['hostname']}', " . "'{$data['ipaddress']}', " . "$privateip, " . "$eth0, " . "$eth1, " . "'{$data['type']}', " . "$notes, " . "'{$data['provisioningid']}', " . "$location)"; doQuery($query, 195); $compid = dbLastInsertID(); $query = "INSERT INTO resource " . "(resourcetypeid, " . "subid) " . "VALUES (12, " . "$compid)"; doQuery($query, 198); $resid = dbLastInsertID(); // add computer into selected groups if(! empty($data['computergroup'])) { $vals = array(); foreach(array_keys($data['computergroup']) as $groupid) $vals[] = "($resid, $groupid)"; $allvals = implode(',', $vals); $query = "INSERT INTO resourcegroupmembers " . "(resourceid, " . "resourcegroupid) " . "VALUES $allvals"; doQuery($query, 101); } if($data['stateid'] == 20) { # create vmhost entry $query = "INSERT INTO vmhost " . "(computerid, " . "vmlimit, " . "vmprofileid) " . "VALUES ($compid, " . "2, " . "{$data['vmprofileid']})"; doQuery($query, 101); } } //////////////////////////////////////////////////////////////////////////////// /// /// \fn printComputerInfo($pripaddress, $ipaddress, $eth0macaddress, /// $eth1macaddress, $stateid, $owner, $platformid, /// $scheduleid, $currentimgid, $ram, $numprocs, /// $procspeed, $network, $hostname, $compid, $type, /// $provisioningid, $location, $vmprofileid='', /// $deploymode='') /// /// \param $pripaddress - private IP address of computer /// \param $ipaddress - public IP address of computer /// \param $eth0macaddress - private MAC address /// \param $eth1macaddress - public MAC address /// \param $stateid - stateid of computer /// \param $owner - owner of computer /// \param $platformid - platformid of computer /// \param $scheduleid - scheduleid of computer /// \param $currentimgid - current imageid of computer /// \param $ram - ram in MB of computer /// \param $numprocs - number of processors in computer /// \param $procspeed - processor speed of computer /// \param $network - network speed of computer's NIC in MBbps /// \param $hostname - hostname of computer /// \param $compid - id of computer from computer table /// \param $type - type of computer (blade or lab) /// \param $provisioningid - id of provisioning engine /// \param $location - location of computer /// \param $vmprofileid - (optional) id of vmprofile if node is in vmhostinuse /// state /// \param $deploymode - (optional) 0 to print that node will be manually /// installed with hypervisor, 1 to print that it will be automatically /// installed /// /// \brief prints a table of information about the computer /// //////////////////////////////////////////////////////////////////////////////// function printComputerInfo($pripaddress, $ipaddress, $eth0macaddress, $eth1macaddress, $stateid, $owner, $platformid, $scheduleid, $currentimgid, $ram, $numprocs, $procspeed, $network, $hostname, $compid, $type, $provisioningid, $location, $vmprofileid='', $deploymode='') { $states = getStates(); $platforms = getPlatforms(); $schedules = getSchedules(); $images = getImages(); $provisioning = getProvisioning(); if(! empty($vmprofileid)) $profiles = getVMProfiles(); print "\n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; if(! empty($vmprofileid)) { print " \n"; print " \n"; print " \n"; print " \n"; } print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; if(! empty($currentimgid)) { print " \n"; print " \n"; print " \n"; print " \n"; } print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; if(! empty($compid)) { print " \n"; print " \n"; print " \n"; print " \n"; } print " \n"; print " \n"; print " \n"; print " \n"; print "
Hostname:$hostname
Type:$type
Public IP Address:$ipaddress
Private IP Address:$pripaddress
Public MAC Address:$eth1macaddress
Private MAC Address:$eth0macaddress
Provisioning Engine:" . $provisioning[$provisioningid]['prettyname'] . "
State:" . $states[$stateid] . "
VM Host Profile:{$profiles[$vmprofileid]['profilename']}
Owner:$owner
Platform:" . $platforms[$platformid] . "
Schedule:" . $schedules[$scheduleid]["name"] . "
Current Image:" . $images[$currentimgid]["prettyname"] . "
RAM (MB):$ram
No. Cores:$numprocs
Processor Speed (MHz):$procspeed
Network Speed (Mbps):$network
Computer ID:$compid
Location:$location
\n"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn getComputerSelection($data) /// /// \param $data - array of data as returned from processComputerInput /// /// \return an array of data to be passed to addContinuationsEntry /// /// \brief returns only the selection data from $data /// //////////////////////////////////////////////////////////////////////////////// function getComputerSelection($data) { $ret = array(); $ret['platforms'] = $data['platforms']; $ret['schedules'] = $data['schedules']; $ret['groups'] = $data['groups']; $keys = array("showhostname", "shownextimage", "showipaddress", "showram", "showstate", "showprocnumber", "showdepartment", "showowner", "showprocspeed", "showplatform", "shownetwork", "showschedule", "showcomputerid", "showcurrentimage", "showtype", "showdeleted", "shownotes", "showcounts", "showprovisioning", "showlocation"); foreach($keys as $key) $ret[$key] = $data[$key]; return $ret; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn jsonCompGroupingComps() /// /// \brief accepts a groupid via form input and prints a json array with 3 /// arrays: an array of computers that are in the group, an array of computers /// not in it, and an array of all computers user has access to /// //////////////////////////////////////////////////////////////////////////////// function jsonCompGroupingComps() { $groupid = processInputVar('groupid', ARG_NUMERIC); $groups = getUserResources(array("computerAdmin"), array("manageGroup"), 1); if(! array_key_exists($groupid, $groups['computer'])) { $arr = array('incomps' => array(), 'outcomps' => array(), 'all' => array()); sendJSON($arr); return; } $resources = getUserResources(array('computerAdmin'), array('manageGroup')); uasort($resources['computer'], 'sortKeepIndex'); $memberships = getResourceGroupMemberships('computer'); $all = array(); $in = array(); $out = array(); foreach($resources['computer'] as $id => $comp) { if(array_key_exists($id, $memberships['computer']) && in_array($groupid, $memberships['computer'][$id])) { $all[] = array('inout' => 1, 'id' => $id, 'name' => $comp); $in[] = array('name' => $comp, 'id' => $id); } else { $all[] = array('inout' => 0, 'id' => $id, 'name' => $comp); $out[] = array('name' => $comp, 'id' => $id); } } $arr = array('incomps' => $in, 'outcomps' => $out, 'all' => $all); sendJSON($arr); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn jsonCompGroupingGroups() /// /// \brief accepts a computer id via form input and prints a json array with 3 /// arrays: an array of groups that the computer is in, an array of groups it /// is not in and an array of all groups user has access to /// //////////////////////////////////////////////////////////////////////////////// function jsonCompGroupingGroups() { $compid = processInputVar('compid', ARG_NUMERIC); $resources = getUserResources(array("computerAdmin"), array("manageGroup")); if(! array_key_exists($compid, $resources['computer'])) { $arr = array('ingroups' => array(), 'outgroups' => array(), 'all' => array()); sendJSON($arr); return; } $groups = getUserResources(array('computerAdmin'), array('manageGroup'), 1); $memberships = getResourceGroupMemberships('computer'); $in = array(); $out = array(); $all = array(); foreach($groups['computer'] as $id => $group) { if(array_key_exists($compid, $memberships['computer']) && in_array($id, $memberships['computer'][$compid])) { $all[] = array('inout' => 1, 'id' => $id, 'name' => $group); $in[] = array('name' => $group, 'id' => $id); } else { $all[] = array('inout' => 0, 'id' => $id, 'name' => $group); $out[] = array('name' => $group, 'id' => $id); } } $arr = array('ingroups' => $in, 'outgroups' => $out, 'all' => $all); sendJSON($arr); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn AJaddCompToGroup() /// /// \brief accepts a groupid and a comma delimited list of computer ids to be /// added to the group; adds them and returns an array of computer ids that were /// added /// //////////////////////////////////////////////////////////////////////////////// function AJaddCompToGroup() { $groupid = processInputVar('id', ARG_NUMERIC); $groups = getUserResources(array("computerAdmin"), array("manageGroup"), 1); if(! array_key_exists($groupid, $groups['computer'])) { $arr = array('comps' => array(), 'addrem' => 1); sendJSON($arr); return; } $resources = getUserResources(array("computerAdmin"), array("manageGroup")); $tmp = processInputVar('listids', ARG_STRING); $tmp = explode(',', $tmp); $compids = array(); foreach($tmp as $id) { if(! is_numeric($id)) continue; if(! array_key_exists($id, $resources['computer'])) { $arr = array('comps' => array(), 'addrem' => 1); sendJSON($arr); return; } $compids[] = $id; } $allcomps = getComputers(); $adds = array(); foreach($compids as $id) { $adds[] = "({$allcomps[$id]['resourceid']}, $groupid)"; } $query = "INSERT IGNORE INTO resourcegroupmembers " . "(resourceid, resourcegroupid) VALUES "; $query .= implode(',', $adds); doQuery($query, 287); $_SESSION['userresources'] = array(); $arr = array('comps' => $compids, 'addrem' => 1); sendJSON($arr); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn AJremCompFromGroup() /// /// \brief accepts a groupid and a comma delimited list of computer ids to be /// removed from the group; removes them and returns an array of computer ids /// that were removed /// //////////////////////////////////////////////////////////////////////////////// function AJremCompFromGroup() { $groupid = processInputVar('id', ARG_NUMERIC); $groups = getUserResources(array("computerAdmin"), array("manageGroup"), 1); if(! array_key_exists($groupid, $groups['computer'])) { $arr = array('comps' => array(), 'addrem' => 0); sendJSON($arr); return; } $resources = getUserResources(array("computerAdmin"), array("manageGroup")); $tmp = processInputVar('listids', ARG_STRING); $tmp = explode(',', $tmp); $compids = array(); foreach($tmp as $id) { if(! is_numeric($id)) continue; if(! array_key_exists($id, $resources['computer'])) { $arr = array('comps' => array(), 'addrem' => 0, 'id' => $id, 'extra' => $resources['computer']); sendJSON($arr); return; } $compids[] = $id; } $allcomps = getComputers(); foreach($compids as $id) { $query = "DELETE FROM resourcegroupmembers " . "WHERE resourceid = {$allcomps[$id]['resourceid']} AND " . "resourcegroupid = $groupid"; doQuery($query, 288); } $_SESSION['userresources'] = array(); $arr = array('comps' => $compids, 'addrem' => 0); sendJSON($arr); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn AJaddGroupToComp() /// /// \brief accepts a computer id and a comma delimited list of group ids that /// the computer should be added to; adds it to them and returns an array of /// groups it was added to /// //////////////////////////////////////////////////////////////////////////////// function AJaddGroupToComp() { $compid = processInputVar('id', ARG_NUMERIC); $resources = getUserResources(array("computerAdmin"), array("manageGroup")); if(! array_key_exists($compid, $resources['computer'])) { $arr = array('groups' => array(), 'addrem' => 1); sendJSON($arr); return; } $groups = getUserResources(array("computerAdmin"), array("manageGroup"), 1); $tmp = processInputVar('listids', ARG_STRING); $tmp = explode(',', $tmp); $groupids = array(); foreach($tmp as $id) { if(! is_numeric($id)) continue; if(! array_key_exists($id, $groups['computer'])) { $arr = array('groups' => array(), 'addrem' => 1); sendJSON($arr); return; } $groupids[] = $id; } $comp = getComputers(0, $compid); $adds = array(); foreach($groupids as $id) { $adds[] = "({$comp[$compid]['resourceid']}, $id)"; } $query = "INSERT IGNORE INTO resourcegroupmembers " . "(resourceid, resourcegroupid) VALUES "; $query .= implode(',', $adds); doQuery($query, 101); $_SESSION['userresources'] = array(); $arr = array('groups' => $groupids, 'addrem' => 1); sendJSON($arr); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn AJremGroupFromComp() /// /// \brief accepts a computer id and a comma delimited list of group ids that /// the computer should be removed from; removes it from them and returns an /// array of groups it was removed from /// //////////////////////////////////////////////////////////////////////////////// function AJremGroupFromComp() { $compid = processInputVar('id', ARG_NUMERIC); $resources = getUserResources(array("computerAdmin"), array("manageGroup")); if(! array_key_exists($compid, $resources['computer'])) { $arr = array('groups' => array(), 'addrem' => 0); sendJSON($arr); return; } $groups = getUserResources(array("computerAdmin"), array("manageGroup"), 1); $tmp = processInputVar('listids', ARG_STRING); $tmp = explode(',', $tmp); $groupids = array(); foreach($tmp as $id) { if(! is_numeric($id)) continue; if(! array_key_exists($id, $groups['computer'])) { $arr = array('groups' => array(), 'addrem' => 0); sendJSON($arr); return; } $groupids[] = $id; } $comp = getComputers(0, $compid); foreach($groupids as $id) { $query = "DELETE FROM resourcegroupmembers " . "WHERE resourceid = {$comp[$compid]['resourceid']} AND " . "resourcegroupid = $id"; doQuery($query, 288); } $_SESSION['userresources'] = array(); $arr = array('groups' => $groupids, 'addrem' => 0); sendJSON($arr); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn AJgenerateUtilData() /// /// \brief generates /etc/hosts or dhcpd.conf and dhcpd.leases for submitted /// computer /// //////////////////////////////////////////////////////////////////////////////// function AJgenerateUtilData() { $mnip = processInputVar('mnip', ARG_STRING); if(empty($mnip)) $method = 'hosts'; else { $method = 'dhcpd'; $octets = explode('.', $mnip); if(! preg_match('/^(([0-9]){1,3}\.){3}([0-9]){1,3}$/', $mnip) || $octets[0] < 1 || $octets[0] > 255 || $octets[1] < 0 || $octets[1] > 255 || $octets[2] < 0 || $octets[2] > 255 || $octets[3] < 0 || $octets[3] > 255) { sendJSON(array('status' => 'error', 'errmsg' => 'invalid IP address submitted')); return; } $hexmnip = sprintf('%02x:%02x:%02x:%02x', $octets[0], $octets[1], $octets[2], $octets[3]); } $dispcompids = getContinuationVar('dispcompids'); $compids = processInputVar('compids', ARG_STRING); if(! preg_match('/[0-9,]*/', $compids)) { sendJSON(array('status' => 'error', 'errmsg' => 'invalid data submitted')); return; } $compids = explode(',', $compids); $others = array_diff($compids, $dispcompids); if(! empty($others)) { $arr = array('status' => 'error', 'errmsg' => 'invalid computer id submitted'); sendJSON($arr); return; } $comps = getComputers(1); $noips = array(); $hosts = ''; $dhcpd = ''; $leases = ''; foreach($compids as $id) { if($method == 'hosts') { if(! empty($comps[$id]['privateIPaddress'])) $hosts .= "{$comps[$id]['privateIPaddress']}\t{$comps[$id]['hostname']}\n"; else $noips[] = $comps[$id]['hostname']; } else { if(! empty($comps[$id]['privateIPaddress']) && ! empty($comps[$id]['eth0macaddress'])) { $tmp = explode('.', $comps[$id]['hostname']); $dhcpd .= "\t\thost {$tmp[0]} {\n"; $dhcpd .= "\t\t\toption host-name \"{$tmp[0]}\";\n"; $dhcpd .= "\t\t\thardware ethernet {$comps[$id]['eth0macaddress']};\n"; $dhcpd .= "\t\t\tfixed-address {$comps[$id]['privateIPaddress']};\n"; $dhcpd .= "\t\t\tfilename \"/tftpboot/pxelinux.0\";\n"; $dhcpd .= "\t\t\toption dhcp-server-identifier $mnip;\n"; $dhcpd .= "\t\t\tnext-server $mnip;\n"; $dhcpd .= "\t\t}\n\n"; $leases .= "host {$tmp[0]} {\n"; $leases .= "\tdynamic;\n"; $leases .= "\thardware ethernet {$comps[$id]['eth0macaddress']};\n"; $leases .= "\tfixed-address {$comps[$id]['privateIPaddress']};\n"; $leases .= "\tsupersede server.ddns-hostname = \"{$tmp[0]}\";\n"; $leases .= "\tsupersede host-name = \"{$tmp[0]}\";\n"; $leases .= "\tif option vendor-class-identifier = \"ScaleMP\" {\n"; $leases .= "\t\tsupersede server.filename = \"vsmp/pxelinux.0\";\n"; $leases .= "\t} else {\n"; $leases .= "\t\tsupersede server.filename = \"pxelinux.0\";\n"; $leases .= "\t}\n"; $leases .= "\tsupersede server.next-server = $hexmnip;\n"; $leases .= "}\n"; } else $noips[] = $comps[$id]['hostname']; } } $h = ''; if(! empty($noips)) { if($method == 'hosts') $h .= "The following computers did not have private IP address entries:
"; else $h .= "The following computers did not have private IP address or private MAC entries:
"; $h .= "
";
		$h .= implode("\n", $noips);
		$h .= "
"; } if(! empty($hosts) && $method == 'hosts') { $h .= "Data to be added to /etc/hosts:
"; $h .= "
$hosts
"; } elseif(! empty($dhcpd) && $method == 'dhcpd') { $h .= "Data to be added to dhcpd.conf:
"; $h .= "
$dhcpd
"; $h .= "Data to be added to dhcpd.leases:
"; $h .= "
$leases
"; } $arr = array('status' => 'success', 'html' => $h); sendJSON($arr); } ?>