• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Search
  • Register
  • Login
Netgate Discussion Forum
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Search
  • Register
  • Login

PHP Shell Scripts: bringing up and down Interfaces and checking whether enabled

Scheduled Pinned Locked Moved Development
5 Posts 3 Posters 1.9k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A
    andipandi
    last edited by Feb 24, 2017, 2:08 PM

    Hello!

    I am trying to both find out if an interface is enabled right now, as well as to change the state. It seems to be half working.

    print_r($config['interfaces']['wan']['enable']);
    
    $config['interfaces']['wan']['enable'] = false;
    $config['interfaces']['wan']['disabled'] = true;
    write_config();
    interfaces_sync_setup();
    exec;
    
    // interfaces_bring_up('wan');
    interface_bring_down('wan');
    interface_bring_down('pppoe0');
    interface_reconfigure('wan');
    print_r(Interface_isppp_type('wan'));
    interface_configure('wan');
    interface_configure('pppoe0');
    //interfaces_setup();
    print_r(get_interface_list());
    exec;
    

    I have 2 main issues:

    1. getting enabled state seems to be unreliable, especially, sometimes this value is not set

    2. changes are not applied. I have to use

    system_reboot_sync();
    

    which works but which I really would like to avoid, since it takes a long time and does not match the "apply changes" web UI option, which seems a little more leightweight.

    Thanks!

    1 Reply Last reply Reply Quote 1
    • G
      guardian Rebel Alliance
      last edited by Feb 24, 2017, 6:40 PM

      Best solution I had for this so far was to parse ifconfig….  but might I suggest that you ask this question in the development forum.... much more likely to be seen by someone who knows their way around pfSense internals/code.

      If you get a good answer please mark your thread solved....

      If you find my post useful, please give it a thumbs up!
      pfSense 2.7.2-RELEASE

      1 Reply Last reply Reply Quote 0
      • A
        andipandi
        last edited by Feb 25, 2017, 6:16 PM

        @Guardian
        Thanks for 1) I thought the same (from what I have seen so far, and not having found a way to access CARP state otherwise).

        For 2) I am still searching.

        Also, I asked mod to move.. only saw "how do I compile x" messages in dev forum, that is why I went to general.

        1 Reply Last reply Reply Quote 0
        • A
          andipandi
          last edited by Feb 27, 2017, 7:21 PM

          So.. i copy/pasted the code from the UI interfaces.php (the "apply" POST). Also, I had to persist the .interfaces.apply for each configuration (enabled and disabled).
          Gateway assignment and defaults still were a huge issue.. so I am happy it is running for now.

          I guess this will break with some update in the future (would be nicer to have a clear cut between UI and some fixed logic with a documented API), so I will be a little more reluctant to update that box.

          So.. what I have now is a PPPoE-CARP (well, the CARP is only on the LAN, but the WAN uses PPPoE depending on who is CARP master, so they also share the same WAN IP), I also just added a VLAN interface to have HA of the relevant parts (for me VPN, IPSEC and OpenVPN) sync from Master to Backup via HA.

          When the MASTER beocmes unavailable, it takes a little over 1 minute till the BACKUP is dialed in, but still, I hope this will prevent me from remotely locking myself out in the future, plus it should make system updates a lot better (internet connection only interrupted for 1 minute, available afterwards again with same features).

          1 Reply Last reply Reply Quote 0
          • U
            UClinux
            last edited by Jul 20, 2023, 2:06 AM

            According to my tests, the valid syntax

            $config['interfaces']['opt1']['enable'] = "";
            or
            unset($config['interfaces']['opt1']['enable']);
            
            interface_reconfigure('opt1');
            write_config('enable/disable opt1 interface');
            exec
            

            Real-time enable/disable interface
            No need for system_reboot_sync();

            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.
              This community forum collects and processes your personal information.
              consent.not_received