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 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"; # by groups $size = count($computergroups); if($size > 13) $size = 13; print "
\n"; printSelectInput("groups[]", $computergroups, -1, 0, 1, '', "size=$size"); 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"; 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"; 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"]) print " \n"; if($data["showcounts"]) print " \n"; $cdata = getComputerSelection($data); $cont = addContinuationsEntry('confirmAddComputer', $cdata); print " \n"; 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"; print " \n"; $count++; } print "
HostnameIP AddressStateOwnerPlatformScheduleCurrent ImageNext ImageRAM(MB)No. ProcessorsProcessor Speed(MHz)Network Speed(Mbps)Computer IDTypeProvisioning EngineDeletedNotesNo. of Reservations
Add Multiple?"; print "\n"; print " \n"; print " "; print "\n"; printSelectInput("stateid", $states, 2); print " \n"; printSelectInput("platformid", $platforms); print " \n"; printSelectInput("scheduleid", $schedules); print " \n"; printSelectInput("numprocs", array("1" => "1", "2" => "2", "4" => "4", "8" => "8")); print " "; print "\n"; printSelectInput("network", array("10" => "10", "100" => "100", "1000" => "1000")); print " \n"; printSelectInput("type", array("blade" => "blade", "lab" => "lab"), "lab"); print " \n"; printSelectInput("provisioningid", $provisioning); print " N/A  
\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"]}
\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; $data2 = processComputerInput2(); $computers = getComputers(); $nocomps = getContinuationVar('nocomps', 0); if($submitErr) { $data = processComputerInput(); } elseif($nocomps) { $data["ipaddress"] = ''; $data["stateid"] = ''; $data["owner"] = ''; $data["platformid"] = ''; $data["scheduleid"] = ''; $data["currentimgid"] = ''; $data["ram"] = ''; $data["numprocs"] = ''; $data["procspeed"] = ''; $data["network"] = ''; $data["hostname"] = ''; $data["type"] = ''; $data["notes"] = ''; $data["computergroup"] = array(); $data["provisioningid"] = ''; } else { $data["compid"] = getContinuationVar("compid"); $id = $data["compid"]; $data["ipaddress"] = $computers[$id]["IPaddress"]; $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"]; } $tmpstates = getStates(); if($data["stateid"]) { $states = array($data["stateid"] => $tmpstates[$data["stateid"]], 2 => "available", 10 => "maintenance"); } else { $states = array(2 => "available", 10 => "maintenance"); } if($state) $states[20] = 'vmhostinuse'; $platforms = getPlatforms(); $tmp = getUserResources(array("scheduleAdmin"), array("manageGroup")); $schedules = $tmp["schedule"]; $allschedules = getSchedules(); $images = getImages(); $provisioning = getProvisioning(); if($state) { print "

Add Computer

\n"; } else { print "

Edit Computer

\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(! $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 " \n"; print " \n"; print " \n"; print "
Hostname:"; printSubmitErr(HOSTNAMEERR); print "
IP Address:"; printSubmitErr(IPADDRERR); print "
State:\n"; printSelectInput("stateid", $states, $data["stateid"]); print " "; printSubmitErr(VMAVAILERR); print "
Owner:"; printSubmitErr(OWNERERR); print "
Platform:\n"; printSelectInput("platformid", $platforms, $data["platformid"]); 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"]); } else printSelectInput("scheduleid", $schedules); print "
Current Image:" . $images[$data["currentimgid"]]["prettyname"] . "
RAM (MB):"; printSubmitErr(RAMERR); print "
No. Processors:\n"; $tmpArr = array("1" => "1", "2" => "2", "4" => "4", "8" => "8"); printSelectInput("numprocs", $tmpArr, $data["numprocs"]); print "
Processor Speed (MHz):"; printSubmitErr(PROCSPEEDERR); print "
Network Speed (Mbps):\n"; $tmpArr = array("10" => "10", "100" => "100", "1000" => "1000"); printSelectInput("network", $tmpArr, $data["network"]); print "
Compter ID:" . $data["compid"] . "
Type:\n"; $tmpArr = array("blade" => "blade", "lab" => "lab", "virtualmachine" => "virtualmachine"); printSelectInput("type", $tmpArr, $data["type"]); print "
Provisioning Engine:\n"; printSelectInput("provisioningid", $provisioning, $data["provisioningid"]); print "
\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"; if($state) { $cont = addContinuationsEntry('confirmAddComputer', $data2, SECINDAY, 0, 1, 1); print " \n"; } else { $data2['currentimgid'] = $data['currentimgid']; $data2['compid'] = $data['compid']; $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; $data = processComputerInput(); if($data["bulk"]) { $submitErr = 0; bulkAddComputer(); return; } if($submitErr) { editOrAddComputer($state); return; } if($state) { $data["currentimgid"] = ""; $data["compid"] = ""; $nextmode = "submitAddComputer"; $title = "Add Computer"; $question = "Submit the following new computer?"; } else { $nextmode = "submitEditComputer"; $title = "Edit Computer"; $question = "Submit the following changes?"; } print "

