123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- <?php
-
-
-
-
- require_once "utils.php";
-
-
- if ( ! isset ( $_POST['A'] ) ) {
-
-
- require_once "customize-flags.php";
-
- exit ();
-
-
- } else if ( $_POST['A'] == "Customize" ) {
-
-
- require_once "customize-flags.php";
-
- exit ();
-
-
-
- } else if ( $_POST['A'] != "Get Image" ) {
-
-
-
-
- $dest = curDirURL ();
- header ( "Location: $dest" );
-
-
-
-
-
- echo "Try this link: <a href=\"$dest\">$dest</a>";
-
- exit ();
- }
-
-
-
-
-
- if ( ! isset ( $_POST['nic'] ) ) {
- die ( "No NIC supplied!" );
- }
- if ( isset ( $nics[$_POST['nic']] ) ) {
- $nic = $nics[$_POST['nic']];
- } else {
- die ( "Invalid NIC \"${_POST['nic']}\" supplied!" );
- }
-
-
- $flags = get_flags ();
-
-
- $ofmt = isset ( $_POST['ofmt'] ) ? $_POST['ofmt'] : "";
- $fmt_extension = isset ( $ofmts[$ofmt] ) ? $ofmts[$ofmt] : 'dsk';
-
-
-
- $pci_vendor_code = "";
- $pci_device_code = "";
-
- if ( $nic == 'undionly' && $fmt_extension == "pxe" ) {
-
-
-
-
-
-
- $fmt_extension = "kpxe";
-
- } else if ( $fmt_extension == "rom" ) {
-
- if ( ! isset ( $_POST['pci_vendor_code'] )
- || ! isset ( $_POST['pci_device_code'] ) ) {
- die ( "rom output format selected but PCI code(s) missing!" );
- }
-
- $pci_vendor_code = $_POST['pci_vendor_code'];
- $pci_device_code = $_POST['pci_device_code'];
-
- if ( $pci_vendor_code == ""
- || $pci_device_code == "" ) {
- die ( "rom output format selected but PCI code(s) missing!" );
- }
-
-
- if ( strtolower ( substr ( $pci_vendor_code, 0, 2 ) ) == "0x"
- && strlen ( $pci_vendor_code ) == 6 ) {
- $pci_vendor_code = substr ( $pci_vendor_code, 2, 4 );
- }
- if ( strtolower ( substr ( $pci_device_code, 0, 2 ) ) == "0x"
- && strlen ( $pci_device_code ) == 6 ) {
- $pci_device_code = substr ( $pci_device_code, 2, 4 );
- }
-
-
-
- $pci_codes = strtolower ( $pci_vendor_code . $pci_device_code );
-
- $nic = $pci_codes;
- if ( ! isset ( $roms[$pci_codes] ) ) {
- die ( "Sorry, no network driver supports PCI codes<br>"
- . "${_POST['pci_vendor_code']}:"
- . "${_POST['pci_device_code']}" );
- }
- } else if ( $fmt_extension != "rom"
- && ( $pci_vendor_code != "" || $pci_device_code != "" ) ) {
- die ( "'$fmt_extension' format was selected but PCI IDs were"
- . " also entered.<br>Did you mean to select 'rom' output format"
- . " instead?" );
- }
-
-
- function rm_build_dir ()
- {
- global $build_dir;
- global $keep_build_dir;
-
- if ( $keep_build_dir !== true ) {
- rm_file_or_dir ( $build_dir );
- }
- }
-
-
- $build_dir = "";
- $keep_build_dir = false;
- register_shutdown_function ( 'rm_build_dir' );
-
-
- $build_dir = mktempcopy ( "$src_dir", "/tmp", "MDCROM" );
- $config_dir = $build_dir . "/config";
-
-
- write_ipxe_config_files ( $config_dir, $flags );
-
-
- $emb_script_cmd = "";
- $embedded_script = isset ( $_POST['embedded_script'] ) ? $_POST['embedded_script'] : "";
- if ( $embedded_script != "" ) {
- $emb_script_path = "$build_dir" . "/script0.ipxe";
-
- if ( substr ( $embedded_script, 0, 5 ) != "#!ipxe" ) {
- $embedded_script = "#!ipxe\n" . $embedded_script;
- }
-
-
- $embedded_script = str_replace ( "\r\n", "\n", $embedded_script );
-
- write_file_from_string ( $emb_script_path, $embedded_script );
- $emb_script_cmd = "EMBEDDED_IMAGE=${emb_script_path}";
- }
-
-
- $make_target = "bin/${nic}.${fmt_extension}";
- $gitversion = exec('git describe --always --abbrev=1 --match "" 2>/dev/null');
- if ($gitversion) {
- $gitversion = "GITVERSION=$gitversion";
- }
-
- $make_cmd = "make -C '$build_dir' '$make_target' $gitversion $emb_script_cmd 2>&1";
-
- exec ( $make_cmd, $maketxt, $status );
-
-
-
-
-
-
-
- if ( $status == 0 ) {
-
- $fp = fopen("${build_dir}/${make_target}", "rb" );
- if ( $fp > 0 ) {
-
- $len = filesize ( "${build_dir}/${make_target}" );
- if ( $len > 0 ) {
-
- $buf = fread ( $fp, $len );
- fclose ( $fp );
-
-
- rm_build_dir ();
-
- $output_filename = preg_replace('/[^a-z0-9\+\.\-]/i', '', "ipxe-${version}-${nic}.${fmt_extension}");
-
-
- Header ( "Cache-control: private");
- Header ( "Content-Type: application/x-octet-stream; " .
- "name=$output_filename");
- Header ( "Content-Disposition: attachment; " .
- "Filename=$output_filename");
- Header ( "Content-Location: $output_filename");
- Header ( "Content-Length: $len");
-
- echo $buf;
-
- exit ();
- }
- }
- }
-
-
-
-
- rm_build_dir ();
-
-
- echo "<h2>Build failed. Status = " . $status . "</h2>";
- echo "<h2>build.php:</h2>";
- echo "<h3>Build options:</h3>";
- echo "<strong>Build directory is:</strong> $build_dir" . "<br><br>";
- echo "\$_POST['ofmt'] = " . "\"${_POST['ofmt']}\"" . "<br>";
- echo "\$_POST['nic'] = " . "\"${_POST['nic']}\"" . "<br>";
- echo "\$_POST['pci_vendor_code'] = " . "\"${_POST['pci_vendor_code']}\"" . "<br>";
- echo "\$_POST['pci_device_code'] = " . "\"${_POST['pci_device_code']}\"" . "<br>";
-
- echo "<h3>Flags:</h3>";
- show_flags ( $flags );
-
- if ( $embedded_script != "" ) {
- echo "<h3>Embedded script:</h3>";
- echo "<blockquote>"."<pre>";
- echo $embedded_script;
- echo "</pre>"."</blockquote>";
- }
-
- echo "<h3>Make output:</h3>";
- echo "Make command: " . $make_cmd . "<br>";
- echo "<blockquote>"."<pre>";
- echo htmlentities ( implode ("\n", $maketxt ) );
- echo "</pre>"."</blockquote>";
-
- echo "Please let us know that this happened, and paste the above output into your email message.<br>";
-
- include_once $bottom_inc;
-
-
-
-
-
-
-
-
- ?>
|