cdromcheckin.php3 6.81 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2002 University of Utah and the Flux Group.
# All rights reserved.
#
require("defs.php3");

# These error codes must match whats in register.pl on the cd.
define("CDROMSTATUS_OKAY"	,	0);
define("CDROMSTATUS_MISSINGARGS",	100);
define("CDROMSTATUS_INVALIDARGS",	101);
define("CDROMSTATUS_BADCDKEY",		102);
define("CDROMSTATUS_BADPRIVKEY",	103);
define("CDROMSTATUS_BADIPADDR",		104);
define("CDROMSTATUS_BADREMOTEIP",	105);
define("CDROMSTATUS_IPADDRINUSE",	106);
define("CDROMSTATUS_OTHER",		199);

#
# Spit back a text message we can display to the user on the console
# of the node running the checkin. We could return an http error, but
# that would be of no help to the user on the other side.
# 
function SPITSTATUS($status)
{
    header("Content-Type: text/plain");
    echo "emulab_status=$status\n";
}

#
# This page is not intended to be invoked by humans!
#
if ((!isset($cdkey) || !strcmp($cdkey, "")) ||
    (!isset($privkey) || !strcmp($privkey, "")) ||
    (!isset($IP) || !strcmp($IP, ""))) {
    SPITSTATUS(CDROMSTATUS_MISSINGARGS);
    return;
}

if (!ereg("[0-9a-zA-Z]+", $cdkey) ||
42
    !ereg("[0-9a-zA-Z ]+", $privkey) ||
43
44
45
46
47
    !ereg("[0-9\.]+", $IP)) {
    SPITSTATUS(CDROMSTATUS_INVALIDARGS);
    return;
}

48
49
50
51
52
53
if (isset($wahostname) &&
    !ereg("[-_0-9a-zA-Z\.]+", $wahostname)) {
    SPITSTATUS(CDROMSTATUS_INVALIDARGS);
    return;
}

54
55
56
57
58
59
60
61
62
#
# Make sure this is a valid CDkey.
#
$query_result =
    DBQueryFatal("select * from cdroms where cdkey='$cdkey'");
if (! mysql_num_rows($query_result)) {
    SPITSTATUS(CDROMSTATUS_BADCDKEY);
    return;
}
63
64
$row    = mysql_fetch_array($query_result);
$cdvers = $row[version];
65
66

#
67
# Grab the privkey record. First squeeze out any spaces.
68
#
69
70
$privkey = str_replace(" ", "", $privkey);

71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
$query_result =
    DBQueryFatal("select * from widearea_privkeys where privkey='$privkey'");

if (!mysql_num_rows($query_result)) {
    SPITSTATUS(CDROMSTATUS_BADPRIVKEY);
    return;
}
$warow  = mysql_fetch_array($query_result);
$privIP = $warow[IP];

#
# If the node is reporting that its finished updating, then make its
# current privkey its nextprivkey.
# 
if (isset($updated) && $updated == 1) {
    if (! strcmp($privIP, "1.1.1.1")) {
        #
        # If the node is brand new, then need to create several records.
	# Pass it off to a perl script.
        #
	DBQueryFatal("update widearea_privkeys ".
		     "set IP='$IP' ".
		     "where privkey='$privkey'");
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120

	#
	# Generate a nickname if given hostname.
	#
	$nickname = "";
	$type     = "pcwa";
	if (isset($wahostname)) {
	    $nickname .= "-n ";
	    
	    if (strpos($wahostname, ".")) {
		$nickname .= str_replace(".", "-", $wahostname);
	    }
	    else {
		$nickname .= $wahostname;
	    }

            #
            # XXX Parse hostname to see if a ron node.
	    # Silly, but effective since we will never have anything else
	    # besides wa/ron.
            #
	    if (strstr($wahostname, ".ron.")) {
		$type = "pcron";
	    }
	}
	SUEXEC("nobody", $TBADMINGROUP,
	       "webnewwanode -w $nickname -t $type -i $IP", 0);
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
    }
    DBQueryFatal("update widearea_privkeys ".
		 "set privkey=nextprivkey,updated=now(),nextprivkey=NULL ".
		 "where privkey='$privkey'");

    SPITSTATUS(CDROMSTATUS_OKAY);
    return;
}

#
# If the record has a valid IP address and matches the node connecting
# then all we do is return a new private key.
#
if (strcmp($privIP, "1.1.1.1")) {
    if (strcmp($privIP, $IP)) {
	SPITSTATUS(CDROMSTATUS_BADIPADDR);
	return;
    }
    if (strcmp($REMOTE_ADDR, $IP)) {
	SPITSTATUS(CDROMSTATUS_BADREMOTEIP);
	return;
    }

    #
145
    # For now we just give them a new privkey. There is no real image upgrade
146
147
148
149
    # path in place yet.
    #
    $newkey = GENHASH();
    DBQueryFatal("update widearea_privkeys ".
150
		 "set nextprivkey='$newkey',updated=now(),cdkey='$cdkey' ".
151
152
153
154
		 "where IP='$IP' and privkey='$privkey'");

    header("Content-Type: text/plain");
    echo "privkey=$newkey\n";
155
156

    if (0) {
157
158
159
    if ($cdvers == 3) {
	    echo "slice1_image=http://${WWWHOST}/images/slice1-v3.ndz\n";
	    echo "slice1_md5=263d82a69e48f37ecd0e31f6f5171faa\n";
160
161
162
163
164
	    echo "slicex_mount=/users\n";
    }
    }
    echo "emulab_status=0\n";
    
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
    return;
}

#
# We need to check for duplicate IPs. 
#
$query_result =
    DBQueryFatal("select * from widearea_privkeys where IP='$IP'");

if (mysql_num_rows($query_result)) {
    SPITSTATUS(CDROMSTATUS_IPADDRINUSE);
    return;
}

#
# Generate a new privkey and return the info. The DB is updated with the
# next key, but it does not become effective until it responds that it
# finished okay. This leaves a window open, but the eventual plan it to
# get rid of these priv keys anyway and go to per-node cert files we update
# on the fly.
# 
$newkey = GENHASH();
DBQueryFatal("update widearea_privkeys ".
188
	     "set nextprivkey='$newkey',updated=now(),cdkey='$cdkey'".
189
190
	     "where privkey='$privkey'");

191
192
header("Content-Type: text/plain");
echo "privkey=$newkey\n";
193
if ($cdvers == 1) {
Mike Hibler's avatar
Mike Hibler committed
194
195
196
197
198
199
    if (0) {
	# one shot setup for ISI (or anyone else who has a corrupt image)
	echo "fdisk=http://${WWWHOST}/images/image.fdisk\n";
	echo "slice1_image=http://${WWWHOST}/images/slice1-v1.ndz\n";
	echo "slice1_md5=2970e2cf045f5872c6728eeea3b51dae\n";
	echo "slicex_mount=/users\n";
200
201
	echo "slicex_tarball=http://${WWWHOST}/images/slicex-v2.tar.gz\n";
	echo "slicex_md5=a5274072a40ebf2fda8b8596a6e60e0d\n";
Mike Hibler's avatar
Mike Hibler committed
202
203
204
205
206
    } else {
	echo "fdisk=image.fdisk\n";
	echo "slice1_image=slice1.ndz\n";
	echo "slice1_md5=cb810b43f49d15b3ac4122ff42f8925d\n";
	echo "slicex_mount=/users\n";
207
208
	echo "slicex_tarball=http://${WWWHOST}/images/slicex.tar.gz\n";
	echo "slicex_md5=a5274072a40ebf2fda8b8596a6e60e0d\n";
Mike Hibler's avatar
Mike Hibler committed
209
    }
210
}
Leigh B. Stoller's avatar
Leigh B. Stoller committed
211
elseif ($cdvers == 2) {
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
    if (0) {
	echo "fdisk=http://${WWWHOST}/images/image.fdisk\n";
	echo "slice1_image=http://${WWWHOST}/images/slice1-v2.ndz\n";
	echo "slice1_md5=402f00f2e46d22507cef3d19846b48f8\n";
	echo "slicex_mount=/users\n";
	echo "slicex_tarball=http://${WWWHOST}/images/slicex-v2.tar.gz\n";
	echo "slicex_md5=a5274072a40ebf2fda8b8596a6e60e0d\n";
    }
    else {
	echo "fdisk=image.fdisk\n";
	echo "slice1_image=slice1.ndz\n";
	echo "slice1_md5=402f00f2e46d22507cef3d19846b48f8\n";
	echo "slicex_mount=/users\n";
	echo "slicex_tarball=slicex.tar.gz\n";
	echo "slicex_md5=a5274072a40ebf2fda8b8596a6e60e0d\n";
    }
228
}
Leigh B. Stoller's avatar
Leigh B. Stoller committed
229
230
231
232
else {
    if (0) {
	echo "fdisk=http://${WWWHOST}/images/image.fdisk\n";
	echo "slice1_image=http://${WWWHOST}/images/slice1-v3.ndz\n";
233
	echo "slice1_md5=263d82a69e48f37ecd0e31f6f5171faa\n";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
234
235
236
237
238
239
240
	echo "slicex_mount=/users\n";
	echo "slicex_tarball=http://${WWWHOST}/images/slicex-v3.tar.gz\n";
	echo "slicex_md5=0a3398cee6104850adaee7afbe75f008\n";
    }
    else {
	echo "fdisk=image.fdisk\n";
	echo "slice1_image=slice1.ndz\n";
241
	echo "slice1_md5=263d82a69e48f37ecd0e31f6f5171faa\n";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
242
243
244
245
246
	echo "slicex_mount=/users\n";
	echo "slicex_tarball=slicex.tar.gz\n";
	echo "slicex_md5=0a3398cee6104850adaee7afbe75f008\n";
    }
}
247
echo "emulab_status=0\n";