Find the answer to your Linux question:
Results 1 to 5 of 5
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Thinking of designing a program to modify config files

    Sorry for the title, it's hard to explain the idea within the character limit. I'm thinking of designing a program that makes it easy to modify config files while maintaining their integrity. Basically, you would create a validation file that points to your config file. The file would contain rules for what the config file must contain, similar to what a DTD does for XML. You could specify what variables need to be included, what values a variable could have, cleanup rules (tolowercase), etc. The system would be pretty granular but could be pretty simple for people to implement if they choose to. The user can then use my program to validate the file (if they wish), or use it as a wrapper around the file. This would allow the user to modify the file like an object in a programming language. The program can also have a GUI interface which allows the user to modify the file like a form.

    I think the file would share the same name as the config file with a unique extension added on. It could be double clicked on to get the GUI, from the command line have it's own interface, plus easily be edited if passed to a text editor. The validation file could be saved in either XML, JSON, or YAML since they can easily be converted to each other and it gives the user the freedom to work in whatever language they like.

    I can think of a lot of benefits and potential uses for this program. First, it frees people up from designing a GUI for their config files. They modify a file and it generates it for them. Second, it allows people to trust the integrity of their config files. It doesn't replace config files, it compliments them. I also can see MMC like interface being implemented that group config files together.

    I was wondering do people know of any systems like this in place? Do people think it's a good idea? If it is and I can get it done, I would like the validation file format to eventually become an open standard so others can create their own programs that interact with the files.

  2. #2
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    The problem is, that there are generally only loose rules for config files.
    They are key/value and thatīs mostly it.

    Comments are sometimes #, sometimes ;
    Some config files feature sections, others dont.
    Is a key uniq or not?

    A config file is very closely bound to the tool/daemon that needs it.
    So I think it is far from trivial to design your program in a way that it is both flexible and still easy.

    That said, there are already ways to deal with config files:
    1) "Good" tools feature the -t switch.
    You can call e.g. httpd -t or bacula-dir -t and they will read and verify their config.

    2) It is (usually) a one time effort to figure out the config for a specific usecase.
    So templates or even a plain file copy can be used to distribute the configs to any amount of servers

    3) If you dont want to replace a whole file but extend existing ones, then have a look at augeas:
    This tool parses config files with the help of "lenses", aka specific grammar for each config file.
    You get a hierarchical tree representation of your config file, which you can operate on similar to files in a filesystem tree.

    You can use augeas as a commandline tool or via c/ruby API.
    We use it as a Puppet module.
    An example snippet looks like this:
    Should be fairly easy to understand:
    In the file "/etc/ssh/sshd_config", make sure that e.g. PermitRootLogin is set to the value of the puppet variable ${ssh::server:ermitrootlogin}

    augeas { "sshd_config":
      context => "/files/etc/ssh/sshd_config",
      changes => [
        "set PermitRootLogin ${ssh::server::permitrootlogin}",
        "set Ciphers ${ssh::server::ciphers}",
        "set ListenAddress ${ssh::server::listenaddress}",
        "set PasswordAuthentication ${ssh::server::passwordauthentication}",
      require => Package['openssh-server'],
      notify  => Service['sshd'],
    You must always face the curtain with a bow.

  3. #3
    From what I've seen, most config files fall into either a shell script style (key/value pairs with ; and # for comments), csv, ini, yaml, json, and xml. I might be missing some, I'm not sure. Script files like python, php or ruby are too complex for this project currently. With the exception of batch though, the format of the files are standard across the board (for parsing at least) and there are tools already designed to read them. My initial goal isn't the large projects with fairly complex config files but smaller projects that might want to provide a GUI to their users, but not want to spend time designing an interface.

    If I was to give an analogy it would probably be the yii framework for php. With yii, you can specify your database connection info in the config file. Once you do, it analyzes your tables and can generate models based on them. You can then configure the models to tell it what data a field can take, different rules and such, etc. Then you can generate a CRUD interface to the database that works with your rules. You can get pretty granular with your rules and generate an interface very quickly.

    My initial goal for this project is similar. You point it at a config file, it analyzes it and can generate a gui interface for you. You can then add rules to it to give you tighter control. It can help protect your script from junk data (at least at the GUI level), and allow users to modify data at a higher level. As time would go on, if the project was successful, I would add more control, better detection, more pre-made parsing options, etc. In my head I can see people right clicking on a config file, generating a model, and then double clicking on the model to edit the config file in a gui.

    I also like the idea that this method doesn't replace config files it wraps around them. Comment structure would be preserved and everything would be written back to the program line by line, with the exception of changes.

    Unfortunately, I'm not in Linux right so I can't check out Augeas yet. It does sound somewhat similar to what I'm thinking of though. I kinda figured there would be something out there. Part of the reason I posted was to find out if there was already something out there. I'll have to check it out though. I still think my idea is different enough that it might be worth trying. Thank you for replying it was some good feedback.

  4. $spacer_open
  5. #4
    Linux Newbie SL6-A1000's Avatar
    Join Date
    May 2011
    I don't think that's such a bad idea,

    I think if you can create a shell that loads the config file and allows you to save a backup and then edit it.

    I don't know if you have ever done any hacking with the Age of Empires Series (1 and 2) or Star Wars Galactic Battlegrounds, but they designed a shell program that loads the files needed and than breaks it down so its easy to understand.

    For example a unit would be broken down into the unit id, name, id number, attack, HP etc..

    It wouldn't have to be a complex shell... The only thing i would be worried about is misinterpretation of the config file. As not everyone writes them the same way.

  6. #5
    I actually loved the AOE series, but I enjoyed Age of Mythology more. I think I downloaded that years ago.

    The people I actually think would make the most use of this would be the developers of the software or people who want to provide a front-end and distribute it to others. I would plan on backing up any files with revision history and diff like style built in to try and limit problems. I have some ideas.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts