Skip to content

Commit

Permalink
Merge branch 'v1_7'
Browse files Browse the repository at this point in the history
  • Loading branch information
gwanglst committed Nov 21, 2022
2 parents d391734 + 85349de commit be4c66a
Show file tree
Hide file tree
Showing 17 changed files with 250 additions and 162 deletions.
2 changes: 1 addition & 1 deletion dist/add-ons/webcachemgr/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.14.0.3
1.14.1.2
4 changes: 2 additions & 2 deletions dist/add-ons/webcachemgr/src/DashNotifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* LiteSpeed Web Server WordPress Dash Notifier
*
* @author LiteSpeed Technologies, Inc. (https://www.litespeedtech.com)
* @copyright (c) 2019
* @copyright (c) 2019-2022
* *******************************************
*/

Expand Down Expand Up @@ -75,7 +75,7 @@ public static function prepLocalDashPluginFiles()
try {
$latestVer = self::getLatestVersion();

if ( version_compare($latestVer, $localVer, '<') ) {
if ( Util::betterVersionCompare($latestVer, $localVer, '<') ) {
self::downloadVersion($latestVer);
}
}
Expand Down
2 changes: 1 addition & 1 deletion dist/add-ons/webcachemgr/src/Panel/CPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ protected static function getInstalledCpanelPluginActiveConfFileLocation(
if ( file_exists($versionFile) ) {
$versionNum = file_get_contents($versionFile);

if ( version_compare($versionNum, '2.1.2.2','>') ) {
if ( Util::betterVersionCompare($versionNum, '2.1.2.2','>') ) {
return self::USER_PLUGIN_CONF;
}
}
Expand Down
11 changes: 7 additions & 4 deletions dist/add-ons/webcachemgr/src/Panel/ControlPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ abstract class ControlPanel
/**
* @var string
*/
const PANEL_API_VERSION = '1.14.0.3';
const PANEL_API_VERSION = '1.14.1.2';

/**
* @since 1.9
Expand Down Expand Up @@ -966,7 +966,7 @@ public static function meetsMinAPIVerRequirement()
$minAPIVer = static::getMinAPIVer();

if ( $minAPIVer == ''
|| version_compare(static::PANEL_API_VERSION, $minAPIVer, '<') ) {
|| Util::betterVersionCompare(static::PANEL_API_VERSION, $minAPIVer, '<') ) {

return false;
}
Expand All @@ -986,6 +986,9 @@ public static function meetsMinAPIVerRequirement()
public static function checkPanelAPICompatibility( $panelAPIVer )
{
$supportedAPIVers = array(
'1.14.1.2',
'1.14.1.1',
'1.14.1',
'1.14.0.3',
'1.14.0.2',
'1.14.0.1',
Expand Down Expand Up @@ -1049,10 +1052,10 @@ public static function checkPanelAPICompatibility( $panelAPIVer )
$maxSupportedAPIVer = $supportedAPIVers[0];
$minSupportedAPIVer = end($supportedAPIVers);

if ( version_compare($panelAPIVer, $maxSupportedAPIVer, '>') ) {
if ( Util::betterVersionCompare($panelAPIVer, $maxSupportedAPIVer, '>') ) {
return static::PANEL_API_VERSION_TOO_HIGH;
}
elseif ( version_compare($panelAPIVer, $minSupportedAPIVer, '<') ) {
elseif ( Util::betterVersionCompare($panelAPIVer, $minSupportedAPIVer, '<') ) {
return static::PANEL_API_VERSION_TOO_LOW;
}
elseif ( ! in_array($panelAPIVer, $supportedAPIVers) ) {
Expand Down
16 changes: 9 additions & 7 deletions dist/add-ons/webcachemgr/src/Panel/DirectAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,21 +404,23 @@ protected function prepareDocrootMap()
*/
protected function getCustomPhpHandlerVer( $wpInstall )
{
if ( ($serverName = $wpInstall->getServerName()) == null
|| ($docroot = $wpInstall->getDocRoot()) == null ) {

return '';
}

$ver = '';

$escServerName = str_replace('.', '\.', $serverName);
$escDocRoot = str_replace(array('.', '/'), array('\.', '\/'), $docroot);

$user = $wpInstall->getOwnerInfo('user_name');

$httpdConfFile = "/usr/local/directadmin/data/users/$user/httpd.conf";
$olsConfFile =
"/usr/local/directadmin/data/users/$user/openlitespeed.conf";

$escServerName = str_replace('.', '\.', $wpInstall->getServerName());
$escDocRoot = str_replace(
array('.', '/'),
array('\.', '\/'),
$wpInstall->getDocRoot()
);

if ( file_exists($httpdConfFile) ) {
$confFile = $httpdConfFile;
$pattern = '/VirtualHost'
Expand Down
118 changes: 66 additions & 52 deletions dist/add-ons/webcachemgr/src/Panel/Plesk.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* LiteSpeed Web Server Cache Manager
*
* @author LiteSpeed Technologies, Inc. (https://www.litespeedtech.com)
* @copyright (c) 2018-2021
* @copyright (c) 2018-2022
* ******************************************* */

namespace Lsc\Wp\Panel;
Expand All @@ -19,7 +19,7 @@ class Plesk extends ControlPanel

/**
*
* @throws LSCMException Thrown indirectly.
* @throws LSCMException Thrown indirectly by parent::__construct() call.
*/
public function __construct()
{
Expand All @@ -30,7 +30,7 @@ public function __construct()
*
* @since 1.13.2
*
* @throws LSCMException Thrown indirectly.
* @throws LSCMException Thrown indirectly by parent::init2() call.
*/
protected function init2()
{
Expand All @@ -43,7 +43,7 @@ protected function init2()
* More reliable than php_uname('s')
*
* @return string
* @throws LSCMException
* @throws LSCMException Thrown when supported OS is not detected.
*/
public function getPleskOS()
{
Expand All @@ -55,7 +55,8 @@ public function getPleskOS()
'rhel',
'ubuntu',
'debian',
'almalinux'
'almalinux',
'rocky'
);

$cmds = array();
Expand All @@ -65,12 +66,12 @@ public function getPleskOS()
}

if ( is_readable('/etc/os-release') ) {
$cmds[] = 'grep ^ID= /etc/os-release | cut -d"=" -f2 | xargs';
$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';
$cmds[] =
'grep ^DISTRIB_ID= /etc/lsb-release | cut -d "=" -f2 | xargs';
}

if ( is_readable('/etc/redhat-release') ) {
Expand All @@ -91,7 +92,7 @@ public function getPleskOS()
throw new LSCMException(
'Plesk detected with unsupported OS. '
. '(Not CentOS/Virtuozzo/Cloudlinux/RedHat/Ubuntu/Debian/'
. 'AlmaLinux)',
. 'AlmaLinux/Rocky)',
LSCMException::E_UNSUPPORTED
);
}
Expand All @@ -109,11 +110,9 @@ protected function getVhDir()
$psaConfFile = '/etc/psa/psa.conf';

if ( file_exists($psaConfFile) ) {
$file_content = file_get_contents($psaConfFile);

$ret = preg_match(
'/HTTPD_VHOSTS_D\s+([^\s]+)/',
$file_content,
'/HTTPD_VHOSTS_D\s+(\S+)/',
file_get_contents($psaConfFile),
$m
);

Expand All @@ -127,7 +126,7 @@ protected function getVhDir()

/**
*
* @throws LSCMException Thrown indirectly.
* @throws LSCMException Thrown indirectly by $this->getPleskOS() call.
*/
protected function initConfPaths()
{
Expand All @@ -140,6 +139,7 @@ protected function initConfPaths()
case 'redhat':
case 'rhel':
case 'almalinux':
case 'rocky':
$this->apacheConf = '/etc/httpd/conf.d/lscache.conf';
break;

Expand Down Expand Up @@ -169,6 +169,10 @@ protected function initConfPaths()
. '/custom/domain/domainVirtualHost.php';
}

/**
*
* @return string
*/
protected function serverCacheRootSearch()
{
$apacheConfDir = dirname($this->apacheConf);
Expand All @@ -180,6 +184,10 @@ protected function serverCacheRootSearch()
return '';
}

/**
*
* @return string
*/
protected function vhCacheRootSearch()
{
if ( file_exists($this->apacheVHConf) ) {
Expand All @@ -191,12 +199,14 @@ protected function vhCacheRootSearch()

/**
*
* @param array $file_contents
* @param string $vhCacheRoot
* @param array $file_contents
* @param string $vhCacheRoot
*
* @return array
*/
protected function addVHCacheRootSection(
$file_contents, $vhCacheRoot = 'lscache' )
$file_contents,
$vhCacheRoot = 'lscache' )
{
return preg_replace(
'!^\s*</VirtualHost>!im',
Expand All @@ -210,10 +220,14 @@ protected function addVHCacheRootSection(
*
* @param string $vhConf
* @param string $vhCacheRoot
* @throws LSCMException Thrown indirectly.
*
* @throws LSCMException Thrown indirectly by $this->log() call.
* @throws LSCMException Thrown indirectly by $this->log() call.
* @throws LSCMException Thrown indirectly by $this->log() call.
*/
public function createVHConfAndSetCacheRoot(
$vhConf, $vhCacheRoot = 'lscache' )
$vhConf,
$vhCacheRoot = 'lscache' )
{
$vhConfTmpl = '/usr/local/psa/admin/conf/templates/default/domain/'
. 'domainVirtualHost.php';
Expand All @@ -233,17 +247,16 @@ public function createVHConfAndSetCacheRoot(
Logger::L_DEBUG
);

$file_contents = file($vhConf);

$replaced_content = preg_replace(
'!^\s*</VirtualHost>!im',
"<IfModule Litespeed>\nCacheRoot $vhCacheRoot\n</IfModule>"
. "\n</VirtualHost>",
$file_contents
file_put_contents(
$vhConf,
preg_replace(
'!^\s*</VirtualHost>!im',
"<IfModule Litespeed>\nCacheRoot $vhCacheRoot\n</IfModule>"
. "\n</VirtualHost>",
file($vhConf)
)
);

file_put_contents($vhConf, $replaced_content);

$this->log(
"Virutal Host cache root set to $vhCacheRoot",
Logger::L_INFO
Expand All @@ -263,14 +276,13 @@ public function applyVHConfChanges()
*/
protected function prepareDocrootMap()
{

$vhDir = $this->getVhDir();

$cmd = 'grep -hro --exclude="stat_ttl.conf" --exclude="*.bak" '
. '--exclude="last_httpd.conf" '
. '"DocumentRoot.*\|ServerName.*\|ServerAlias.*" '
. "$vhDir/system/*/conf/*";
exec( $cmd, $lines);
exec(
'grep -hro --exclude="stat_ttl.conf" --exclude="*.bak" '
. '--exclude="last_httpd.conf" '
. '"DocumentRoot.*\|ServerName.*\|ServerAlias.*" '
. "{$this->getVhDir()}/system/*/conf/*",
$lines
);

/**
* [0]=servername, [1]=serveralias, [2]=serveralias, [3]=docroot, etc.
Expand Down Expand Up @@ -311,10 +323,10 @@ protected function prepareDocrootMap()
continue;
}

$serverNameAsUrl =
(preg_match('#^https?://#', $m1[1])) ? $m1[1] : "http://$m1[1]";
$UrlInfo = parse_url(
(preg_match('#^https?://#', $m1[1])) ? $m1[1] : "http://$m1[1]"
);

$UrlInfo = parse_url($serverNameAsUrl);
$names[] = $UrlInfo['host'];
$x++;

Expand Down Expand Up @@ -400,26 +412,25 @@ protected function getDefaultPhpBinary()
/**
*
* @param WPInstall $wpInstall Not used
*
* @return string
*/
public function getPhpBinary( WPInstall $wpInstall )
{
$phpBin = 'php';

$serverName = $wpInstall->getData(WPInstall::FLD_SERVERNAME);

if ( $serverName != null ) {
$escapedServerName = escapeshellarg($serverName);

$cmd = 'plesk db -Ne "SELECT s.value '
. 'FROM ((domains d INNER JOIN hosting h ON h.dom_id=d.id) '
. 'INNER JOIN ServiceNodeEnvironment s '
. 'ON h.php_handler_id=s.name) '
. "WHERE d.name=$escapedServerName "
. 'AND s.section=\'phphandlers\'" '
. '| sed -n \'s:.*<clipath>\(.*\)</clipath>.*:\1:p\'';

$binPath = trim(shell_exec($cmd));
$binPath = trim(
shell_exec(
'plesk db -Ne "SELECT s.value '
. 'FROM ((domains d INNER JOIN hosting h ON h.dom_id=d.id) '
. 'INNER JOIN ServiceNodeEnvironment s '
. 'ON h.php_handler_id=s.name) '
. 'WHERE d.name=' . escapeshellarg($serverName)
. ' AND s.section=\'phphandlers\'" '
. '| sed -n \'s:.*<clipath>\(.*\)</clipath>.*:\1:p\''
)
);
}

if ( !empty($binPath) ) {
Expand All @@ -428,6 +439,9 @@ public function getPhpBinary( WPInstall $wpInstall )
elseif ( ($defaultBinary = $this->getDefaultPHPBinary()) != '' ) {
$phpBin = $defaultBinary;
}
else {
$phpBin = 'php';
}

return "$phpBin $this->phpOptions";
}
Expand Down
2 changes: 1 addition & 1 deletion dist/add-ons/webcachemgr/src/PluginVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ protected function refreshVersionList( $isforced = false )
*/
protected function filterVerList( $ver )
{
return version_compare($ver, '1.2.2', '>');
return Util::betterVersionCompare($ver, '1.2.2', '>');
}

/**
Expand Down
Loading

0 comments on commit be4c66a

Please sign in to comment.