Getting crazy with CaptivePortal and PHP execution



  • Hello,

    I have created a bit complex captive portal php page which I cannot get to work on pfSense.
    The page loads, but the PHP code just doesn't get executed.
    If I happen to auth via the form that is in the page, the page reloads itself (before loading another form to $PORTAL_ACTION$) and then the PHP code gets executed then.

    I have struggled a lot to find answers, tried the following log files which are all empty

    
    clog /var/log/lighttpd.log
    cat /tmp/php_errors.txt
    
    

    The page executes smoothly on my local dev server.

    Any clues where I could look into to find why the PHP code is not executed ?

    Regards,
    Ozy.


  • Banned

    @deajan:

    Any clues where I could look into to find why the PHP code is not executed ?

    Without the code? Sure:



  • LMAO when I saw the image :)
    I was actually way to tired when I posted this.

    I found that php in pfSense just doesn't like global variables:

    
    $somevar = "Hello world !";
    echo $somevar; // Gets shown
    
    startPage();
    
    function startPage()
    {
    	global $somevar;
    	?>
    
    							echo $somevar; // Doesn't get shown
    			?>
    
    	}
    ?>
    
    

    So I rewrote it to this that works:

    
    $somevar = "Hello world !";
    echo $somevar; // Gets shown
    
    startPage($somevar);
    
    function startPage($somevar)
    {
    	?>
    
    							echo $somevar; // Gets shown
    			?>
    
    	}
    ?>
    
    

    Is there any security reason why the global keyword doesn't work in pfSense ?

    Regards,
    Ozy.


  • Banned

    It shows just fine. Please, post real code that doesn't work if you want to debug anything.



  • This is the content of my test.php I just re-uploaded to pfSense CP.
    The variable inside the function does not show.

    
    $somevar = "Hello world !";
    echo "Say ". $somevar."
    ";
    
    startPage();
    
    function startPage()
    {
    	global $somevar;
    	?>
    
    							echo "I will never show the variable ". $somevar."
    ";
    			?>
    
    	}
    
    echo "I too say ". $somevar;
    ?>
    
    

    The real code of my project works now since I replaced all global keywords with function($varX, $varY).
    I'll upload my real code to github once I have removed the company branding stuff, and will post a new HowTo once everything is ready for me.


  • Banned

    As noted above - the variable inside the function shows perfectly fine on any box I tried… Your real code is broken.

    
    Say Hello world !
    
    			I will never show the variable Hello world !
    
    	I too say Hello world !
    
    

    Global variables are used extensively across the entire pfSense code.  ::)



  • Well I'm sorry to insist, but this code gives me the following when executed on pfSense 2.1.4 CP:

    
    Say Hello world !
    
    			I will never show the variable 
    
    	I too say Hello world !
    
    

    Maybe something is corrupt in my installation (I've played a bit with it to install MySQL, but this shouldn't be an issue after all).
    I'll investigate from a new install, redo all steps, and see where it hangs.


  • Banned

    I don't have any pfSense 2.1.4 anywhere. Noone cares about dead code. If you have a PHP bug there, it will never get fixed. (As noted, global variables are extensively used in the entire pfSense code. And frankly, tired of "debugging" some wannabe reduced test case that doesn't reproduce anything anyway.) If you want to debug something, post the real thing, not broken "testcases".



  • Typo, using pfSense 2.2.4 of course.
    I frankly don't get it. I narrowed down the problem to this test case so I it would be easier to find the problem.

    I usually wait until I my code gets a bit polished before bringing it online, but here it is:
    https://github.com/deajan/pfSense-cp-auth-onestep

    The file used on the captive portal is ozy-captive.php

    Here's what I get once uploaded. The red marks show where variables are missing.

    I wrote the documention to setup this captive portal along with FreeRADIUS & MySQL. Once I could get all my problems resolved, I'll make a HowTo thread here.



  • @doktornotor Code has been posted, anything missing ?


  • Banned

    Did not have time to look at all yet, sorry. Need some break on weekends. :P



  • Okay, no hurry. I'll take patience until you may find what's the problem here.  :P


  • Banned

    Before I forget this again: perhaps you'd have better luck if you stick something like this into captiveportal-config.php

    
    global $brand, $hotelName, $hotelSite, $identificator;
    
    

    before declaring those variables.



  • Hi,

    Seems you're right, the php version on FreeBSD needs declaration of global variables before the functions, mine didn't.
    Thanks, works like a charm :)


  • Banned

    Thanks for reporting back; have completely forgotten about this one meanwhile.



  • Hello,

    I've finally posted the how to that goes with my single step captive portal wrapper here https://forum.pfsense.org/index.php?topic=108493.msg604190#msg604190
    If you find this useful, could you consider putting it as sticky post ?

    Regards,
    Ozy.


Log in to reply