The Community Forums

Interact with an entire community of cPanel & WHM users.
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Obtain the domain name and the feature value in a WHM hook

Discussion in 'cPanel Developers' started by donda, Dec 18, 2012.

  1. donda

    donda Member

    Joined:
    Nov 23, 2012
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Hello

    There's a WHM hook here that fires on Accounts::change_package event, gets a new package name and cPanel account name and should do different stuff based on the account domain name and the 'my_custom_feature' value for the account (the one that's in the package feature list).
    The problem is to find here the domain name and the feature value. I failed to find a way to do it using API1 and API2. There's a way to do it in the external API, but it seems to be an overkill to call the external api from inside the application, and the authentication would be a problem as well. Currently the domain name is found as follows:

    my $mainDomain = Cpanel::AcctUtils::Domain::getdomain($data->{'user'});

    But it's not from specs and there's no(?) guarantee it'll stay in future cPanel releases. Besides, finding the feature value is still a question.
    Sorry if it's too obvious and thanks in advance.
     
  2. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Technically speaking, you could use the external api without much fuss. The key is to use Cpanel::PublicAPI as your client and to have an access hash for the root user. The hook point will be executed as root, so if your StdHook is a Perl module then it's really easy to just spawn the client which will handle the magic: The module is already available in @INC for use, and if you do not provide any additional constructor arguments, it will fallback to using 127.0.0.1 & the .accesshash of the user that has instantiated the object (aka, root).

    Getting the feature item value from the user perspective is much more complicated since features are applied/merged from multiple sources which include the reseller chain of inheritance as well as the user's config file. You *might* be able to create an API1 'if' or 'hasfeature' call to send through the external API, but I would be surprised to see it work...those API1 calls are designed for flow control within a cPanel theme/branding page or LiveAPI interface page and likely aren't exposed outside a cpanel runtime rendering process.

    I think there might be a request for and external API call specifically to fetch feature values from a user perspective. If not, there probably should be one. You might want to follow up on that at cPanel Feature Requests

    Regards,
    -DavidN
     
  3. donda

    donda Member

    Joined:
    Nov 23, 2012
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Thank you for the answer. Yes, external api seems to be usable here, and the domain name can be easily found. :) But as for features, the set of available actions is next to empty. It should be possible to check the feature value for a user or get the list of enabled features in a feature list - that's to start with. And it would be nice to have a way to edit feature lists, but that's of lower priority. Unfortunately i cann't see anything on the matter at cPanel Feature Requests. Have i missed it or am i the first one who needs it, i wonder? :)
     
Loading...

Share This Page