panelName = 'Plesk';
$this->defaultSvrCacheRoot = '/var/www/vhosts/lscache/';
parent::init2();
}
/**
* More reliable than php_uname('s')
*
* @return string
*
* @throws LSCMException Thrown when supported Plesk OS detection command
* fails.
* @throws LSCMException Thrown when supported OS is not detected.
*/
public function getPleskOS()
{
$supportedOsList = array(
'centos',
'virtuozzo',
'cloudlinux',
'redhat',
'rhel',
'ubuntu',
'debian',
'almalinux',
'rocky'
);
$cmds = array();
if ( file_exists('/etc/debian_version') ) {
return 'debian';
}
if ( is_readable('/etc/os-release') ) {
$cmds[] = 'grep ^ID= /etc/os-release | cut -d "=" -f2 | xargs';
}
if ( is_readable('/etc/lsb-release') ) {
$cmds[] =
'grep ^DISTRIB_ID= /etc/lsb-release | cut -d "=" -f2 | xargs';
}
if ( is_readable('/etc/redhat-release') ) {
$cmds[] = 'cat /etc/redhat-release | awk \'{print $1}\'';
}
foreach ( $cmds as $cmd ) {
if ( !($output = shell_exec($cmd)) ) {
throw new LSCMException(
'Supported Plesk OS detection command failed.',
LSCMException::E_UNSUPPORTED
);
}
$OS = trim($output);
foreach ( $supportedOsList as $supportedOs ) {
if ( stripos($OS, $supportedOs) !== false ) {
return $supportedOs;
}
}
}
throw new LSCMException(
'Plesk detected with unsupported OS. '
. '(Not CentOS/Virtuozzo/Cloudlinux/RedHat/Ubuntu/Debian/'
. 'AlmaLinux/Rocky)',
LSCMException::E_UNSUPPORTED
);
}
/**
*
* @since 1.13.3
*
* @return string
*/
protected function getVhDir()
{
$vhDir = '/var/www/vhosts';
$psaConfFile = '/etc/psa/psa.conf';
if ( file_exists($psaConfFile) ) {
$ret = preg_match(
'/HTTPD_VHOSTS_D\s+(\S+)/',
file_get_contents($psaConfFile),
$m
);
if ( $ret == 1 ) {
$vhDir = $m[1];
}
}
return $vhDir;
}
/**
*
* @throws LSCMException Thrown indirectly by $this->getPleskOS() call.
*/
protected function initConfPaths()
{
$OS = $this->getPleskOS();
switch ( $OS ) {
case 'centos':
case 'virtuozzo':
case 'cloudlinux':
case 'redhat':
case 'rhel':
case 'almalinux':
case 'rocky':
$this->apacheConf = '/etc/httpd/conf.d/lscache.conf';
break;
case 'ubuntu':
$this->apacheConf = '/etc/apache2/conf-enabled/lscache.conf';
break;
case 'debian':
if ( is_dir('/etc/apache2/conf-enabled') ) {
$this->apacheConf =
'/etc/apache2/conf-enabled/lscache.conf';
}
else {
/**
* Old location.
*/
$this->apacheConf = '/etc/apache2/conf.d/lscache.conf';
}
break;
//no default case
}
$this->apacheVHConf = '/usr/local/psa/admin/conf/templates'
. '/custom/domain/domainVirtualHost.php';
}
/**
*
* @return string
*/
protected function serverCacheRootSearch()
{
$apacheConfDir = dirname($this->apacheConf);
if ( file_exists($apacheConfDir) ) {
return $this->cacheRootSearch($apacheConfDir);
}
return '';
}
/**
*
* @return string
*/
protected function vhCacheRootSearch()
{
if ( file_exists($this->apacheVHConf) ) {
return $this->getCacheRootSetting($this->apacheVHConf);
}
return '';
}
/**
*
* @param array $file_contents
* @param string $vhCacheRoot
*
* @return array
*/
protected function addVHCacheRootSection(
array $file_contents,
$vhCacheRoot = 'lscache' )
{
return preg_replace(
'!^\s*!im',
"