3 require_once 'plc_login.php'; // Require login
4 require_once 'plc_session.php'; // Get session and API handles
5 global $plc, $api, $adm;
8 require_once 'plc_drupal.php';
10 include 'plc_header.php';
13 require_once 'plc_functions.php';
14 require_once 'plc_config.php';
15 include 'plc_objects.php';
18 class Download extends Controller {
21 function stage5_bootimage($pcu_id=0, $site_id=0, $node_id=0)
24 $this->load->helper(array('form', 'url'));
25 $this->load->library('validation');
27 $this->validation->set_error_delimiters('<span class="error">', '</span>');
29 # TODO: if result is false, redirect to beginning.
30 /*$result = $this->validation->run();*/
31 /*print "RESULT: ".$result . "<br>";*/
32 /*print $this->validation->error_string . "<br>";*/
35 $data['pcu_id'] = intval($pcu_id);
36 $data['node_id'] = intval($node_id);
37 $data['site_id'] = intval($site_id);
39 $this->load->view('header', $data);
40 $this->load->view('debug', $data);
41 $this->load->view('stage5_bootimage', $data);
42 $this->load->view('footer', $data);
45 function stage6_download($pcu_id=0, $site_id=0, $node_id=0)
48 $this->load->helper(array('form', 'url'));
49 $this->load->helper('download');
50 $this->load->library('validation');
52 $this->validation->set_error_delimiters('<span class="error">', '</span>');
53 $person = new Person($plc->person);
55 $fields['action'] = "Download Action";
56 $this->validation->set_fields($fields);
58 $rules['action'] = "required";
59 $this->validation->set_rules($rules);
61 # TODO: if result is false, redirect to beginning.
62 $result = $this->validation->run();
65 $data['pcu_id'] = intval($pcu_id);
66 $data['node_id'] = intval($node_id);
67 $data['site_id'] = intval($site_id);
68 $data['action'] = $this->validation->action;
70 $data['generic_iso_name'] = $this->get_bootcd_version();
71 $data = $this->get_stage6_data($person, $data);
72 print $this->validation->error_string . "<br>";
73 $this->load->view('header', $data);
74 $this->load->view('debug', $data);
75 $this->load->view('stage6_download', $data);
76 $this->load->view('footer', $data);
79 function getnode($node_id)
82 $plc_node_list = $api->GetNodes(array('node_id' => intval($node_id) ));
83 return $plc_node_list[0];
86 function get_stage6_data($person, $data=NULL)
93 $data['has_primary'] = 1;
94 $node_detail = $this->getnode($data['node_id']);
95 $data['node_detail'] = $node_detail;
96 $node_id = $data['node_id'];
97 $action = $_REQUEST['action'];
100 case "download-generic-iso":
101 case "download-generic-usb":
103 if ($action=="download-generic-iso") {
104 $boot_action="generic-iso";
105 $basename=PLC_NAME."-BootCD.iso";
107 $boot_action="generic-usb";
108 $basename=PLC_NAME."-BootCD.usb";
111 $api->UpdateNode( $hostname, array( "boot_state" => 'disabled',
112 "version" => $this->get_bootcd_version() ) );
113 /* exits on success */
114 $success = $this->deliver_bootmedium($node_id, $boot_action, $basename);
116 $error="Unexpected error from deliver_bootmedium - probably wrong directory modes";
117 print ("<div class='plc-error'> $error </div>\n");
118 print ("<p><a href='/db/nodes/index.php?id=$node_id'>Back to node </a>\n");
123 case "download-node-floppy-with-iso":
124 case "download-node-floppy-with-usb":
125 case "download-node-floppy":
126 case "download-node-iso":
127 case "download-node-usb":
128 case "download-node-usb-partition":
130 $return= $api->GetNodes( array( $node_id ) );
131 $node_detail= $return[0];
133 // non-admin people need to be affiliated with the right site
134 if( !in_array( 10, $person->data['role_ids'] ) ) {
135 $node_site_id = $node_detail['site_id'];
136 $in_site = in_array ($node_site_id,$person->data['site_ids']);
138 $error= "Insufficient permission. You cannot create configuration files for this node.";
142 $hostname= $node_detail['hostname'];
143 $return= $api->GetInterfaces( array( "node_id" => $node_id ), NULL );
146 $data['has_primary']= 0;
148 if( count($return) > 0 ) {
149 foreach( $return as $node_network_detail ) {
150 if( $node_network_detail['is_primary'] == true ) {
151 $data['has_primary']= 1;
155 $data['node_network_detail'] = $node_network_detail;
158 if( !$data['has_primary'] ) {
161 if( $node_detail['hostname'] == "" ) {
163 $node_detail['hostname']= "<i>Missing</i>";
166 $fields= array("method","ip");
167 foreach( $fields as $field ) {
168 if( $node_network_detail[$field] == "" ) {
170 $node_network_detail[$field]= "<i>Missing</i>";
174 if( $node_network_detail['method'] == "static" ) {
175 $fields= array("gateway","netmask","network","broadcast","dns1");
176 foreach( $fields as $field ) {
177 if( $node_network_detail[$field] == "" ) {
179 $node_network_detail[$field]= "<i>Missing</i>";
184 if( $node_network_detail['method'] != "static" && $node_network_detail['method'] != "dhcp" ) {
186 $node_network_detail['method']= "<i>Unknown method</i>";
190 if( $can_gen_config && isset($_REQUEST['download']) ) {
191 $download = $_REQUEST['download'];
192 if (method_exists($api, "GetBootMedium"))
193 $file_contents= $api->GetBootMedium($node_id, "node-floppy", "");
195 $file_contents= $api->GenerateNodeConfFile($node_id, true);
198 case 'download-node-floppy-with-iso':
199 case 'download-node-floppy-with-usb':
200 case 'download-node-floppy':
201 $boot_action='node-floppy';
202 $basename = "plnode.txt";
204 case 'download-node-iso':
205 $boot_action='node-iso';
206 $basename = "$hostname.iso";
208 case 'download-node-usb':
209 $boot_action='node-usb';
210 $basename = "$hostname.usb";
212 case "download-node-usb-partition":
213 $boot_action='node-usb-partition';
214 $basename = "$hostname-partition.usb";
217 if ($action != 'download-node-floppy')
219 $api->UpdateNode( $hostname, array( "boot_state" => 'disabled',
220 "version" => $this->get_bootcd_version() ) );
222 /* exits on success */
223 $success = $this->deliver_bootmedium($node_id, $boot_action, $basename);
225 $error="Unexpected error from deliver_bootmedium - probably wrong directory modes";
226 print ("<div class='plc-error'> $error </div>\n");
227 print ("<p><a href='/db/nodes/index.php?id=$node_id'>Back to node </a>\n");
231 $action_labels = array (
232 'download-node-floppy' => 'textual node config (for floppy)' ,
233 'download-node-floppy-with-iso' => 'textual node config (for floppy)' ,
234 'download-node-floppy-with-usb' => 'textual node config (for floppy)' ,
235 'download-node-iso' => 'ISO image',
236 'download-node-usb-partition' => 'USB image',
237 'download-node-usb' => 'USB image' );
239 $format = $action_labels [ $action ] ;
240 /*drupal_set_title("Download boot material for $hostname");*/
244 echo "Unknown action $action.";
248 $data['format'] = $format;
249 $data['can_gen_config'] = $can_gen_config;
252 function get_bootcd_version()
254 // pick default bootcd flavors. need more flexibility
255 // TODO: find a way to handle 32/64 bit.
256 if ( defined("PLC_FLAVOUR_NODE_PLDISTRO") )
258 // This approach only works for 5.0
259 $BOOTCD = "/usr/share/bootcd-" . PLC_FLAVOUR_NODE_PLDISTRO . "-" . PLC_FLAVOUR_NODE_FCDISTRO . "-" . PLC_FLAVOUR_NODE_ARCH;
261 $BOOTCD = exec ("ls -d /usr/share/bootcd*");
264 $BOOTCDVERSION="$BOOTCD/build/version.txt";
265 $version = trim(file_get_contents($BOOTCDVERSION));
266 $bootcd_version = PLC_NAME . "-BootCD-".$version;
267 return $bootcd_version;
270 function deliver_bootmedium($node_id, $action, $filename)
273 ini_set("memory_limit","450M");
276 case "node-usb-partition":
277 $action = "node-usb";
278 $options[] = "partition";
281 $b64_data = $api->GetBootMedium($node_id,$action,"", $options);
282 $error= $api->error();
285 if ( $action == "node-floppy" )
287 # data comes back in plain text for node-floppy.
290 $data = base64_decode($b64_data);
292 $size = strlen($data);
293 /* exits on success */
294 force_download($filename, $data);