Widget PHP script problems



  • Hi everybody.

    I am working on a custom widget, and are having some PHP issues that i hope someone here can shed some light on.

    My pfSense box has multiple LAN's, LAN #1 through #4, and for various reasons, there is a need for a few lower level superusers to turn LAN #2 on and off when needed. My plan is to accomplish this with a couple of nice buttons on the dashboard, in a widget.

    First, I have placed my widget in the default folder: /usr/local/www/widgets/widgets/management_widget.widget.php. The HTML code for the widget itself is quite simply as follows:

    As you can see, i call on a couple of PHP scripts on click of buttons, thats execute shell commands in pfSense.

    Now, to continue, the PHP scripts looks as follows:
    /usr/local/www/widgets/include/lan2_down.inc

    $outPut = shell_exec("ifconfig em2 down");
    echo "```
    $outPut

    ?>
    
    And the second script is:
    /usr/local/www/widgets/include/lan2_up.inc
    
    $outPut = shell_exec("ifconfig em2 up");
    echo "```
    $outPut
    ```";
    ?>
    
    The scripts work perfectly fine. So far so good. But now my problem is starting. I will explain:
    
    When the above PHP-scripts reside in the include-folder, the scripts are also run every single time someone enters the dashboard page. That is of course not a usable solution. I see two possible solutions to this, but so far I have been unsuccesfull in accomplishing both of them, and i hope someone with a better knowledge of pfSense than me, can bring some ideas to my table:
    
    1) I have tried putting the PHP-scripts in subfolders, both below and above the include-folder, for example in /usr/local/www/widgets/include/include2/lan2_up.inc. But pfSense refuses to run the scripts in ANY OTHER folder than the default include-folder. As far as i have read, this is by design in pfSense, i.e. the include-folder is the only one that have permissions in regards to running PHP-scripts that call on the use of shell commands. So question is, is it possible to somehow tweak pfSense to run PHP-scripts from a folder other than the default Include-folder?
    
    2) A possible second solution would be to modify both the HTML-code and the PHP-script, so that my above code is ONLY run upon click of buttons, and NOT when the script is run automatically when entering the dashboard page. However, such programming is above my level of coding capabilities. If this is the only solution, any ideas on how such a set of code would have to look like?
    
    I will be very grateful for any replies on the matter. Thanks in advance.
    
    Regards,
    Rustfri1\.