123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684 |
- <?php
-
-
-
-
- require_once "flag-table.php";
-
-
- require_once "globals.php";
-
-
- if ( is_file ( 'local-config.php' ) ) {
- include_once "local-config.php";
- }
-
-
-
-
-
-
- function cleanstring ( $s )
- {
- $len = strlen ( $s );
- if ( $len > 80 ) {
- $s = substr ( $s, 0, 80 );
- }
-
- $s = trim ( $s );
- $pos = 0;
- $result = "";
-
- while ( $pos < $len ) {
- $ltr = ord ( ucfirst ( $s[$pos] ) );
- if ( ( $ltr >= ord ( "A" ) ) && ( $ltr <= ord ( "Z" ) ) ||
- ( $ltr >= ord ( "0" ) ) && ( $ltr <= ord ( "9" ) ) ||
- ( $ltr == ord ( "." ) ) && ( strlen ( $result ) > 0 ) ||
- ( $ltr == ord ( "_" ) ) ||
- ( $ltr == ord ( "+" ) ) ||
- ( $ltr == ord ( ":" ) ) ||
- ( $ltr == ord ( "/" ) ) ||
- ( $ltr == ord ( "-" ) ) ) {
- $result .= $s[$pos];
- }
- $pos++;
- }
- return $result;
- }
-
-
- function curDirURL ()
- {
- $dir = dirname ( $_SERVER['PHP_SELF'] );
-
- if ( $dir == "." || $dir == "/" ) {
- $dir = "";
- }
-
- $isHTTPS = ( isset ( $_SERVER["HTTPS"] ) && $_SERVER["HTTPS"] == "on" );
- $port = ( isset($_SERVER["SERVER_PORT"] ) &&
- ( ( !$isHTTPS && $_SERVER["SERVER_PORT"] != "80" ) ||
- ( $isHTTPS && $_SERVER["SERVER_PORT"] != "443" ) ) );
-
- $port = ( $port ) ? ':' . $_SERVER["SERVER_PORT"] : '';
-
- $dest = ( $isHTTPS ? 'https://' : 'http://' ) .
- $_SERVER["SERVER_NAME"] . $dir . "/";
-
- return $dest;
- }
-
-
- function parse_nic_file ()
- {
- global $src_dir;
-
- $fd = fopen ( "$src_dir/bin/NIC", "r" );
- if ( ! $fd ) {
- die ( "Missing src/bin/NIC file. 'make bin/NIC'" );
- }
-
- $nics = array ();
- $roms = array ();
- $nic = "";
-
- while ( !feof ( $fd ) ) {
-
- $line = trim ( fgets ( $fd, 200 ) );
-
- $first_eight_chars = substr ( $line, 0, 8 );
- settype ( $first_eight_chars, "string" );
-
- if ( strpos ( $first_eight_chars, "family" ) === 0 ) {
-
-
-
- list ( $dummy, $nic ) = explode("\t", $line);
- settype ( $nic, "string" );
-
-
- $nic = substr ( $nic, strrpos ( $nic, "/" ) + 1,
- strlen ( $nic ) - strrpos ( $nic, "/" ) + 1 );
-
- $nics[$nic] = $nic;
-
-
- $roms[$nic] = $nic;
- }
-
-
-
-
- if ( ( strlen ( $first_eight_chars ) == 8 )
- && ( ctype_xdigit ( $first_eight_chars ) )
- && ( $nic != "" ) ) {
-
- $roms[$first_eight_chars] = $nic;
- }
- }
- fclose ( $fd );
-
-
- ksort ( $nics );
-
-
-
- $new_nics = array ( "all-drivers" => "ipxe",
- "undionly" => "undionly",
- "undi" => "undi",
- );
-
- foreach ( $nics as $key => $value ) {
-
- if ( $key != "undi" ) {
- $new_nics[$key] = $value;
- }
- }
-
- return array ( $new_nics, $roms );
- }
-
-
-
-
-
-
- function hidden ( $flag, $value )
- {
- $value = htmlentities ( $value );
- return "<input type=\"hidden\" value=\"$value\" name=\"$flag\"></input>";
- }
-
-
- function checkbox ( $flag, $value )
- {
- return "<input type=\"checkbox\" value=\"on\" name=\"$flag\"" .
- ($value == "on" ? " checked>" : ">" );
- }
-
-
- function textbox ( $flag, $value, $size )
- {
- $value = htmlentities ( $value );
- return "<input type=\"text\" size=\"$size\" value=\"$value\" name=\"$flag\">";
- }
-
-
- function textarea ( $flag, $value, $rows, $cols )
- {
- $value = htmlentities ( $value );
- return "<textarea name=\"$flag\" rows=\"$rows\" cols=\"$cols\">"
- . $value . "</textarea>";
- }
-
-
- function menubox ( $name, $options, $value )
- {
- $s="<select name=\"$name\">";
-
- foreach ( $options as $ignore => $option ) {
- if ( !$value ) $value = $option;
- $s .= "<option" . ( $option == $value ? " selected>" : ">" ) .
- htmlentities ( $option ) . "</option>";
- }
- return $s . "</select>";
- }
-
-
- function keys_menubox ( $name, $options, $value )
- {
- $s="<select name=\"$name\">";
-
- foreach ( $options as $option => $ignore ) {
- if ( !$value ) $value = $option;
- $s .= "<option" . ( $option == $value ? " selected>" : ">" ) .
- htmlentities ( $option ) . "</option>";
- }
- return $s . "</select>";
- }
-
-
-
-
-
-
- function default_flags ()
- {
- global $flag_table;
-
- $flags = array ();
-
- foreach ( $flag_table as $key => $props ) {
-
- $flag = $props["flag"];
- $type = $props["type"];
-
-
- if ( isset ( $props["value"] ) ) {
- $flags[$flag] = $props["value"];
- }
- }
- return $flags;
- }
-
-
- function get_flags ()
- {
- global $flag_table;
-
- $flags = default_flags ();
-
- if ( ! isset ( $_POST["use_flags"] ) )
- return $flags;
-
- foreach ( $flag_table as $key => $props ) {
-
- $flag = $props["flag"];
- $type = $props["type"];
-
- if ( isset ( $_POST["$flag"] ) ) {
- $flags[$flag] = $_POST["$flag"];
- if ( $type == "integer-hex" ) {
- if ( strtolower ( substr ( $flags[$flag], 0, 2 ) ) != "0x" ) {
- $flags[$flag] = "0x" . $flags[$flag];
- }
- }
- } else if ( $type == "on/off" ) {
-
-
-
-
-
-
- $flags[$flag] = "off";
- }
- }
- return $flags;
- }
-
-
- function pprint_flag ( $key, $value )
- {
- global $flag_table;
-
-
- $type = $flag_table[$key]["type"];
- $s = "";
-
- if ( $type == "on/off" && $value == "on" ) {
- $s = "#define $key";
- } else if ( $type == "on/off" && $value != "on" ) {
- $s = "#undef $key";
- } else if ( $type == "string" ) {
- $s = ( "#define $key \"" . cleanstring ( $value ) . "\"" );
- } else if ($type == "qstring" ) {
- $s = ( "#define $key \\\"" . cleanstring ( $value ) . "\\\"" );
- } else {
- $s = "#define $key " . cleanstring ( $value );
- }
-
- return $s;
- }
-
-
- function echo_flags ( $flags )
- {
- global $flag_table;
-
- echo "<table>\n";
-
- foreach ( $flag_table as $key => $props ) {
-
-
- $hide_from_user = isset ( $props["hide_from_user"] ) ? $props["hide_from_user"] : "no";
-
- $flag = $props["flag"];
- $type = $props["type"];
-
- $value = isset ( $flags[$flag] ) ? $flags[$flag] : '';
-
- if ( $hide_from_user == "yes" ) {
-
-
-
- if ( $type != "header" ) {
- echo hidden ( $flag, $value );
- }
-
- } else {
-
-
-
- if ( $type == "header" ) {
-
- $label = $props["label"];
- echo "<td colspan=2><hr><h3>$label</h3><hr></td>";
-
- } else if ($type == "on/off" ) {
-
- echo "<td>", checkbox ( $flag, $value ), "</td><td><strong>$flag</strong></td>";
-
- } else {
-
- echo "<td> </td><td><strong>$flag: </strong>";
-
- if ($type == "choice" ) {
- $options = $props["options"];
- echo menubox($flag, $options, $value);
-
- } else {
-
- echo textbox($flag, $value, ($type == "integer" ||
- $type == "integer-hex"
- ? 7 : 25));
- }
- echo "</td>";
- }
- echo "</tr>\n";
-
- if ( $type != "header" ) {
- echo "<tr><td> </td>";
- echo "<td>\n";
- if ( is_file ( "doc/$flag.html" ) ) {
- include_once "doc/$flag.html";
- }
- echo "\n</td></tr>\n";
- }
- }
- }
- echo "</table>";
- }
-
-
- function get_flag_cfgsecs ()
- {
- global $flag_table;
- $cfgsecs = array ();
-
- foreach ( $flag_table as $key => $props ) {
- if ( isset ( $props['cfgsec'] ) ) {
- $cfgsec = $props["cfgsec"];
- $cfgsecs[$cfgsec] = $cfgsec;
- }
- }
- return $cfgsecs;
- }
-
-
-
-
-
-
- function mktempcopy ( $src, $dst, $prefix )
- {
- if ( $src[0] != "/" ) {
- $src = dirname ( $_SERVER['SCRIPT_FILENAME'] ) . "/" . $src;
- }
-
-
- $dir = tempnam ( $dst, $prefix );
-
-
-
- unlink ( $dir );
-
- exec ( "/bin/cp -a '$src' '$dir' 2>&1", $cpytxt, $status );
-
- if ( $status != 0 ) {
- die ( "src directory copy failed!" );
- }
- return $dir;
- }
-
-
- function write_ipxe_config_files ( $config_dir, $flags )
- {
- global $flag_table;
-
- $cfgsecs = get_flag_cfgsecs ();
-
- foreach ( $cfgsecs as $cfgsec ) {
-
- $fname = $config_dir . "/" . $cfgsec . ".h";
-
- $fp = fopen ( $fname, "wb" );
- if ( $fp <= 0 ) {
- die ( "Unable to open $fname file for output!" );
- }
-
- $ifdef_secname = "CONFIG_" . strtoupper ( $cfgsec ) . "_H";
-
- fwrite ( $fp, "#ifndef ${ifdef_secname}\n" );
- fwrite ( $fp, "#define ${ifdef_secname}\n" );
- fwrite ( $fp, "#include <config/defaults.h>\n" );
-
- foreach ( $flags as $key => $value ) {
-
- if ( $flag_table[$key]["cfgsec"] == $cfgsec ) {
- fwrite ( $fp, pprint_flag ( $key, $value ) . "\n" );
- }
- }
- fwrite ( $fp, "#endif /* ${ifdef_secname} */\n" );
- fclose ( $fp );
- }
- }
-
-
- function write_file_from_string ( $fname, $ftext )
- {
- $fp = fopen ( $fname, "wb" );
- if ( ! $fp ) {
- die ( "Unable to open $fname file for output!" );
- }
- fwrite ( $fp, $ftext );
- fclose ( $fp );
- }
-
-
- function rm_file_or_dir ( $file_or_dir_name )
- {
- if ( ! file_exists ( $file_or_dir_name ) ) {
- return false;
- }
-
- if ( is_file ( $file_or_dir_name ) || is_link ( $file_or_dir_name ) ) {
- return unlink ( $file_or_dir_name );
- }
-
- $dir = dir ( $file_or_dir_name );
- while ( ( $dir_entry = $dir->read () ) !== false ) {
-
- if ( $dir_entry == '.' || $dir_entry == '..') {
- continue;
- }
- rm_file_or_dir ( $file_or_dir_name . '/' . $dir_entry );
- }
- $dir->close();
-
- return rmdir ( $file_or_dir_name );
- }
-
-
-
-
-
-
- function show_flags ( $flags )
- {
- echo ( "\$flags contains " . count ( $flags ) . " elements:" . "<br>" );
-
- foreach ( $flags as $key => $flag ) {
- echo ( "\$flags[" . $key . "]=" . "\"$flag\"" . "<br>" );
- }
- }
-
-
- function dump_flag_table ()
- {
- global $flag_table;
-
- echo ( "\$flag_table contains " . count ( $flag_table ) . " elements:" . "<br>" );
-
- foreach ( $flag_table as $key => $props ) {
- print ( "flag_table[" . $key . "] = " . "<br>" );
-
- foreach ( $props as $key2 => $props2 ) {
- print ( " " . $key2 . " = " . $props2 . "<br>" );
- }
- }
- }
-
-
- list ( $nics, $roms ) = parse_nic_file ();
-
-
-
-
-
-
-
-
- ?>
|