kpmedia

Well-Known Member
Feb 13, 2011
87
1
58
USA, Europe
cPanel Access Level
Root Administrator
The following post explains how to block outgoing email to specific domain names:
That's not AT ALL the same thing.
Blocking all emails to Gmail is NOT the same as blocking forwards to Gmail.

This was the old code:
Code:
package Cpanel::CustomEventHandler;
use strict;
use Cpanel::Logger ();
sub event {
    my ( $apiv, $type, $module, $event, $cfgref, $dataref ) = @_;
    my $return = 1;
    if ( ($module eq 'email') && ($event eq 'addforward') ) {
        my($localpart, $domain) = split(/@/, $cfgref->{'fwdemail'});
        if (-f "/etc/forwarder_blocked_domains.txt") {
            open(BLOCK, "</etc/forwarder_blocked_domains.txt");
            while (<BLOCK>) {
                chomp($_);
                if ($_ eq $domain) {
                    $return = 0;
                }
            }
            close(BLOCK);
        }
    }
    return $return;
}
1;
I was able to use it, but I don't 100% fully comprehend what it was doing. Telling me to recode it is like telling me to build a car from scratch. I use cars, I buy cars, I don't build cars.

So would somebody there at cPanel perhaps assist with re-writing it as a hook, since that's what it now needs? (since cPanel deprecated/killed it)

Thanks. :)
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,884
2,250
463
So would somebody there at cPanel perhaps assist with re-writing it as a hook, since that's what it now needs? (since cPanel deprecated/killed it)
Hello :)

While we are happy to point you in the right direction, our developers don't generally write custom scripts for these types of requests. Feature requests are the best way to see an actual option from cPanel. Here is an open feature request for this:

option to prevent forwarders to free email accounts

Here's the most recent staff comment:

While this does not mean that the feature request will not be considered, I do want to point out that this functionality is presently able to be leveraged through Custom Event Hooks.

Guide to Standardized Hooks - Custom Event Handlers - Software Development Kit - cPanel Documentation

You would be able to write a custom event handler for "Email::addforward" that errors and refuses to add forwarders that match certain text.

This does, of course, require some basic programming knowledge.
Thank you.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,884
2,250
463

brianoz

Well-Known Member
Mar 13, 2004
1,146
7
168
Melbourne, Australia
cPanel Access Level
Root Administrator
... Also, yes, as mentioned in my earlier post, hookable events should be used:

Guide to Standardized Hooks - Software Development Kit - cPanel Documentation
Michael, I may be missing something, but that guide doesn't appear to give a list of hookable events. I should be fine once I find that, are you able to help? I've spent some time reading it, and as an experienced programmer and admin I found it confusing.

Given that this is a relatively small hook application, perhaps it would be a good case for a simple example? Most of the code is published in the code fragment above anyway?
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,884
2,250
463
Michael, I may be missing something, but that guide doesn't appear to give a list of hookable events. I should be fine once I find that, are you able to help? I've spent some time reading it, and as an experienced programmer and admin I found it confusing.
Here's a specific URL:

Guide to Standardized Hooks - Cpanel Functions - Software Development Kit - cPanel Documentation

Per the document:

Cpanel events all use the API::Module::function naming format, where:

  • API is the API that calls the hook point.
    • Use Api1 for cPanel API 1 functions, Api2 for cPanel API 2 functions, or UAPI for UAPI functions.
    • This value is case-sensitive.
  • Module is the function's module name (for example, StatsBar).
  • function is the function name (for example, stat).
Here's a post that shows an example for a different function:

Force backup to run using new 11.38 system

Thank you.
 

kpmedia

Well-Known Member
Feb 13, 2011
87
1
58
USA, Europe
cPanel Access Level
Root Administrator
I still fail to understand why, if it's so damned easy, cPanel techs are are not actually helping with this. It's clearly confusing to non-cPanel developers. I have no idea WTF is going on in either the docs or the example, and I'm NOT a complete novice.

The fact that it takes 2 months to respond is ridiculous as well.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,884
2,250
463
Last edited: