Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Custom Event Handler - prevent default behavior and replace Module output

Discussion in 'cPanel Developers' started by ruyrocha, Mar 20, 2012.

  1. ruyrocha

    ruyrocha Member

    Oct 12, 2010
    Likes Received:
    Trophy Points:

    I've setup two development servers (A and B) to separate a few services from main cPanel installation, like email and DNS. I'm able to create, remove and update email accounts transparently on box B from server A using, but cannot list those email accounts and get quota information. Let me show you:

    root@opsbox [/usr/local/cpanel/Cpanel]# cat
    package Cpanel::CustomEventHandler;
    # cpanel12 -                      Copyright(c) 2008 cPanel, Inc.
    #                                                           All rights Reserved.
    # This code is subject to the cPanel license. Unauthorized copying is prohibited
    use strict;
    use Cpanel::Logger ();
    use Cpanel::PublicAPI ();
    sub event {
      my ( $apiv, $type, $module, $event, $cfgref, $dataref ) = @_;
      return 1 if ( $module ne 'email' );
      if ($module eq 'email') {
        if ($event eq 'listpopswithdisk' && $type eq 'post') {
          my $user     = $Cpanel::user;
          my $domain   = $cfgref->{'domain'};
          # get remote domain mailboxes
          if ( $domain eq '' ) {
    	my $pubapi = Cpanel::PublicAPI->new('user' => 'root', 'pass' => 'superpassword', 'host' => 'x.x.x.x');
    	my $emails = $pubapi->cpanel_api2_request(
    	  { 'module' => 'Email',
    	    'func'   => 'listpopswithdisk',
    	    'user'   => $user,
      return 1;
    This piece of code is incomplete, but do you have any ideas how to properly get Email::listpopswithdisk from server B and show it on server A?

    Ruy Rocha
  2. KostonConsulting

    KostonConsulting Well-Known Member

    Jun 17, 2010
    Likes Received:
    Trophy Points:
    San Francisco, CA
    cPanel Access Level:
    Root Administrator
    Re: Custom Event Handler - prevent default behavior and replace Module outp

    I believe that having the module as 'email' rather than 'Email' is the cause for this not to execute. Try adding a line which checks the inputs to make sure:

    print STDERR "MODULE: $module EVENT: $event TYPE: $type";
    Other than that, your PublicAPI call seems ok. One other thing to note is that you should use the 'ip' parameter if you're using the IP of the remote server, rather than the hostname:

    my $pubapi = Cpanel::PublicAPI->new('user' => 'root', 'pass' => 'superpassword', 'ip' => 'x.x.x.x');

    You may wish to look at cPanel's Standardized Hooks System to capture Api2::Email::listpopswithdisk as there can only be one copy of while the standardized hooks system allows for as many hooks into each function as required (less chance you'll need to keep adding code to in the future or some third party program will overwrite it and remove your hook).
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice