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

pfssh: how to add (initial) VLANs?

Scheduled Pinned Locked Moved Development
2 Posts 2 Posters 366 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.
  • J
    JeGr LAYER 8 Moderator
    last edited by May 29, 2020, 12:09 PM

    Hi,

    as it's a tedious task we do multiple times on various machines, I opted to write a little playback for pfssh.php to add a VLAN. Problem is, if there's no VLAN created on a particular machine, the config.xml doesn't have the <vlan> array inside the <vlans> and I can't seem to add an (initial) new VLAN with the "normal" way that works for adding VLANs afterwards:

    $newvlan = array(
    	'if'     => "igbX",
    	'tag'    => 123,
    	'vlanif' => "igbX.123",
    	'descr'  => "dummy123",
    );
    
    $config['vlans']['vlan'][] = $newvlan;
    write_config();
    exec
    

    That works without problems, if there's already a $config[vlans][vlan][0] / a first VLAN in existence. But I can't seem to create the initial one as everything I tried (to make the "vlan" appear), seems to fail:

    Fatal error: Uncaught Error: Cannot use string offset as an array in /usr/local/sbin/pfSsh.php(371) : eval()'d code:11
    Stack trace:
    #0 /usr/local/sbin/pfSsh.php(371): eval()
    #1 /usr/local/sbin/pfSsh.php(271): playback_text('$newvlan = arra...')
    #2 {main}
      thrown in /usr/local/sbin/pfSsh.php(371) : eval()'d code on line 11
    PHP ERROR: Type: 1, File: /usr/local/sbin/pfSsh.php(371) : eval()'d code, Line: 11, Message: Uncaught Error: Cannot use string offset as an array in /usr/local/sbin/pfSsh.php(371) : eval()'d code:11
    Stack trace:
    #0 /usr/local/sbin/pfSsh.php(371): eval()
    #1 /usr/local/sbin/pfSsh.php(271): playback_text('$newvlan = arra...')
    #2 {main}
    

    Neither $config['vlans']['vlan'][0] = $newvlan; or $config['vlans']['vlan'][] = $newvlan; or manually trying to add the vlan node manually in the array seem to work. Something silly I'm obviously overlooking but I'd be happy for anyone to chime in ^^

    Greets
    Jens

    Don't forget to upvote 👍 those who kindly offered their time and brainpower to help you!

    If you're interested, I'm available to discuss details of German-speaking paid support (for companies) if needed.

    1 Reply Last reply Reply Quote 0
    • J
      jimp Rebel Alliance Developer Netgate
      last edited by Jun 3, 2020, 7:41 PM

      You have to declare each level of the hash/array as you go. Like this:

      $config['vlans'] = array();
      $config['vlans']['vlan'] = array();
      $config['vlans']['vlan'][] = $newvlan;
      

      There is a convenience function that can help:

      init_config_arr(array('vlans', 'vlan'));
      $config['vlans']['vlan'][] = $newvlan;
      

      That function only initializes the arrays if they are unset/don't exist/are not arrays so it's safe to run unconditionally.

      Remember: Upvote with the 👍 button for any user/post you find to be helpful, informative, or deserving of recognition!

      Need help fast? Netgate Global Support!

      Do not Chat/PM for help!

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