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/boot";
19 $candidates = array();
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 $candidates [] = "bootmanager" . "_" . strtolower($node['hostname']);
63 // Custom bootmanager for the deployment tag, e.g.
64 $deployment = $adm->GetNodeDeployment($node['node_id']);
65 if ( ! empty ($deployment) ) {
66 $candidates[] = "bootmanager" . "_" . $deployment;
70 // Default bootmanager
71 $candidates[] = "bootmanager_regular";
73 foreach ($candidates as $bootmanager) {
74 $candidate=$bmdir . "/" . $bootmanager . $bmext ;
75 if (file_exists($candidate)) {