• 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";
    interface_vlan_configure($vlan);
    

    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:

     <vlans></vlans> 
    

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

    [vlans] =>


  • Oh, sorry …

    	 <interfaces><wan><enable><if>em0</if>
    			 <mtu><ipaddr>10.10.0.1</ipaddr>
    			<subnet>24</subnet>
    			 <gateway><blockpriv><blockbogons><dhcphostname><media><mediaopt></mediaopt></media></dhcphostname></blockbogons></blockpriv></gateway></mtu></enable></wan> 
    		 <lan><enable><if>em1</if>
    			<ipaddr>10.10.1.1</ipaddr>
    			<subnet>24</subnet>
    			 <media><mediaopt></mediaopt></media></enable></lan></interfaces> 
    
    

  • 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:

    
    require_once('util.inc');
    require_once('filter.inc');
    require_once('interfaces.inc');
    require_once('config.inc');
    
    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;
    
    write_config();
    ?>
    
    

    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,
    Sander


  • Great, it works …

    thanks a lot