$title

\n"; print "

$question

\n"; printComputerInfo($data["ipaddress"], $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"]); 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); elseif($state && $data['stateid'] == 20) $cont = addContinuationsEntry('addComputerSetVMHostProfile', $data, SECINDAY, 0); else $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"]); # maintenance to maintenance if($compdata[$data["compid"]]["stateid"] == 10 && $data["stateid"] == 10) { // possibly update notes with new text $testdata = explode('@', $compdata[$data["compid"]]["notes"]); if(count($testdata) != 2) $testdata[1] = ""; if($testdata[1] == $data["notes"]) // don't update the notes field $data["notes"] = $compdata[$data["compid"]]["notes"]; else // update user, timestamp, and text $data["notes"] = $user["unityid"] . " " . unixToDatetime(time()) . "@" . $data["notes"]; } # available or failed to maintenance if(($compdata[$data["compid"]]["stateid"] == 2 || $compdata[$data["compid"]]["stateid"] == 5) && $data["stateid"] == 10) { // set notes to new data $data["notes"] = $user["unityid"] . " " . unixToDatetime(time()) . "@" . $data["notes"]; } # maintenance or failed to available if(($compdata[$data["compid"]]["stateid"] == 10 || $compdata[$data["compid"]]["stateid"] == 5) && $data["stateid"] == 2) { $data["notes"] = ""; } 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(); $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 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 addComputerSetVMHostProfile() /// /// \brief prints a page for user to select a vm host profile for the /// computer(s) /// //////////////////////////////////////////////////////////////////////////////// function addComputerSetVMHostProfile() { $dobulk = getContinuationVar('dobulk', 0); print "
\n"; print "

Add Computer

\n"; print "Select a VM Host Profile to be used on this computer:

\n"; $profiles = getVMProfiles(); print "
\n"; print "

\n"; print "VM Host Profiles can be created/modified under Virtual Hosts

