remove svn keywords and use %{SCMURL} in spec file
[bootmanager.git] / nodeconfig / boot / index.php
1 <?php
2
3 //
4 // Returns node boot script
5 //
6 // Mark Huang <mlhuang@cs.princeton.edu>
7 // Copyright (C) 2006 The Trustees of Princeton University
8 //
9
10 // Get admin API handle
11 require_once 'plc_api.php';
12 global $adm;
13
14 // location for signed scripts
15 $bmdir="/var/www/html/boot";
16 $bmext=".sh.sgn";
17
18 $candidates = array();
19
20 // Look up the node
21 $interfaces = $adm->GetInterfaces(array('ip' => $_SERVER['REMOTE_ADDR']));
22 if (!empty($interfaces)) {
23   $nodes = $adm->GetNodes(array($interfaces[0]['node_id']));
24   if (!empty($nodes)) {
25     $node = $nodes[0];
26   }
27 }
28
29 if (isset($node)) {
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
36   // the node.
37
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']);
43   } else {
44     $version = "2.0";
45   }
46
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']);
52     } else {
53       $nonce = bin2hex($_REQUEST['nonce']);
54     }
55     $adm->UpdateNode($node['node_id'], array('boot_nonce' => $nonce));
56   }
57
58   // Custom bootmanager for the node, e.g.
59   // planetlab-1.cs.princeton.edu_bootmanager.sh.sgn
60   $candidates [] = "bootmanager" . "_" . strtolower($node['hostname']);
61
62   // Custom bootmanager for the deployment tag, e.g.
63   $deployment = $adm->GetNodeDeployment($node['node_id']);
64   if ( ! empty ($deployment) ) {
65     $candidates[] = "bootmanager" . "_" . $deployment;
66   }
67 }
68
69 // Default bootmanager
70 $candidates[] = "bootmanager_regular";
71
72 foreach ($candidates as $bootmanager) {
73   $candidate=$bmdir . "/" . $bootmanager . $bmext ;
74   if (file_exists($candidate)) {
75     readfile($candidate);
76     exit();
77   }
78 }
79
80 ?>