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 // location for signed scripts
16 $bmdir="/var/www/html/bootmanager";
18 // Default bootmanager
19 $bootmanager = "bootmanager.sh.sgn";
22 $interfaces = $adm->GetInterfaces(array('ip' => $_SERVER['REMOTE_ADDR']));
23 if (!empty($interfaces)) {
24 $nodes = $adm->GetNodes(array($interfaces[0]['node_id']));
31 // Allow very old nodes that do not have a node key in their
32 // configuration files to use their "boot nonce" instead. The boot
33 // nonce is a random value generated by the node itself and POSTed
34 // by the Boot CD when it requests the Boot Manager. This is
35 // obviously not very secure, so we only allow it to be used if the
36 // requestor IP is the same as the IP address we have on record for
39 // 3.x CDs post 'version', 2.x CDs post 'id'.
40 if (!empty($_REQUEST['version'])) {
41 $version = trim($_REQUEST['version']);
42 } elseif (!empty($_REQUEST['id'])) {
43 $version = trim($_REQUEST['id']);
48 if (empty($node['key']) && !empty($_REQUEST['nonce'])) {
49 // 3.x CDs post the boot nonce in ASCII hex. 2.x CDs post it in binary.
50 if (strstr($version, "2.0") === FALSE) {
51 // 3.x CDs post a trailing newline...sigh
52 $nonce = trim($_REQUEST['nonce']);
54 $nonce = bin2hex($_REQUEST['nonce']);
56 $adm->UpdateNode($node['node_id'], array('boot_nonce' => $nonce));
59 // Custom bootmanager for the node, e.g.
60 // planetlab-1.cs.princeton.edu_bootmanager.sh.sgn
61 $bootmanagers = array(strtolower($node['hostname']) . "_" . $bootmanager);
63 // Custom bootmanager for the deployment tag, e.g.
65 if (!empty($node['nodegroup_ids'])) {
66 $nodegroups = $adm->GetNodeDeployment($node['nodegroup_ids']);
67 foreach ($nodegroups as $nodegroup) {
68 $bootmanagers[] = strtolower($nodegroup['groupname']) . "_" . $bootmanager;
73 // Default bootmanager
74 $bootmanagers[] = "regular_" . $bootmanager;
76 foreach ($bootmanagers as $bootmanager) {
77 $candidate=$bmdir . "/" . $bootmanager;
78 if (file_exists($candidate)) {