\n"; if($dobulk) { $data = processBulkComputerInput(); $data['profiles'] = $profiles; $cont = addContinuationsEntry('submitAddBulkComputers', $data, SECINDAY, 0, 0); print "\n"; } else { $data = processComputerInput(); $data['profiles'] = $profiles; $cont = addContinuationsEntry('submitAddComputer', $data, SECINDAY, 0, 0); print "\n"; } print "\n"; print "
\n"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn submitAddComputer() /// /// \brief adds a new computer with the submitted information /// //////////////////////////////////////////////////////////////////////////////// function submitAddComputer() { $data = processComputerInput(); addComputer($data); clearPrivCache(); viewComputers(); } //////////////////////////////////////////////////////////////////////////////// /// /// \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]["IPaddress"], $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"]); 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 " . "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, $viewmode; $data = processBulkComputerInput(0); $data2 = processComputerInput2(); //yes, this is somewhat redundant, but it // makes things easier later $states = array("2" => "available", "10" => "maintenance", "20" => "vmhostinuse"); $platforms = getPlatforms(); $tmp = getUserResources(array("scheduleAdmin"), array("manageGroup")); $schedules = $tmp["schedule"]; $images = getImages(); $provisioning = getProvisioning(); 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 "
Hostname*:"; printSubmitErr(HOSTNAMEERR); print "
Start value*:"; printSubmitErr(STARTHOSTVALERR); print "
End value*:"; printSubmitErr(ENDHOSTVALERR); print "
Start IP Address*:"; printSubmitErr(IPADDRERR); print "
End 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 "
State:\n"; printSelectInput("stateid", $states, $data["stateid"]); print "
Owner*:"; printSubmitErr(OWNERERR); print "
Platform:\n"; printSelectInput("platformid", $platforms, $data["platformid"]); print "
Schedule:\n"; printSelectInput("scheduleid", $schedules, $data["scheduleid"]); print "
RAM (MB)*:"; printSubmitErr(RAMERR); print "
No. Processors:\n"; $tmpArr = array("1" => "1", "2" => "2", "4" => "4", "8" => "8"); printSelectInput("numprocs", $tmpArr, $data["numprocs"]); print "
Processor Speed (MHz)*:"; printSubmitErr(PROCSPEEDERR); print "
Network Speed (Mbps):\n"; $tmpArr = array("10" => "10", "100" => "100", "1000" => "1000"); printSelectInput("network", $tmpArr, $data["network"]); print "
Type:\n"; $tmpArr = array("blade" => "blade", "lab" => "lab", "virtualmachine" => "virtualmachine"); printSelectInput("type", $tmpArr, $data["type"]); print "
Provisioning Engine:\n"; printSelectInput("provisioningid", $provisioning, $data["provisioningid"]); print "
\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"; if(! empty($data['startpraddress'])) { 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"; 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
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)
State:" . $states[$data["stateid"]] . "
Owner:" . $data["owner"] . "
Platform:" . $platforms[$data["platformid"]] . "
Schedule:" . $schedules[$data["scheduleid"]]["name"] . "
RAM (MB):" . $data["ram"] . "
No. Processors:" . $data["numprocs"] . "
Processor Speed (MHz):" . $data["procspeed"] . "
Network Speed (Mbps):" . $data["network"] . "
Type:" . $data["type"] . "
Provisioning Engine:" . $provisioning[$data["provisioningid"]]['prettyname'] . "
\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"; if($data['stateid'] == 20) { $data['dobulk'] = 1; $cont = addContinuationsEntry('addComputerSetVMHostProfile', $data, SECINDAY, 0); } else $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; } if($data['stateid'] == 20) { $profileid = processInputVar('profileid', ARG_NUMERIC); $profiles = getContinuationVar('profiles'); if(! array_key_exists($profileid, $profiles)) { $tmp = array_keys($profiles); $profileid = $tmp[0]; } } $dhcpdata = array(); $count = 0; $addedrows = 0; 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, " . "RAM, " . "procnumber, " . "procspeed, " . "network, " . "hostname, " . "IPaddress, "; if($dopr) $query .= "privateIPaddress, "; if($domacs) $query .= "eth0macaddress, " . "eth1macaddress, "; $query .= "type) " . "VALUES ({$data["stateid"]}, " . "$ownerid, " . "{$data["platformid"]}, " . "{$data["provisioningid"]}, " . "{$data["scheduleid"]}, " . "4, " . "{$data["ram"]}, " . "{$data["numprocs"]}, " . "{$data["procspeed"]}, " . "{$data["network"]}, " . "'$hostname', " . "'$ipaddress', "; if($dopr) $query .= "'$pripaddress', "; if($domacs) $query .= "'$eth0', " . "'$eth1', "; $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 $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, " . "$profileid)"; 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"; if($domacs) generateDhcpForm($dhcpdata); clearPrivCache(); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn generateDhcpForm($data) /// /// \brief prints a form for entering an ip address for a management node so /// that data for a dhcpd.conf file can be generated /// //////////////////////////////////////////////////////////////////////////////// function generateDhcpForm($data) { global $submitErr; $mnipaddr = processInputVar('mnipaddr', ARG_STRING, ""); print "
\n"; print "

Generate Data for dhcpd.conf File (Optional)

