function AJcompNATchange() { $natenabled = processInputVar('natenabled', ARG_NUMERIC); $nathostid = processInputVar('nathostid', ARG_NUMERIC); $nathosts = getNAThosts(); if ($natenabled != 0 && $natenabled != 1 || $nathostid != 0 && !array_key_exists($nathostid, $nathosts)) { $ret = array('status' => 'error', 'errormsg' => 'Invalid value submitted.'); sendJSON($ret); return; } $compids = $this->validateCompIDs(); if (array_key_exists('error', $compids)) { $ret = array('status' => 'error', 'errormsg' => $compids['msg']); sendJSON($ret); return; } if (count($compids) == 0) { $ret = array('status' => 'noaction'); sendJSON($ret); return; } $allids = implode(',', $compids); $inusecompids = array(); $vclreloadid = getUserlistID('vclreload@Local'); $query = "SELECT rs.computerid " . "FROM request rq, " . "reservation rs " . "WHERE rs.requestid = rq.id AND " . "rs.computerid IN ({$allids}) AND " . "rq.start <= NOW() AND " . "rq.end > NOW() AND " . "rq.stateid NOT IN (1,5,11,12) AND " . "rq.laststateid NOT IN (1,5,11,12) AND " . "rq.userid != {$vclreloadid}"; $qh = doQuery($query); while ($row = mysql_fetch_assoc($qh)) { $inusecompids[] = $row['computerid']; } $tmp = getUserResources(array($this->restype . "Admin"), array("administer"), 0, 1); $computers = $tmp['computer']; $msg = ''; if (count($inusecompids)) { $msg .= "The following computers are currently in use and cannot have<br>"; $msg .= "NAT settings changed at this time:<br><br>\n"; $complist = ''; foreach ($inusecompids as $compid) { $complist .= $computers[$compid] . "<br>\n"; } $msg .= "<div class=\"wait\">{$complist}<br></div>\n"; $compids = array_diff($compids, $inusecompids); } if (count($compids)) { if ($natenabled) { $msg .= "<strong>Enable</strong> Connect Using NAT and set the NAT "; $msg .= "host<br>to <strong>{$nathosts[$nathostid]['hostname']}"; $msg .= "</strong> for the following computers?<br><br>"; } else { $msg .= "<strong>Disable</strong> Connect Using NAT for the following "; $msg .= "computers?<br><br>"; } } $complist = ''; foreach ($compids as $compid) { $complist .= $computers[$compid] . "<br>\n"; } $complist .= "<br>\n"; $cdata = $this->basecdata; $cdata['compids'] = $compids; $cdata['natenabled'] = $natenabled; $cdata['nathostid'] = $nathostid; $cont = addContinuationsEntry('AJsubmitCompNATchange', $cdata, SECINDAY, 1, 0); $ret = array('status' => 'success', 'title' => "Connect Using NAT Change", 'btntxt' => 'Submit Connect Using NAT Change', 'cont' => $cont, 'actionmsg' => $msg, 'complist' => $complist); if (empty($compids)) { $ret['status'] = 'error'; $ret['errormsg'] = $ret['actionmsg']; unset($ret['actionmsg']); } sendJSON($ret); }
function getComputers($sort = 0, $includedeleted = 0, $compid = "") { $nathosts = getNAThosts(); $return = array(); $query = "SELECT c.id AS id, " . "st.name AS state, " . "c.stateid AS stateid, " . "CONCAT(u.unityid, '@', a.name) AS owner, " . "u.id AS ownerid, " . "p.name AS platform, " . "c.platformid AS platformid, " . "sc.name AS schedule, " . "c.scheduleid AS scheduleid, " . "cur.prettyname AS currentimg, " . "c.currentimageid AS currentimgid, " . "c.imagerevisionid, " . "next.prettyname AS nextimg, " . "c.nextimageid AS nextimgid, " . "c.RAM AS ram, " . "c.procnumber AS procnumber, " . "c.procspeed AS procspeed, " . "c.network AS network, " . "c.hostname AS hostname, " . "c.IPaddress AS IPaddress, " . "c.privateIPaddress, " . "c.eth0macaddress, " . "c.eth1macaddress, " . "c.type AS type, " . "c.deleted AS deleted, " . "r.id AS resourceid, " . "c.notes, " . "c.vmhostid, " . "c2.hostname AS vmhost, " . "c2.id AS vmhostcomputerid, " . "c.location, " . "c.provisioningid, " . "pr.prettyname AS provisioning, " . "vh2.vmprofileid, " . "c.predictivemoduleid, " . "m.prettyname AS predictivemodule, " . "nh.id AS nathostid, " . "nh2.id AS nathostenabledid, " . "COALESCE(nh2.publicIPaddress, '') AS natpublicIPaddress, " . "COALESCE(nh2.internalIPaddress, '') AS natinternalIPaddress " . "FROM state st, " . "platform p, " . "schedule sc, " . "image cur, " . "user u, " . "affiliation a, " . "module m, " . "computer c " . "LEFT JOIN resourcetype t ON (t.name = 'computer') " . "LEFT JOIN resource r ON (r.resourcetypeid = t.id AND r.subid = c.id) " . "LEFT JOIN vmhost vh ON (c.vmhostid = vh.id) " . "LEFT JOIN vmhost vh2 ON (c.id = vh2.computerid) " . "LEFT JOIN computer c2 ON (c2.id = vh.computerid) " . "LEFT JOIN image next ON (c.nextimageid = next.id) " . "LEFT JOIN provisioning pr ON (c.provisioningid = pr.id) " . "LEFT JOIN nathostcomputermap nm ON (nm.computerid = c.id) " . "LEFT JOIN nathost nh ON (nm.nathostid = nh.id) " . "LEFT JOIN nathost nh2 ON (r.id = nh2.resourceid) " . "WHERE c.stateid = st.id AND " . "c.platformid = p.id AND " . "c.scheduleid = sc.id AND " . "c.currentimageid = cur.id AND " . "c.ownerid = u.id AND " . "u.affiliationid = a.id AND " . "c.predictivemoduleid = m.id "; if (!$includedeleted) { $query .= "AND c.deleted = 0 "; } if (!empty($compid)) { $query .= "AND c.id = {$compid} "; } $query .= "ORDER BY c.hostname"; $qh = doQuery($query, 180); while ($row = mysql_fetch_assoc($qh)) { if (is_null($row['nathostid'])) { $row['natenabled'] = 0; $row['nathost'] = ''; } else { $row['natenabled'] = 1; $row['nathost'] = $nathosts[$row['nathostid']]['hostname']; } if (is_null($row['nathostenabledid'])) { $row['nathostenabled'] = 0; } else { $row['nathostenabled'] = 1; } $return[$row['id']] = $row; } if ($sort) { uasort($return, "sortComputers"); } return $return; }