Post Reply 
 
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
iPXE and calling PHP
2019-02-27, 04:36
Post: #3
RE: iPXE and calling PHP
Thanks, initrd advice was useful cheers Wink

I'm not sure half the time what I am doing, just managing to get it to work, however after testing various things with my colleague, we came to realise chain and initrd are quite different animals and managed to get a working solution using a stub php file and then calling the actual php. Not sure if its the optimal way but it works so far.

menu.ipxe
Code:
:prestage
#params
#param mac ${netX/mac}
#param serial ${smbios/serial}
#param uuid ${uuid}
#param asset ${asset}
echo Adding following details into prestage DB:
echo serial: ${smbios/serial}
echo mac: ${netX/mac}
# chain command is used here to pass to another 'ipxe menu'
chain --autofree http://172.16.0.17/prestage/stub.php
echo Done!
echo Returning to Main Menu
sleep 3
goto start

stub.php
Code:
<?php
// this is a 'ipxe compliant' menu
// use \n for line return and \ to escape $ values
header ( "Content-type: text/plain" );
echo "#!ipxe\n";
// initrd is used to call external php script where no ipxe commands are used
echo "initrd -a http://172.16.0.17/prestage/index.php?serial=\${smbios/serial}&mac=\${netX/mac}\n";
?>

index.php
Code:
<?php
include "conn.php";

$serial = $_GET['serial'];
$mac    = $_GET['mac'];

if ($serial !="") {
    $sql = "insert into prestage (serial, mac) values ('$serial', '$mac')";
    // built in php command to write data to sqlite DB
    mysqli_query($conn, $sql);
    };    
?>


On a side note I'd prefer the params command but we didn't know how to call/test variables from it. The http://ipxe.org/cmd/params shows an example, "Issues an HTTP Post request using a form parameter list", but from the boot.php side, how does it get the values from there?
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
iPXE and calling PHP - ndog - 2019-02-26, 00:33
RE: iPXE and calling PHP - NiKiZe - 2019-02-26, 00:55
RE: iPXE and calling PHP - ndog - 2019-02-27 04:36
RE: iPXE and calling PHP - NiKiZe - 2019-02-27, 08:11
RE: iPXE and calling PHP - ndog - 2019-02-27, 20:59



User(s) browsing this thread: 1 Guest(s)