2026-02-20 21:53:34 +03:00
|
|
|
<?php
|
|
|
|
|
|
2026-04-05 22:38:36 +03:00
|
|
|
/**
|
|
|
|
|
* DomainResolver — domain resolver
|
|
|
|
|
*
|
|
|
|
|
* @package XC_VM_Core_Config
|
|
|
|
|
* @author Divarion_D <https://github.com/Divarion-D>
|
|
|
|
|
* @copyright 2025-2026 Vateron Media
|
|
|
|
|
* @link https://github.com/Vateron-Media/XC_VM
|
|
|
|
|
* @license AGPL-3.0 https://www.gnu.org/licenses/agpl-3.0.html
|
|
|
|
|
*/
|
|
|
|
|
|
2026-02-20 21:53:34 +03:00
|
|
|
class DomainResolver {
|
2026-03-07 21:53:45 +03:00
|
|
|
public static function resolve($rServerID, $rForceSSL = false) {
|
2026-03-08 16:19:30 +03:00
|
|
|
global $rServers, $rSettings;
|
2026-02-20 21:53:34 +03:00
|
|
|
$rOriginatorID = null;
|
|
|
|
|
if ($rForceSSL) {
|
|
|
|
|
$rProtocol = 'https';
|
|
|
|
|
} else {
|
|
|
|
|
if (isset($_SERVER['SERVER_PORT']) && $rSettings['keep_protocol']) {
|
|
|
|
|
$rProtocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? 'https' : 'http');
|
|
|
|
|
} else {
|
|
|
|
|
$rProtocol = $rServers[$rServerID]['server_protocol'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$rProxied = $rServers[$rServerID]['enable_proxy'];
|
|
|
|
|
if ($rProxied) {
|
2026-03-07 21:53:45 +03:00
|
|
|
$rProxyIDs = array_keys(ConnectionTracker::getProxies($rServerID, true));
|
2026-02-20 21:53:34 +03:00
|
|
|
if (count($rProxyIDs) == 0) {
|
2026-03-07 21:53:45 +03:00
|
|
|
$rProxyIDs = array_keys(ConnectionTracker::getProxies($rServerID, false));
|
2026-02-20 21:53:34 +03:00
|
|
|
}
|
|
|
|
|
if (count($rProxyIDs) != 0) {
|
|
|
|
|
$rOriginatorID = $rServerID;
|
|
|
|
|
$rServerID = $rProxyIDs[array_rand($rProxyIDs)];
|
|
|
|
|
} else {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$rHost = ($_SERVER['HTTP_HOST'] ?? '');
|
|
|
|
|
if (strpos($rHost, ':') !== false) {
|
|
|
|
|
list($rDomain, $rAccessPort) = explode(':', $rHost, 2);
|
|
|
|
|
} else {
|
|
|
|
|
$rDomain = $rHost;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($rProxied || $rSettings['use_mdomain_in_lists'] == 1) {
|
2026-03-03 20:00:34 +03:00
|
|
|
$rResellerDomains = CacheReader::get('reseller_domains') ?: array();
|
2026-02-20 21:53:34 +03:00
|
|
|
if (!(strlen($rDomain) > 0 && in_array(strtolower($rDomain), $rResellerDomains))) {
|
|
|
|
|
if (empty($rServers[$rServerID]['domain_name'])) {
|
|
|
|
|
$rDomain = escapeshellcmd($rServers[$rServerID]['server_ip']);
|
|
|
|
|
} else {
|
|
|
|
|
$rDomain = str_replace(array('http://', '/', 'https://'), '', escapeshellcmd(explode(',', $rServers[$rServerID]['domain_name'])[0]));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (strlen($rDomain) == 0) {
|
|
|
|
|
if (empty($rServers[$rServerID]['domain_name'])) {
|
|
|
|
|
$rDomain = escapeshellcmd($rServers[$rServerID]['server_ip']);
|
|
|
|
|
} else {
|
|
|
|
|
$rDomain = str_replace(array('http://', '/', 'https://'), '', escapeshellcmd(explode(',', $rServers[$rServerID]['domain_name'])[0]));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$rServerURL = $rProtocol . '://' . $rDomain . ':' . $rServers[$rServerID][$rProtocol . '_broadcast_port'] . '/';
|
|
|
|
|
if ($rServers[$rServerID]['server_type'] == 1 && $rOriginatorID && $rServers[$rOriginatorID]['is_main'] == 0) {
|
|
|
|
|
$rServerURL .= md5($rServerID . '_' . $rOriginatorID . '_' . OPENSSL_EXTRA) . '/';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $rServerURL;
|
|
|
|
|
}
|
|
|
|
|
}
|