iPXE discussion forum
iPXE/PHP - Printable Version

+- iPXE discussion forum (https://forum.ipxe.org)
+-- Forum: iPXE user forums (/forumdisplay.php?fid=1)
+--- Forum: General (/forumdisplay.php?fid=2)
+--- Thread: iPXE/PHP (/showthread.php?tid=5435)



iPXE/PHP - Torgeir - 2012-09-17 11:15

Hi!

I am pretty new to iPXE, but fell in love when I could build dynamic around my menus.

As of $NOW I have a working installmenu /dynamic, which allows reinstall, based on if we can find our MACADDRESS in a hostfile together with a HOSTNAME, that sets this hostname together with a bunch of other variables.

If its a new computer we have a password protected menu, and hostname as input (we dont allow our users to install new computers, for that we use our IT-personell).

I have som simple problems with PHP in my iPXE menu (which I have ignored (found other solutions), but I dont understanda why PHP is behaving the way it does (I am testing my PHP scripts in a browser before I try on the iPXE menu).

* How does actually PHP work together with iPXE?
* Can I do everything in iPXE with PHP as I can do on a website with a browser reading?
* Some simple logic in my menu like turning on and off a variable does not work (instead iPXE runs brutally over the variables, and sets them instead of checking, even if I use "===" my If/elseif it is not working as it should (the logic is working correctly in my browser Smile )

Everything in iPXE with PHP is running on the server right?
I can use shell_exec and use the output to something useful. Like ls and get back a filelist on the server. Read and write files on the server.
$_SERVER variables is also giving me the server IP Smile

For instance (atm) I am using the "login" menu to check username/password, with iseq (what bothers me is that this password is in clear text if anyone tries to read this menu with a browser, if they know the filename of course Smile I tried to use simple PHP logic for cheking this password, and go back to "login" if not correct. But PHP is not able to do that (in iPXE).

Why is PHP in iPXE not always working as PHP does on my browser...

Its hard to find some documents around this, so any input/advice etc?

Regards,
Torgeir

(When I am doneTweaking/optimizing the menu, Ill be happy to share my findings/solutions.


RE: iPXE/PHP - robinsmidsrod - 2012-09-17 11:55

I think you should post some code for what you're trying to do. Please post the setting you use in your DHCP server to load the initial iPXE script, and if that points to a PHP file, it would be useful if you post the PHP script (with any sensitive information garbled) so any PHP wizard can see where things go wrong.


RE: iPXE/PHP - Torgeir - 2012-09-17 13:44

Hi!

Ive tried with different configs:
Config 1:

With undionly.kpxe built from git (newest version)
Code:
if exists user-class and option user-class = "iPXE" {
                filename "http://<ip-address>/login.check.php";
        } else {
                filename "undionly.kpxe";
        }

Config 2 (which i prefer. With our current config in mind):

With ipxe linux kernel built from git (newest version)
make bin/ipxe.lkrn EMBED=dhcp.ipxe
with an ipxe script:
Code:
#!ipxe

dhcp
chain http://<ip-address>/login.check.php

DHCP option
Code:
if exists user-class and option user-class = "iPXE" {
                filename "http://<ip-address>/login.check.php";
        } else {
                filename "pxelinux.0";
        }

And with this in my pxelinux.cfg/default
Code:
label ipxe
kernel ipxe.lkrn

For various reasons, Ive tried to make undinoly.kpxe/ipxe.lkrn with and without EMBED scripts (with our current config in mind).

The example is as easy as this (this was written by hand, no copy/paste, so may contain "bugs" Smile But the logic should be clear.

PURE PHP login.php (This login does work as intended)
Code:
$user = "torgeir";
$pass = "torgeir";

if ($user === "torgeir" && $pass === "torgeir") {
          echo "Correct user/pass";
} else {
          echo "Wrong user/pass";
}

login.check.php (chain login.check2.php with arguments $_REQUEST. I know I'm not using MAC in this one, but this is the way my menu is working.

Code:
header ("Content-type: text/plain");
echo "#!ipxe\n";

# Get mac from ipxes built in variables
$MACADDRESS = "\${net0/mac}";

echo "chain ".
"http://".$_SERVER["SERVER_NAME"].
dirname($_SERVER["REQUEST_URI"] ) .
"login.check2.php?mac=${MACADDRESS}";

login.check2.php (this logic is not working)
Code:
header ("Content-type: text/plain");
echo "#!ipxe\n";

# Go back to this if wrong password
echo ":login \n";

# ipXE login menu
echo "logn \n";

# Get input from ipxe menu into php variables
# I can output these variables so I know whats in them.
# It works in the rest of my menu system.
# like: choose os && goto ${os}
# $OSTYPE = "\${os}";

$user = "\${username}";
$pass = "\${password}";

# I have tried with "\${password}" directly instead of $user/pass
if ($user === "torgeir" && $pass === "torgeir") {
          #echo "Correct user/pass";
           echo "chain http://serverip/next.step.php \n";
} else {
          #echo "Wrong user/pass";
          echo "goto login \n";
}



RE: iPXE/PHP - Torgeir - 2012-09-18 07:29

Got it working with this:

login.check.php

Code:
<?
header ("Content-type: text/plain");
echo "#!ipxe\n";

# ipXE login menu
echo "logn \n";

$user = "\${username}";
$pass = "\${password}";

echo "chain http://serverip/login.check2.php?user=${user}&pass=${pass} \n";
?>

login.check2.php
Code:
<?
header ("Content-type: text/plain");
echo "#!ipxe\n";

$user = $_REQUEST["user"];
$pass = $_REQUEST["pass"];

if ($user === "torgeir" && $pass === "torgeir") {
          #echo "Correct user/pass";
           echo "chain http://serverip/next.step.php \n";
} else {
          #echo "Wrong user/pass back to login";
          echo "chain http://serverip/login.check.php \n";
}
?>



RE: iPXE/PHP - Torgeir - 2012-09-18 11:52

Edit: cleanup!


Torgeir