Hook file allowing to customize hosts file

  • On the standard setup, the /etc/hosts file is recreated every time the setup is run, since there might be stuff that depends on static dns entries, having a way to add (and preserve custom changes) might be useful.


    With this hook the content you store in a file (defaults to /etc/imscp/hooks.files/hosts.custom) will be concatenated to the imscp generate hosts file.


    You can find the most recent version of the code at bitbucket
    I've tested it with current master (as of 27/06/13)


    For any issues, just drop a line in this thread.

    Edited once, last by Nuxwin ().


  • ok, it was fixed on my local version, just pushed the fixed version, now there are some points I'd like to be adressed


    • Is it ok to store the .custom file in the hooks dir?
    • There's to be some way to manage the exit of the program in case the file is not found, die, or exit or just keep working but spit a debug message
  • I see there no problem to store the file there, because only .pl will we included.

    Code
    1. if(-f '/etc/imscp/hooks.d/host.custom') {
    2. do all want you want
    3. } else {
    4. error('File /etc/imscp/hooks.d/host.custom not found');
    5. return 1;
    6. }
    • Is it ok to store the .custom file in the hooks dir?
    • There's to be some way to manage the exit of the program in case the file is not found, die, or exit or just keep working but spit a debug message


    Hello ;


    badge.php?id=1239063037&bid=2518&key=1747635596&format=png&z=547451206

    Edited once, last by Nuxwin ().

  • Very nice code, I had to make some changes to make it work, but it's working fine now, still in the github here


    • Instead of storing the custom file in /etc/imscp/ woudln't it fit somewhere else? This si is the place where the keys are stored and there is all the important files, what do you think of using for example /etc/imscp/hooks.files or something similar. (in the code I am using /etc/imscp/hooks.files)
    • Could we store these snippets in github, so people don't keep reinventing the wheel and have more variety of stuff read from? You decide where, it's more a matter of having it versioned/organized
    • Finally adding the extension .custom is safer than changing the file name to custom.hosts, because if there are more hooks using files it'll be more clear if all of them have the same extension (filename+ custom)
    • If I preserve the "Package Plugin::CustomHost;" line, I can't use the plugin

      Quote

      Can't locate object method "Package" via package "Plugin::CustomHost" (perhaps you forgot to load "Plugin::CustomHost"?) at /etc/imscp/hooks.d/preserve_custom_hosts.pl line 32, <$fh> line 738.
      Compilation failed in require at /root/imscp-git/engine/PerlLib/iMSCP/HooksManager.pm line 163, <$fh> line 738.



    That's it for the moment..


  • Use

    Code
    1. package Plugin::CustomHost;


    Thanks. I did not tested :P

    badge.php?id=1239063037&bid=2518&key=1747635596&format=png&z=547451206


  • Instead of storing the custom file in /etc/imscp/ woudln't it fit somewhere else? This si is the place where the keys are stored and there is all the important files, what do you think of using for example /etc/imscp/hooks.files or something similar. (in the code I am using /etc/imscp/hooks.files)


    You store the file where you want. You can edit the path in the plugin file easily. Storing the file under /etc/imscp should not harm since the "hook file" is only run by root. But again, you store this file where you want.



    Could we store these snippets in github, so people don't keep reinventing the wheel and have more variety of stuff read from? You decide where, it's more a matter of having it versioned/organized


    We have created the Plugin section on our forum exactly for that purpose. Hook files (wrongly called plugin there) are only some piece of code allowing to change default i-MSCP behavior or adding custom changes. We will not provide a specific repository to store/share such a files.


    Of course, feel free to create you own repository to share your own contributions.



    [Finally adding the extension .custom is safer than changing the file name to custom.hosts, because if there are more hooks using files it'll be more clear if all of them have the same extension (filename+ custom)


    Again, since you can edit the path easily in the hook file, you can name it as you want.



    If I preserve the "Package Plugin::CustomHost;" line, I can't use the plugin


    Instead of simply removing some part of code without asking you why it was added , try to debug them. Here, you are removing the package name, which acts as namespace for your hook file. A namespace allow to avoid any collision with other hook file and even with the i-MSCP core.

    badge.php?id=1239063037&bid=2518&key=1747635596&format=png&z=547451206

    Edited once, last by Nuxwin ().

  • We have created the Plugin section on our forum exactly for that purpose. Hook files (wrongly called plugin there) are only some piece of code allowing to change default i-MSCP behavior or adding custom changes. We will not provide a specific repository to store/share such a files.


    Since you don't want to create a repository for the hooks, at leas I'd create specific subforum for this, having the plugins and the hooks mixed in the same place doesn't make things clearer.



    Of course, feel free to create you own repository to share your own contributions.


    Done, I created a new repo in my bitbucket here where I'll store the hooks I use
    https://bitbucket.org/aseques/imscp-hooks/src if at some point this gets integrated into the imscp tree I'll delete it.