noderdp.php3 3.39 KB
Newer Older
1 2
<?php
#
3
# Copyright (c) 2000-2004, 2006, 2007 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
23 24
#
include("defs.php3");
25
include_once("node_defs.php");
26 27 28 29 30 31 32 33 34

#
# This script generates an "tbc" file, to be passed to ./rdp-mime.pl
# on the remote node, when set up as a proper mime type.
#

#
# Only known and logged in users.
#
35 36
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
37

38 39 40 41 42 43 44 45
#
# Verify form arguments.
#
$reqargs = RequiredPageArguments("node", PAGEARG_NODE);

# Need these below
$node_id = $node->node_id();

46 47 48
if ($this_user->w_pswd() != "") {
    $pswd = $this_user->w_pswd();
}
49 50 51
else {
    # The initial random default for the Windows Password is based on the Unix
    # encrypted password, in particular the random salt if it's an MD5 crypt,
52 53 54
    # consisting of the 8 characters after an initial "$1$" and followed by a
    # "$". 
    $unixpwd = explode('$', $this_user->pswd());
55 56 57 58 59 60 61
    if (strlen($unixpwd[0]) > 0)
	# When there's no $ at the beginning, it's not an MD5 hash.
	$pswd = substr($unixpwd[0],0,8);
    else
	$pswd = substr($unixpwd[2],0,8); # The MD5 salt string.
}

62
$query_result =
63
    DBQueryFatal("select n.jailflag,n.jailip,n.sshdport, ".
64 65 66 67 68 69 70 71 72 73 74 75
		 "       r.vname,r.pid,r.eid, ".
		 "       t.isvirtnode,t.isremotenode,t.isplabdslice ".
		 " from nodes as n ".
		 "left join reserved as r on n.node_id=r.node_id ".
		 "left join node_types as t on t.type=n.type ".
		 "where n.node_id='$node_id'");

if (mysql_num_rows($query_result) == 0) {
    USERERROR("The node $node_id does not exist!", 1);
}

$row = mysql_fetch_array($query_result);
76 77
$jailflag = $row["jailflag"];
$jailip   = $row["jailip"];
78
$sshdport = $row["sshdport"];
79 80 81 82 83 84
$vname    = $row["vname"];
$pid      = $row["pid"];
$eid      = $row["eid"];
$isvirt   = $row["isvirtnode"];
$isremote = $row["isremotenode"];
$isplab   = $row["isplabdslice"];
85 86 87 88 89 90 91 92 93 94 95 96

if (!isset($pid)) {
    USERERROR("$node_id is not allocated to an experiment!", 1);
}

$filename = $node_id . ".tbrdp"; 
header("Content-Type: text/x-testbed-rdp");
header("Content-Disposition: inline; filename=$filename;");
header("Content-Description: RDP description file for a testbed node");

echo "hostname: $vname.$eid.$pid.$OURDOMAIN\n";
echo "login:    $uid\n";
97
echo "password: $pswd\n";
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123

if ($isvirt) {
    if ($isremote) {
	#
	# Remote nodes run sshd on another port since they so not
	# have per-jail IPs. Of course, might not even be jailed!
	#
	if ($jailflag || $isplab) {
	    echo "port: $sshdport\n";
	}
    }
    else {
	#
	# Local virt nodes are on the private network, so have to
	# bounce through ops node to get there. They run sshd on
	# on the standard port, but on a private IP.
	#
	echo "gateway: $USERNODE\n";
    }
}
elseif ($ELABINELAB) {
    echo "gateway: $USERNODE\n";
}

?>