Re: Reading and *writing* configuration files
by tachyon (Chancellor) on Apr 08, 2002 at 23:48 UTC
|
There is BIND::Conf_Parser which is a base class for parsing 8.x named.conf files.
In a nutshell to retain bits of an existing conf file you first need to parse it
so you can find the bits you want to keep, change the bits you want to change, then put Humpty Dumpty back together again....
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
| [reply] |
|
I've looked at Bind::Conf, but it only reads named.conf files, it doesn't write them. :-(
| [reply] |
|
Ah that's kinda the idea. You read in the current file and parse it using a parser module. *You* make your changes to this parsed data set. *You* print out the new file from your munged data set.
One significant problem with retaining comments is that they are only useful if the are relevant. Comments that relate to parts of the file which have been changed are worse than useless.
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
| [reply] |
|
|
Re: Reading and *writing* configuration files
by Fletch (Bishop) on Apr 09, 2002 at 02:08 UTC
|
Another option would be to use something like
Template Toolkit
to process a skelleton file. If the user has any non-standard
edits, they can place them in the skelleton file and they'll
be preserved in the output. That of course requires some
handwaving if the user expects something of theirs to override
the generated output (perhaps use some sort of directive which
sets a variable that the generated portion inspects).
| [reply] |
|
Text::Template might be worth looking at, too. I use that one for Java Servlet configs.
One of these days, I'll get around to playing with Template Toolkit... I continue to hear much good about it.
| [reply] |
|
Also worth looking into, for its simplicity if for no other reason, is CGI::FastTemplate. The "CGI" in its name can be misleading -- it's just a darn fine template parser. I use it all the time, and often for things that get nowhere near the web.
| [reply] |
Re: Reading and *writing* configuration files
by seanbo (Chaplain) on Apr 09, 2002 at 12:52 UTC
|
You may want to take a look at Perl for System Administration by O'Reilly and Associates. Chapter 5 (TCP/IP Name Services) pages 149-167 describe generating BIND config files from a db. You can make all your changes to the db (through CGI if you like) and then dump the config files from the db. This way, there is no need to parse the existing files because the data is stored in the db.
I highly recommend taking a look at this chapter. Even though the example is rather simplistic and wouldn't suit the needs where I work, it could be easily modified to incorporate the changes we need. We are looking into moving in this direction in the future.
perl -e 'print reverse qw/o b n a e s/;' | [reply] |
Re: Reading and *writing* configuration files
by gav^ (Curate) on Apr 09, 2002 at 03:51 UTC
|
| [reply] |
|
Hmmm.. those are not bad ideas. I don't know why I didn't think of Algorithm::Diff. I'll look at Config::IniFiles first to see if I can steal any ideas, then checkout Algorithm::Diff and see if it can be of any help.
thanks!
| [reply] |
Re: Reading and *writing* configuration files
by CukiMnstr (Deacon) on Apr 09, 2002 at 02:53 UTC
|
Another option would be to have the 'default' (or changed trough your CGI) values in some sort of database (could be CSV). Then when you are generating the configuration from the CGI, you could merge both configs and keep the hand edits (by comparing existing tokens) and comments from the configuration file (comments are *somewhat* easier, since they probably have an 'opening token').
yet another option would be to put and 'End of CGI config' tag at the end (or beginning) of the cgi-generated part, and then add some comments instructing the user making the hand edits to put his or her config directives in the proper section...
hope this helps, | [reply] |
Re: Reading and *writing* configuration files
by Stegalex (Chaplain) on Apr 09, 2002 at 12:48 UTC
|
Here's some HERESY for you:
You can use Config::IniFiles if you want to use Window$-like .ini files. Works well. Check it:
use Config::IniFiles;
my $handle = Config::IniFiles->new(-file=>$filename);
my $setting = $handle->val ('sectionname','yoursetting')
print "I like chicken.\n";
| [reply] [d/l] |
Re: Reading and *writing* configuration files
by DaWolf (Curate) on Apr 09, 2002 at 02:28 UTC
|
Hi there.
I don't know almost anything about conf files, but I tought I could add one generic comment that MAYBE will help you.
Sorry if it doesn't.
Is there a pattern for a comment on them? Probably, right? So you could find a way to write a "simple" (the quotes are here because I can't tell the real complexity of your task) sub that ensures that anything matching that pattern would be preserved.
I know this sound pretty obvious, but sometimes we forgot the simple things - happens a lot to me.
Hope It helps you.
Best regards,
Er Galvão Abbott
a.k.a. Lobo, DaWolf
Webdeveloper
| [reply] |
Re: Reading and *writing* configuration files
by sporte01 (Acolyte) on Apr 09, 2002 at 16:55 UTC
|
Here's an idea. WHy not write your own format in XML, do all your management in XML, and use XSLT to write bind format files. That way if the BIND people decide, "wait, let's use format X", you have less to worry about. Just rewrite the XSLT and you won't have to change your programming.
well.. just that inside the xslt, but that's easy enough :) At least you won't have to write another script to go from bind 9.x -> bind 9+n.x
| [reply] |
|
Dear god I hope your kidding! If not, I hope you'll elaborate. That sounds complicated and roundabout as hell, but that could just be because of my lack of XML knowledge.
| [reply] |
Webmin might be a good example
by SwellJoe (Scribe) on Apr 09, 2002 at 19:23 UTC
|
For what it's worth, Webmin has a nice BIND module that reads and writes BIND configuration files (all of them), and it respects comments and the existing formatting.
The code isn't as modular as one might like, but it is thoroughly readable in all of the modules I've studied. It is probably worth looking into as a working example.
It can be found here: http://www.webmin.com | [reply] |
Re: Reading and *writing* configuration files
by archimago (Pilgrim) on Apr 09, 2002 at 20:34 UTC
|
Interesting article on IBM developer works covers this ground and recommends the AppConfig module:
http://www-106.ibm.com/developerworks/linux/library/l-perl3/ | [reply] |
|
| [reply] |
|
Outputting configs was the ENTIRE point of the original article. I'm already parsing the config just fine. And, as you said, Appconfig while awesome, won't read named.conf files.
| [reply] |