Files
SODEW/SODEW Instalátory/installer-int-salted/autoinstall-partials/functions.php
T
2026-08-18 10:33:14 +02:00

71 lines
2.5 KiB
PHP

<?php
// Funkce generuje náhodné heslo
function generateRandomString($minLength = 10, $maxLength = 20) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters); $length = rand($minLength, $maxLength);
$randomString = '';
for ($i = 0; $i < $length; $i++) $randomString .= $characters[rand(0, $charactersLength - 1)];
return $randomString;
}
// Funkce pro získání prefixu emailu
function getEmailPrefix($email) {
$atPos = strpos($email, '@');
return $atPos !== false ? substr($email, 0, $atPos) : '';
}
// Funkce maže soubory autoinstalátoru, přepisuje auto-installation.php na přesměrování
function delete_self($root_file, $full_login_url) {
$directory = dirname(__FILE__);
$files = glob($directory . '/*');
foreach ($files as $file) {
if (is_file($file) && basename($file) !== 'functions.php')
unlink($file);
}
$functions_file = $directory . '/functions.php';
if (file_exists($functions_file))
unlink($functions_file);
if (is_dir($directory))
rmdir($directory);
if (file_exists($root_file)) // unlink($kill_file);
file_put_contents($root_file, '<?php header("Location: '.$full_login_url.'"); ?>');
}
/**
* Nahradí výchozí AUTH/SECURE/LOGGED_IN/NONCE klíče a salty ve wp-config.php
* vlastními náhodnými hodnotami. Musí být volána PŘED require wp-load.php,
* jinak se PHP konstanty definují starými hodnotami a přihlašovací cookie
* po redirectu přestane sedět (uživatel by se odhlásil).
*/
function replace_wp_config_salts($config_path) {
if (!file_exists($config_path) || !is_writable($config_path))
return false;
$config_content = file_get_contents($config_path);
if ($config_content === false)
return false;
// Pokud config už neobsahuje placeholder frázi, nemá smysl nic dělat
if (strpos($config_content, 'put your unique phrase here') === false)
return true;
$keys = [
'AUTH_KEY', 'SECURE_AUTH_KEY', 'LOGGED_IN_KEY', 'NONCE_KEY',
'AUTH_SALT', 'SECURE_AUTH_SALT', 'LOGGED_IN_SALT', 'NONCE_SALT',
];
foreach ($keys as $key) {
$new_value = addslashes(base64_encode(random_bytes(48)));
$pattern = "/define\(\s*'" . preg_quote($key, '/') . "'\s*,\s*'(?:[^'\\\\]|\\\\.)*'\s*\);/";
$replacement = "define('" . $key . "', '" . $new_value . "');";
$config_content = preg_replace($pattern, $replacement, $config_content, 1);
}
return file_put_contents($config_path, $config_content) !== false;
}
?>