• Hi all,

    I would like to create a api for an automated creation of vlans (atm).
    I've created a file (api.php) at /usr/local/www and try to create the vlan 700.

    $vlan = array();
    $vlan["if"] = "em1";
    $vlan["tag"] = 700;
    $vlan["descr"] = "Test-VLAN";
    $vlan["vlanif"] = "em1_vlan700";

    But … no errors ... no logs ... no vlans  >:(

    Do I have to reload something?
    Thanks in advance

  • Hi. Do you check the interfaces section in the config file after running this?

  • Yes, I do.

    The backuped config-file:


    And the php output of echo("
    " . print_r($config, true));

    [vlans] =>

  • Oh, sorry …


  • Do you try to run write_config() function after your code? if I remember correctly, It writes changes to config file.

  • Yes, I do. Nothing changed!

  • Hi craCH,

    I'm working on a similar project, also implementing an API for PFSense. I have put your code in my project and after a few changes it worked. Your code was already creating the VLAN interface (checked it by running ifconfig on the shell). But you have to update config params yourself, this isn't done by the interface_vlan_configure method.

    This is my test code:

    if (!is_array($config['vlans']['vlan']))
            $config['vlans']['vlan'] = array();
    $vlan = array();
    $vlan["if"] = "em1";
    $vlan["tag"] = 700;
    $vlan["descr"] = "Test-VLAN";
    $vlan["vlanif"] = "em1_vlan700";
    $vlan["vlanif"] = interface_vlan_configure($vlan);
    $config['vlans']['vlan'][] = $vlan;

    Note on my example: It doesn't check if the VLAN already exists in the config. So running the test script more than once may break things  ;)

    I normally use the github of PFSense for example code on howto use methods. In your case: https://github.com/bsdperimeter/pfsense/blob/master/usr/local/www/interfaces_vlan_edit.php .

    I hope this will help you in the right direction.

    Best regards,

  • Great, it works …

    thanks a lot