3 // Returns node boot script
5 // Mark Huang <mlhuang@cs.princeton.edu>
6 // Copyright (C) 2006 The Trustees of Princeton University
11 // Get admin API handle
12 require_once 'plc_api.php';
15 // Default bootmanager
16 $bootmanager = "bootmanager.sh.sgn";
19 $nodenetworks = $adm->GetNodeNetworks(array('ip' => $_SERVER['REMOTE_ADDR']));
20 if (!empty($nodenetworks)) {
21 $nodes = $adm->GetNodes(array($nodenetworks[0]['node_id']));
28 // Allow very old nodes that do not have a node key in their
29 // configuration files to use their "boot nonce" instead. The boot
30 // nonce is a random value generated by the node itself and POSTed
31 // by the Boot CD when it requests the Boot Manager. This is
32 // obviously not very secure, so we only allow it to be used if the
33 // requestor IP is the same as the IP address we have on record for
36 // 3.x CDs post 'version', 2.x CDs post 'id'.
37 if (!empty($_REQUEST['version'])) {
38 $version = trim($_REQUEST['version']);
39 } elseif (!empty($_REQUEST['id'])) {
40 $version = trim($_REQUEST['id']);
45 if (empty($node['key']) && !empty($_REQUEST['nonce'])) {
46 // 3.x CDs post the boot nonce in ASCII hex. 2.x CDs post it in binary.
47 if (strstr($version, "2.0") === FALSE) {
48 // 3.x CDs post a trailing newline...sigh
49 $nonce = trim($_REQUEST['nonce']);
51 $nonce = bin2hex($_REQUEST['nonce']);
53 $adm->UpdateNode($node['node_id'], array('boot_nonce' => $nonce));
56 // Custom bootmanager for the node, e.g.
57 // planetlab-1.cs.princeton.edu_bootmanager.sh.sgn
58 $bootmanagers = array(strtolower($node['hostname']) . "_" . $bootmanager);
60 // Custom bootmanager for the node group, e.g.
61 // alpha_bootmanager.sh.sgn
62 if (!empty($node['nodegroup_ids'])) {
63 $nodegroups = $adm->GetNodeGroups($node['nodegroup_ids']);
64 foreach ($nodegroups as $nodegroup) {
65 $bootmanagers[] = strtolower($nodegroup['name']) . "_" . $bootmanager;
70 // Default bootmanager
71 $bootmanagers[] = $bootmanager;
73 foreach ($bootmanagers as $bootmanager) {
74 if (file_exists($bootmanager)) {
75 readfile($bootmanager);