Improved admin packages/extensions code

This commit is contained in:
the-djmaze 2022-01-11 09:47:24 +01:00
parent f15644bcb6
commit 9d280ab97e
2 changed files with 31 additions and 36 deletions

View file

@ -205,6 +205,7 @@ trait Admin
$totp = $this->Config()->Get('security', 'admin_totp', ''); $totp = $this->Config()->Get('security', 'admin_totp', '');
// \explode(':',`getent shadow root`)[1];
if (!\strlen($sLogin) || !\strlen($sPassword) || if (!\strlen($sLogin) || !\strlen($sPassword) ||
!$this->Config()->Get('security', 'allow_admin_panel', true) || !$this->Config()->Get('security', 'allow_admin_panel', true) ||
$sLogin !== $this->Config()->Get('security', 'admin_login', '') || $sLogin !== $this->Config()->Get('security', 'admin_login', '') ||
@ -544,15 +545,16 @@ trait Admin
{ {
$aResult = array(); $aResult = array();
try { try {
$notDev = '0.0.0' !== APP_VERSION;
foreach ($this->getRepositoryDataByUrl($bReal) as $oItem) { foreach ($this->getRepositoryDataByUrl($bReal) as $oItem) {
if ($oItem && isset($oItem->type, $oItem->id, $oItem->name, if ($oItem && isset($oItem->type, $oItem->id, $oItem->name,
$oItem->version, $oItem->release, $oItem->file, $oItem->description)) $oItem->version, $oItem->release, $oItem->file, $oItem->description))
{ {
if (!empty($oItem->required) && '0.0.0' !== APP_VERSION && version_compare(APP_VERSION, $oItem->required, '<')) { if (!empty($oItem->required) && $notDev && \version_compare(APP_VERSION, $oItem->required, '<')) {
continue; continue;
} }
if (!empty($oItem->depricated) && '0.0.0' !== APP_VERSION && version_compare(APP_VERSION, $oItem->depricated, '>=')) { if (!empty($oItem->depricated) && $notDev && \version_compare(APP_VERSION, $oItem->depricated, '>=')) {
continue; continue;
} }
@ -577,6 +579,16 @@ trait Admin
$sError = "{$e->getCode()} {$e->getMessage()}"; $sError = "{$e->getCode()} {$e->getMessage()}";
$this->Logger()->Write($sError, \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER'); $this->Logger()->Write($sError, \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
} }
return $aResult;
}
public function DoAdminPackagesList() : array
{
$this->IsAdminLoggined();
$bReal = false;
$sError = '';
$aList = $this->getRepositoryData($bReal, $sError);
$aEnabledPlugins = \array_map('trim', $aEnabledPlugins = \array_map('trim',
\explode(',', \strtolower($this->Config()->Get('plugins', 'enabled_list', ''))) \explode(',', \strtolower($this->Config()->Get('plugins', 'enabled_list', '')))
@ -585,13 +597,13 @@ trait Admin
$aInstalled = $this->Plugins()->InstalledPlugins(); $aInstalled = $this->Plugins()->InstalledPlugins();
foreach ($aInstalled as $aItem) { foreach ($aInstalled as $aItem) {
if ($aItem) { if ($aItem) {
if (isset($aResult[$aItem[0]])) { if (isset($aList[$aItem[0]])) {
$aResult[$aItem[0]]['installed'] = $aItem[1]; $aList[$aItem[0]]['installed'] = $aItem[1];
$aResult[$aItem[0]]['enabled'] = \in_array(\strtolower($aItem[0]), $aEnabledPlugins); $aList[$aItem[0]]['enabled'] = \in_array(\strtolower($aItem[0]), $aEnabledPlugins);
$aResult[$aItem[0]]['canBeDeleted'] = true; $aList[$aItem[0]]['canBeDeleted'] = true;
$aResult[$aItem[0]]['canBeUpdated'] = \version_compare($aItem[1], $aResult[$aItem[0]]['version'], '<'); $aList[$aItem[0]]['canBeUpdated'] = \version_compare($aItem[1], $aList[$aItem[0]]['version'], '<');
} else { } else {
\array_push($aResult, array( \array_push($aList, array(
'type' => 'plugin', 'type' => 'plugin',
'id' => $aItem[0], 'id' => $aItem[0],
'name' => $aItem[0], 'name' => $aItem[0],
@ -608,28 +620,11 @@ trait Admin
} }
} }
return \array_values($aResult);
}
public function DoAdminPackagesList() : array
{
$this->IsAdminLoggined();
$bReal = false;
$sError = '';
$aList = $this->getRepositoryData($bReal, $sError);
$bRainLoopUpdatable = \file_exists(APP_INDEX_ROOT_PATH.'index.php')
&& \is_writable(APP_INDEX_ROOT_PATH.'index.php')
&& \is_writable(APP_INDEX_ROOT_PATH.'snappymail/')
&& APP_VERSION !== '0.0.0';
// \uksort($aList, function($a, $b){return \strcasecmp($a['name'], $b['name']);}); // \uksort($aList, function($a, $b){return \strcasecmp($a['name'], $b['name']);});
return $this->DefaultResponse(__FUNCTION__, array( return $this->DefaultResponse(__FUNCTION__, array(
'Real' => $bReal, 'Real' => $bReal,
'MainUpdatable' => $bRainLoopUpdatable, 'List' => \array_values($aList),
'List' => $aList,
'Error' => $sError 'Error' => $sError
)); ));
} }
@ -675,15 +670,12 @@ trait Admin
if ($sError) { if ($sError) {
throw new \Exception($sError); throw new \Exception($sError);
} }
foreach ($aList as $oItem) { if (isset($aList[$sId]) && $sFile === $aList[$sId]['file']) {
if ($oItem && $sFile === $oItem['file'] && $sId === $oItem['id']) {
$sRealFile = $sFile; $sRealFile = $sFile;
$sTmp = \SnappyMail\Repository::download($sFile, $sTmp = \SnappyMail\Repository::download($sFile,
$this->Config()->Get('labs', 'curl_proxy', ''), $this->Config()->Get('labs', 'curl_proxy', ''),
$this->Config()->Get('labs', 'curl_proxy_auth', '') $this->Config()->Get('labs', 'curl_proxy_auth', '')
); );
break;
}
} }
} }
@ -721,7 +713,7 @@ trait Admin
'loaded' => true 'loaded' => true
] ]
]; ];
foreach (['APCu', 'cURL','GD','Gmagick','Imagick','intl','LDAP','OpenSSL','pdo_mysql','pdo_pgsql','pdo_sqlite','Sodium','XXTEA','Zip'] as $name) { foreach (['APCu', 'cURL','GD','Gmagick','Imagick','intl','LDAP','OpenSSL','pdo_mysql','pdo_pgsql','pdo_sqlite','redis','Sodium','uuid','XXTEA','Zip'] as $name) {
$aResult[] = [ $aResult[] = [
'name' => $name, 'name' => $name,
'loaded' => \extension_loaded(\strtolower($name)) 'loaded' => \extension_loaded(\strtolower($name))

View file

@ -12,6 +12,7 @@ if (defined('APP_VERSION'))
$aOptional = array( $aOptional = array(
'cURL' => extension_loaded('curl'), 'cURL' => extension_loaded('curl'),
'exif' => extension_loaded('exif'),
'gd' => extension_loaded('gd'), 'gd' => extension_loaded('gd'),
'gmagick' => extension_loaded('gmagick'), 'gmagick' => extension_loaded('gmagick'),
'imagick' => extension_loaded('imagick'), 'imagick' => extension_loaded('imagick'),
@ -20,8 +21,10 @@ if (defined('APP_VERSION'))
'OpenSSL' => extension_loaded('openssl'), 'OpenSSL' => extension_loaded('openssl'),
'mysql' => extension_loaded('pdo_mysql'), 'mysql' => extension_loaded('pdo_mysql'),
'pgsql' => extension_loaded('pdo_pgsql'), 'pgsql' => extension_loaded('pdo_pgsql'),
'redis' => extension_loaded('redis'),
'Sodium' => extension_loaded('sodium'), 'Sodium' => extension_loaded('sodium'),
'sqlite' => extension_loaded('pdo_sqlite'), 'sqlite' => extension_loaded('pdo_sqlite'),
'uuid' => extension_loaded('uuid'),
'xxtea' => extension_loaded('xxtea'), 'xxtea' => extension_loaded('xxtea'),
'zip' => extension_loaded('zip') 'zip' => extension_loaded('zip')
); );