Duplicator - Bootloader |
version: |
hasZipArchive = class_exists('ZipArchive');
$this->hasShellExecUnzip = $this->getUnzipFilePath() != null ? true : false;
$this->installerContentsPath = str_replace("\\", '/', (dirname(__FILE__). '/' .self::INSTALLER_DIR_NAME));
$this->installerExtractPath = str_replace("\\", '/', (dirname(__FILE__)));
$this->archiveExpectedSize = strlen(self::ARCHIVE_SIZE) ? self::ARCHIVE_SIZE : 0 ;
$this->archiveActualSize = $archiveActualSize;
if($this->archiveExpectedSize > 0) {
$this->archiveRatio = (((1.0) * $this->archiveActualSize) / $this->archiveExpectedSize) * 100;
} else {
$this->archiveRatio = 100;
}
$this->overwriteMode = (isset($_GET['mode']) && ($_GET['mode'] == 'overwrite'));
}
/**
* Run the bootstrap process which includes checking for requirements and running
* the extraction process
*
* @return null | string Returns null if the run was successful otherwise an error message
*/
public function run()
{
date_default_timezone_set('UTC'); // Some machines don't have this set so just do it here
self::log('==DUPLICATOR INSTALLER BOOTSTRAP v1.4.4==');
self::log('----------------------------------------------------');
self::log('Installer bootstrap start');
$archive_filepath = $this->getArchiveFilePath();
$archive_filename = self::ARCHIVE_FILENAME;
$error = null;
$is_installer_file_valid = true;
if (preg_match('/_([a-z0-9]{7})[a-z0-9]+_[0-9]{6}([0-9]{8})_archive.(?:zip|daf)$/', $archive_filename, $matches)) {
$expected_package_hash = $matches[1].'-'.$matches[2];
if (self::PACKAGE_HASH != $expected_package_hash) {
$is_installer_file_valid = false;
self::log("[ERROR] Installer and archive mismatch detected.");
}
} else {
self::log("[ERROR] Invalid archive file name.");
$is_installer_file_valid = false;
}
if (false === $is_installer_file_valid) {
$error = "Installer and archive mismatch detected.
Ensure uncorrupted installer and matching archive are present.";
return $error;
}
$extract_installer = true;
$installer_directory = dirname(__FILE__).'/'.self::INSTALLER_DIR_NAME;
$extract_success = false;
$archiveExpectedEasy = $this->readableByteSize($this->archiveExpectedSize);
$archiveActualEasy = $this->readableByteSize($this->archiveActualSize);
//$archive_extension = strtolower(pathinfo($archive_filepath)['extension']);
$archive_extension = strtolower(pathinfo($archive_filepath, PATHINFO_EXTENSION));
$manual_extract_found = (
file_exists($installer_directory."/main.installer.php")
&&
file_exists($installer_directory."/dup-archive__".self::PACKAGE_HASH.".txt")
&&
file_exists($installer_directory."/dup-database__".self::PACKAGE_HASH.".sql")
);
$isZip = ($archive_extension == 'zip');
//MANUAL EXTRACTION NOT FOUND
if (! $manual_extract_found) {
//MISSING ARCHIVE FILE
if (! file_exists($archive_filepath)) {
self::log("[ERROR] Archive file not found!");
$error = ""
. "Archive not found! The required archive file must be present in the 'Extraction Path' below. When the archive file name was created "
. "it was given a secure hashed file name. This file name must be the exact same name as when it was created character for character. "
. "Each archive file has a unique installer associated with it and must be used together. See the list below for more options:
"
. "
'.htmlspecialchars($log_message).''); break; case E_NOTICE : case E_WARNING : default : $log_message = self::getMessage($errno, $errstr, $errfile, $errline); DUPX_Bootstrap::log($log_message); break; } } private static function getMessage($errno, $errstr, $errfile, $errline) { $result = '[PHP ERR]'; switch ($errno) { case E_ERROR : $result .= '[FATAL]'; break; case E_WARNING : $result .= '[WARN]'; break; case E_NOTICE : $result .= '[NOTICE]'; break; default : $result .= '[ISSUE]'; break; } $result .= ' MSG:'; $result .= $errstr; $result .= ' [CODE:'.$errno.'|FILE:'.$errfile.'|LINE:'.$errline.']'; return $result; } /** * Shutdown handler * * @return void */ public static function shutdown() { if (($error = error_get_last())) { DUPX_Handler::error($error['type'], $error['message'], $error['file'], $error['line']); } } } class DUPX_CSRF { /** * Session var name prefix * @var string */ public static $prefix = '_DUPX_CSRF'; /** * Stores all CSRF values: Key as CSRF name and Val as CRF value * @var array */ private static $CSRFVars; /** * Set new CSRF * * @param $key string CSRF Key * @param $key string CSRF Val * * @return Void */ public static function setKeyVal($key, $val) { $CSRFVars = self::getCSRFVars(); $CSRFVars[$key] = $val; self::saveCSRFVars($CSRFVars); self::$CSRFVars = false; } /** * Get CSRF value by passing CSRF key * * @param $key string CSRF key * * @return string|boolean If CSRF value set for give n Key, It returns CRF value otherise returns false */ public static function getVal($key) { $CSRFVars = self::getCSRFVars(); if (isset($CSRFVars[$key])) { return $CSRFVars[$key]; } else { return false; } } /** Generate DUPX_CSRF value for form * * @param string $form - Form name as session key * @return string - token */ public static function generate($form = NULL) { $keyName = self::getKeyName($form); $existingToken = self::getVal($keyName); if (false !== $existingToken) { $token = $existingToken; } else { $token = DUPX_CSRF::token() . DUPX_CSRF::fingerprint(); } self::setKeyVal($keyName, $token); return $token; } /** * Check DUPX_CSRF value of form * * @param string $token - Token * @param string $form - Form name as session key * @return boolean */ public static function check($token, $form = NULL) { $keyName = self::getKeyName($form); $CSRFVars = self::getCSRFVars(); if (isset($CSRFVars[$keyName]) && $CSRFVars[$keyName] == $token) { // token OK return true; } return FALSE; } /** Generate token * @param void * @return string */ protected static function token() { mt_srand((double) microtime() * 10000); $charid = strtoupper(md5(uniqid(rand(), TRUE))); return substr($charid, 0, 8) . substr($charid, 8, 4) . substr($charid, 12, 4) . substr($charid, 16, 4) . substr($charid, 20, 12); } /** Returns "digital fingerprint" of user * @param void * @return string - MD5 hashed data */ protected static function fingerprint() { return strtoupper(md5(implode('|', array($_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_USER_AGENT'])))); } /** * Generate CSRF Key name * * @param string the form name for which CSRF key need to generate * @return string CSRF key */ private static function getKeyName($form) { return DUPX_CSRF::$prefix . '_' . $form; } /** * Get Package hash * * @return string Package hash */ private static function getPackageHash() { if (class_exists('DUPX_Bootstrap')) { return DUPX_Bootstrap::PACKAGE_HASH; } else { return $GLOBALS['DUPX_AC']->package_hash; } } /** * Get file path where CSRF tokens are stored in JSON encoded format * * @return string file path where CSRF token stored */ private static function getFilePath() { if (class_exists('DUPX_Bootstrap')) { $dupInstallerfolderPath = dirname(__FILE__).'/dup-installer/'; } else { $dupInstallerfolderPath = $GLOBALS['DUPX_INIT'].'/'; } $packageHash = self::getPackageHash(); $fileName = 'dup-installer-csrf__'.$packageHash.'.txt'; $filePath = $dupInstallerfolderPath.$fileName; return $filePath; } /** * Get all CSRF vars in array format * * @return array Key as CSRF name and value as CSRF value */ private static function getCSRFVars() { if (!isset(self::$CSRFVars) || false === self::$CSRFVars) { $filePath = self::getFilePath(); if (file_exists($filePath)) { $contents = file_get_contents($filePath); if (!($contents = file_get_contents($filePath))) { throw new Exception('Fail to read the CSRF file.'); } if (empty($contents)) { self::$CSRFVars = array(); } else { $CSRFobjs = json_decode($contents); foreach ($CSRFobjs as $key => $value) { self::$CSRFVars[$key] = $value; } } } else { self::$CSRFVars = array(); } } return self::$CSRFVars; } /** * Stores all CSRF vars * * @param $CSRFVars array holds all CSRF key val * @return void */ private static function saveCSRFVars($CSRFVars) { $contents = json_encode($CSRFVars); $filePath = self::getFilePath(); if (!file_put_contents($filePath, $contents, LOCK_EX)) { throw new Exception('Fail to write the CSRF file.'); } } } try { $boot = new DUPX_Bootstrap(); $boot_error = $boot->run(); $auto_refresh = isset($_POST['auto-fresh']) ? true : false; if ($boot_error == null) { $step1_csrf_token = DUPX_CSRF::generate('step1'); DUPX_CSRF::setKeyVal('archive', $boot->archive); DUPX_CSRF::setKeyVal('bootloader', $boot->bootloader); DUPX_CSRF::setKeyVal('secondaryHash', DUPX_Bootstrap::SECONDARY_PACKAGE_HASH); DUPX_CSRF::setKeyVal('installerOrigCall', DUPX_Bootstrap::getCurrentUrl()); DUPX_CSRF::setKeyVal('installerOrigPath', __FILE__); DUPX_CSRF::setKeyVal('booturl', '//'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); DUPX_CSRF::setKeyVal('bootLogFile', DUPX_Bootstrap::getBootLogFilePath()); DUPX_CSRF::setKeyVal('package_hash', DUPX_Bootstrap::PACKAGE_HASH); } } catch (Exception $e) { $boot_error = $e->getMessage(); } ?>
Duplicator - Bootloader |
version: |