I am trying to write a hook that changes the Mail Exchange to "Auto" after account creation as this is something Cpanel still hasn't given us the ability to do as standard from what I can tell.
I have written this:
I receive the following error.
[2021-05-12 12:29:19 +0200] warn [whostmgr5] Can't call method "uapi" on an undefined value at /usr/local/cpanel/mxauto.pm line 56.
at /usr/local/cpanel/Cpanel/Hooks.pm line 545.
This is driving me nuts. I can find one other thread on the forum here specifically for Cpanel::LiveAPI and the same issue, but that was only resolved when the user abandoned this approach and used other methods apart from LiveAPI in hooks.
Running this in shell works fine:
I have written this:
Code:
#!/usr/bin/perl
# Package this module.
package mxauto;
# Return errors if Perl experiences problems.
use strict;
use warnings;
# Use cPanel's error logging module.
use Cpanel::Logger;
# Use the core Perl module with file-copying functionality.
use Cpanel::LiveAPI ();
# Properly decode JSON.
use JSON;
# Instantiate the cPanel logging object.
my $logger = Cpanel::Logger->new();
# Embed hook attributes alongside the action code.
sub describe {
my $hooks = [
{
'category' => 'Whostmgr',
'event' => 'Accounts::Create',
'stage' => 'post',
'hook' => 'mxauto::setmxauto',
'exectype' => 'module',
}
];
return $hooks;
}
# Set the file names.
sub _more_logging {
my ( $context, $data ) = @_;
my $pretty_json = JSON->new->pretty;
}
sub setmxauto {
# Get the data that the system passes to the hook.
my ( $context, $data ) = @_;
# Add a log entry for debugging.
$logger->info("*** Dumping relevant data $data->{user} $data->{domain} ***");
#Set Mail Exchanger to AUTO
my $cpliveapi = Cpanel::LiveAPI->new(); # Connect to cPanel - only do this once.
# Set example.com's mail exchanger type.
my $set_mx_type = $cpliveapi->uapi(
'Email', 'set_always_accept',
{
'domain' => 'tullball.no',
'mxcheck' => 'auto',
'alwaysaccept' => '1',
}
); $logger->info("*** MX for {domain} set to AUTO. ***");
};
1;
[2021-05-12 12:29:19 +0200] warn [whostmgr5] Can't call method "uapi" on an undefined value at /usr/local/cpanel/mxauto.pm line 56.
at /usr/local/cpanel/Cpanel/Hooks.pm line 545.
This is driving me nuts. I can find one other thread on the forum here specifically for Cpanel::LiveAPI and the same issue, but that was only resolved when the user abandoned this approach and used other methods apart from LiveAPI in hooks.
Running this in shell works fine:
Code:
uapi --user=tulluser Email set_always_accept domain=tullball.no mxcheck=auto
Last edited by a moderator: