first commit

This commit is contained in:
Roman Pyrih
2026-04-21 15:48:41 +02:00
commit 7483681901
10216 changed files with 3236626 additions and 0 deletions

View File

@@ -0,0 +1,87 @@
<?php
/**
* Standard: PSR-2
*
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
*
* @package SC\DUPX
*/
use Duplicator\Installer\Core\Security;
use Duplicator\Libs\Snap\FunctionalityCheck;
use Duplicator\Libs\Snap\SnapUtil;
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
/**
* In this class all the utility functions related to the wordpress configuration and the package are defined.
*/
class DUPX_Conf_Utils
{
/**
*
* @staticvar bool $present
* @return bool
*/
public static function isManualExtractFilePresent()
{
static $present = null;
if (is_null($present)) {
$present = file_exists(DUPX_Package::getManualExtractFile());
}
return $present;
}
/**
*
* @staticvar null|bool $enable
* @return bool
*/
public static function isShellZipAvailable()
{
static $enable = null;
if (is_null($enable)) {
$enable = DUPX_Server::get_unzip_filepath() != null;
}
return $enable;
}
/**
*
* @return bool
*/
public static function isPhpZipAvailable()
{
return SnapUtil::classExists(ZipArchive::class);
}
/**
*
* @staticvar bool $exists
* @return bool
*/
public static function archiveExists()
{
static $exists = null;
if (is_null($exists)) {
$exists = file_exists(Security::getInstance()->getArchivePath());
}
return $exists;
}
/**
* Get archive size
*
* @return int
*/
public static function archiveSize()
{
static $arcSize = null;
if (is_null($arcSize)) {
$archivePath = Security::getInstance()->getArchivePath();
$arcSize = file_exists($archivePath) ? (int) @filesize($archivePath) : 0;
}
return $arcSize;
}
}

View File

@@ -0,0 +1,128 @@
<?php
/**
* Class used to update and edit web server configuration files
* for both Apache and IIS files .htaccess and web.config
*
* Standard: PSR-2
*
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
*
* @package SC\DUPX\WPConfig
*/
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
use Duplicator\Installer\Core\Deploy\ServerConfigs;
use Duplicator\Installer\Core\Params\PrmMng;
use Duplicator\Installer\Utils\InstallerOrigFileMng;
use Duplicator\Installer\Utils\Log\Log;
use Duplicator\Libs\Snap\SnapIO;
use Duplicator\Libs\WpConfig\WPConfigTransformer;
class DUPX_WPConfig
{
const ADMIN_SERIALIZED_SECURITY_STRING = 'a:1:{s:13:"administrator";b:1;}';
const ADMIN_LEVEL = 10;
/**
* get wp-config default path (not relative to orig file manger)
*
* @return string
*/
public static function getWpConfigDeafultPath(): string
{
return PrmMng::getInstance()->getValue(PrmMng::PARAM_PATH_NEW) . '/wp-config.php';
}
/**
*
* @return bool|string false if fail
*/
public static function getWpConfigPath()
{
$origWpConfTarget = InstallerOrigFileMng::getInstance()->getEntryTargetPath(ServerConfigs::CONFIG_ORIG_FILE_WPCONFIG_ID, self::getWpConfigDeafultPath());
$origWpDir = SnapIO::safePath(dirname($origWpConfTarget));
if ($origWpDir === PrmMng::getInstance()->getValue(PrmMng::PARAM_PATH_NEW)) {
return $origWpConfTarget;
} else {
return PrmMng::getInstance()->getValue(PrmMng::PARAM_PATH_WP_CORE_NEW) . "/wp-config.php";
}
}
/**
*
*
* @return boolean|WPConfigTransformer
*/
public static function getLocalConfigTransformer()
{
static $confTransformer = null;
if (is_null($confTransformer)) {
try {
if (($wpConfigPath = ServerConfigs::getWpConfigLocalStoredPath()) === false) {
$wpConfigPath = DUPX_WPConfig::getWpConfigPath();
}
if (is_readable($wpConfigPath)) {
$confTransformer = new WPConfigTransformer($wpConfigPath);
} else {
$confTransformer = false;
}
} catch (Exception $e) {
$confTransformer = false;
}
}
return $confTransformer;
}
/**
*
* @param string $name constant name
* @param string $type constant | variable
* @param mixed $default default value
*
* @return mixed
*/
public static function getValueFromLocalWpConfig($name, $type = 'constant', $default = '')
{
if (($confTransformer = self::getLocalConfigTransformer()) !== false) {
return $confTransformer->exists($type, $name) ? $confTransformer->getValue($type, $name) : $default;
} else {
return null;
}
}
/**
* Check if the wp-config of the source site is valid.
*
* @return bool true on success, false on failure
*/
public static function isSourceWpConfigValid()
{
static $wpConfigValid = null;
if (is_null($wpConfigValid)) {
try {
if (($wpConfigPath = ServerConfigs::getSourceWpConfigPath()) == false) {
throw new Exception('Source wp-config.php don\'t exists');
}
$configTransformer = new WPConfigTransformer($wpConfigPath);
$requiredConst = [
'DB_NAME',
'DB_USER',
'DB_PASSWORD',
'DB_HOST',
];
foreach ($requiredConst as $constName) {
if (!$configTransformer->exists('constant', $constName)) {
throw new Exception($constName . ' don\'t exist');
}
}
$wpConfigValid = true;
} catch (Exception | Error $e) {
Log::info('CHECK WP CONFIG FAIL msg: ' . $e->getMessage());
$wpConfigValid = false;
}
}
return $wpConfigValid;
}
}

