Manage Management Nodes\n"; print "
\n"; if($mnAdminCnt) { $cont = addContinuationsEntry('viewMgmtnodes'); print "Edit "; print "Management Node Information
\n"; } if($mnGroupCnt) { $cont = addContinuationsEntry('viewMgmtnodeGrouping'); print "Edit "; print "Management Node Grouping
\n"; if($compGroupCnt) { $cont = addContinuationsEntry('viewMgmtnodeMapping'); print "Edit "; print "Management Node Mapping
\n"; } } if($mnAdminCnt || $mnGroupCnt) print "\n"; else { print "You do not have access to manage any management nodes.
\n"; } print "
\n"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn viewMgmtnodes() /// /// \brief prints a page to view management node information /// //////////////////////////////////////////////////////////////////////////////// function viewMgmtnodes() { global $viewmode, $user, $mode; $mgmtnodes = getManagementNodes(); $resources = getUserResources(array("mgmtNodeAdmin"), array("administer")); $userMgmtnodeIDs = array_keys($resources["managementnode"]); $premodules = getPredictiveModules(); print "

Management Node Information

\n"; if($mode == "submitAddMgmtnode") { print "Management node successfully added"; print "

\n"; } elseif($mode == "submitEditMgmtnode") { print "Management node successfully updated"; print "

\n"; } elseif($mode == "submitDeleteMgmtnode") { print "Management node successfully deleted"; print "

\n"; } print "\n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; $cont = addContinuationsEntry('addMgmtNode'); print " \n"; print " \n"; print " \n"; foreach(array_keys($mgmtnodes) as $id) { if(! in_array($id, $userMgmtnodeIDs)) continue; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; if($mgmtnodes[$id]["lastcheckin"] == "") print " \n"; else print " \n"; print " \n"; } print "
HostnameIP addressOwnerStatePredictive Loading ModuleLast Check In
\n"; $mgmtnodestates = array(2 => "available", 1 => "deleted", 10 => "maintenance"); printSelectInput("stateid", $mgmtnodestates); print " \n"; printSelectInput('premoduleid', $premodules); print " N/A
\n"; print "
\n"; $cdata = array('mgmtnodeid' => $id); $cont = addContinuationsEntry('confirmDeleteMgmtnode', $cdata); print " \n"; print " \n"; print "
\n"; print "
\n"; print "
\n"; $cdata = array('mgmtnodeid' => $id); $cont = addContinuationsEntry('editMgmtNode', $cdata); print " \n"; print " \n"; print "
\n"; print "
{$mgmtnodes[$id]["hostname"]}{$mgmtnodes[$id]["IPaddress"]}{$mgmtnodes[$id]["owner"]}{$mgmtnodes[$id]["state"]}{$mgmtnodes[$id]["predictivemodule"]}never" . $mgmtnodes[$id]["lastcheckin"] . "
\n"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn editOrAddMgmtnode($state) /// /// \param $state - 0 for edit, 1 for add /// /// \brief prints a form for editing an image /// //////////////////////////////////////////////////////////////////////////////// function editOrAddMgmtnode($state) { global $submitErr; $mgmtnodes = getManagementNodes(); $premodules = getPredictiveModules(); if($submitErr || $state == 1) { $data = processMgmtnodeInput(0); } else { $data["mgmtnodeid"] = getContinuationVar("mgmtnodeid"); $id = $data["mgmtnodeid"]; $data["hostname"] = $mgmtnodes[$id]["hostname"]; $data["IPaddress"] = $mgmtnodes[$id]["IPaddress"]; $data["owner"] = $mgmtnodes[$id]["owner"]; $data["stateid"] = $mgmtnodes[$id]["stateid"]; $data["premoduleid"] = $mgmtnodes[$id]["predictivemoduleid"]; $data["checkininterval"] = $mgmtnodes[$id]["checkininterval"]; $data["installpath"] = $mgmtnodes[$id]["installpath"]; if($mgmtnodes[$id]['imagelibenable']) $data['imagelibenable'] = "checked"; else $data['imagelibenable'] = ""; $data['imagelibgroupid'] = $mgmtnodes[$id]['imagelibgroupid']; $data['imagelibuser'] = $mgmtnodes[$id]['imagelibuser']; $data['imagelibkey'] = $mgmtnodes[$id]['imagelibkey']; $data['keys'] = $mgmtnodes[$id]['keys']; $data['sshport'] = $mgmtnodes[$id]['sshport']; $data['publicIPconfig'] = $mgmtnodes[$id]['publicIPconfig']; $data['publicnetmask'] = $mgmtnodes[$id]['publicnetmask']; $data['publicgateway'] = $mgmtnodes[$id]['publicgateway']; $data['publicdnsserver'] = $mgmtnodes[$id]['publicdnsserver']; $data['sysadminemail'] = $mgmtnodes[$id]['sysadminemail']; $data['sharedmailbox'] = $mgmtnodes[$id]['sharedmailbox']; } $disabled = ''; if(! $data['imagelibenable']) $disabled = 'disabled'; $disabled2 = ''; if($data['publicIPconfig'] != 'static') $disabled2 = 'disabled'; print "
\n"; print "
\n"; if($state) { print "

Add Management Node

\n"; } else { print "

Edit Management Node

\n"; } print "\n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; # sysadmin email print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; # shared mailbox print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; # checkininterval print " \n"; print " \n"; print " \n"; print " \n"; # installpath print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; # keys print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; # sshport print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; # imagelibenable print " \n"; print " \n"; print " \n"; print " \n"; # imagelibgroupid print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; # imagelibuser print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; # imagelibkey print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; # publicIPconfig print " \n"; print " \n"; print " \n"; print " \n"; # public netmask print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; # public gateway print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; # public dnsserver print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print "
Hostname:"; printSubmitErr(MNHOSTNAMEERR); print "
IP address:"; printSubmitErr(IPADDRESSERR); print "
Owner:"; printSubmitErr(MNOWNERERR); print "
State:\n"; $mgmtnodestates = array(2 => "available", 1 => "deleted", 10 => "maintenance", 5 => "failed"); printSelectInput("stateid", $mgmtnodestates, $data["stateid"]); print "
SysAdmin Email Address(es):"; print ""; printSubmitErr(MNSYSADMINEMAILERR); print "
Address for Shadow Emails:"; print ""; printSubmitErr(MNSHAREDMAILBOXERR); print "
Predictive Loading Module:\n"; printSelectInput("premoduleid", $premodules, $data["premoduleid"]); print " \n"; print "
Check-in Interval (sec):\n"; print " \n"; print " \n"; print "
Install Path:"; print ""; printSubmitErr(MNINSTPATHERR); print "
End Node SSH Identity Key Files:"; print ""; printSubmitErr(MNSSHIDKEYSERR); print "
SSH Port for this node:\n"; print " \n"; print " \n"; print " "; printSubmitErr(MNSSHPORTERR); print "
Enable Image Library:"; else print "id=imagelibenable>"; print "
Image Library Management Node Group:"; $mgmtnodegroups = getUserResources(array('mgmtNodeAdmin'), array("manageGroup"), 1); printSelectInput("imagelibgroupid", $mgmtnodegroups['managementnode'], $data['imagelibgroupid'], 0, 0, 'imagelibgroupid', $disabled); print " \n"; print " "; printSubmitErr(MNIMGLIBGRPIDERR); print "
Image Library User:"; print ""; printSubmitErr(MNIMGLIBUSERERR); print "
Image Library SSH Identity Key File:"; print ""; printSubmitErr(MNIMGLIBKEYERR); print "
Public NIC configuration method:"; $publicipconfigs = array('dynamicDHCP' => 'Dynamic DHCP', 'manualDHCP' => 'Manual DHCP', 'static' => 'Static'); printSelectInput("publicIPconfig", $publicipconfigs, $data['publicIPconfig'], 0, 0, 'publicIPconfig', "onChange=\"togglePublic();\""); print " \n"; print "
Public Netmask:"; print ""; printSubmitErr(MNPUBLICNETMASKERR); print "
Public Gateway:"; print ""; printSubmitErr(MNPUBLICGATEWAYERR); print "
Public DNS Server:"; print ""; printSubmitErr(MNPUBLICDNSSERVERERR); print "
\n"; print "\n"; print " \n"; print " \n"; print " \n"; print " \n"; print "
\n"; if($state) { $cdata = array('mgmtgroups' => $mgmtnodegroups['managementnode'], 'publicipconfigs' => $publicipconfigs); $cont = addContinuationsEntry('confirmAddMgmtnode', $cdata, SECINDAY, 0, 1, 1); print " \n"; print " \n"; } else { $cdata = array('mgmtnodeid' => $data['mgmtnodeid'], 'mgmtgroups' => $mgmtnodegroups['managementnode'], 'publicipconfigs' => $publicipconfigs); $cont = addContinuationsEntry('confirmEditMgmtnode', $cdata, SECINDAY, 0, 1, 1); print " \n"; print " \n"; } print " \n"; print " \n"; print "
\n"; $cont = addContinuationsEntry('viewMgmtnodes'); print " \n"; print " \n"; print "
\n"; print "
\n"; print "
\n"; # tooltips print << Comma delimited list of email addresses for sysadmins
who should receive error emails from this management
node. Leave empty to disable this feature.
Single email address to which copies of all user
emails should be sent. This is a high traffic set
of emails. Leave empty to disable this feature.
This is the method used to determine which image should
be loaded on a computer at the end of a reservation.
the number of seconds that this management node
will wait before checking the database for tasks.
path to parent directory of image repository
directories (typically /install) - only needed
with bare metal installs or VMWare with local disk
comma delimited list of full paths to ssh identity
keys to try when connecting to end nodes (optional)
SSH port this node is listening on for image file transfers
Enable sharing of images between management nodes. This allows
a management node to attempt fetching files for a requested
image from other management nodes if it does not have them.
This management node will try to get image
files from other nodes in the selected group.
userid to use for scp when copying image
files from another management node
path to ssh identity key file to use for scp when
copying image files from another management node
Method by which public NIC on nodes controlled by
this management node recive their network configuration
Netmask for public NIC
IP address of gateway for public NIC
comma delimited list of IP addresses of DNS servers for public network
END; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn confirmEditOrAddMgmtnode($state) /// /// \param $state - 0 for edit, 1 for add /// /// \brief prints a form for confirming changes to an image /// //////////////////////////////////////////////////////////////////////////////// function confirmEditOrAddMgmtnode($state) { global $submitErr; $data = processMgmtnodeInput(1); $premodules = getPredictiveModules(); $publicipconfigs = getContinuationVar('publicipconfigs'); if($submitErr) { editOrAddMgmtnode($state); return; } if($state) { $nextmode = "submitAddMgmtnode"; $title = "Add Management Node"; $question = "Add the following management node?"; } else { $nextmode = "submitEditMgmtnode"; $title = "Edit Management Node"; $question = "Submit changes to the management node?"; } $mgmtnodestates = array(2 => "available", 1 => "deleted", 10 => "maintenance"); print "
\n"; print "

$title

\n"; print "$question

\n"; print "\n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; if(empty($data['sysadminemail'])) print " \n"; else print " \n"; print " \n"; print " \n"; print " \n"; if(empty($data['sharedmailbox'])) print " \n"; else print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; if($data['imagelibenable']) { print " \n"; print " \n"; print " \n"; print " \n"; $mgmtgroups = getContinuationVar('mgmtgroups'); print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; } else { print " \n"; print " \n"; print " \n"; print " \n"; } print " \n"; print " \n"; print " \n"; print " \n"; if($data['publicIPconfig'] == 'static') { print " \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:{$data["hostname"]}
IP address:{$data["IPaddress"]}
Owner:{$data["owner"]}
State:{$mgmtnodestates[$data["stateid"]]}
SysAdmin Email Address(es):(SysAdmin emails disabled){$data["sysadminemail"]}
Address for Shadow Emails:(Shadow emails disabled){$data["sharedmailbox"]}
Predictive Loading Module:{$premodules[$data["premoduleid"]]['prettyname']}
Check-in Interval(sec):{$data["checkininterval"]}
Install Path:{$data["installpath"]}
End node SSH Identity Key Files:{$data["keys"]}
SSH Port for this node:{$data["sshport"]}
Image Library:enabled
Image Library Management Node Group:{$mgmtgroups[$data["imagelibgroupid"]]}
Image Library User:{$data["imagelibuser"]}
Image Library SSH Identity Key File:{$data["imagelibkey"]}
Image Library:disabled
Public NIC configuration method:{$publicipconfigs[$data["publicIPconfig"]]}
Public Netmask:{$data["publicnetmask"]}
Public Gateway:{$data["publicgateway"]}
Public DNS Server:{$data["publicdnsserver"]}
\n"; print "\n"; print " \n"; print " \n"; print " \n"; print " \n"; print "
\n"; print "
\n"; $cont = addContinuationsEntry($nextmode, $data, SECINDAY, 0, 0); print " \n"; print " \n"; print "
\n"; print "
\n"; print "
\n"; $cont = addContinuationsEntry('viewMgmtnodes'); print " \n"; print " \n"; print "
\n"; print "
\n"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn submitEditMgmtnode() /// /// \brief submits changes to management node and notifies user /// //////////////////////////////////////////////////////////////////////////////// function submitEditMgmtnode() { $data = processMgmtnodeInput(0); updateMgmtnode($data); viewMgmtnodes(); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn submitAddMgmtnode() /// /// \brief processes form to add the management node /// //////////////////////////////////////////////////////////////////////////////// function submitAddMgmtnode() { $data = processMgmtnodeInput(0); addMgmtnode($data); clearPrivCache(); viewMgmtnodes(); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn confirmDeleteMgmtnode() /// /// \brief prints a page confirming deletion of a management node /// //////////////////////////////////////////////////////////////////////////////// function confirmDeleteMgmtnode() { $mgmtnodeid = getContinuationVar("mgmtnodeid"); $nodes = getManagementNodes(); print "
\n"; print "

Delete Management Node

\n"; print "Delete the following management node?

\n"; print "\n"; print " \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:{$nodes[$mgmtnodeid]['hostname']}
IP address:{$nodes[$mgmtnodeid]['IPaddress']}
Owner:{$nodes[$mgmtnodeid]['owner']}
\n"; print "\n"; print " \n"; print " \n"; print " \n"; print " \n"; print "
\n"; print "
\n"; $cdata = array('mgmtnodeid' => $mgmtnodeid); $cont = addContinuationsEntry('submitDeleteMgmtnode', $cdata, SECINDAY, 0, 0); print " \n"; print " \n"; print "
\n"; print "
\n"; print "
\n"; $cont = addContinuationsEntry('viewMgmtnodes'); print " \n"; print " \n"; print "
\n"; print "
\n"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn submitDeleteMgmtnode() /// /// \brief deletes a management node and calls viewMgmtnodes /// //////////////////////////////////////////////////////////////////////////////// function submitDeleteMgmtnode() { $mgmtnodeid = getContinuationVar("mgmtnodeid"); doQuery("DELETE FROM managementnode WHERE id = $mgmtnodeid", 385); doQuery("DELETE FROM resource WHERE resourcetypeid = 16 AND subid = $mgmtnodeid", 385); $_SESSION['userresources'] = array(); $_SESSION['usersessiondata'] = array(); viewMgmtnodes(); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn viewMgmtnodeGrouping() /// /// \brief prints a page to view and modify management node grouping /// //////////////////////////////////////////////////////////////////////////////// function viewMgmtnodeGrouping() { global $mode; $mgmtnodemembership = getResourceGroupMemberships("managementnode"); $resources = getUserResources(array("mgmtNodeAdmin"), array("manageGroup")); $tmp = getUserResources(array("mgmtNodeAdmin"), array("manageGroup"), 1); $mgmtnodegroups = $tmp["managementnode"]; uasort($mgmtnodegroups, "sortKeepIndex"); uasort($resources["managementnode"], "sortKeepIndex"); if(count($resources["managementnode"])) { print "

Management Node Grouping

\n"; if($mode == "submitMgmtnodeGroups") { print "Management Node groups successfully updated"; print "

\n"; } print "
\n"; print "\n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; foreach($mgmtnodegroups as $group) { print " \n"; } print " \n"; $count = 1; foreach($resources["managementnode"] as $mgmtnodeid => $mgmtnode) { if($count % 8 == 0) { print " \n"; print " \n"; foreach($mgmtnodegroups as $group) { print " \n"; } print " \n"; } print " \n"; print " \n"; foreach(array_keys($mgmtnodegroups) as $groupid) { $name = "mgmtnodegroup[" . $mgmtnodeid . ":" . $groupid . "]"; if(array_key_exists($mgmtnodeid, $mgmtnodemembership["managementnode"]) && in_array($groupid, $mgmtnodemembership["managementnode"][$mgmtnodeid])) { $checked = "checked"; } else { $checked = ""; } print " \n"; } print " \n"; $count++; } print "
Management NodeGroups
$group
$group
$mgmtnode\n"; print " \n"; print "
\n"; $cont = addContinuationsEntry('submitMgmtnodeGroups', array(), SECINDAY, 1, 0); print "\n"; print "\n"; print "\n"; print "
\n"; } } //////////////////////////////////////////////////////////////////////////////// /// /// \fn submitMgmtnodeGroups /// /// \brief updates image groupings /// //////////////////////////////////////////////////////////////////////////////// function submitMgmtnodeGroups() { $groupinput = processInputVar("mgmtnodegroup", ARG_MULTINUMERIC); $mgmtnodes = getManagementNodes(); # build an array of memberships currently in the db $tmp = getUserResources(array("mgmtNodeAdmin"), array("manageGroup"), 1); $mgmtnodegroupsIDs = array_keys($tmp["managementnode"]); // ids of groups that user can manage $resources = getUserResources(array("mgmtNodeAdmin"), array("manageGroup")); $userMgmtnodeIDs = array_keys($resources["managementnode"]); // ids of images that user can manage $mgmtnodemembership = getResourceGroupMemberships("managementnode"); $basemgmtnodegroups = $mgmtnodemembership["managementnode"]; // all image group memberships $mgmtnodegroups = array(); foreach(array_keys($basemgmtnodegroups) as $mgmtnodeid) { if(in_array($mgmtnodeid, $userMgmtnodeIDs)) { foreach($basemgmtnodegroups[$mgmtnodeid] as $grpid) { if(in_array($grpid, $mgmtnodegroupsIDs)) { if(array_key_exists($mgmtnodeid, $mgmtnodegroups)) array_push($mgmtnodegroups[$mgmtnodeid], $grpid); else $mgmtnodegroups[$mgmtnodeid] = array($grpid); } } } } # build an array of posted in memberships $newmembers = array(); foreach(array_keys($groupinput) as $key) { list($mgmtnodeid, $grpid) = explode(':', $key); if(array_key_exists($mgmtnodeid, $newmembers)) { array_push($newmembers[$mgmtnodeid], $grpid); } else { $newmembers[$mgmtnodeid] = array($grpid); } } $adds = array(); $removes = array(); foreach(array_keys($mgmtnodes) as $mgmtnodeid) { $id = $mgmtnodes[$mgmtnodeid]["resourceid"]; // if $mgmtnodeid not in $userMgmtnodeIds, don't bother with it if(! in_array($mgmtnodeid, $userMgmtnodeIDs)) continue; // if $mgmtnodeid is not in $newmembers and not in $mgmtnodegroups, do nothing if(! array_key_exists($mgmtnodeid, $newmembers) && ! array_key_exists($mgmtnodeid, $mgmtnodegroups)) { continue; } // check that $mgmtnodeid is in $newmembers, if not, remove it from all groups // user has access to if(! array_key_exists($mgmtnodeid, $newmembers)) { $removes[$id] = $mgmtnodegroups[$mgmtnodeid]; continue; } // check that $mgmtnodeid is in $mgmtnodegroups, if not, add all groups in // $newmembers if(! array_key_exists($mgmtnodeid, $mgmtnodegroups)) { $adds[$id] = $newmembers[$mgmtnodeid]; continue; } // adds are groupids that are in $newmembers, but not in $mgmtnodegroups $adds[$id] = array_diff($newmembers[$mgmtnodeid], $mgmtnodegroups[$mgmtnodeid]); if(count($adds[$id]) == 0) { unset($adds[$id]); } // removes are groupids that are in $mgmtnodegroups, but not in $newmembers $removes[$id] = array_diff($mgmtnodegroups[$mgmtnodeid], $newmembers[$mgmtnodeid]); if(count($removes[$id]) == 0) { unset($removes[$id]); } } foreach(array_keys($adds) as $mgmtnodeid) { foreach($adds[$mgmtnodeid] as $grpid) { $query = "INSERT INTO resourcegroupmembers " . "(resourceid, resourcegroupid) " . "VALUES ($mgmtnodeid, $grpid)"; doQuery($query, 287); } } foreach(array_keys($removes) as $mgmtnodeid) { foreach($removes[$mgmtnodeid] as $grpid) { $query = "DELETE FROM resourcegroupmembers " . "WHERE resourceid = $mgmtnodeid AND " . "resourcegroupid = $grpid"; doQuery($query, 288); } } viewMgmtnodeGrouping(); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn viewMgmtnodeMapping($mngroups) /// /// \param $mngroups - (optional) array of mngroups as returned by /// getUserResources /// /// \brief prints a page to view and edit management node to computer group /// mappings /// //////////////////////////////////////////////////////////////////////////////// function viewMgmtnodeMapping($mngroups=0) { global $mode; if(! is_array($mngroups)) { $tmp = getUserResources(array("mgmtNodeAdmin"), array("manageGroup"), 1); $mngroups = $tmp["managementnode"]; } $mapping = getResourceMapping("managementnode", "computer"); $resources2 = getUserResources(array("computerAdmin"), array("manageGroup"), 1); $compgroups = $resources2["computer"]; uasort($compgroups, "sortKeepIndex"); if(count($mngroups) && count($compgroups)) { print "

Management Node Group to Computer Group Mapping

\n"; if($mode == "submitMgmtnodeMapping") { print "Management node group to computer "; print "group mapping successfully updated"; print "

\n"; } print "
\n"; print "\n"; print " \n"; foreach(array_keys($compgroups) as $id) { print " \n"; } print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; foreach($compgroups as $id => $group) { print " \n"; } print " \n"; $count = 1; foreach($mngroups as $mnid => $mnname) { if($count % 12 == 0) { print " \n"; print " \n"; foreach($compgroups as $id => $group) { print " \n"; } print " \n"; } print " \n"; print " \n"; foreach($compgroups as $compid => $compname) { $name = "mapping[" . $mnid . ":" . $compid . "]"; if(array_key_exists($mnid, $mapping) && in_array($compid, $mapping[$mnid])) { $checked = "checked"; } else $checked = ""; print " \n"; } print " \n"; $count++; } print "
Management Node GroupComputer Groups
$group
$group
$mnname\n"; print " \n"; print "
\n"; $cont = addContinuationsEntry('submitMgmtnodeMapping', array(), SECINDAY, 1, 0); print "\n"; print "\n"; print "\n"; print "
\n"; } } //////////////////////////////////////////////////////////////////////////////// /// /// \fn submitMgmtnodeMapping /// /// \brief updates management node group to computer group mapping /// //////////////////////////////////////////////////////////////////////////////// function submitMgmtnodeMapping() { $mapinput = processInputVar("mapping", ARG_MULTINUMERIC); $mntypeid = getResourceTypeID("managementnode"); $comptypeid = getResourceTypeID("computer"); # build an array of memberships currently in the db $tmp = getUserResources(array("mgmtNodeAdmin"), array("manageGroup"), 1); $mngroups = $tmp["managementnode"]; $tmp = getUserResources(array("computerAdmin"), array("manageGroup"), 1); $compgroups = $tmp["computer"]; $mninlist = implode(',', array_keys($mngroups)); $compinlist = implode(',', array_keys($compgroups)); $mapping = getResourceMapping("managementnode", "computer", $mninlist, $compinlist); # build an array of posted in memberships $newmembers = array(); foreach(array_keys($mapinput) as $key) { list($mnid, $compid) = explode(':', $key); if(array_key_exists($mnid, $newmembers)) array_push($newmembers[$mnid], $compid); else $newmembers[$mnid] = array($compid); } $adds = array(); $removes = array(); foreach(array_keys($mngroups) as $mnid) { // if $mnid is not in $newmembers and not in $mapping, do nothing if(! array_key_exists($mnid, $newmembers) && ! array_key_exists($mnid, $mapping)) { continue; } // check that $mnid is in $newmembers, if not, remove it from all groups // user has access to if(! array_key_exists($mnid, $newmembers)) { $removes[$mnid] = $mapping[$mnid]; continue; } // check that $mnid is in $mapping, if not, add all groups in // $newmembers if(! array_key_exists($mnid, $mapping)) { $adds[$mnid] = $newmembers[$mnid]; continue; } // adds are groupids that are in $newmembers, but not in $mapping $adds[$mnid] = array_diff($newmembers[$mnid], $mapping[$mnid]); if(count($adds[$mnid]) == 0) { unset($adds[$mnid]); } // removes are groupids that are in $mapping, but not in $newmembers $removes[$mnid] = array_diff($mapping[$mnid], $newmembers[$mnid]); if(count($removes[$mnid]) == 0) { unset($removes[$mnid]); } } foreach(array_keys($adds) as $mnid) { foreach($adds[$mnid] as $compid) { $query = "INSERT INTO resourcemap " . "(resourcegroupid1, " . "resourcetypeid1, " . "resourcegroupid2, " . "resourcetypeid2) " . "VALUES ($mnid, " . "$mntypeid, " . "$compid, " . "$comptypeid)"; doQuery($query, 101); } } foreach(array_keys($removes) as $mnid) { foreach($removes[$mnid] as $compid) { $query = "DELETE FROM resourcemap " . "WHERE resourcegroupid1 = $mnid AND " . "resourcetypeid1 = $mntypeid AND " . "resourcegroupid2 = $compid AND " . "resourcetypeid2 = $comptypeid"; doQuery($query, 101); } } viewMgmtnodeMapping(); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn updateMgmtnode($data) /// /// \param $data - an array returned from processMgmtnodeInput /// /// \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 management node with data from $data /// //////////////////////////////////////////////////////////////////////////////// function updateMgmtnode($data) { if(empty($data['sysadminemail'])) $data['sysadminemail'] = 'NULL'; else $data['sysadminemail'] = "'" . mysql_real_escape_string($data['sysadminemail']) . "'"; if(empty($data['sharedmailbox'])) $data['sharedmailbox'] = 'NULL'; else $data['sharedmailbox'] = "'" . mysql_real_escape_string($data['sharedmailbox']) . "'"; $ownerid = getUserlistID($data["owner"]); $data['installpath'] = mysql_real_escape_string($data['installpath']); $data['keys'] = mysql_real_escape_string($data['keys']); $data['imagelibuser'] = mysql_real_escape_string($data['imagelibuser']); if($data['imagelibuser'] != 'NULL') $data['imagelibuser'] = "'{$data['imagelibuser']}'"; $data['imagelibkey'] = mysql_real_escape_string($data['imagelibkey']); if($data['imagelibkey'] != 'NULL') $data['imagelibkey'] = "'{$data['imagelibkey']}'"; if($data['imagelibenable'] != 1) $data['imagelibenable'] = 0; if($data['keys'] == '') $data['keys'] = 'NULL'; else $data['keys'] = "'{$data['keys']}'"; if($data['publicIPconfig'] != 'static') { $data['publicnetmask'] = 'NULL'; $data['publicgateway'] = 'NULL'; $data['publicdnsserver'] = 'NULL'; } else { $data['publicnetmask'] = "'" . mysql_real_escape_string($data['publicnetmask']) . "'"; $data['publicgateway'] = "'" . mysql_real_escape_string($data['publicgateway']) . "'"; $data['publicdnsserver'] = "'" . mysql_real_escape_string($data['publicdnsserver']) . "'"; } $query = "UPDATE managementnode " . "SET hostname = '{$data["hostname"]}', " . "IPaddress = '{$data["IPaddress"]}', " . "ownerid = $ownerid, " . "stateid = {$data["stateid"]}, " . "predictivemoduleid = {$data["premoduleid"]}, " . "checkininterval = {$data["checkininterval"]}, " . "installpath = '{$data["installpath"]}', " . "`keys` = {$data["keys"]}, " . "sshport = {$data["sshport"]}, " . "imagelibenable = {$data["imagelibenable"]}, " . "imagelibgroupid = {$data["imagelibgroupid"]}, " . "imagelibuser = {$data["imagelibuser"]}, " . "imagelibkey = {$data["imagelibkey"]}, " . "publicIPconfiguration = '{$data["publicIPconfig"]}', " . "publicSubnetMask = {$data["publicnetmask"]}, " . "publicDefaultGateway = {$data["publicgateway"]}, " . "publicDNSserver = {$data["publicdnsserver"]}, " . "sysadminEmailAddress = {$data["sysadminemail"]}, " . "sharedMailBox = {$data["sharedmailbox"]} " . "WHERE id = " . $data["mgmtnodeid"]; $qh = doQuery($query, 101); return mysql_affected_rows($GLOBALS["mysql_link_vcl"]); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn addMgmtnode($data) /// /// \param $data - an array returned from processMgmtnodeInput /// /// \return number of rows affected by the insert\n /// /// \brief performs a query to insert the management node with data from $data /// //////////////////////////////////////////////////////////////////////////////// function addMgmtnode($data) { $ownerid = getUserlistID($data["owner"]); if(empty($data['sysadminemail'])) $data['sysadminemail'] = 'NULL'; else $data['sysadminemail'] = "'" . mysql_real_escape_string($data['sysadminemail']) . "'"; if(empty($data['sharedmailbox'])) $data['sharedmailbox'] = 'NULL'; else $data['sharedmailbox'] = "'" . mysql_real_escape_string($data['sharedmailbox']) . "'"; $data['installpath'] = mysql_real_escape_string($data['installpath']); $data['keys'] = mysql_real_escape_string($data['keys']); $data['imagelibuser'] = mysql_real_escape_string($data['imagelibuser']); if($data['imagelibuser'] != 'NULL') $data['imagelibuser'] = "'{$data['imagelibuser']}'"; $data['imagelibkey'] = mysql_real_escape_string($data['imagelibkey']); if($data['imagelibkey'] != 'NULL') $data['imagelibkey'] = "'{$data['imagelibkey']}'"; if($data['imagelibenable'] != 1) $data['imagelibenable'] = 0; if($data['keys'] == '') $data['keys'] = 'NULL'; else $data['keys'] = "'{$data['keys']}'"; if($data['publicIPconfig'] != 'static') { $data['publicnetmask'] = 'NULL'; $data['publicgateway'] = 'NULL'; $data['publicdnsserver'] = 'NULL'; } else { $data['publicnetmask'] = "'" . mysql_real_escape_string($data['publicnetmask']) . "'"; $data['publicgateway'] = "'" . mysql_real_escape_string($data['publicgateway']) . "'"; $data['publicdnsserver'] = "'" . mysql_real_escape_string($data['publicdnsserver']) . "'"; } $query = "INSERT INTO managementnode " . "(hostname, " . "IPaddress, " . "ownerid, " . "stateid, " . "checkininterval, " . "installpath, " . "imagelibenable, " . "imagelibgroupid, " . "imagelibuser, " . "imagelibkey, " . "`keys`, " . "predictivemoduleid, " . "sshport, " . "publicIPconfiguration, " . "publicSubnetMask, " . "publicDefaultGateway, " . "publicDNSserver, " . "sysadminEmailAddress, " . "sharedMailBox) " . "VALUES ('{$data["hostname"]}', " . "'{$data["IPaddress"]}', " . "$ownerid, " . "{$data["stateid"]}, " . "{$data["checkininterval"]}, " . "'{$data["installpath"]}', " . "{$data["imagelibenable"]}, " . "{$data["imagelibgroupid"]}, " . "{$data["imagelibuser"]}, " . "{$data["imagelibkey"]}, " . "{$data["keys"]}, " . "{$data["premoduleid"]}, " . "{$data["sshport"]}, " . "'{$data["publicIPconfig"]}', " . "{$data["publicnetmask"]}, " . "{$data["publicgateway"]}, " . "{$data["publicdnsserver"]}, " . "{$data["sysadminemail"]}, " . "{$data["sharedmailbox"]})"; doQuery($query, 205); // get last insert id $qh = doQuery("SELECT LAST_INSERT_ID() FROM managementnode", 101); if(! $row = mysql_fetch_row($qh)) { abort(101); } $id = $row[0]; // add entry in resource table $query = "INSERT INTO resource " . "(resourcetypeid, " . "subid) " . "VALUES (16, " . "$id)"; doQuery($query, 209); return $id; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn processMgmtnodeInput($checks) /// /// \param $checks - (optional) 1 to perform validation, 0 not to /// /// \return an array with the following indexes:\n /// mgmtnodeid, hostname, IPaddress, owner, stateid /// /// \brief validates input from the previous form; if anything was improperly /// submitted, sets submitErr and submitErrMsg /// //////////////////////////////////////////////////////////////////////////////// function processMgmtnodeInput($checks=1) { global $submitErr, $submitErrMsg, $user, $mode; $return = array(); $mgmtnodes = getManagementNodes(); $return["mgmtnodeid"] = getContinuationVar("mgmtnodeid"); $return["hostname"] = getContinuationVar("hostname", processInputVar("hostname" , ARG_STRING)); $return["IPaddress"] = getContinuationVar("IPaddress", processInputVar("IPaddress", ARG_STRING)); $return["owner"] = getContinuationVar("owner", processInputVar("owner", ARG_STRING, $user["unityid"])); $return["stateid"] = getContinuationVar("stateid", processInputVar("stateid", ARG_STRING)); $return["premoduleid"] = getContinuationVar("premoduleid", processInputVar("premoduleid", ARG_NUMERIC)); $return["checkininterval"] = getContinuationVar("checkininterval", processInputVar("checkininterval", ARG_NUMERIC)); $return["installpath"] = getContinuationVar("installpath", processInputVar("installpath", ARG_STRING)); $return["keys"] = getContinuationVar("keys", processInputVar("keys", ARG_STRING)); $return["sshport"] = getContinuationVar("sshport", processInputVar("sshport", ARG_NUMERIC)); $return["imagelibenable"] = getContinuationVar("imagelibenable", processInputVar("imagelibenable", ARG_NUMERIC)); $return["imagelibgroupid"] = getContinuationVar("imagelibgroupid", processInputVar("imagelibgroupid", ARG_NUMERIC)); $return["imagelibuser"] = getContinuationVar("imagelibuser", processInputVar("imagelibuser", ARG_STRING)); $return["imagelibkey"] = getContinuationVar("imagelibkey", processInputVar("imagelibkey", ARG_STRING)); $return['publicIPconfig'] = getContinuationVar("publicIPconfig", processInputVar("publicIPconfig", ARG_STRING)); $return['publicnetmask'] = getContinuationVar("publicnetmask", processInputVar("publicnetmask", ARG_STRING)); $return['publicgateway'] = getContinuationVar("publicgateway", processInputVar("publicgateway", ARG_STRING)); $return['publicdnsserver'] = getContinuationVar("publicdnsserver", processInputVar("publicdnsserver", ARG_STRING)); $return['sysadminemail'] = getContinuationVar("sysadminemail", processInputVar("sysadminemail", ARG_STRING)); $return['sharedmailbox'] = getContinuationVar("sharedmailbox", processInputVar("sharedmailbox", ARG_STRING)); if($return['checkininterval'] < 5) $return['checkininterval'] = 5; if($return['checkininterval'] > 30) $return['checkininterval'] = 30; if($return['sshport'] < 1 || $return['sshport'] > 65535) $return['sshport'] = 22; if($return['imagelibenable'] != '' && $return['imagelibenable'] != 1) $return['imagelibenable'] = ''; if($return['imagelibenable'] != 1) { $return["imagelibgroupid"] = 'NULL'; $return["imagelibuser"] = 'NULL'; $return["imagelibkey"] = 'NULL'; } if(! $checks) return $return; if(! preg_match('/^[a-zA-Z0-9_][-a-zA-Z0-9_\.]{1,49}$/', $return["hostname"])) { $submitErr |= MNHOSTNAMEERR; $submitErrMsg[MNHOSTNAMEERR] = "Hostname can only contain letters, numbers, dashes(-), periods(.), and underscores(_). It can be from 1 to 50 characters long"; } if(! ($submitErr & MNHOSTNAMEERR) && $mode != "confirmEditMgmtnode" && checkForMgmtnodeHostname($return["hostname"])) { $submitErr |= MNHOSTNAMEERR; $submitErrMsg[MNHOSTNAMEERR] = "A node already exists with this hostname."; } $ipaddrArr = explode('.', $return["IPaddress"]); if(! preg_match('/^(([0-9]){1,3}\.){3}([0-9]){1,3}$/', $return["IPaddress"]) || $ipaddrArr[0] < 1 || $ipaddrArr[0] > 255 || $ipaddrArr[1] < 0 || $ipaddrArr[1] > 255 || $ipaddrArr[2] < 0 || $ipaddrArr[2] > 255 || $ipaddrArr[3] < 1 || $ipaddrArr[3] > 255) { $submitErr |= IPADDRESSERR; $submitErrMsg[IPADDRESSERR] = "Invalid IP address. Must be w.x.y.z with each of " . "w, x, y, and z being between 1 and 255 (inclusive)"; } if($mode != "confirmEditMgmtnode" && ! ($submitErr & IPADDRESSERR) && checkForMgmtnodeIPaddress($return["IPaddress"])) { $submitErr |= IPADDRESSERR; $submitErrMsg[IPADDRESSERR] = "A node already exists with this IP address."; } if(! validateUserid($return["owner"])) { $submitErr |= MNOWNERERR; $submitErrMsg[MNOWNERERR] = "Submitted ID is not valid"; } if(! preg_match('/^([-a-zA-Z0-9_\.\/]){2,100}$/', $return["installpath"])) { $submitErr |= MNINSTPATHERR; $submitErrMsg[MNINSTPATHERR] = "This can only contain letters, numbers, dashes(-), periods(.), underscores(_), and forward slashes(/). It can be from 2 to 100 characters long"; } if(! empty($return['keys']) && ! preg_match('/^([-a-zA-Z0-9_\.\/,]){2,1024}$/', $return["keys"])) { $submitErr |= MNSSHIDKEYSERR; $submitErrMsg[MNSSHIDKEYSERR] = "This can only contain letters, numbers, dashes(-), periods(.), underscores(_), forward slashes(/), and commas(,). It can be from 2 to 1024 characters long"; } if($return['imagelibenable'] == 1) { $validgroups = getUserResources(array('mgmtNodeAdmin'), array("manageGroup"), 1); if(! in_array($return['imagelibgroupid'], array_keys($validgroups['managementnode']))) { $submitErr |= MNIMGLIBGRPIDERR; $submitErrMsg[MNIMGLIBGRPIDERR] = "The selected group was invalid"; } if(! preg_match('/^([-a-zA-Z0-9_\.\/,]){2,20}$/', $return["imagelibuser"])) { $submitErr |= MNIMGLIBUSERERR; $submitErrMsg[MNIMGLIBUSERERR] = "This can only contain letters, numbers, and dashes(-) and can be from 2 to 20 characters long"; } if(! preg_match('/^([-a-zA-Z0-9_\.\/,]){2,100}$/', $return["imagelibkey"])) { $submitErr |= MNIMGLIBKEYERR; $submitErrMsg[MNIMGLIBKEYERR] = "This can only contain letters, numbers, dashes(-), periods(.), underscores(_), and forward slashes(/). It can be from 2 to 100 characters long"; } } else { $return["imagelibgroupid"] = 'NULL'; $return["imagelibuser"] = 'NULL'; $return["imagelibkey"] = 'NULL'; } if(! preg_match('/^(dynamicDHCP|manualDHCP|static)$/', $return['publicIPconfig'])) $return['publicIPconfig'] = 'dynamicDHCP'; if($return['publicIPconfig'] == 'static') { if(! preg_match('/^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/', $return['publicnetmask'], $matches) || $matches[1] < 0 || $matches[1] > 255 || $matches[2] < 0 || $matches[2] > 255 || $matches[3] < 0 || $matches[3] > 255 || $matches[4] < 0 || $matches[4] > 255) { $submitErr |= MNPUBLICNETMASKERR; $submitErrMsg[MNPUBLICNETMASKERR] = "Invalid subnet mask entered"; } if(preg_match('/^([0-9]{1,3}(\.?))+$/', $return['publicgateway'])) { if(preg_match('/^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/', $return['publicgateway'], $matches)) { if($matches[1] < 0 || $matches[1] > 255 || $matches[2] < 0 || $matches[2] > 255 || $matches[3] < 0 || $matches[3] > 255 || $matches[4] < 0 || $matches[4] > 255) { $submitErr |= MNPUBLICGATEWAYERR; $submitErrMsg[MNPUBLICGATEWAYERR] = "Invalid ip address entered"; } } else { $submitErr |= MNPUBLICGATEWAYERR; $submitErrMsg[MNPUBLICGATEWAYERR] = "Invalid ip address entered"; } } elseif(! preg_match('/^[a-zA-Z0-9_][-a-zA-Z0-9_\.]{1,56}$/', $return["publicgateway"], $matches)) { $submitErr |= MNPUBLICGATEWAYERR; $submitErrMsg[MNPUBLICGATEWAYERR] = "Public gateway must be an IP address or a hostname containing only letters, numbers, dashes(-), periods(.), and underscores(_). It can be up to 56 characters long"; } $servers = explode(',', $return['publicdnsserver']); if(empty($servers)) { $submitErr |= MNPUBLICDNSSERVERERR; $submitErrMsg[MNPUBLICDNSSERVERERR] = "Please enter at least one dns server"; } else { foreach($servers as $server) { if(! preg_match('/^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})+$/', $server, $matches) || $matches[1] < 0 || $matches[1] > 255 || $matches[2] < 0 || $matches[2] > 255 || $matches[3] < 0 || $matches[3] > 255 || $matches[4] < 0 || $matches[4] > 255) { $submitErr |= MNPUBLICDNSSERVERERR; $submitErrMsg[MNPUBLICDNSSERVERERR] = "Invalid ip address entered"; } } } } else { $return['publicnetmask'] = ''; $return['publicgateway'] = ''; $return['publicdnsserver'] = ''; } if(strlen($return['sysadminemail']) && (! preg_match('/^([A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}(,?))+$/i', $return['sysadminemail']) || strlen($return['sysadminemail']) > 128)) { $submitErr |= MNSYSADMINEMAILERR; $submitErrMsg[MNSYSADMINEMAILERR] = "Invalid email address(es) entered or field too long (128 char max)"; } if(strlen($return['sharedmailbox']) && (! preg_match('/^([A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4})$/i', $return['sharedmailbox']) || strlen($return['sharedmailbox']) > 128)) { $submitErr |= MNSHAREDMAILBOXERR; $submitErrMsg[MNSHAREDMAILBOXERR] = "Invalid email address entered"; } return $return; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn checkForMgmtnodeHostname($hostname) /// /// \param $hostname - a computer hostname /// /// \return 0 if $hostname is not in managementnode table, 1 if it is /// /// \brief checks for the existance of $hostname in the managementnode table /// //////////////////////////////////////////////////////////////////////////////// function checkForMgmtnodeHostname($hostname) { $query = "SELECT id FROM managementnode WHERE hostname = '$hostname'"; $qh = doQuery($query, 101); return mysql_num_rows($qh); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn checkForMgmtnodeIPaddress($addr) /// /// \param $addr - a computer ip address /// /// \return 0 if $addr is not in managementnode table, 1 if it is /// /// \brief checks for the existance of $addr in the managementnode table /// //////////////////////////////////////////////////////////////////////////////// function checkForMgmtnodeIPaddress($addr) { $query = "SELECT id FROM managementnode WHERE IPaddress = '$addr'"; $qh = doQuery($query, 101); return mysql_num_rows($qh); } ?>