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

Creating API

Scheduled Pinned Locked Moved Development
8 Posts 3 Posters 3.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.
  • C
    crach
    last edited by Feb 16, 2013, 5:17 PM Feb 16, 2013, 4:30 PM

    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

    1 Reply Last reply Reply Quote 0
    • A
      ardunio
      last edited by Feb 16, 2013, 5:34 PM Feb 16, 2013, 5:28 PM

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

      1 Reply Last reply Reply Quote 0
      • C
        crach
        last edited by Feb 16, 2013, 5:31 PM

        Yes, I do.

        The backuped config-file:

         <vlans></vlans> 
        

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

        [vlans] =>

        1 Reply Last reply Reply Quote 0
        • C
          crach
          last edited by Feb 16, 2013, 5:35 PM

          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> 
          
          
          1 Reply Last reply Reply Quote 0
          • A
            ardunio
            last edited by Feb 16, 2013, 5:35 PM

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

            1 Reply Last reply Reply Quote 0
            • C
              crach
              last edited by Feb 16, 2013, 6:21 PM

              Yes, I do. Nothing changed!

              1 Reply Last reply Reply Quote 0
              • S
                Sander88
                last edited by Feb 17, 2013, 5:09 PM

                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

                1 Reply Last reply Reply Quote 0
                • C
                  crach
                  last edited by Feb 17, 2013, 6:53 PM

                  Great, it works …

                  thanks a lot

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