Skip to main content

Hook to enable IPv6 after account creation

Comments

16 comments

  • snewton
    What I ended up doing was changing the script to: #!/bin/bash ls -1 /var/cpanel/users | while read USER; do /usr/local/cpanel/bin/whmapi1 ipv6_enable_account user=${USER} range=SHARED; done
    Now when a new account is created, it enables IPv6 for all accounts. I had existing accounts, so the new test account I created took a while to create since it was enabling IPv6 on all the other accounts. Going to "Assign IPv6 Address" in WHM and enabling all existing accounts prior would probably be preferred if you have existing accounts. After all accounts have IPv6 enabled, the new account creation runs quickly. Again, if anyone has any suggestions for a better way of doing it, I'd love to hear. Thanks!
    0
  • cPanelTJ
    @snewton I'm looking into reproducing your original issue now. Could you give me the full string you used over CLI to register your hook?
    0
  • snewton
    I used: /usr/local/cpanel/bin/manage_hooks add script /opt/ipv6.sh --manual --category Whostmgr --event 'Accounts::Create' --stage post
    0
  • cPanelTJ
    I needed a refresher on using a bash script with a hook, but it appears there isn't really a clear and easy way to get the event's variables into a bash script. Are you comfortable using Perl, PHP, or another language?
    0
  • snewton
    I needed a refresher on using a bash script with a hook, but it appears there isn't really a clear and easy way to get the event's variables into a bash script. Are you comfortable using Perl, PHP, or another language?

    I would definitely use another if it gets the job done.
    0
  • plesk4lyf
    #!/bin/sh /usr/local/cpanel/bin/whmapi1 ipv6_enable_account user=$user range=SHARED
    Are you sure that $user is a valid variable? From what the developer documentation has, it sounds like your code needs to parse JSON to get the user first:
    0
  • snewton
    #!/bin/sh /usr/local/cpanel/bin/whmapi1 ipv6_enable_account user=$user range=SHARED
    Are you sure that $user is a valid variable? From what the developer documentation has, it sounds like your code needs to parse JSON to get the user first:
    0
  • plesk4lyf
    Hey @snewton, This will do what you want. 1. Make a file /scripts/postwwwacct 2. Put this into it: #!/bin/bash ARRAY=($@) ARRAYLENGTH=${#ARRAY[@]} for (( ARG=0 ; ARG < $ARRAYLENGTH ; ARG++ )) do if [ "${ARRAY[$ARG]}" = "user" ] ; then USERNAME=${ARRAY[$ARG +1]} test -f /var/cpanel/users/$USERNAME && /usr/local/cpanel/bin/whmapi1 ipv6_enable_account user="$USERNAME" range=SHARED fi done
    3. Make it executable with # chmod +x /scripts/postwwwacct When you make a test account, you should see the whmapi1 output under "Running post creation scripts". I've tested it on WHM82 and it works fine. This uses the old "script hooks" method:
    0
  • snewton
    The Standardized Hooks method can be just as straightforward, if not even more simple. Using the
    If anything related to using Standardized Hooks feels daunting, I sincerely would appreciate your feedback. We hope to take a look at making this system more intuitive to use in the near future.

    Thanks @cPanelTJ What we be the proper method of registering it?
    0
  • cPanelTJ
    Simply: /usr/local/cpanel/bin/manage_hooks add module NewAccountHook
    You'll need to ensure that the perl module is in any of the following directories: /opt/cpanel/perl5/514/site_lib/x86_64-linux-64int /opt/cpanel/perl5/514/site_lib /var/cpanel/perl5/lib
    (reference step 10 in this tutorial:
    0
  • snewton
    Works great, @cPanelTJ and is definitely much simpler. Thanks for your help on this!
    0
  • cPanelTJ
    Excellent to hear! I did trim down the directory list in my previous post to show the supported directories that we'd recommend storing this module. Speaking with a developer internally, /usr/local/cpanel/
    may have some risk in future updates where your file could be overwritten or cause conflict with newly added functionality.
    0
  • snewton
    Excellent to hear! I did trim down the directory list in my previous post to show the supported directories that we'd recommend storing this module. Speaking with a developer internally, /usr/local/cpanel/
    may have some risk in future updates where your file could be overwritten or cause conflict with newly added functionality.

    I did in fact use "/usr/local/cpanel" too! :D I've changed it to "/var/cpanel/perl5/lib". One last thing. When creating an account in WHM manually, I see the following towards the top of the output now: {"data":{"ipv6":{"testacc":""},"failures":{},"fail_cnt":0},"metadata":{"result":1,"reason":"OK","version":1,"command":"ipv6_enable_account"}}
    Any chances of suppressing that? Again, thanks for all your help!
    0
  • cPanelTJ
    Looks like replacing system("...");
    with backticks, such as `whmapi1 ipv6_enable_account user=$user range=SHARED --output=json`;
    will stop the spew to STDOUT.
    0
  • snewton
    Looks like replacing system("...");
    with backticks, such as `whmapi1 ipv6_enable_account user=$user range=SHARED --output=json`;
    will stop the spew to STDOUT.

    That did the trick. Again, thanks for all your help @cPanelTJ
    0

Please sign in to leave a comment.