nodessh.php3 3.98 KB
Newer Older
1 2
<?php
#
3
# Copyright (c) 2000-2011, 2013 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 ./ssh-mime.pl
# on the remote node, when set up as a proper mime type.
#

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

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

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

$query_result =
48
    DBQueryFatal("select n.jailflag,n.jailip,n.sshdport, ".
49
		 "       r.vname,r.pid,r.eid, ".
50
		 "       t.isvirtnode,t.isremotenode,t.isplabdslice, ".
51
		 "       t.issubnode,t.isfednode,t.class ".
52 53 54
		 " 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 ".
55
		 "left join os_info as oi on n.def_boot_osid=oi.osid ".
56 57 58 59 60 61 62
		 "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);
63 64
$jailflag = $row["jailflag"];
$jailip   = $row["jailip"];
65
$sshdport = $row["sshdport"];
66 67 68 69 70 71 72 73
$vname    = $row["vname"];
$pid      = $row["pid"];
$eid      = $row["eid"];
$isvirt   = $row["isvirtnode"];
$isremote = $row["isremotenode"];
$isplab   = $row["isplabdslice"];
$issubnode= $row["issubnode"];
$class    = $row["class"];
74
$isfednode= $row["isfednode"];
75

76 77 78 79 80
#
# XXX hack to determine if target node is on a routable network
#
$unroutable = ($ELABINELAB || !strncmp($CONTROL_NETWORK, "192.168.", 8));

81 82 83 84 85 86 87 88 89 90 91 92
#
# If we need a proxy host, determine whether it is ops or boss.
# Normally it is ops, unless ops is a VM and it is in an inner elab.
# In that case, there is no external DNS alias ("myops.eid.pid.emulab.net")
# created for the inner ops so it cannot be the proxy.
#
if ($ELABINELAB && $OPS_VM) {
    $PROXYNODE = $BOSSNODE;
} else {
    $PROXYNODE = $USERNODE;
}

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

97
$filename = $node_id . ".tbssh"; 
98 99 100 101 102
header("Content-Type: application/x-unknown");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Disposition: attachment; filename=\"$filename\"");
103 104
header("Content-Description: SSH description file for a testbed node");

105 106 107 108 109
if ($NONAMEDSETUP) {
    echo "hostname: $node_id.$OURDOMAIN\n";
} else {
    echo "hostname: $vname.$eid.$pid.$OURDOMAIN\n";
}
110 111 112 113 114 115 116 117
echo "login:    $uid\n";

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!
	#
118
	if ($jailflag || $isplab || $isfednode) {
119 120 121 122 123 124 125 126 127
	    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.
	#
128
	echo "gateway: $PROXYNODE\n";
129 130
    }
}
131 132 133 134
elseif ($unroutable) {
    #
    # If nodes are unroutable, gateway via the user node
    #
135
    echo "gateway: $PROXYNODE\n";
136
}
137 138 139 140 141 142
elseif ($issubnode && $class == 'ixp') {
    #
    # IXP hack: pass <node-id>-gw as the gateway address
    #
    echo "gateway: $node_id-gw.$OURDOMAIN\n";
}
143 144

?>