Last active
February 27, 2023 21:46
-
-
Save john-clark/5355544 to your computer and use it in GitHub Desktop.
ipxe php boot system
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!ipxe | |
# | |
# This file gets compiled into undionly.kpxe | |
################################################################ | |
:vars | |
set next-server 192.168.2.121 | |
cpuid --ext 29 && set arch amd64 || set arch x86 | |
:netconfig | |
dhcp net0 || goto ipxeshell | |
:prompt | |
prompt --key 0x02 --timeout 3000 Press Ctrl-B for the iPXE command line... && goto ipxeshell || | |
# | |
# We call strap so we can escape out of logging for some computers | |
chain http://${next-server}/boot/strap.php && goto exit || | |
echo | |
echo Failed to boot to: http://${next-server}/boot/strap.php | |
echo | |
echo Type help for commands. | |
:ipxeshell | |
shell | |
:exit | |
exit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
echo "#!ipxe\n:start\necho Boot menu\nmenu Selection\n"; | |
$directory = new RecursiveDirectoryIterator("/var/www/iso/"); | |
$display = Array ( 'iso' ); | |
$count = 0; | |
foreach(new RecursiveIteratorIterator($directory) as $file) | |
{ | |
if (in_array(strtolower(array_pop(explode('.', $file))), $display)) | |
echo "item ". $count . " " . array_pop(explode("/", $file)) . "\n"; | |
$count += 1; | |
} | |
echo "choose os && goto \${os}\n"; | |
$count = 0; | |
foreach(new RecursiveIteratorIterator($directory) as $file) | |
{ | |
if (in_array(strtolower(array_pop(explode('.', $file))), $display)) | |
echo ":". $count ."\nsanboot http://debian" . substr($file,8) . "\ngoto start\n"; | |
$count += 1; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
////////////////////////////////////////////////////////////////////////////////////////////////////// | |
// | |
// This is for logging or not who is booting | |
// | |
// make sure bootlog.csv is writable by the webserver | |
// use skipfile.txt a list of mac address on each line to skip logging | |
// | |
////////////////////////////////////////////////////////////////////////////////////////////////////// | |
//if you no mac or webview is set then it is probably a webbrowser | |
if (!isset($_GET['MAC']) ) { | |
?> | |
<table style="border:5px dotted red" width=800><tr><td> | |
This was not started as an iPXE script. There is a logic in the script you can't see.<br> | |
</td></tr></table> | |
<pre> | |
<?php | |
} | |
// start building the file display | |
echo "#!ipxe\n"; | |
echo "imgfree\n"; | |
//get variables | |
foreach($_GET as $k=>$v) { | |
$$k=$v; | |
#echo "echo $k=$v\n"; #uncomment to debug | |
} | |
$logfile = 'bootlog.csv'; | |
//check to make sure logfile can be opened | |
if (!$handle = fopen($logfile, 'a+')) { | |
die("Failed to open log file"); | |
} | |
//first lets figure out what protocol is needed | |
//this isn't actually used corectly when building the file - fix | |
if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) { | |
$serverproto = "https://"; | |
} else { | |
$serverproto = "http://"; | |
} | |
////////////////////////////////////////////////////////////////////////////////////////////////////// | |
// | |
// Check for macaddress to skip adding to the log file ...aka machines you test boot a lot | |
// | |
////////////////////////////////////////////////////////////////////////////////////////////////////// | |
$skipfile = "skipmaclog.txt"; | |
//check to see if file exists load it | |
if ($skipfile) { $skipmac = file($skipfile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); } | |
//if mac matches then | |
if (in_array($MAC, $skipmac)) { | |
echo "echo not logged.\n"; | |
echo "chain http://".$_SERVER['SERVER_NAME']."/boot/menu.php?MANUFACTURER=\${manufacturer}&PRODUCT=\${product}&SERIAL=\${serial}&MAC=\${netX/mac}&ASSET=\${asset}&HOSTNAME=\${hostname}&USER-CLASS=\${user-class}&UUID=\${uuid}&DHCP-SERVER=\${dhcp-server}&NEXT-SERVER=\${next-server}&FILENAME=\${filename}&ROOT-PATH=\${root-path}&IQN=\${initiator-iqn}\n"; | |
// this was break for php 5 but that no longer works | |
return false; | |
} | |
////////////////////////////////////////////////////////////////////////////////////////////////////// | |
// | |
// computer mac is not in skip file so finish the ipxe file contruction | |
// | |
////////////////////////////////////////////////////////////////////////////////////////////////////// | |
//fill out variables for log file | |
$ipaddress = $_SERVER['REMOTE_ADDR']; | |
$servername = $_SERVER['SERVER_NAME']; | |
$port = $_SERVER['SERVER_PORT']; | |
$page = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}"; | |
$page .= (!empty($_SERVER['QUERY_STRING'])) ? "?{$_SERVER['QUERY_STRING']}" : ""; | |
$referrer = $_SERVER['HTTP_REFERER']; | |
$useragent = $_SERVER['HTTP_USER_AGENT']; | |
$remotehost = @getHostByAddr($ipaddress); | |
$datetime = mktime(); | |
$logline = $datetime . '|' . $serverproto . '|' . $servername . '|' . $port . '|' . $page . '|' . $referrer . '|' . $useragent . '|' . $MANUFACTURER . '|' . $PRODUCT . '|' . $SERIAL . '|' . $ARCH . '|' . $remotehost . '|'. $ipaddress . '|' . $MAC . '|' . $UUID . "\n"; | |
//echo "echo $datetime . '|' . $serverproto . '|' . $servername . '|' . $port . '|' . $page . '|' . $referrer . '|' . $useragent . '|' . $MANUFACTURER . '|' . $PRODUCT . '|' . $SERIAL . '|' . $ARCH . '|' . $remotehost . '|'. $ipaddress . '|' . $MAC . '|' . $UUID . "\n""; | |
if (fwrite($handle, $logline) === FALSE) { | |
die("Failed to write to log file"); | |
} | |
fclose($handle); | |
echo "echo logged.\n"; | |
echo "chain http://".$_SERVER['SERVER_NAME']."/boot/menu.php?MANUFACTURER=\${manufacturer}&PRODUCT=\${product}&SERIAL=\${serial}&MAC=\${netX/mac}&ASSET=\${asset}&HOSTNAME=\${hostname}&USER-CLASS=\${user-class}&UUID=\${uuid}&DHCP-SERVER=\${dhcp-server}&NEXT-SERVER=\${next-server}&FILENAME=\${filename}&ROOT-PATH=\${root-path}&IQN=\${initiator-iqn}\n"; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
header ( "Content-type: text/plain" ); | |
echo "#!ipxe \n"; | |
echo "imgfree\n"; | |
echo "cpuid --ext 29 && set arch x64 || set arch x86\n"; | |
echo "chain http://".$_SERVER['SERVER_NAME']."/boot/log.php?MANUFACTURER=\${manufacturer}&PRODUCT=\${product}&SERIAL=\${serial}&MAC=\${netX/mac}&ASSET=\${asset}&ARCH=\${arch}&HOSTNAME=\${hostname}&USER-CLASS=\${user-class}&UUID=\${uuid}&DHCP-SERVER=\${dhcp-server}&NEXT-SERVER=\${next-server}&FILENAME=\${filename}&ROOT-PATH=\${root-path}&IQN=\${initiator-iqn}\n"; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
////////////////////////////////////////////////////////////////////////////////////////////////////// | |
// | |
// This file views the csv file made by log.php | |
// | |
////////////////////////////////////////////////////////////////////////////////////////////////////// | |
$logfile = 'bootlog.csv'; | |
if (file_exists($logfile)) { | |
$handle = fopen($logfile, "r"); | |
$log = fread($handle, filesize($logfile)); | |
fclose($handle); | |
} else { | |
die ("The log file doesn't exist!"); | |
} | |
$log = explode("\n", trim($log)); | |
for ($i = 0; $i < count($log); $i++) { | |
$log[$i] = trim($log[$i]); | |
$log[$i] = explode('|', $log[$i]); | |
} | |
echo count($log) . " have hit this file."; | |
echo '<table border="1">'; | |
echo '<th>Date</th>'; | |
//echo '<th>Proto</th>'; | |
//echo '<th>Server</th>'; | |
//echo '<th>Port</th>'; | |
//echo '<th>Page</th>'; | |
//echo '<th>Referrer</th>'; | |
//echo '<th>Useragent</th>'; | |
echo '<th>Manufacturer</th>'; | |
echo '<th>Product</th>'; | |
echo '<th>Service Tag</th>'; | |
echo '<th>Arch</th>'; | |
echo '<th>Remote Hostname</th>'; | |
echo '<th>IP Address</th>'; | |
echo '<th>MAC Address</th>'; | |
echo '<th>UUID</th>'; | |
foreach ($log as $logline) { | |
echo '<tr>'; | |
echo '<td nowrap>' . date('d/m/Y H:i:s', $logline['0']) . '</td>'; | |
//echo '<td nowrap>' . $logline['1'] . '</td>'; | |
//echo '<td nowrap>' . $logline['2'] . '</td>'; | |
//echo '<td nowrap>' . $logline['3'] . '</td>'; | |
//echo '<td nowrap>' . $logline['4'] . '</td>'; | |
//echo '<td nowrap>' . $logline['5'] . '</td>'; | |
//echo '<td nowrap>' . $logline['6'] . '</td>'; | |
echo '<td nowrap>' . $logline['7'] . '</td>'; | |
echo '<td nowrap>' . $logline['8'] . '</td>'; | |
echo '<td nowrap>' . $logline['9'] . '</td>'; | |
echo '<td nowrap>' . $logline['10'] . '</td>'; | |
echo '<td nowrap>' . $logline['11'] . '</td>'; | |
echo '<td nowrap>' . $logline['12'] . '</td>'; | |
echo '<td nowrap>' . urldecode($logline['13']) . '</td>'; | |
echo '<td nowrap>' . $logline['14'] . '</td>'; | |
echo '</tr>'; | |
} | |
echo '</table>'; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Info
I was playing around with ipxe and php in 2013
I was asked about it in 2020 and took a look at it. PHP no longer supports the shortcuts I took (aka if break) and so I fixed a few things.
This probably isn't the best way to do this, or ever was. It was just a learning experience.
install
notes
view.php shows bootlog.csv of the computers hitting the server
list.php was never implemented but just a test script
About
http://creativecommons.org/licenses/by-sa/3.0/