OPNsense
  • Home
  • Help
  • Search
  • Login
  • Register

  • OPNsense Forum »
  • English Forums »
  • Development and Code Review (Moderator: fabian) »
  • [Solved] os-bind: Custom parameters causing configuration save issues
« previous next »
  • Print
Pages: [1]

Author Topic: [Solved] os-bind: Custom parameters causing configuration save issues  (Read 3605 times)

pxpunx

  • Newbie
  • *
  • Posts: 6
  • Karma: 0
    • View Profile
[Solved] os-bind: Custom parameters causing configuration save issues
« on: February 27, 2022, 01:04:28 am »
I wanted to add a syslog option to os-bind, so I played around and tested it. Code is below. It works, but I've encountered odd behavior when I try to save the configuration.

For example, if I select one or more of my new syslog options from the drop-down list I created, the configuration saves and the underlying configuration file is updated successfully. If I do not select any syslog options, the configuration saves but is not updated. If I do not select any syslog options, other standard configuration parameters also do not save. It's as if the state of the new `syslog` field controls whether or not the configuration file is updated.

I'm sure it's something ridiculous that I've missed and wanted to see if anyone had any ideas.

Code: [Select]
# /usr/local/opnsense/mvc/app/models/OPNsense/Bind/General.xml

<model>
    <mount>//OPNsense/bind/general</mount>
    ...
    <items>
        ...
        <syslog type="OptionField">
            <Required>N</Required>
            <Multiple>Y</Multiple>
            <OptionValues>
                <default>default</default>
                 # note: I've tried with and without <default> to make sure it didn't conflict
                <general>general</general>
                <queries>queries</queries>
                <rpz>rpz</rpz>
            </OptionValues>
            <default></default>
            # tried with and without this parameter, and with and without a value set
        </syslog>
        ...
    </items>
</model>

Code: [Select]
# /usr/local/opnsense/mvc/app/controllers/OPNsense/Bind/forms/general.xml

<form>
    ...
    <field>
        <id>general.syslog</id>
        <label>Enable Syslog</label>
        <type>select_multiple</type>
        <help>Enable syslog per logging channel.</help>
    </field>
    ...
</form>

This feels a little crude, but it works:

Code: [Select]
# /usr/local/opnsense/service/templates/OPNsense/Bind/named.conf

...

logging {
        ...
{% if helpers.exists('OPNsense.bind.general.syslog') %}
        channel syslog {
                syslog daemon;
                severity info;
        };
{% endif %}

        category default { default_log; {% if 'default' in OPNsense.bind.general.syslog %}syslog;{% endif %} };
        category general { default_log; {% if 'general' in OPNsense.bind.general.syslog %}syslog;{% endif %} };
        category queries { query_log; {% if 'queries' in OPNsense.bind.general.syslog %}syslog;{% endif %} };
        category rpz { rpz_log; {% if 'rpz' in OPNsense.bind.general.syslog %}syslog;{% endif %} };       
        ...
};
...
« Last Edit: February 27, 2022, 04:13:15 am by skpio »
Logged

pxpunx

  • Newbie
  • *
  • Posts: 6
  • Karma: 0
    • View Profile
Re: os-bind: Custom parameters causing configuration save issues
« Reply #1 on: February 27, 2022, 01:39:53 am »
It looks like the issue has to do with the modifications I made to the named.conf template. I made some small tweaks to test and am able to save correctly. I will post an update when I sort out just what I did to ruin the template.
Logged

pxpunx

  • Newbie
  • *
  • Posts: 6
  • Karma: 0
    • View Profile
Re: [Solved] os-bind: Custom parameters causing configuration save issues
« Reply #2 on: February 27, 2022, 04:16:22 am »
Solved!

Code: [Select]
logging {
        ...

{% if helpers.exists('OPNsense.bind.general.syslog') %}
        channel syslog {
                syslog daemon;
                severity info;
        };
{% endif %}

        category default { default_log;{{ ' syslog;' if 'default' in OPNsense.bind.general.syslog|string }} };
        category general { default_log;{{ ' syslog;' if 'general' in OPNsense.bind.general.syslog|string }} };
        category queries { query_log;{{ ' syslog;' if 'queries' in OPNsense.bind.general.syslog|string }} };
        category rpz { rpz_log;{{ ' syslog;' if 'rpz' in OPNsense.bind.general.syslog|string }} };
        ...
};

I had to add |string at the end of the variable name to force it to treat the variable like a string when performing the string search.

I also streamlined it a little.
Logged

franco

  • Administrator
  • Hero Member
  • *****
  • Posts: 17707
  • Karma: 1618
    • View Profile
Re: [Solved] os-bind: Custom parameters causing configuration save issues
« Reply #3 on: February 28, 2022, 12:17:02 pm »
Thanks for looking into this! Relevant PR for future reference:

https://github.com/opnsense/plugins/pull/2867


Cheers,
Franco
Logged

  • Print
Pages: [1]
« previous next »
  • OPNsense Forum »
  • English Forums »
  • Development and Code Review (Moderator: fabian) »
  • [Solved] os-bind: Custom parameters causing configuration save issues
 

OPNsense is an OSS project © Deciso B.V. 2015 - 2024 All rights reserved
  • SMF 2.0.19 | SMF © 2021, Simple Machines
    Privacy Policy
    | XHTML | RSS | WAP2