File: //homepages/oneclick/WordPress/6.9/601/scripts/config/pre-configure.php
<?php
class PreConfigure
{
public function __construct($argv)
{
$uid = $argv[1];
$gid = $argv[2];
$ocuser = 'ocuser';
$ftpusers = $argv[2];
$webspace = $this->get('WEB___DIR');
try {
if ($this->managedMode()) {
// ensure UTECHAUFTRAG for 'wp-config.php'
$this->execShell("chown -R $uid:$gid $webspace/wp-config.php");
$this->execShells(array(
"chown -R $uid:$gid $webspace",
"find $webspace -type d -exec chmod 755 {} \\;",
"find $webspace -type f -exec chmod 644 {} \\;"
));
if (file_exists("$webspace/.htaccess")) {
copy("$webspace/.htaccess", "$webspace/.htaccess.ionos");
$this->execShell("chown $uid:$gid $webspace/.htaccess.ionos");
}
$wpContentFolders = array(
"plugins",
"mu-plugins",
"themes",
"uploads",
"upgrade",
"languages",
"ngg",
"gallery"
);
foreach ($wpContentFolders as $contentFolder) {
$folder = "$webspace/wp-content/$contentFolder";
if (is_dir($folder)) {
$this->execShell("chown -R $uid:$gid $folder");
}
}
}
exit(0);
} catch (Exception $e) {
echo $e;
exit(1);
}
}
protected function get($varname)
{
$value = getenv($varname);
if ($value === false) {
throw new Exception("Undefined variable: $varname");
}
return $value;
}
protected function managedMode()
{
// check if managedMode env var
if ($this->isManaged() || $this->isSafemode()) {
return true;
}
return false;
}
/**
* Check if installation is a Managed WordPress based on the env vars
*
* @return boolean
*/
protected function isManaged()
{
return filter_var($this->get('managedMode'), FILTER_VALIDATE_BOOLEAN);
}
/**
* Check if installation is a Safemode WordPress based on the installation folder
*
* @return boolean
*/
protected function isSafemode()
{
// check safemode installation
if ($this->get('WEB___DIR')) {
return
preg_match("/^app\d{5,15}$/", basename($this->get('WEB___DIR'))) ||
preg_match("/^trial\d{9,15}$/", basename($this->get('WEB___DIR')));
}
return false;
}
protected function execShell($command, &$print = true)
{
exec($command . ' 2>&1', $output, $return_var);
if ($return_var !== 0) {
print_r($output);
throw new Exception("Failed command: $command");
} else {
if (true === $print) {
for ($i = 0; $i < count($output); $i++) {
print("$output[$i]\n");
}
}
}
}
protected function execShells(array $commands)
{
foreach ($commands as $command) {
$this->execShell($command);
}
}
}