Skip to main content

Hook for post account creation

Comments

24 comments

  • snewton
    I did some more searching and I found:
    0
  • cPRex Jurassic Moderator
    Hey there! That feature request you found is correct as the hooks do not currently work for resellers. I did reach out to our Accounts team and they confirmed this isn't something that is doable at the moment, although they are aware of the feature request.
    0
  • snewton
    Hey there! That feature request you found is correct as the hooks do not currently work for resellers. I did reach out to our Accounts team and they confirmed this isn't something that is doable at the moment, although they are aware of the feature request.

    So no workaround for this? If not, then it looks like CloudLinux needs to update their documentation:
    0
  • cPRex Jurassic Moderator
    That does seem out of date as it's pointed to our older documentation site as well, where the new data is now at cPanel & WHM Developer Portal " cPanel & WHM Developer Portal for API calls and cPanel & WHM Documentation | cPanel & WHM Documentation for the standard documentation.
    0
  • snewton
    That does seem out of date as it's pointed to our older documentation site as well, where the new data is now at for API calls and
    0
  • snewton
    I had an idea for a work around for this, but during testing the "$plan" doesn't seem to be working. I came across the event "Whostmgr::Resellers::setup". Any idea if that would achieve what I need? Basically, if a reseller account is created, I want the ability to automatically assign specific CloudLinux Reseller Limits to that reseller account. There simply has to be a way to achieve this with cPanel.
    0
  • snewton
    Perhaps @cPanelTJ can suggest something or point me in the right direction?
    0
  • cPRex Jurassic Moderator
    He is who I really want to poke as he is the API/hook master, but he's out this week.
    0
  • snewton
    He is who I really want to poke as he is the API/hook master, but he's out this week.

    Ahhh! Thanks, cPRex. I will try harassing him next week then. Hopefully he can shed some light on this and point me in the right direction.
    0
  • cPRex Jurassic Moderator
    I have this open as a reminder to poke him as well!
    0
  • snewton
    Just to update, I've been working with CloudLinux support regarding this and the correct command to use for enabling Reseller Limits for an account, so I am using the following code: #!/usr/local/cpanel/3rdparty/bin/perl package ResellerLimits; use strict; use warnings; sub describe { my $hook = { 'category' => 'Whostmgr', 'event' => 'Accounts::Create', 'stage' => 'post', 'hook' => 'ResellerLimits::actions', 'exectype' => 'module', }; return $hook; } sub actions { my ( $context, $data ) = @_; my $user = $data->{'user'}; my $plan = $data->{'plan'}; if ( $plan == 'Reseller Plan 1' ) { system`lvectl set-reseller $user --speed='100%' --pmem=3G --nproc=200 --maxEntryProcs=30 --iops=5024 --io=102400`; } elsif ( $plan == 'Reseller Plan 2' ) { system`lvectl set-reseller $user --speed='150%' --pmem=5G --nproc=200 --maxEntryProcs=50 --iops=7024 --io=256000`; } elsif ( $plan == 'Reseller Plan 3' ) { system`lvectl set-reseller $user --speed='200%' --pmem=6G --nproc=200 --maxEntryProcs=60 --iops=10024 --io=358400`; } elsif ( $plan == 'Reseller Plan 4 ' ) { system`lvectl set-reseller $user --speed='250%' --pmem=4G --nproc=200 --maxEntryProcs=40 --iops=10024 --io=204800`; } else { # Do nothing } } 1;
    However, it still does not work.
    0
  • snewton
    @cPanelTJ, have you had a chance to look at this issue?
    0
  • cPRex Jurassic Moderator
    We definitely haven't forgot about this and we're still doing some testing on our end.
    0
  • cPanelTJ
    Just to update, I've been working with CloudLinux support regarding this and the correct command to use for enabling Reseller Limits for an account, so I am using the following code: ... However, it still does not work.

    @snewton My apologies for the delay in response. It has been quite a week playing catch-up as we're working on a lot of new, cool things right now. I wasn't able to fully finish reproducing your issue as I'm not exceptionally proficient with CloudLinux and lvectl, but one problem that jumps out to me immediately is that your perl operator for comparing $plan to the account's package is incorrect. In perl, `==` is meant for numerical comparisons. For string comparisons, `eq` should be used. Here is a resource with some good examples: Perl | Comparing Scalars - GeeksforGeeks If this doesn't work, you can turn on Standardized Hooks - Debug Mode (level 4) in WHM -> Tweak Settings, then you can watch the error_log in a split/separate terminal window (tail -F /usr/local/cpanel/logs/error_log
    ) to confirm that your hook triggers when you create a new account.
    0
  • snewton
    @snewton My apologies for the delay in response. It has been quite a week playing catch-up as we're working on a lot of new, cool things right now. I wasn't able to fully finish reproducing your issue as I'm not exceptionally proficient with CloudLinux and lvectl, but one problem that jumps out to me immediately is that your perl operator for comparing $plan to the account's package is incorrect. In perl, `==` is meant for numerical comparisons. For string comparisons, `eq` should be used. Here is a resource with some good examples: #!/usr/local/cpanel/3rdparty/bin/perl package ResellerLimits; use strict; use warnings; sub describe { my $hook = { 'category' => 'Whostmgr', 'event' => 'Accounts::Create', 'stage' => 'post', 'hook' => 'ResellerLimits::actions', 'exectype' => 'module', }; return $hook; } sub actions { my ( $context, $data ) = @_; my $user = $data->{'user'}; my $plan = $data->{'plan'}; if ( $plan eq 'Reseller Plan 1' ) { system`echo "Test succeeded" >> /usr/local/cpanel/test.txt`; } else { system`echo "Test failed" >> /usr/local/cpanel/test.txt`; } } 1;
    The above should write to the file test.txt with either succeeded or failed after account creation and instead the file test.txt is empty after account creation, so something is not right.
    0
  • cPanelTJ
    Are you getting any error spew from the hook module when you call whmapi1 createacct over CLI? What directory is your hook in? Is it registering properly through the manage_hooks script without error?
    0
  • snewton
    Are you getting any error spew from the hook module when you call whmapi1 createacct over CLI? What directory is your hook in? Is it registering properly through the manage_hooks script without error?

    No error is shown when creating an account via CLI. The hook .pm file has the correct permissions and is in: /usr/local/cpanel/ The hook is properly registered with no errors. (I've tried deleting and re-adding it several times trying to debug the issue)
    0
  • snewton
    Any word on this?
    0
  • cPanelTJ
    Hi @snewton , The script is working for me in /usr/local/cpanel
    and in /user/local/cpanel/hooks
    . Here is my code from ULC: [CODE=perl]#!/usr/local/cpanel/3rdparty/bin/perl package ResellerTest; use strict; use warnings; sub describe { my $hook = { 'category' => 'Whostmgr', 'event' => 'Accounts::Create', 'stage' => 'post', 'hook' => 'ResellerTest::actions', 'exectype' => 'module', }; return $hook; } sub actions { my ( $context, $data ) = @_; my $user = $data->{'user'}; my $plan = $data->{'plan'}; if ( $plan eq 'Package with Spaces' ) { system`echo "FROM ULC Test succeeded for User: $user and Plan: $plan" >> /usr/local/cpanel/test.txt`; } else { system`echo "Test failed FROM ULC" >> /usr/local/cpanel/test.txt`; } } 1;
    Here is my output to the test.txt
    file: FROM ULC Test succeeded for User: delete13me and Plan: Package with Spaces
    0
  • cPanelTJ
    Using the manage_hooks utility to list my hooks, this hook appears as: # /usr/local/cpanel/bin/manage_hooks list ... ... Whostmgr: Accounts::Create: stage: post id: c19ec9d1-7b3b-40c7-b2a3-53d00ea83eb5 hook: /usr/share/cloudlinux/hooks/cpanel/postwwwacct exectype: script weight: 200 escalateprivs: 0 -- exectype: module weight: 300 stage: post id: 58d006ef-4747-4a45-9b01-6d6503b0829c hook: ResellerTest::actions ... ...
    0
  • snewton
    Thanks @cPanelTJ! I tried this code with the current registered hook and initially it didn't work, which had me shaking my head. So I started over from scratch and found that I was registering the hook incorrectly. After registering the hook correctly, your code as well as the code I was previously trying to use worked for the event "Accounts::Create" with no issues. So now I want to use the same code so when an account is modified it will also do the same thing. I tried it with the events "Accounts::Modify" and "Accounts::change_package", but the code doesn't seem to run for either. What event do you recommend using so when a resellers plan/package is modified, the code will run? Thanks!
    0
  • cPanelTJ
    Thanks @cPanelTJ! I tried this code with the current registered hook and initially it didn't work, which had me shaking my head. So I started over from scratch and found that I was registering the hook incorrectly. After registering the hook correctly, your code as well as the code I was previously trying to use worked for the event "Accounts::Create" with no issues. So now I want to use the same code so when an account is modified it will also do the same thing. I tried it with the events "Accounts::Modify" and "Accounts::change_package", but the code doesn't seem to run for either. What event do you recommend using so when a resellers plan/package is modified, the code will run? Thanks!

    How did you set up your code to check for these additional events? Here is an example from our documentation that shows how to trigger off of multiple events within a single hook module: Tutorial - Create a Standardized Hook " cPanel & WHM Developer Portal One thing to keep in mind: Anytime you change contents within the describe() method, you need to re-register your hook.
    0
  • snewton
    I figured it out. For the additional hook for when accounts are modified, I needed to use "Accounts::change_package" for the event and then update the code to: my $plan = $data->{'new_pkg'};
    Both create and modify work as intended, but I do see an error when an account is created and/or modified. This is the code I am currently using for when accounts are modified: #!/usr/local/cpanel/3rdparty/bin/perl package ResellerLimitsModify; use strict; use warnings; sub describe { my $hook = { 'category' => 'Whostmgr', 'event' => 'Accounts::change_package', 'stage' => 'post', 'hook' => 'ResellerLimitsModify::actions', 'exectype' => 'module', }; return $hook; } sub actions { my ( $context, $data ) = @_; my $user = $data->{'user'}; my $plan = $data->{'new_pkg'}; if ( $plan eq 'Reseller Plan 1' ) { system`lvectl set-reseller $user --speed='100%' --pmem=3G --nproc=200 --maxEntryProcs=100 --iops=5024 --io=102400`; } elsif ( $plan eq 'Reseller Plan 2' ) { system`lvectl set-reseller $user --speed='150%' --pmem=5G --nproc=200 --maxEntryProcs=150 --iops=7024 --io=256000`; } elsif ( $plan eq 'Reseller Plan 3' ) { system`lvectl set-reseller $user --speed='200%' --pmem=6G --nproc=275 --maxEntryProcs=250 --iops=10024 --io=358400`; } elsif ( $plan eq 'Reseller Plan 4 ' ) { system`lvectl set-reseller $user --speed='250%' --pmem=4G --nproc=300 --maxEntryProcs=200 --iops=10024 --io=204800`; } elsif ( $plan eq 'Reseller Plan 5' ) { system`lvectl set-reseller $user --speed='450% --pmem=6G --nproc=425 --maxEntryProcs=400 --iops=20024 --io=460800`; } elsif ( $plan eq 'Reseller Plan 6') { system`lvectl set-reseller $user --speed='550%' --pmem=8G --nproc=625 --maxEntryProcs=600 --iops=25024 --io=614400`; } else { # Do nothing } } 1;
    The above code works but during account modification, it gives the error: A warning occurred while processing this directive. With the following error output: Can't exec "": No such file or directory at /usr/local/cpanel/ResellerLimitsModify.pm line 34. at /usr/local/cpanel/ResellerLimitsModify.pm line 25.
    Line 34 is: system`lvectl set-reseller $user --speed="450%" --pmem=6G --nproc=425 --maxEntryProcs=400 --iops=20024 --io=460800`;
    It doesn't matter which package I change to, the error output line is whichever I choose. The code from that line runs successfully though and I can't understand what could be causing the error: Can't exec ""
    0
  • newjustice
    The code from that line runs successfully though and I can't understand what could be causing the error: Can't exec ""

    Hi, Have you found a solution for the Can't exec error? I created a hook with the example provided by @cPanelTJ and I get the can't exec error for the file /usr/local/cpanel/test.txt, and the file exists and the output from the hook is executed. [CODE=perl]#!/usr/local/cpanel/3rdparty/bin/perl package PMGAddDomAndTransport; use strict; use warnings; sub describe { my $hook = { 'category' => 'Whostmgr', 'event' => 'Accounts::Create', 'stage' => 'post', 'hook' => 'PMGAddDomAndTransport::actions', 'exectype' => 'module', }; return $hook; } sub actions { my ( $context, $data ) = @_; my $user = $data->{'user'}; my $plan = $data->{'plan'}; my $domain = $data->{'domain'}; if ( $plan eq 'Package with Spaces' ) { system`echo "FROM ULC Test succeeded for User: $user and domain: $domain" >> /usr/local/cpanel/test.txt`; } else { system`echo "Test failed FROM ULC $domain" >> /usr/local/cpanel/test.txt`; } } 1;
    [2021-11-18 21:42:48 +0200] warn [Internal Warning while parsing [stdin] 20353] Can't exec "": No such file or directory at /var/cpanel/perl5/lib/PMGAddDomAndTransport.pm line 29. at /var/cpanel/perl5/lib/PMGAddDomAndTransport.pm line 29. PMGAddDomAndTransport::actions(HASH(0x58fe688), HASH(0x1ed0360)) called at /usr/local/cpanel/Cpanel/Hooks.pm line 536 eval {...} called at /usr/local/cpanel/Cpanel/Hooks.pm line 534 Cpanel::Hooks::_exec_module("main", HASH(0x5289a48), HASH(0x58fe688), HASH(0x1ed0360)) called at /usr/local/cpanel/Cpanel/Hooks.pm line 354 Cpanel::Hooks::_exec_hook("main", HASH(0x5289a48), HASH(0x58fe688), HASH(0x1ed0360)) called at /usr/local/cpanel/Cpanel/Hooks.pm line 273 eval {...} called at /usr/local/cpanel/Cpanel/Hooks.pm line 268 Cpanel::Hooks::hook(HASH(0x58fe688), HASH(0x1ed0360)) called at /usr/local/cpanel/Whostmgr/Accounts/Create.pm line 2743 Whostmgr::Accounts::Create::_execute_post_creation_hooks(HASH(0x4586458), HASH(0x1ed0360)) called at /usr/local/cpanel/Whostmgr/Accounts/Create.pm line 461 Whostmgr::Accounts::Create::_wwwacct(__CPANEL_HIDDEN__, 0, __CPANEL_HIDDEN__, undef, __CPANEL_HIDDEN__, __CPANEL_HIDDEN__, __CPANEL_HIDDEN__, __CPANEL_HIDDEN__, ...) called at /usr/local/cpanel/Whostmgr/Accounts/Create.pm line 3336 Whostmgr::Accounts::Create::__createaccount(__CPANEL_HIDDEN__, __CPANEL_HIDDEN__, __CPANEL_HIDDEN__, __CPANEL_HIDDEN__, __CPANEL_HIDDEN__, 0, __CPANEL_HIDDEN__, __CPANEL_HIDDEN__, ...) called at /usr/local/cpanel/Whostmgr/Accounts/Create.pm line 3471 Whostmgr::Accounts::Create::_createaccount(__CPANEL_HIDDEN__, __CPANEL_HIDDEN__, __CPANEL_HIDDEN__, __CPANEL_HIDDEN__, __CPANEL_HIDDEN__, 0, __CPANEL_HIDDEN__, __CPANEL_HIDDEN__, ...) called at whostmgr/bin/whostmgr5.pl line 791 main::wwwacct("wwwacct") called at /usr/local/cpanel/Whostmgr/Dispatch.pm line 366 Whostmgr::Dispatch::_do_call("wwwacct", HASH(0x3d6ea90), HASH(0x3d72b48)) called at /usr/local/cpanel/Whostmgr/Dispatch.pm line 178 Whostmgr::Dispatch::dispatch("wwwacct", 1, ARRAY(0x3d44998), HASH(0x3d72b48)) called at whostmgr/bin/whostmgr5.pl line 264
    Thanks.
    0

Please sign in to leave a comment.