Home
Help
Search
Login
Register
OPNsense Forum
»
English Forums
»
Development and Code Review
(Moderator:
fabian
) »
Need Advice: Managing Configuration Files
« previous
next »
Print
Pages: [
1
]
Author
Topic: Need Advice: Managing Configuration Files (Read 1948 times)
gunior80
Newbie
Posts: 5
Karma: 0
Need Advice: Managing Configuration Files
«
on:
May 11, 2024, 04:35:58 pm »
Hello everyone! I've encountered an issue while developing a plugin and need your help. My task is as follows: I have a service that utilizes multiple configuration files, named in the format e2guardianfN.conf, where N is a sequential number starting from one. In my model, I've added an 'instance' field where the file number is inputted. However, the service is sensitive to the order of these files, and it's not possible to simply delete a random file without restoring the naming order. My idea is to modify entries with an 'instance' number greater than the one being deleted. But how can I do this in the most appropriate way? I'd appreciate any tips and advice!
Also, I've uploaded a draft of the code to GitHub. Here is the link:
https://github.com/Gunior80/E2G-OPNsense
Logged
Monviech (Cedrik)
Global Moderator
Hero Member
Posts: 1601
Karma: 176
Re: Need Advice: Managing Configuration Files
«
Reply #1 on:
May 11, 2024, 05:50:33 pm »
Is there a reason that the whole configuration can't be generated inside the main e2guardian.conf file in the right order?
Logged
Hardware:
DEC740
gunior80
Newbie
Posts: 5
Karma: 0
Re: Need Advice: Managing Configuration Files
«
Reply #2 on:
May 11, 2024, 06:05:18 pm »
From what I know, it doesn't support that and relies specifically on additional files and their sequence. Configuration files for groups (e2guardianfN.conf) don't contain sections.
Logged
Monviech (Cedrik)
Global Moderator
Hero Member
Posts: 1601
Karma: 176
Re: Need Advice: Managing Configuration Files
«
Reply #3 on:
May 11, 2024, 06:24:09 pm »
What if one of the sequenced files is empty, or only has a minimal configuration inside that can keep it valid for the service without doing anything?
Logged
Hardware:
DEC740
gunior80
Newbie
Posts: 5
Karma: 0
Re: Need Advice: Managing Configuration Files
«
Reply #4 on:
May 11, 2024, 06:54:13 pm »
Yes, the idea is promising! Thank you! So, this can be done, but then we'll need to address another issue. In the main service config, there's a parameter called 'filtergroups', which equals the number of groups. I've set it up to autofill using '{{ OPNsense.e2guardian.group.groups.group|length }}'. We'll need to adjust it to always increment this parameter by one when a new group is created. I think we could add a counter to the main model and increment it there when adding a new group, but how should we do it properly?
ps
I've considered that there might be issues with exporting and importing settings in the future. In that case, we might need to disallow the deletion of groups. However, on the other hand, it's also not ideal that entries can't be deleted.
p.p.s.
Ultimately, I'll disable the ability to delete groups and take the highest 'instance' value for the main config. Configurations for disabled groups will be rewritten to an inert state. Thanks a lot for the idea!
«
Last Edit: May 11, 2024, 07:21:19 pm by gunior80
»
Logged
mimugmail
Hero Member
Posts: 6766
Karma: 494
Re: Need Advice: Managing Configuration Files
«
Reply #5 on:
May 11, 2024, 08:59:20 pm »
Have a look at the bind plugin, there I template filenames like the domain value. Should perfectly fit your needs
Logged
WWW:
www.routerperformance.net
Support plans:
https://www.max-it.de/en/it-services/opnsense/
Commercial Plugins (German):
https://opnsense.max-it.de/
gunior80
Newbie
Posts: 5
Karma: 0
Re: Need Advice: Managing Configuration Files
«
Reply #6 on:
May 11, 2024, 09:08:54 pm »
I was looking at the bind and wireguard plugins for reference. However, they don't require strict file sequencing like this.
Logged
mimugmail
Hero Member
Posts: 6766
Karma: 494
Re: Need Advice: Managing Configuration Files
«
Reply #7 on:
May 12, 2024, 07:15:52 am »
How about using calculation like serial numbers in bind domains? Just count date which is always higher than previous?
Logged
WWW:
www.routerperformance.net
Support plans:
https://www.max-it.de/en/it-services/opnsense/
Commercial Plugins (German):
https://opnsense.max-it.de/
gunior80
Newbie
Posts: 5
Karma: 0
Re: Need Advice: Managing Configuration Files
«
Reply #8 on:
May 12, 2024, 12:33:11 pm »
I don't need to do that. There are group files with names containing uninterrupted numbering starting from 1. The number of these groups is stored in the global configuration file. The initial issue is that you can't simply delete a random group file and decrement the value in the global config by one, as it will disrupt the sequence of group file names, causing a service error. Ideally, we need to restore the sequence by automatically resaving the entries with the restored sequence in numbering. I don't know how to do this properly because I haven't seen such solutions in other plugins, and I'm not fully proficient in PHP. Therefore, I've decided to temporarily bypass this issue by disallowing the deletion of configs.
p.s.
Thank you for your help! I've simplified things significantly. In the view, I've restricted deletion of all entries except the last one. As a result, the sequence remains intact, and it's permitted to delete group entries, but only from the end of the list.
«
Last Edit: May 12, 2024, 01:35:14 pm by gunior80
»
Logged
Print
Pages: [
1
]
« previous
next »
OPNsense Forum
»
English Forums
»
Development and Code Review
(Moderator:
fabian
) »
Need Advice: Managing Configuration Files