HEX
Server: Apache
System: Linux hz.vslconceptsdomains.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: dkfounda (3233)
PHP: 8.1.34
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/local/mailchannels/hooks/PostAddOnDomainAddAddOnDomain.php
<?php

namespace MailChannels;


class PostAddOnDomainAddAddOnDomain extends PostAccountsCreate {
    public function execute($hookData) {
        //'output' is an array; therefore, take the object at index 0 of 'output' to parse 'result' and 'reason'
        if (!isset($hookData['data']) || !isset($hookData['data']['output']) || !isset($hookData['data']['output'][0]['result']) || !isset($hookData['data']['output'][0]['reason'])) {
           return array(false, "missing result and / or reason parameter");
        } else if ($hookData['data']['output'][0]['result'] == 0) {
           return array(false, "cpanel api function addaddondomain failed, reason: {$hookData['data']['output'][0]['reason']}");
        } else if (!isset($hookData['data']['args']) || !isset($hookData['data']['args']['newdomain'])) {
            return array(false, "required element in parameters is not present ([data][args][newdomain])");
        }

        $domainName = $hookData['data']['args']['newdomain'];
        $result = true;
        $message = "";

        if ($this->inboundEnabled()) {
            $isAutoProtectionEnabled = $this->inboundConfig->isAutomaticDomainProtectionEnabled();
            $processParkedAndAddonDomains = $this->inboundConfig->processParkedAndAddonDomains();

            if ($isAutoProtectionEnabled && $processParkedAndAddonDomains) {
                try {
                    list($result, $message) = $this->inboundProvision($domainName);
                    $message .= ";";
                } catch (\Exception $e) {
                    $errorMessage = $e->getTraceAsString();
                    $message = "error provisioning addon domain $domainName: $errorMessage;";
                    $result = false;
                }
            }else{
                $strIsAutoProtectionEnabled = var_export($isAutoProtectionEnabled, true);
                $strProcessParkedAndAddonDomains = var_export($processParkedAndAddonDomains, true);
                $message = "action not taken, automaticDomainProtectionEnabled: $strIsAutoProtectionEnabled, processParkedAndAddonDomains: $strProcessParkedAndAddonDomains;";
            }
        } else {
            $message = "action not taken, inbound not enabled;";
        }

        if ($this->outboundEnabled() && $this->outboundConfig->autoUpdateSPFRecords()) {
            list($spfAdded, $spfMessage) = $this->addMCSPF($domainName);
            $result = $spfAdded ? $result : false;
            $message .= " " . $spfMessage . ";";
        } else {
            $isOutbound =  var_export($this->outboundEnabled(), true);
            $isOutboundAutoUpdateSPFRecordsOn = $this->outboundEnabled() ? var_export($this->outboundConfig->autoUpdateSPFRecords(), true) : "false";
            $message .= " not adding the mailchannels spf record for $domainName, outbound enabled: $isOutbound, autoUpdateSPFRecords: $isOutboundAutoUpdateSPFRecordsOn;";
        }

        return array($result, $message);
    }

    public static function category() {
        return 'Cpanel';
    }

    public static function event() {
        return 'Api2::AddonDomain::addaddondomain';
    }

    public static function stage() {
        return 'post';
    }

}