Skip to main content

Hook to prevent external email forward

Comments

10 comments

  • Andy Baugh cPanel Staff

    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=pre

    If 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
  • Benito

    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.php

     

    0
  • Benito

    Looks like for some reason now is not taking the needed info from these lines

    0
  • Andy Baugh cPanel Staff

    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
  • Andy Baugh cPanel Staff

    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
  • Benito

    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 information

    etc...

    0
  • Benito

    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
  • Benito

    Well, you're not going to believe this. I found here about this zend and php problem

    https://stackoverflow.com/questions/42615545/cant-execute-a-php-script-without-using-php-command-before

    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
  • Andy Baugh cPanel Staff

    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
  • Andy Baugh cPanel Staff

    Hah, of course I see your post now, glad to see it was something simple!

    1

Please sign in to leave a comment.