7 // Returns node boot script
9 // Mark Huang <mlhuang@cs.princeton.edu>
10 // Copyright (C) 2006 The Trustees of Princeton University
15 // Get admin API handle
16 require_once 'plc_api.php';
19 // location for signed scripts
20 $bmdir="/var/www/html/boot";
23 $candidates = array();
26 $interfaces = $adm->GetInterfaces(array('ip' => $_SERVER['REMOTE_ADDR']));
27 if (!empty($interfaces)) {
28 $nodes = $adm->GetNodes(array($interfaces[0]['node_id']));
35 // Allow very old nodes that do not have a node key in their
36 // configuration files to use their "boot nonce" instead. The boot
37 // nonce is a random value generated by the node itself and POSTed
38 // by the Boot CD when it requests the Boot Manager. This is
39 // obviously not very secure, so we only allow it to be used if the
40 // requestor IP is the same as the IP address we have on record for
43 // 3.x CDs post 'version', 2.x CDs post 'id'.
44 if (!empty($_REQUEST['version'])) {
45 $version = trim($_REQUEST['version']);
46 } elseif (!empty($_REQUEST['id'])) {
47 $version = trim($_REQUEST['id']);
52 if (empty($node['key']) && !empty($_REQUEST['nonce'])) {
53 // 3.x CDs post the boot nonce in ASCII hex. 2.x CDs post it in binary.
54 if (strstr($version, "2.0") === FALSE) {
55 // 3.x CDs post a trailing newline...sigh
56 $nonce = trim($_REQUEST['nonce']);
58 $nonce = bin2hex($_REQUEST['nonce']);
60 $adm->UpdateNode($node['node_id'], array('boot_nonce' => $nonce));
63 // Custom bootmanager for the node, e.g.
64 // planetlab-1.cs.princeton.edu_bootmanager.sh.sgn
65 $candidates [] = "bootmanager" . "_" . strtolower($node['hostname']);
67 // Custom bootmanager for the deployment tag, e.g.
68 $deployment = $adm->GetNodeDeployment($node['node_id']);
69 if ( ! empty ($deployment) ) {
70 $candidates[] = "bootmanager" . "_" . $deployment;
74 // Default bootmanager
75 $candidates[] = "bootmanager_regular";
77 foreach ($candidates as $bootmanager) {
78 $candidate=$bmdir . "/" . $bootmanager . $bmext ;
79 if (file_exists($candidate)) {