View File

@@ -0,0 +1,88 @@
<?php
/**
* Class used to group all global constants
*
* Standard: PSR-2
*
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
*
* @package SC\DUPX\Constants
*/
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
use Duplicator\Installer\Utils\InstDescMng;
use Duplicator\Libs\Shell\Shell;
class DUPX_Constants
{
const CHUNK_EXTRACTION_TIMEOUT_TIME_ZIP = 5;
const CHUNK_EXTRACTION_TIMEOUT_TIME_DUP = 5;
const CHUNK_DBINSTALL_TIMEOUT_TIME = 5;
const CHUNK_MAX_TIMEOUT_TIME = 5;
const DEFAULT_MAX_STRLEN_SERIALIZED_CHECK_IN_M = 4; // 0 no limit
const DUP_SITE_URL = 'https://duplicator.com/';
const FAQ_URL = 'https://duplicator.com/knowledge-base/';
const MIN_NEW_PASSWORD_LEN = 6;
const BACKUP_RENAME_PREFIX = 'dp___bk_';
const DEBUG_MODE = false;
/**
* Init method used to auto initialize the global params
* This function init all params before read from request
*
* @return void
*/
public static function init(): void
{
//DATABASE SETUP: all time in seconds
//max_allowed_packet: max value 1073741824 (1268MB) see my.ini
$GLOBALS['DB_MAX_TIME'] = 5000;
$GLOBALS['DATABASE_PAGE_SIZE'] = 3500;
$GLOBALS['DB_MAX_PACKETS'] = 268435456;
$GLOBALS['DBCHARSET_DEFAULT'] = 'utf8';
$GLOBALS['DBCOLLATE_DEFAULT'] = 'utf8_general_ci';
$GLOBALS['DB_RENAME_PREFIX'] = self::BACKUP_RENAME_PREFIX . date("dHi") . '_';
$GLOBALS['DB_INSTALL_MULTI_THREADED_MAX_RETRIES'] = 3;
if (!defined('MAX_SITES_TO_DEFAULT_ENABLE_CORSS_SEARCH')) {
define('MAX_SITES_TO_DEFAULT_ENABLE_CORSS_SEARCH', 10);
}
//GLOBALS
$GLOBALS["NOTICES_FILE_PATH"] = DUPX_INIT . '/' . InstDescMng::getInstance()->getName(InstDescMng::TYPE_INST_NOTICES);
$GLOBALS["CHUNK_DATA_FILE_PATH"] = DUPX_INIT . '/' . InstDescMng::getInstance()->getName(InstDescMng::TYPE_INST_CHUNK_DATA);
$GLOBALS['PHP_MEMORY_LIMIT'] = ini_get('memory_limit') === false ? 'n/a' : ini_get('memory_limit');
$GLOBALS['PHP_SUHOSIN_ON'] = Shell::isSuhosinEnabled() ? 'enabled' : 'disabled';
$GLOBALS['DISPLAY_MAX_OBJECTS_FAILED_TO_SET_PERM'] = 5;
// Displaying notice for slow zip chunk extraction
$GLOBALS['ZIP_ARC_CHUNK_EXTRACT_DISP_NOTICE_AFTER'] = 5 * 60 * 60; // 5 minutes
$GLOBALS['ZIP_ARC_CHUNK_EXTRACT_DISP_NOTICE_MIN_EXPECTED_EXTRACT_TIME'] = 10 * 60 * 60; // 10 minutes
$GLOBALS['ZIP_ARC_CHUNK_EXTRACT_DISP_NEXT_NOTICE_INTERVAL'] = 5 * 60 * 60; // 5 minutes
$additional_msg = ' for additional details <a href="' . self::FAQ_URL . 'how-to-handle-various-install-scenarios/" target="_blank">click here</a>.';
$GLOBALS['ZIP_ARC_CHUNK_EXTRACT_NOTICES'] = [
'This server looks to be under load or throttled, the extraction process may take some time',
'This host is currently experiencing very slow I/O. You can continue to wait or try a manual extraction.',
'This host I/O is currently having issues. It is recommended to try a manual extraction.',
];
foreach ($GLOBALS['ZIP_ARC_CHUNK_EXTRACT_NOTICES'] as $key => $val) {
$GLOBALS['ZIP_ARC_CHUNK_EXTRACT_NOTICES'][$key] = $val . $additional_msg;
}
$GLOBALS['FW_USECDN'] = false;
$GLOBALS['NOW_TIME'] = @date("His");
}
/**
* Is debug mode enabled
*
* @return bool
*/
public static function isDebugMode(): bool
{
return self::DEBUG_MODE;
}
}

View File

@@ -0,0 +1,3 @@
<?php
//silent