\n"; print "
\n"; print "Enter the private address for the management node
"; print "on which the data will be used:
\n"; print "\n"; printSubmitErr(IPADDRERR); print "
\n"; print "\n"; $cont = addContinuationsEntry('generateDHCP', $data, SECINDAY, 1, 0); print "\n"; print "
\n"; print "
\n"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn generateDHCP() /// /// \brief prints content for a dhcpd.conf file from saved continuation data /// //////////////////////////////////////////////////////////////////////////////// function generateDHCP() { global $submitErr, $submitErrMsg, $HTMLheader, $printedHTMLheader; $mnipaddr = processInputVar('mnipaddr', ARG_STRING); $data = getContinuationVar(); $addrArr = explode('.', $mnipaddr); if(! preg_match('/^(([0-9]){1,3}\.){3}([0-9]){1,3}$/', $mnipaddr) || $addrArr[0] < 1 || $addrArr[0] > 255 || $addrArr[1] < 0 || $addrArr[1] > 255 || $addrArr[2] < 0 || $addrArr[2] > 255 || $addrArr[3] < 1 || $addrArr[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)"; print $HTMLheader; $printedHTMLheader = 1; generateDhcpForm($data); print getFooter(); return; } header("Content-type: text/plain"); header("Content-Disposition: inline; filename=\"dhcpdata.txt\""); foreach($data as $comp) { $tmp = explode('.', $comp['hostname']); print "\t\thost {$tmp[0]} {\n"; print "\t\t\toption host-name \"{$tmp[0]}\";\n"; print "\t\t\thardware ethernet {$comp['eth0mac']};\n"; print "\t\t\tfixed-address {$comp['prip']};\n"; print "\t\t\tfilename \"/tftpboot/pxelinux.0\";\n"; print "\t\t\toption dhcp-server-identifier $mnipaddr;\n"; print "\t\t\tnext-server $mnipaddr;\n"; print "\t\t}\n\n"; } } //////////////////////////////////////////////////////////////////////////////// /// /// \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; $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; 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"; print " \n"; if($computers[$id]['state'] == 'failed') 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. ProcessorsProcessor 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"); 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 "
Reload selected computers with this image:\n"; printSelectInput("imageid", $resources["image"], -1, 1); print "
Change state of selected computers to:\n"; printSelectInput("stateid", $states); print " "; print "
Change schedule of selected computers to:\n"; printSelectInput("scheduleid", $schedules); print " "; print "
\n"; print "\n"; print "
\n"; print "
$count computers found
\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"; } $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"; } } 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)); $return["stateid"] = getContinuationVar("stateid", processInputVar("stateid", ARG_NUMERIC)); $return["owner"] = getContinuationVar("owner", processInputVar("owner", ARG_STRING)); $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)); $return["numprocs"] = getContinuationVar("numprocs", processInputVar("numprocs", ARG_NUMERIC)); $return["procspeed"] = getContinuationVar("procspeed", processInputVar("procspeed", ARG_NUMERIC)); $return["network"] = getContinuationVar("network", processInputVar("network", ARG_NUMERIC)); $return["hostname"] = getContinuationVar("hostname", processInputVar("hostname", ARG_STRING)); $return["compid"] = getContinuationVar("compid", processInputVar("compid", ARG_NUMERIC)); $return["type"] = getContinuationVar("type", processInputVar("type", ARG_STRING, "lab")); $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["showdeleted"] = getContinuationVar('showdeleted', 0); 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] < 1 || $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)"; } /*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"] > 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) && 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'] == 'virtualmachine' && $return['stateid'] == 2) { $submitErr |= VMAVAILERR; $submitErrMsg[VMAVAILERR] = "Virtual machines can only be added in the maintenance state."; } 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 $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, $viewmode; $return = processComputerInput2(); $ipaddress = getContinuationVar("ipaddress", processInputVar("ipaddress", ARG_STRING)); 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)); $return["endipaddress"] = getContinuationVar("endipaddress", processInputVar("endipaddress", ARG_STRING)); $return["starthostval"] = getContinuationVar("starthostval", processInputVar("starthostval", ARG_NUMERIC)); $return["endhostval"] = getContinuationVar("endhostval", processInputVar("endhostval", ARG_NUMERIC)); } $return["startpripaddress"] = getContinuationVar("startpripaddress", processInputVar("startpripaddress", ARG_STRING)); $return["endpripaddress"] = getContinuationVar("endpripaddress", processInputVar("endpripaddress", ARG_STRING)); $return["startmac"] = getContinuationVar("startmac", processInputVar("startmac", ARG_STRING)); $return["stateid"] = getContinuationVar("stateid", processInputVar("stateid", ARG_NUMERIC)); $return["owner"] = getContinuationVar("owner", processInputVar("owner", ARG_STRING)); $return["platformid"] = getContinuationVar("platformid", processInputVar("platformid", ARG_NUMERIC)); $return["scheduleid"] = getContinuationVar("scheduleid", processInputVar("scheduleid", ARG_NUMERIC)); $return["ram"] = getContinuationVar("ram", processInputVar("ram", ARG_NUMERIC)); $return["numprocs"] = getContinuationVar("numprocs", processInputVar("numprocs", ARG_NUMERIC)); $return["procspeed"] = getContinuationVar("procspeed", processInputVar("procspeed", ARG_NUMERIC)); $return["network"] = getContinuationVar("network", processInputVar("network", ARG_NUMERIC)); $return["hostname"] = getContinuationVar("hostname", processInputVar("hostname", ARG_STRING)); $return["type"] = getContinuationVar("type", processInputVar("type", ARG_STRING)); $return["provisioningid"] = getContinuationVar("provisioningid", processInputVar("provisioningid", ARG_NUMERIC)); $return["computergroup"] = getContinuationVar("computergroup", processInputVar("computergroup", ARG_MULTINUMERIC)); $return['macs'] = getContinuationVar('macs', 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(); $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($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(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] = "The number of IP addresses ($numipaddrs) " . "does not match the number of hostnames ($numhostnames)."; } if($viewmode == ADMIN_DEVELOPER && ! empty($return['startpripaddress']) && ! empty($return['endpripaddress']) && (! ($submitErr & IPADDRERR2 || $submitErr & IPADDRERR4) && ! empty($endpraddrArr) && ($endaddrArr[3] - $startaddrArr[3] != $endpraddrArr[3] - $startpraddrArr[3]))) { $numpubaddrs = $endaddrArr[3] - $startaddrArr[3] + 1; $numpraddrs = $endpraddrArr[3] - $startpraddrArr[3] + 1; $submitErr |= IPADDRERR2; $submitErrMsg[IPADDRERR2] = "The number of public IP addresses ($numpubaddrs) " . "does not match the number of private IP addresses ($numpraddrs)."; $submitErr |= IPADDRERR4; $submitErrMsg[IPADDRERR4] = $submitErrMsg[IPADDRERR2]; } 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"]); $query = "UPDATE computer " . "SET stateid = {$data["stateid"]}, " . "ownerid = $ownerid, " . "platformid = {$data["platformid"]}, " . "scheduleid = {$data["scheduleid"]}, " . "RAM = {$data["ram"]}, " . "procnumber = {$data["numprocs"]}, " . "procspeed = {$data["procspeed"]}, " . "network = {$data["network"]}, " . "hostname = '{$data["hostname"]}', " . "IPaddress = '{$data["ipaddress"]}', " . "type = '{$data["type"]}', " . "provisioningid = {$data["provisioningid"]}, " . "notes = '{$data["notes"]}' " . "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'; $query = "INSERT INTO computer " . "(stateid, " . "ownerid, " . "platformid, " . "scheduleid, " . "currentimageid, " . "RAM, " . "procnumber, " . "procspeed, " . "network, " . "hostname, " . "IPaddress, " . "type, " . "notes, " . "provisioningid) " . "VALUES ({$data["stateid"]}, " . "$ownerid, " . "{$data["platformid"]}, " . "{$data["scheduleid"]}, " . "4, " . "{$data["ram"]}, " . "{$data["numprocs"]}, " . "{$data["procspeed"]}, " . "{$data["network"]}, " . "'{$data["hostname"]}', " . "'{$data["ipaddress"]}', " . "'{$data["type"]}', " . "$notes, " . "'{$data["provisioningid"]}')"; doQuery($query, 195); $compid = dbLastInsertID(); $query = "INSERT INTO resource " . "(resourcetypeid, " . "subid) " . "VALUES (12, " . "$compid)"; doQuery($query, 198); $resid = dbLastInsertID(); // add computer into selected groups $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) { $profileid = processInputVar('profileid', ARG_NUMERIC); $profiles = getContinuationVar('profiles'); if(! array_key_exists($profileid, $profiles)) { $tmp = array_keys($profiles); $profileid = $tmp[0]; } # create vmhost entry $query = "INSERT INTO vmhost " . "(computerid, " . "vmlimit, " . "vmprofileid) " . "VALUES ($compid, " . "2, " . "$profileid)"; doQuery($query, 101); } } //////////////////////////////////////////////////////////////////////////////// /// /// \fn printComputerInfo($ipaddress, $stateid, $owner, $platformid, /// $scheduleid, $currentimgid, $ram, $numprocs, /// $procspeed, $network, $hostname, $compid, $type, /// $provisioningid) /// /// \param $ipaddress - IP address of computer /// \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 /// /// \brief prints a table of information about the computer /// //////////////////////////////////////////////////////////////////////////////// function printComputerInfo($ipaddress, $stateid, $owner, $platformid, $scheduleid, $currentimgid, $ram, $numprocs, $procspeed, $network, $hostname, $compid, $type, $provisioningid) { $states = getStates(); $platforms = getPlatforms(); $schedules = getSchedules(); $images = getImages(); $provisioning = getProvisioning(); 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($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 " \n"; print " \n"; print " \n"; print " \n"; print "
Hostname:$hostname
IP Address:$ipaddress
State:" . $states[$stateid] . "
Owner:$owner
Platform:" . $platforms[$platformid] . "
Schedule:" . $schedules[$scheduleid]["name"] . "
Current Image:" . $images[$currentimgid]["prettyname"] . "
RAM (MB):$ram
No. Processors:$numprocs
Processor Speed (MHz):$procspeed
Network Speed (Mbps):$network
Computer ID:$compid
Type:$type
Provisioning Engine:" . $provisioning[$provisioningid]['prettyname'] . "
\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"); 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()); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($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); print '/*{"items":' . json_encode($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()); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($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); print '/*{"items":' . json_encode($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); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($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); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($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); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($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); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($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']); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($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); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($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); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($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); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($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); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($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); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($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); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($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); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($arr) . '}*/'; } ?>