function sendRDPfile() { global $user; # for more info on this file, see # http://dev.remotenetworktechnology.com/ts/rdpfile.htm $requestid = getContinuationVar("requestid"); $resid = getContinuationVar("resid"); $request = getRequestInfo("{$requestid}"); if ($request['stateid'] == 11 || $request['stateid'] == 12 || $request['stateid'] == 14 && ($request['laststateid'] == 11 || $request['laststateid'] == 12)) { $cont = addContinuationsEntry('viewRequests'); header("Location: " . BASEURL . SCRIPT . "?continuation={$cont}"); return; } foreach ($request["reservations"] as $res) { if ($res['reservationid'] == $resid) { $ipaddress = $res["connectIP"]; break; } } if (empty($ipaddress)) { return; } $passwd = $request['passwds'][$resid][$user['id']]; $connectData = getImageConnectMethodTexts($res['imageid'], $res['imagerevisionid']); $natports = getNATports($resid); $port = ''; foreach ($connectData as $cmid => $method) { if (preg_match('/remote desktop/i', $method['description']) || preg_match('/RDP/i', $method['description'])) { # assume index 0 of ports for nat if (!empty($natports) && array_key_exists($method['ports'][0]['key'], $natports[$cmid])) { $port = ':' . $natports[$cmid][$method['ports'][0]['key']]['publicport']; } else { if ($method['ports'][0]['key'] == '#Port-TCP-3389#' && $user['rdpport'] != 3389) { $port = ':' . $user['rdpport']; } else { $port = ':' . $method['ports'][0]['port']; } } break; } } $width = $user["width"]; $height = $user["height"]; if ($width == 0) { $screenmode = 2; $width = 1024; $height = 768; } else { $screenmode = 1; } $bpp = $user["bpp"]; if ($user["audiomode"] == "none") { $audiomode = 2; } else { $audiomode = 0; } $redirectdrives = $user["mapdrives"]; $redirectprinters = $user["mapprinters"]; $redirectcomports = $user["mapserial"]; header("Content-type: application/rdp"); if ($request['serverrequest']) { if (count($request['reservations']) == 1) { header("Content-Disposition: inline; filename=\"{$request['servername']}.rdp\""); } else { header("Content-Disposition: inline; filename=\"{$request['servername']}-{$res['prettyimage']}.rdp\""); } } else { header("Content-Disposition: inline; filename=\"{$res['prettyimage']}.rdp\""); } print "screen mode id:i:{$screenmode}\r\n"; print "desktopwidth:i:{$width}\r\n"; print "desktopheight:i:{$height}\r\n"; print "session bpp:i:{$bpp}\r\n"; print "winposstr:s:0,1,382,71,1182,671\r\n"; print "full address:s:{$ipaddress}{$port}\r\n"; print "compression:i:1\r\n"; print "keyboardhook:i:2\r\n"; print "audiomode:i:{$audiomode}\r\n"; print "redirectdrives:i:{$redirectdrives}\r\n"; print "redirectprinters:i:{$redirectprinters}\r\n"; print "redirectcomports:i:{$redirectcomports}\r\n"; print "redirectsmartcards:i:1\r\n"; print "displayconnectionbar:i:1\r\n"; print "autoreconnection enabled:i:1\r\n"; if ($request["forimaging"] && $res['OStype'] == 'windows') { print "username:s:Administrator\r\n"; } else { if (preg_match('/(.*)@(.*)/', $user['unityid'], $matches)) { print "username:s:" . $matches[1] . "\r\n"; } else { print "username:s:" . $user["unityid"] . "\r\n"; } } print "clear password:s:{$passwd}\r\n"; print "domain:s:\r\n"; print "alternate shell:s:\r\n"; print "shell working directory:s:\r\n"; print "disable wallpaper:i:1\r\n"; print "disable full window drag:i:1\r\n"; print "disable menu anims:i:1\r\n"; print "disable themes:i:0\r\n"; print "disable cursor setting:i:0\r\n"; print "bitmapcachepersistenable:i:1\r\n"; //print "connect to console:i:1\r\n"; }
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 XMLRPCgetRequestConnectData($requestid, $remoteIP) { global $user; $requestid = processInputData($requestid, ARG_NUMERIC); $remoteIP = processInputData($remoteIP, ARG_STRING, 1); if (!preg_match('/^([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})$/', $remoteIP, $matches) || $matches[1] < 1 || $matches[1] > 223 || $matches[2] > 255 || $matches[3] > 255 || $matches[4] > 255) { return array('status' => 'error', 'errorcode' => 2, 'errormsg' => 'invalid IP address'); } $userRequests = getUserRequests('all', $user['id']); $found = 0; foreach ($userRequests as $req) { if ($req['id'] == $requestid) { $request = $req; $found = 1; break; } } if (!$found) { return array('status' => 'error', 'errorcode' => 1, 'errormsg' => 'unknown requestid'); } // FIXME - add support for cluster requests if (requestIsReady($request)) { $requestData = getRequestInfo($requestid); $query = "UPDATE reservation " . "SET remoteIP = '{$remoteIP}' " . "WHERE requestid = {$requestid}"; $qh = doQuery($query, 101); addChangeLogEntry($requestData["logid"], $remoteIP); $serverIP = $requestData["reservations"][0]["connectIP"]; $passwd = $requestData["reservations"][0]["password"]; $connectMethods = getImageConnectMethodTexts($requestData["reservations"][0]["imageid"], $requestData["reservations"][0]["imagerevisionid"]); if ($requestData["forimaging"]) { $thisuser = '******'; } else { if (preg_match('/(.*)@(.*)/', $user['unityid'], $matches)) { $thisuser = $matches[1]; } else { $thisuser = $user['unityid']; } } $natports = getNATports($requestData['reservations'][0]['reservationid']); $portdata = array(); foreach ($connectMethods as $key => $cm) { $connecttext = $cm["connecttext"]; $connecttext = preg_replace("/#userid#/", $thisuser, $connecttext); $connecttext = preg_replace("/#password#/", $passwd, $connecttext); $connecttext = preg_replace("/#connectIP#/", $serverIP, $connecttext); foreach ($cm['ports'] as $port) { if (!empty($natports) && array_key_exists($port['key'], $natports[$key])) { $connecttext = preg_replace("/{$port['key']}/", $natports[$key][$port['key']]['publicport'], $connecttext); $connectMethods[$key]['connectports'][] = "{$port['protocol']}:{$port['port']}:{$natports[$key][$port['key']]['publicport']}"; } else { if ((preg_match('/remote desktop/i', $cm['description']) || preg_match('/RDP/i', $cm['description'])) && $port['key'] == '#Port-TCP-3389#') { $connecttext = preg_replace("/{$port['key']}/", $user['rdpport'], $connecttext); $connectMethods[$key]['connectports'][] = "{$port['protocol']}:{$port['port']}:{$user['rdpport']}"; } else { $connecttext = preg_replace("/{$port['key']}/", $port['port'], $connecttext); $connectMethods[$key]['connectports'][] = "{$port['protocol']}:{$port['port']}:{$port['port']}"; } } } $connectMethods[$key]["connecttext"] = $connecttext; $portdata[$key] = $connectMethods[$key]['ports']; unset($connectMethods[$key]['ports']); } $tmp = array_keys($portdata); $cmid = $tmp[0]; if (empty($natports)) { if ((preg_match('/remote desktop/i', $connectMethods[$cmid]['description']) || preg_match('/RDP/i', $connectMethods[$cmid]['description'])) && $portdata[$cmid][0]['port'] == 3389) { $connectport = $user['rdpport']; } else { $connectport = $portdata[$cmid][0]['port']; } } else { $key = $portdata[$cmid][0]['key']; $connectport = $natports[$cmid][$key]['publicport']; } return array('status' => 'ready', 'serverIP' => $serverIP, 'user' => $thisuser, 'password' => $passwd, 'connectport' => $connectport, 'connectMethods' => $connectMethods); } return array('status' => 'notready'); }