HEX
Server: LiteSpeed
System: Linux server801.shared.spaceship.host 4.18.0-553.54.1.lve.el8.x86_64 #1 SMP Wed Jun 4 13:01:13 UTC 2025 x86_64
User: yvigantdvn (2232)
PHP: 8.3.30
Disabled: NONE
Upload Files
File: //opt/hc_php/unversioned/SoftaculousEventsHandler.php
<?php

$publisher_library = '/opt/hc_php/unversioned/EventPublisher.php';
if (file_exists($publisher_library)) {
    include_once($publisher_library);
    define('HAS_EVENT_PUBLISHER', true);
}

function getSoftaculousInstallationDir($docroot, $path)
{
    // doctoot - "/home/moaddib"
    // path - "/home/moaddib/test1"
    $docrootSize = strlen($docroot);
    if ($path && substr($path, 0, $docrootSize) == $docroot) {
        // Remove path prefix by len
        $path = substr($path, $docrootSize + 1); // 1 - remove ending `/`
    }
    // return string
    return $path ? $path : "";
}

function _sendEvent($payload, $eventName) {
    if (defined('HAS_EVENT_PUBLISHER')) {
        try {
            $publisher = new HcEventPublisher\EventPublisher();
            return $publisher->send($payload);
        } catch (Exception $e) {
            error_log("EventPublisher Error [$eventName]: " . $e->getMessage());
        }
    } else {
        return true;
    }
}

function softaculousWebsiteDeleted($instalation)
{
    global $softpanel;
    $data = $instalation[0];
    $domain = $data['softdomain'];
    $payload = [
        'metadata' => [
            'entityId' => $data['insid'],
            'entityName' => 'website',
            'eventName' => 'softaculousWebsiteDeleted'
        ],
        'payload' => [
            'path' => getSoftaculousInstallationDir($softpanel->domainroots[$domain], $data['softpath']),
            'url' => $data['softurl'],
            'domain' => $domain,
            'db' => isset($data['softdb']) ? $data['softdb'] : "",
            'dbUser' => isset($data['softdbuser']) ? $data['softdbuser'] : "",
            'user' => $softpanel->user['name']
        ]
    ];

    return _sendEvent($payload, 'softaculousWebsiteDeleted');
}

function softaculousWebsiteCreated($instalation)
{
    global $softpanel;
    global $__settings;

    $data = $instalation[0];
    $domain = $data['softdomain'];

    $payload = [
        'metadata' => [
            'entityId' => $data['insid'],
            'entityName' => 'website',
            'eventName' => 'softaculousWebsiteCreated',
        ],
        'payload' => [
            'path' => getSoftaculousInstallationDir($softpanel->domainroots[$domain], $data['softpath']),
            'url' => $data['softurl'],
            'domain' => $data['softdomain'],
            'db' => isset($data['softdb']) ? $data['softdb'] : "",
            'dbUser' => isset($data['softdbuser']) ? $data['softdbuser'] : "",
            'user' => $softpanel->user['name'],
            'admin_email' => $data["admin_email"],
            'version' => $data['ver'],
            'cms' => (int) $data['sid'],
            'site_name' => $data['site_name'],
            'auto_upgrade_plugins' => (bool) $data['auto_upgrade_plugins'],
            'auto_upgrade_themes' => (bool) $data['auto_upgrade_themes'],
            'disable_notify_update' => (int) $data['disable_notify_update'],
            'core_auto_upgrade' => (int) $data['eu_auto_upgrade']
        ]
    ];

    return _sendEvent($payload, 'softaculousWebsiteCreated');
}

function softaculousWebsiteDiscovered($installation)
{
    global $softpanel;
    global $__settings;

    $domain = $installation['softdomain'];

    $payload = [
        'metadata' => [
            'entityId' => '_',  //there is no id here yet, but the protocol provides this field as required
            'entityName' => 'website',
            'eventName' => 'softaculousWebsiteDiscovered',
        ],
        'payload' => [
            'path' => getSoftaculousInstallationDir($softpanel->domainroots[$domain], $installation['softpath']),
            'url' => $installation['softurl'],
            'domain' => $domain,
            'db' => isset($installation['softdb']) ? $installation['softdb'] : "",
            'dbUser' => isset($installation['softdbuser']) ? $installation['softdbuser'] : "",
            'user' => $softpanel->user['name'],
            'version' => $installation['ver'],
            'cms' => (int) $installation['sid'],
            'siteName' => isset($installation['site_name']) ? $installation['site_name'] : ""
        ]
    ];

    return _sendEvent($payload, 'softaculousWebsiteDiscovered');
}

?>