Hook to prevent external email forward
Hello!
I am not a developer but I understand that this is related to this topic. On my old servers with cPanel 110 I used this hook to prevent my clients from forwarding emails to gmail, hotmail, etc.
Disable email forwarding to external domains in cPanel · GitHub
Now with cPanel 120 I can no longer add the hook with
/usr/local/cpanel/bin/manage_hooks add script /usr/local/src/coursevector/disable_email_forward_hook.php
The server answers me the following:
[root@server coursevector]# /usr/local/cpanel/bin/manage_hooks add script /usr/local/src/coursevector/disable_email_forward_hook.php
The script, when executed with --describe printed data via STDERR: Error in argument 3, char 3: no argument for option dHook failed to return proper JSON data
WARNING: Does not "describe" pattern found in script. It is HIGHLY recommended to pass the "--manual" when providing hook descriptors on the command line.
The "add" management action requires that a module or script name is specified example:
bin/manage_hooks add module My::ModuleOptions can also be manually specified using the following params --category, --event and --stage are defined, example:
bin/manage_hooks add script /var/MyApp/hooks/something.pl --category=Whostmgr --event=Accounts::Create --stage=preSee --help for more information
[root@server coursevector]#
Can you help me install this hook that worked very well?
Thanks!
-
You should not have ever seen success via just
/usr/local/cpanel/bin/manage_hooks add script /usr/local/src/coursevector/disable_email_forward_hook.php
as that does not specify any arguments regarding what it is supposed to hook into. No changes occurred to v120 as well either which would have changed things in the manner you suggest they have changed. The help output was attempting to steer you in the right direction by saying:
Options can also be manually specified using the following params --category, --event and --stage are defined, example:
bin/manage_hooks add script /var/MyApp/hooks/something.pl --category=Whostmgr --event=Accounts::Create --stage=preIf it were a hook *module*, then the module code itself could specify this, but since it is a script, you will need to manually specify when the script hook fires via those arguments. Please take a look at the documentation for hookable actions as to what you'd actually want the values for these arguments to be: https://api.docs.cpanel.net/guides/guide-to-standardized-hooks/guide-to-standardized-hooks-hookable-events/
Hope this helps!
0 -
How strange, maybe I'm wrong with the versions. Maybe it's from long before 110? I have it on two old servers with cPanel 110 installed and I just installed it by following these instructions:
// Install
// cd /usr/local/src/coursevector;
// copy file to folder
// chown root:root /usr/local/src/coursevector/disable_email_forward_hook.php;
// chmod 755 /usr/local/src/coursevector/disable_email_forward_hook.php;
// /usr/local/cpanel/bin/manage_hooks add script /usr/local/src/coursevector/disable_email_forward_hook.php0 -
Looks like for some reason now is not taking the needed info from these lines
0 -
So then when you run that script (/usr/local/src/coursevector/disable_email_forward_hook.php), does it output JSON with a similar looking datastructure when passing it the --describe option? That'd be how the script has to be delivering this information to manage_hooks if it never needed to pass it in manually. Now that I look at what it is doing in that gist, that *appears* to be what it should be trying to do, and you did mark it executable with the chmod, so it should run. If it is throwing an exception or something maybe that could be the problem?
Going to look at this script in a few minutes, see if I can figure out what's going on with it
0 -
Hmm, looks like this should be what it's outputting:
~/hook.php --describe
[{"blocking":1,"category":"Cpanel","event":"Api2::Email::addforward","stage":"pre","hook":"\/usr\/local\/src\/coursevector\/disable_email_forward_hook.php --add_api2","exectype":"script"},{"blocking":1,"category":"Cpanel","event":"UAPI::Email::add_forwarder","stage":"pre","hook":"\/usr\/local\/src\/coursevector\/disable_email_forward_hook.php --add_uapi","exectype":"script"}]That all looks right in general.
That said, looking back at the error in your earlier post, I'm betting that won't be your result:
The script, when executed with --describe printed data via STDERR: Error in argument 3, char 3: no argument for option d
Do you get some strange error printed to STDERR when you run manually with --describe?
0 -
Things are becoming clearer. This happens on the old server when I try to run it.
[root@old coursevector]# /usr/local/src/coursevector/disable_email_forward_hook.php
0 coursevector/disable_email_forward_hook.php needs a valid switch
[root@old coursevector]# /usr/local/src/coursevector/disable_email_forward_hook.php --describe
[{"blocking":1,"category":"Cpanel","event":"Api2::Email::addforward","stage":"pre","hook":"\/usr\/local\/src\/coursevector\/disable_email_forward_hook.php --add_api2","exectype":"script"},{"blocking":1,"category":"Cpanel","event":"UAPI::Email::add_forwarder","stage":"pre","hook":"\/usr\/local\/src\/coursevector\/disable_email_forward_hook.php --add_uapi","exectype":"script"}]
And this on the new server
[root@new src]# /usr/local/src/coursevector/disable_email_forward_hook.php
Exception: Zend Extension "/usr/local/src/coursevector/disable_email_forward_hook.php" does not exist[root@new src]# /usr/local/src/coursevector/disable_email_forward_hook.php --describe
Error in argument 3, char 3: no argument for option d
Usage: php [options] [-f] <file> [--] [args...]
php [options] -r <code> [--] [args...]
php [options] [-B <begin_code>] -R <code> [-E <end_code>] [--] [args...]
php [options] [-B <begin_code>] -F <file> [-E <end_code>] [--] [args...]
php [options] -S <addr>:<port> [-t docroot] [router]
php [options] -- [args...]
php [options] -a-a Run as interactive shell (requires readline extension)
-c <path>|<file> Look for php.ini file in this directory
-n No configuration (ini) files will be used
-d foo[=bar] Define INI entry foo with value 'bar'
-e Generate extended information for debugger/profiler
-f <file> Parse and execute <file>.
-h This help
-i PHP informationetc...
0 -
If I call the script with "php" ahead, it shows results.
[root@new coursevector]# php ./disable_email_forward_hook.php --describe
[{"blocking":1,"category":"Cpanel","event":"Api2::Email::addforward","stage":"pre","hook":"\/usr\/local\/src\/coursevector\/disable_email_forward_hook.php --add_api2","exectype":"script"},{"blocking":1,"category":"Cpanel","event":"UAPI::Email::add_forwarder","stage":"pre","hook":"\/usr\/local\/src\/coursevector\/disable_email_forward_hook.php --add_uapi","exectype":"script"}]0 -
Well, you're not going to believe this. I found here about this zend and php problem
I had uploaded the file via FTP, so I deleted it and created it by copying and pasting into VI. Now go.
[root@new coursevector]# /usr/local/cpanel/bin/manage_hooks add script /usr/local/src/coursevector/disable_email_forward_hook.php --describe
Added hook for Cpanel::Api2::Email::addforward to hooks registry
Added hook for Cpanel::UAPI::Email::add_forwarder to hooks registry
SORRY!0 -
Sounds like maybe something is odd with the PHP version installed.
The script's shebang is currently
#!/usr/local/cpanel/3rdparty/bin/php -q
so it should be trying to use the PHP installed there (instead of the easyapache PHP). Perhaps running
/usr/local/cpanel/scripts/check_cpanel_packages --fix
will help?
You could also alter the shebang to use the PHP which the system is configured to use for now to work around it if you can't figure out what's going on with the cPanel installed PHP.
0 -
Hah, of course I see your post now, glad to see it was something simple!
1
Please sign in to leave a comment.
Comments
10 comments