Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 15 of 16
  1. #1
    Member Kailash1's Avatar
    Join Date
    Nov 2006
    Location
    webhostingdiscussion.net
    Posts
    225
    cPanel/Enkompass Access Level

    Root Administrator

    Default block forwarding

    Hi,

    Is there a way I can setup global setting so that we can not set email forwarding to particular domain.

    For example, I do not want to allow email forwarder to @xyz.com from my server. Is it possible to block this for all the domains.

    Kailash

  2. #2
    Member
    Join Date
    Mar 2009
    Posts
    9

    Default

    Well, if you want to stop email forwarding an easy wey is to remove the email forwarding feature from your package feature list.

    In that case the user wont be able to access to that option in cpanel. Also remember to set :fail: in all domains at /etc/valiases

    Cheers!

    Be Hard!
    Optimization & Security Services for Cpanel

  3. #3
    Member Kailash1's Avatar
    Join Date
    Nov 2006
    Location
    webhostingdiscussion.net
    Posts
    225
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    I don't want to remove email forwarding feature. I just don't want to allow forwarding to few domains i.e. block email forwarding to AOL, Comcast accounts.

    Kailash

  4. #4
    Registered User
    Join Date
    Apr 2009
    Posts
    2

    Default anwser?

    Hi,

    Yes, I would like to know the answer me too!

  5. #5
    Technical Product Specialist cPanelDavidG's Avatar
    Join Date
    Nov 2006
    Location
    Houston, TX
    Posts
    11,189
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    Quote Originally Posted by Kailash1 View Post
    I don't want to remove email forwarding feature. I just don't want to allow forwarding to few domains i.e. block email forwarding to AOL, Comcast accounts.

    Kailash
    If you have a basic understanding of Perl, you can implement this at this time using Custom Event Handlers. This is different from the function hooks we talk about in that function hooks allow you to do additional things after an action has been performed. With Custom Event Handlers, you can create a "pre" handler that intercepts the call to Email::addforward and aborts it if certain conditions are met (e.g. the fwdemail parameter contains comcast.net).

    To implement a Custom Event Handler, create a new Perl Module called CustomEventHandler.pm in /usr/local/cpanel/Cpanel/ and create a subroutine called event in the module. You will also need to add this line of code to your event subroutine to pull in all the parameters being passed to it:

    Code:
    my ( $apiv, $type, $module, $event, $cfgref, $dataref ) = @_;
    As for what each of the parameters is:

    type is either pre or post. If the type is pre then that means this is before the event is happening. If the type is post, then the event has already happened

    module is the name of the module. This will be Cpanel:: followed by the module name from the API1 or API2 function being called. For example: Cpanel::Email

    event is the name of the function being called by API1 or API2. For example: addforward

    cfgref is a hash of the variables passed to the event. For example: $cfgref{'fwdemail'} would contain the email address to forward email to if email forwarding was the selected option.

    dataref is only used in post events. This simply contains the data returned from the event.


    Your event subroutine will be called every time an action is performed in the cPanel interface (both before and after). Actions are disallowed by returning false. Therefore, return true by default and only return false when you explicitly do not want something to happen. Otherwise, you may inadvertently disable all cPanel functionality.

    For example, you may want to have an if block where you see if the module is Cpanel::Email and the event is addforward and $cfgref{'fwdemail'} contains any of the domains you do not want mail forwarded to, and inside that block of code return false. If that if block is never executed, return true.

    Returning false on a pre event will prevent that event from happening. Returning false on a post event only prevents output from that event from being displayed.

    We plan to write up formal documentation on this. In the meantime, you can find some documentation in /usr/local/cpanel/hooks/README and the files it references. DO NOT EDIT EventHandler.pm! Instead, create your own CustomEventHandler.pm for your own event handling functions.

    I only recommend this if you are familiar with Perl as this can only be done in Perl. If you are not familiar with Perl, I recommend reading a book that can introduce you to the language so you become familiar with the syntax of Perl.

  6. #6
    Member Kailash1's Avatar
    Join Date
    Nov 2006
    Location
    webhostingdiscussion.net
    Posts
    225
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    Thanks David,

    I am not much familiar with Perl so I will not try this right now.

    Kailash

  7. #7
    Member
    Join Date
    Aug 2002
    Posts
    1,120

    Default

    A feature request for this has been logged in Bugzilla for a few years now:

    http://bugzilla.cpanel.net/show_bug.cgi?id=1525

  8. #8
    Member
    Join Date
    Aug 2002
    Posts
    1,120

    Default

    If you don't already have a CustomEventHandler.pm in /usr/local/cpanel/Cpanel try adding this attached file into that directory.

    Then create a file /etc/forwarder_blocked_domains.txt which contains the domain names of the forwarders you want to block from being created. One on each line.

    Example:
    Code:
    yahoo.com
    comcast.net
    Now when you try to create a forwarder that uses one of these domain names, you will get an error:

    The forwarder could not be added because the form was not complete or would create a mail loop.

    Not sure how to change that text, but it will prevent it from being created.

    I haven't really tested all of this, so use this at your own risk. If you have problems just delete the CustomEventHandler.pm file.

    Be sure that you place this file in the /usr/local/cpanel/Cpanel directory on your server. And be sure that you name the file CustomEventHandler.pm
    Attached Files

  9. #9
    Member sawbuck's Avatar
    Join Date
    Jan 2004
    Posts
    1,313
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    Nice work Sparek.

    Hopefully this will provide some momentum to be inlcuded in cPanel by default.

  10. #10
    Registered User
    Join Date
    Apr 2009
    Posts
    2

    Default wow!!

    Oh wow! Thank you for the script! I'm verry glad!

  11. #11
    Registered User
    Join Date
    Jan 2009
    Posts
    2

    Default

    Great scripts!!! btw, have any 1 tried this scripts? & is it working?

  12. #12
    Member sawbuck's Avatar
    Join Date
    Jan 2004
    Posts
    1,313
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    Quote Originally Posted by joehanz30 View Post
    is it working?
    It is for us.

  13. #13
    Member Kailash1's Avatar
    Join Date
    Nov 2006
    Location
    webhostingdiscussion.net
    Posts
    225
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    Quote Originally Posted by sparek-3 View Post
    If you don't already have a CustomEventHandler.pm in /usr/local/cpanel/Cpanel try adding this attached file into that directory.

    Then create a file /etc/forwarder_blocked_domains.txt which contains the domain names of the forwarders you want to block from being created. One on each line.

    Example:
    Code:
    yahoo.com
    comcast.net
    Now when you try to create a forwarder that uses one of these domain names, you will get an error:

    The forwarder could not be added because the form was not complete or would create a mail loop.

    Not sure how to change that text, but it will prevent it from being created.

    I haven't really tested all of this, so use this at your own risk. If you have problems just delete the CustomEventHandler.pm file.

    Be sure that you place this file in the /usr/local/cpanel/Cpanel directory on your server. And be sure that you name the file CustomEventHandler.pm
    Hi Sparek,

    Sorry for remain silent for few days. Thanks for the script.

    Kailash

  14. #14
    cPanel Partner NOC cPanel Partner NOC Badge
    Join Date
    Jun 2006
    Posts
    18

    Default

    Hi,

    Did any one got idea how to modify the error "
    The forwarder could not be added because the form was not complete or would create a mail loop."

    to other message such as forwarding to yahoo is not allowed, etc?

    Rgds
    Loh

  15. #15
    Member Janak's Avatar
    Join Date
    Jul 2009
    Posts
    71

    Default

    I think it is possible to modify message for Email Forwarding. There is similar kind of discussion in below thread

    Email forward creator script problem

    Janak

Similar Threads & Tags
Similar threads

  1. Email forwarding problem - Not forwarding emails
    By fattwam in forum E-mail Discussions
    Replies: 1
    Last Post: 08-19-2011, 05:10 PM
  2. IP Block
    By threeg in forum New User Questions
    Replies: 1
    Last Post: 08-01-2010, 04:11 AM
  3. How do I block an IP that has been
    By HiTechFX in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 03-17-2009, 04:39 AM
  4. email domain forwarding vs. email forwarding
    By johndoe in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 04-19-2007, 08:45 PM
  5. block IP
    By danielldf in forum cPanel and WHM Discussions
    Replies: 11
    Last Post: 07-30-2006, 06:47 AM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube