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['imagelibgroup'] = $mgmtnodes[$id]['imagelibgroup']; # TODO this can be removed $data['imagelibuser'] = $mgmtnodes[$id]['imagelibuser']; $data['imagelibkey'] = $mgmtnodes[$id]['imagelibkey']; $data['keys'] = $mgmtnodes[$id]['keys']; $data['sshport'] = $mgmtnodes[$id]['sshport']; } $disabled = ''; if(! $data['imagelibenable']) $disabled = '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"; print " \n"; print " \n"; print " \n"; print " \n"; # checkininterval print " \n"; print " \n"; print " \n"; print " "; 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"; else print "id=imagelibenable>\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"; 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 "
Predictive Loading Module:\n"; printSelectInput("premoduleid", $premodules, $data["premoduleid"]); print "
\n"; print " Check-in Interval (sec):\n"; print " \n"; print " \n"; print "
\n"; print " Install Path:"; printSubmitErr(MNINSTPATHERR); print "
\n"; print " End Node SSH Identity Key Files:"; printSubmitErr(MNSSHIDKEYSERR); print "
\n"; print " SSH Port for this node:\n"; print " \n"; print " \n"; print " "; printSubmitErr(MNSSHPORTERR); print "
\n"; print " Enable Image Library:
\n"; print " Image Library Management Node Group:"; $mgmtnodegroups = getUserResources(array('mgmtNodeAdmin'), array("manageGroup"), 1); printSelectInput("imagelibgroupid", $mgmtnodegroups['managementnode'], -1, 0, 0, 'imagelibgroupid', $disabled); print " "; printSubmitErr(MNIMGLIBGRPIDERR); print "
\n"; print " Image Library User:"; printSubmitErr(MNIMGLIBUSERERR); print "
\n"; print " Image Library SSH Identity Key File:"; printSubmitErr(MNIMGLIBKEYERR); print "
\n"; print "\n"; print " \n"; print " \n"; print " \n"; print " \n"; print "
\n"; if($state) { $cdata = array('mgmtgroups' => $mgmtnodegroups['managementnode']); $cont = addContinuationsEntry('confirmAddMgmtnode', $cdata, SECINDAY, 0, 1, 1); print " \n"; print " \n"; } else { $cdata = array('mgmtnodeid' => $data['mgmtnodeid'], 'mgmtgroups' => $mgmtnodegroups['managementnode']); $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"; } //////////////////////////////////////////////////////////////////////////////// /// /// \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(); 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"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; 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 "
Hostname:{$data["hostname"]}
IP address:{$data["IPaddress"]}
Owner:{$data["owner"]}
State:{$mgmtnodestates[$data["stateid"]]}
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
\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("groupAdmin"), 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) { $ownerid = getUserlistID($data["owner"]); $data['installpath'] = mysql_escape_string($data['installpath']); $data['keys'] = mysql_escape_string($data['keys']); $data['imagelibuser'] = mysql_escape_string($data['imagelibuser']); if($data['imagelibuser'] != 'NULL') $data['imagelibuser'] = "'{$data['imagelibuser']}'"; $data['imagelibkey'] = mysql_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']}'"; $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"]} " . "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"]); $data['installpath'] = mysql_escape_string($data['installpath']); $data['keys'] = mysql_escape_string($data['keys']); $data['imagelibuser'] = mysql_escape_string($data['imagelibuser']); if($data['imagelibuser'] != 'NULL') $data['imagelibuser'] = "'{$data['imagelibuser']}'"; $data['imagelibkey'] = mysql_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']}'"; $query = "INSERT INTO managementnode " . "(hostname, " . "IPaddress, " . "ownerid, " . "stateid, " . "checkininterval, " . "installpath, " . "imagelibenable, " . "imagelibgroupid, " . "imagelibuser, " . "imagelibkey, " . "`keys`, " . "predictivemoduleid, " . "sshport) " . "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"]}) "; 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)); 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(! ereg('^[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(! ereg('^(([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'; } 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); } ?>