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