function AJconnectRequest() { global $remoteIP, $user; $requestid = getContinuationVar('requestid'); $requestData = getRequestInfo($requestid, 1); if (is_null($requestData)) { $h = i("This reservation is no longer available."); sendJSON(array('html' => $h, 'refresh' => 1)); return; } if ($requestData['stateid'] == 11 || $requestData['stateid'] == 12 || $requestData['stateid'] == 14 && ($requestData['laststateid'] == 11 || $requestData['laststateid'] == 12)) { $h = i("This reservation has timed out due to lack of user activity and is no longer available."); sendJSON(array('html' => $h, 'refresh' => 1)); return; } $h = ''; $now = time(); if ($requestData['reservations'][0]['remoteIP'] != $remoteIP) { $query = "UPDATE reservation " . "SET remoteIP = '{$remoteIP}' " . "WHERE requestid = {$requestid}"; $qh = doQuery($query, 226); addChangeLogEntry($requestData["logid"], $remoteIP); if ($requestData['reservations'][0]['remoteIP'] == '') { addConnectTimeout($requestData['reservations'][0]['reservationid'], $requestData['reservations'][0]['computerid']); } } $timeout = getReservationNextTimeout($requestData['reservations'][0]['reservationid']); if (!is_null($timeout)) { $h .= "<input type=\"hidden\" id=\"connecttimeout\" value=\"{$timeout}\">\n"; } if ($requestData['forimaging']) { $h .= "<font color=red><big>"; $m = "<strong>" . i("NOTICE:") . "</strong> "; $m .= i("Later in this process, you must accept a <a>click-through agreement</a> about software licensing."); $h .= preg_replace('|<a>(.+)</a>|', '<a href="' . BASEURL . SCRIPT . '?mode=viewRequests#" onClick="previewClickThrough();">\\1</a>', $m); $h .= "</big></font><br><br>\n"; } $imagenotes = getImageNotes($requestData['reservations'][0]['imageid']); if (!preg_match('/^\\s*$/', $imagenotes['usage'])) { $h .= "<h3>" . i("Notes on using this environment:") . "</h3>\n"; $h .= "{$imagenotes['usage']}<br><br><br>\n"; } if (count($requestData["reservations"]) > 1) { $cluster = 1; } else { $cluster = 0; } if ($cluster) { $h .= "<h2>" . i("Cluster Reservation") . "</h2>\n"; $h .= i("This is a cluster reservation. Depending on the makeup of the cluster, you may need to use different methods to connect to the different environments in your cluster."); $h .= "<br><br>\n"; } foreach ($requestData["reservations"] as $key => $res) { $osname = $res["OS"]; if (array_key_exists($user['id'], $requestData['passwds'][$res['reservationid']])) { $passwd = $requestData['passwds'][$res['reservationid']][$user['id']]; } else { $passwd = ''; } $connectData = getImageConnectMethodTexts($res['imageid'], $res['imagerevisionid']); $natports = getNATports($res['reservationid']); $usenat = 0; if (count($natports)) { $usenat = 1; } $first = 1; if ($cluster) { $h .= "<fieldset>\n"; $h .= "<legend><big><b>{$res['prettyimage']}</b></big></legend>\n"; } foreach ($connectData as $cmid => $method) { if ($first) { $first = 0; } else { $h .= "<hr>\n"; } if ($requestData['forimaging'] && $res['OStype'] == 'windows') { $conuser = '******'; } elseif (preg_match('/(.*)@(.*)/', $user['unityid'], $matches)) { $conuser = $matches[1]; } else { $conuser = $user['unityid']; } if (!strlen($passwd)) { $passwd = i('(use your campus password)'); } if ($cluster) { $h .= "<h4>" . i("Connect to reservation using") . " {$method['description']}</h4>\n"; } else { $h .= "<h3>" . i("Connect to reservation using") . " {$method['description']}</h3>\n"; } $froms = array('/#userid#/', '/#password#/', '/#connectIP#/'); # check that connecttext includes port if nat is being used if ($usenat) { $found = 0; foreach ($method['ports'] as $port) { if (preg_match("/{$port['key']}/", $method['connecttext'])) { $found = 1; break; } } if (!$found) { # no port in connect text, assume first port will work $method['connecttext'] = preg_replace("/#connectIP#/", "#connectIP#:{$method['ports'][0]['key']}", $method['connecttext']); } } $tos = array($conuser, $passwd, $res['connectIP']); $msg = preg_replace($froms, $tos, $method['connecttext']); foreach ($method['ports'] as $port) { if ($usenat && array_key_exists($port['key'], $natports[$cmid])) { $msg = preg_replace("/{$port['key']}/", $natports[$cmid][$port['key']]['publicport'], $msg); } else { if ((preg_match('/remote desktop/i', $method['description']) || preg_match('/RDP/i', $method['description'])) && $port['key'] == '#Port-TCP-3389#') { $msg = preg_replace("/{$port['key']}/", $user['rdpport'], $msg); } else { $msg = preg_replace("/{$port['key']}/", $port['port'], $msg); } } } #$h .= preg_replace("/(.{1,120}([ ]|$))/", '\1<br>', $msg); $h .= $msg; if (preg_match('/remote desktop/i', $method['description']) || preg_match('/RDP/i', $method['description'])) { #$h .= "<div id=\"counterdiv\" class=\"hidden\"></div>\n"; #$h .= "<div id=\"connectdiv\">\n"; $h .= "<FORM action=\"" . BASEURL . SCRIPT . "\" method=post>\n"; $cdata = array('requestid' => $requestid, 'resid' => $res['reservationid']); $expire = datetimeToUnix($requestData['end']) - $now + 1800; # remaining reservation time plus 30 min $cont = addContinuationsEntry('sendRDPfile', $cdata, $expire); $h .= "<INPUT type=hidden name=continuation value=\"{$cont}\">\n"; $h .= "<INPUT type=submit value=\"" . i("Get RDP File") . "\">\n"; $h .= "</FORM>\n"; #$h .= "</div>\n"; } } if ($cluster) { $h .= "</fieldset><br>\n"; } } $cdata = array('requestid' => $requestid); $cont = addContinuationsEntry('AJcheckConnectTimeout', $cdata, SECINDAY); $h .= "<input type=\"hidden\" id=\"refreshcont\" value=\"{$cont}\">\n"; $return = array('html' => $h); if (!is_null($timeout)) { $return['timeoutid'] = "timeoutvalue|{$requestid}"; $return['timeout'] = $timeout; } sendJSON($return); }
function AJsaveResource() { $add = getContinuationVar('add', 0); if ($add) { $this->createImage(); return; } $data = $this->validateResourceData(); if ($data['error']) { $ret = array('status' => 'error', 'msg' => $data['errormsg']); sendJSON($ret); return; } $olddata = getContinuationVar('olddata'); $imagenotes = getImageNotes($data['imageid']); $ownerid = getUserlistID($data['owner']); if (empty($data['concurrent']) || !is_numeric($data['concurrent'])) { $data['concurrent'] = 'NULL'; } $updates = array(); # name if ($data['name'] != $olddata['prettyname']) { $updates[] = "prettyname = '{$data['name']}'"; } # ownerid if ($ownerid != $olddata['ownerid']) { $updates[] = "ownerid = {$ownerid}"; # update newimages groups $this->changeOwnerPermissions($olddata['ownerid'], $ownerid, $data['imageid']); } # minram if ($data['ram'] != $olddata['minram']) { $updates[] = "minram = {$data['ram']}"; } # minprocnumber if ($data['cores'] != $olddata['minprocnumber']) { $updates[] = "minprocnumber = {$data['cores']}"; } # minprocspeed if ($data['cpuspeed'] != $olddata['minprocspeed']) { $updates[] = "minprocspeed = {$data['cpuspeed']}"; } # minnetwork if ($data['networkspeed'] != $olddata['minnetwork']) { $updates[] = "minnetwork = {$data['networkspeed']}"; } # maxconcurrent if ($data['concurrent'] != $olddata['maxconcurrent']) { $updates[] = "maxconcurrent = {$data['concurrent']}"; } # reloadtime if ($data['reload'] != $olddata['reloadtime']) { $updates[] = "reloadtime = {$data['reload']}"; } # forcheckout if ($data['checkout'] != $olddata['forcheckout']) { $updates[] = "forcheckout = {$data['checkout']}"; } # description if ($data['desc'] != $olddata['description']) { $escdesc = mysql_real_escape_string($data['desc']); $updates[] = "description = '{$escdesc}'"; } # usage if ($data['usage'] != $olddata['usage']) { $escusage = mysql_real_escape_string($data['usage']); $updates[] = "`usage` = '{$escusage}'"; } if (count($updates)) { $query = "UPDATE image SET " . implode(', ', $updates) . " WHERE id = {$data['imageid']}"; doQuery($query); } if (empty($olddata['imagemetaid']) && ($data['checkuser'] == 0 || $data['rootaccess'] == 0 || $olddata['ostype'] == 'windows' && $data['sethostname'] == 1 || $olddata['ostype'] == 'linux' && $data['sethostname'] == 0)) { if ($olddata['ostype'] != 'windows' && $olddata['ostype'] != 'linux' || $olddata['ostype'] == 'windows' && $data['sethostname'] == 0 || $olddata['ostype'] == 'linux' && $data['sethostname'] == 1) { $data['sethostname'] = 'NULL'; } $query = "INSERT INTO imagemeta " . "(checkuser, " . "rootaccess, " . "sethostname) " . "VALUES ({$data['checkuser']}, " . "{$data['rootaccess']}, " . "{$data['sethostname']})"; doQuery($query, 101); $qh = doQuery("SELECT LAST_INSERT_ID() FROM imagemeta", 101); if (!($row = mysql_fetch_row($qh))) { abort(101); } $imagemetaid = $row[0]; $query = "UPDATE image " . "SET imagemetaid = {$imagemetaid} " . "WHERE id = {$data['imageid']}"; doQuery($query, 101); } elseif (!empty($olddata['imagemetaid'])) { if ($data['checkuser'] != $olddata['checkuser'] || $data['rootaccess'] != $olddata['rootaccess'] || ($olddata['ostype'] == 'windows' || $olddata['ostype'] == 'linux') && $data['sethostname'] != $olddata['sethostname']) { if ($olddata['ostype'] != 'windows' && $olddata['ostype'] != 'linux' || $olddata['ostype'] == 'windows' && $data['sethostname'] == 0 || $olddata['ostype'] == 'linux' && $data['sethostname'] == 1) { $data['sethostname'] = 'NULL'; } $query = "UPDATE imagemeta " . "SET checkuser = {$data['checkuser']}, " . "rootaccess = {$data['rootaccess']}, " . "sethostname = {$data['sethostname']} " . "WHERE id = {$olddata['imagemetaid']}"; doQuery($query, 101); } checkClearImageMeta($olddata['imagemetaid'], $data['imageid']); } $args = $this->defaultGetDataArgs; $args['rscid'] = $data['imageid']; $tmp = $this->getData($args); $image = $tmp[$data['imageid']]; $image['description'] = $data['desc']; $image['usage'] = $data['usage']; if (isset($imagemetaid)) { $image['imagemetaid'] = $imagemetaid; } sendJSON(array('status' => 'success', 'data' => $image)); }
function updateImage($data) { $imgdata = getImages(0, $data["imageid"]); $imagenotes = getImageNotes($data['imageid']); $ownerid = getUserlistID($data["owner"]); if (empty($data['maxconcurrent']) || !is_numeric($data['maxconcurrent'])) { $data['maxconcurrent'] = 'NULL'; } $query = "UPDATE image " . "SET prettyname = '{$data["prettyname"]}', " . "ownerid = {$ownerid}, " . "minram = {$data["minram"]}, " . "minprocnumber = {$data["minprocnumber"]}, " . "minprocspeed = {$data["minprocspeed"]}, " . "minnetwork = {$data["minnetwork"]}, " . "maxconcurrent = {$data["maxconcurrent"]}, " . "reloadtime = {$data["reloadtime"]}, " . "forcheckout = {$data["forcheckout"]}, " . "description = '{$data["description"]}', " . "`usage` = '{$data["usage"]}' " . "WHERE id = {$data["imageid"]}"; $qh = doQuery($query, 200); $return = mysql_affected_rows($GLOBALS["mysql_link_vcl"]); if (empty($imgdata[$data["imageid"]]["imagemetaid"]) && ($data["checkuser"] == 0 || $data["usergroupid"] != 0)) { if ($data["usergroupid"] == 0) { $data["usergroupid"] = "NULL"; } $query = "INSERT INTO imagemeta " . "(checkuser, " . "usergroupid) " . "VALUES ({$data["checkuser"]}, " . "{$data["usergroupid"]})"; doQuery($query, 101); $qh = doQuery("SELECT LAST_INSERT_ID() FROM imagemeta", 101); if (!($row = mysql_fetch_row($qh))) { abort(101); } $imagemetaid = $row[0]; $query = "UPDATE image " . "SET imagemetaid = {$imagemetaid} " . "WHERE id = {$data["imageid"]}"; doQuery($query, 101); } elseif (!empty($imgdata[$data["imageid"]]["imagemetaid"]) && ($data["checkuser"] != $imgdata[$data["imageid"]]["checkuser"] || $data["usergroupid"] != $imgdata[$data["imageid"]]["usergroupid"])) { if ($data["usergroupid"] == 0) { $data["usergroupid"] = "NULL"; } $query = "UPDATE imagemeta " . "SET checkuser = {$data["checkuser"]}, " . "usergroupid = {$data["usergroupid"]} " . "WHERE id = {$imgdata[$data["imageid"]]["imagemetaid"]}"; doQuery($query, 101); } return $return; }
function connectRequest() { global $remoteIP, $user, $inContinuation; if ($inContinuation) { $requestid = getContinuationVar('requestid', 0); } else { $requestid = processInputVar("requestid", ARG_NUMERIC); } $requestData = getRequestInfo($requestid); if ($requestData['reservations'][0]['remoteIP'] != $remoteIP) { $setback = unixToDatetime(time() - 600); $query = "UPDATE reservation " . "SET remoteIP = '{$remoteIP}', " . "lastcheck = '{$setback}' " . "WHERE requestid = {$requestid}"; $qh = doQuery($query, 226); addChangeLogEntry($requestData["logid"], $remoteIP); } print "<H2 align=center>Connect!</H2>\n"; if ($requestData['forimaging']) { print "<font color=red><big><strong>NOTICE:</strong> Later in this process, you must accept a\n\t\t<a href=\"" . BASEURL . SCRIPT . "?mode=imageClickThrough\">click-through agreement</a> about software licensing.</big></font><br><br>\n"; } if (count($requestData["reservations"]) == 1) { $serverIP = $requestData["reservations"][0]["reservedIP"]; $osname = $requestData["reservations"][0]["OS"]; $passwd = $requestData["reservations"][0]["password"]; if (eregi("windows", $osname)) { print "You will need to use a "; print "Remote Desktop program to connect to the "; print "system. If you did not click on the <b>Connect!</b> button from "; print "the computer you will be using to access the VCL system, you "; print "will need to cancel this reservation, request a new one, and "; print "make sure you click the <strong>Connect!</strong> button in "; print "a web browser running on the same computer from which you will "; print "be connecting to the VCL system. Otherwise, you may be denied "; print "access to the remote computer.<br><br>\n"; print "Use the following information when you are ready to connect:<br>\n"; print "<UL>\n"; print "<LI><b>Remote Computer</b>: {$serverIP}</LI>\n"; if ($requestData["forimaging"]) { print "<LI><b>User ID</b>: Administrator</LI>\n"; } else { if (preg_match('/(.*)@(.*)/', $user['unityid'], $matches)) { print "<LI><b>User ID</b>: " . $matches[1] . "</LI>\n"; } else { print "<LI><b>User ID</b>: " . $user['unityid'] . "</LI>\n"; } } if (strlen($passwd)) { print "<LI><b>Password</b>: {$passwd}<br></LI>\n"; print "</UL>\n"; print "<b>NOTE</b>: The given password is for <i>this reservation "; print "only</i>. You will be given a different password for any other "; print "reservations.<br>\n"; } else { print "<LI><b>Password</b>: (use your campus password)</LI>\n"; print "</UL>\n"; } /*print "<br>\n"; print "<FORM action=\"" . BASEURL . SCRIPT . "\" method=post>\n"; print "<h3>NEW!</h3>\n"; print "Connect to the server using a java applet:<br>\n"; print "<INPUT type=submit value=\"Connect with Applet\">\n"; print "<INPUT type=hidden name=mode value=connectRDPapplet>\n"; print "<INPUT type=hidden name=requestid value=$requestid>\n"; print "</FORM><br>\n";*/ print "For automatic connection, you can download an RDP file that can "; print "be opened by the Remote Desktop Connection program.<br><br>\n"; print "<table summary=\"\">\n"; print " <TR>\n"; print " <TD>\n"; print " <FORM action=\"" . BASEURL . SCRIPT . "\" method=post>\n"; $cdata = array('requestid' => $requestid); $expire = datetimeToUnix($requestData['end']) - datetimeToUnix($requestData['start']) + 1800; # reservation time plus 30 min $cont = addContinuationsEntry('sendRDPfile', $cdata, $expire); print " <INPUT type=hidden name=continuation value=\"{$cont}\">\n"; print " <INPUT type=submit value=\"Get RDP File\">\n"; print " </FORM>\n"; print " </TD>\n"; print " </TR>\n"; print "</table>\n"; } else { print "You will need to have an "; print "X server running on your local computer and use an "; print "ssh client to connect to the system. If you did not "; print "click on the <b>Connect!</b> button from the computer you will "; print "need to cancel this reservation, request a new one, and "; print "make sure you click the <strong>Connect!</strong> button in "; print "a web browser running on the same computer from which you will "; print "be connecting to the VCL system. Otherwise, you may be denied "; print "access to the remote computer.<br><br>\n"; print "Use the following information when you are ready to connect:<br>\n"; print "<UL>\n"; print "<LI><b>Remote Computer</b>: {$serverIP}</LI>\n"; if (preg_match('/(.*)@(.*)/', $user['unityid'], $matches)) { print "<LI><b>User ID</b>: " . $matches[1] . "</LI>\n"; } else { print "<LI><b>User ID</b>: " . $user['unityid'] . "</LI>\n"; } if (strlen($passwd)) { print "<LI><b>Password</b>: {$passwd}<br></LI>\n"; print "</UL>\n"; print "<b>NOTE</b>: The given password is for <i>this reservation "; print "only</i>. You will be given a different password for any other "; print "reservations.<br>\n"; } else { print "<LI><b>Password</b>: (use your campus password)</LI>\n"; print "</UL>\n"; } print "<strong><big>NOTE:</big> You cannot use the Windows Remote "; print "Desktop Connection to connect to this computer. You must use an "; print "ssh client.</strong>\n"; /*if(eregi("windows", $_SERVER["HTTP_USER_AGENT"])) { print "<br><br><h3>NEW!</h3>\n"; print "Connect to the server using a java applet:<br>\n"; print "<FORM action=\"" . BASEURL . SCRIPT . "\" method=post>\n"; print "<INPUT type=submit value=\"Connect with Applet\">\n"; print "<INPUT type=hidden name=mode value=connectMindterm>\n"; print "<INPUT type=hidden name=serverip value=\"$serverIP\">\n"; print "</FORM>\n"; }*/ } } else { print "You will need an "; print "ssh client to connect to any unix systems.<br>\n"; print "You will need a "; print "Remote Desktop program</a> to connect to any windows systems.<br><br>\n"; print "Use the following information when you are ready to connect:<br>\n"; $total = count($requestData["reservations"]); $count = 0; foreach ($requestData["reservations"] as $key => $res) { $count++; print "<h3>{$res["prettyimage"]}</h3>\n"; print "<UL>\n"; print "<LI><b>Platform</b>: {$res["OS"]}</LI>\n"; print "<LI><b>Remote Computer</b>: {$res["reservedIP"]}</LI>\n"; print "<LI><b>User ID</b>: " . $user['unityid'] . "</LI>\n"; if (eregi("windows", $res["OS"])) { if (strlen($res['password'])) { print "<LI><b>Password</b>: {$res['password']}<br></LI>\n"; print "</UL>\n"; print "<b>NOTE</b>: The given password is for <i>this reservation "; print "only</i>. You will be given a different password for any other "; print "reservations.<br>\n"; } else { print "<LI><b>Password</b>: (use your campus password)</LI>\n"; print "</UL>\n"; } /*print "Connect to the server using a java applet:<br>\n"; print "<INPUT type=submit value=\"Connect with Applet\">\n"; print "<INPUT type=hidden name=mode value=connectRDPapplet>\n"; print "<INPUT type=hidden name=requestid value=$requestid>\n"; print "<INPUT type=hidden name=reservedIP value=\"{$res["reservedIP"]}\">\n"; print "</FORM><br><br>\n";*/ print "Automatic connection using an RDP file:<br>\n"; print "<FORM action=\"" . BASEURL . SCRIPT . "\" method=post>\n"; $cdata = array('requestid' => $requestid, 'reservedIP' => $res['reservedIP']); $expire = datetimeToUnix($requestData['end']) - datetimeToUnix($requestData['start']) + 1800; # reservation time plus 30 min $cont = addContinuationsEntry('sendRDPfile', $cdata, $expire); print "<INPUT type=hidden name=continuation value=\"{$cont}\">\n"; print "<INPUT type=submit value=\"Get RDP File\">\n"; print "</FORM>\n"; } else { if (strlen($res['password'])) { print "<LI><b>Password</b>: {$res['password']}<br></LI>\n"; print "</UL>\n"; print "<b>NOTE</b>: The given password is for <i>this reservation "; print "only</i>. You will be given a different password for any other "; print "reservations.<br>\n"; } else { print "<LI><b>Password</b>: (use your campus password)</LI>\n"; print "</UL>\n"; } /*if(eregi("windows", $_SERVER["HTTP_USER_AGENT"])) { print "Connect to the server using a java applet:<br>\n"; print "<FORM action=\"" . BASEURL . SCRIPT . "\" method=post>\n"; print "<INPUT type=submit value=\"Connect with Applet\">\n"; print "<INPUT type=hidden name=mode value=connectMindterm>\n"; print "<INPUT type=hidden name=requestid value=$requestid>\n"; print "<INPUT type=hidden name=serverip value=\"{$res["reservedIP"]}\">\n"; print "</FORM>\n"; }*/ } if ($count < $total) { print "<hr>\n"; } } } foreach ($requestData["reservations"] as $res) { if ($res["forcheckout"]) { $imageid = $res["imageid"]; break; } } $imagenotes = getImageNotes($imageid); if (preg_match('/\\w/', $imagenotes['usage'])) { print "<h3>Notes on using this environment:</h3>\n"; print "{$imagenotes['usage']}<br><br><br>\n"; } }
function XMLRPCgetImages() { $resources = getUserResources(array("imageAdmin", "imageCheckOut")); $resources["image"] = removeNoCheckout($resources["image"]); $return = array(); foreach ($resources['image'] as $key => $val) { $notes = getImageNotes($key); $tmp = array('id' => $key, 'name' => $val, 'description' => $notes['description'], 'usage' => $notes['usage']); array_push($return, $tmp); } return $return; }