Commit 0ddf927d authored by Marius Burkard's avatar Marius Burkard
Browse files

- updated for ubuntu 20.04

parent 3f497245
...@@ -6,9 +6,9 @@ ...@@ -6,9 +6,9 @@
*/ */
class ISPConfigBaseOS { class ISPConfigBaseOS {
private $ispc_config = false; private $ispc_config = false;
private static $os_data = null; private static $os_data = null;
/** /**
* @return array * @return array
* @throws ISPConfigOSException * @throws ISPConfigOSException
...@@ -38,14 +38,14 @@ class ISPConfigBaseOS { ...@@ -38,14 +38,14 @@ class ISPConfigBaseOS {
throw new ISPConfigOSException('Version ' . $os['VERSION_ID'] . ' is not supported for ' . $os['ID']); throw new ISPConfigOSException('Version ' . $os['VERSION_ID'] . ' is not supported for ' . $os['ID']);
} }
} elseif($os['ID'] === 'ubuntu') { } elseif($os['ID'] === 'ubuntu') {
if(!in_array($os['VERSION_ID'], array('18.04'))) { if(!in_array($os['VERSION_ID'], array('18.04', '20.04'))) {
throw new ISPConfigOSException('Version ' . $os['VERSION_ID'] . ' is not supported for ' . $os['ID']); throw new ISPConfigOSException('Version ' . $os['VERSION_ID'] . ' is not supported for ' . $os['ID']);
} }
} else { } else {
// cannot be reached, but just to be on the safe side ... // cannot be reached, but just to be on the safe side ...
throw new ISPConfigOSException($os['ID'] . ' is not a supported distribution.'); throw new ISPConfigOSException($os['ID'] . ' is not a supported distribution.');
} }
self::$os_data = array( self::$os_data = array(
'ID' => $os['ID'], 'ID' => $os['ID'],
'VERSION' => $os['VERSION_ID'], 'VERSION' => $os['VERSION_ID'],
...@@ -55,10 +55,10 @@ class ISPConfigBaseOS { ...@@ -55,10 +55,10 @@ class ISPConfigBaseOS {
throw new ISPConfigOSException('Unknown or unsupported OS.'); throw new ISPConfigOSException('Unknown or unsupported OS.');
} }
} }
return self::$os_data; return self::$os_data;
} }
/** /**
* @return ISPConfigBaseOS * @return ISPConfigBaseOS
* @throws Exception * @throws Exception
...@@ -66,11 +66,11 @@ class ISPConfigBaseOS { ...@@ -66,11 +66,11 @@ class ISPConfigBaseOS {
public static function getOSInstance() { public static function getOSInstance() {
try { try {
$os = self::getOSVersion(); $os = self::getOSVersion();
$class_name = 'ISPConfig' . ucfirst($os['ID']) . $os['VERSION'] . 'OS'; $class_name = 'ISPConfig' . ucfirst($os['ID']) . str_replace('.', '', $os['VERSION']) . 'OS';
if(!is_file(LIB_DIR . '/os/class.' . $class_name . '.inc.php')) { if(!is_file(LIB_DIR . '/os/class.' . $class_name . '.inc.php')) {
$class_name = 'ISPConfig' . ucfirst($os['ID']) . 'OS'; $class_name = 'ISPConfig' . ucfirst($os['ID']) . 'OS';
} }
return new $class_name; return new $class_name;
} catch(Exception $ex) { } catch(Exception $ex) {
throw $ex; throw $ex;
...@@ -78,7 +78,7 @@ class ISPConfigBaseOS { ...@@ -78,7 +78,7 @@ class ISPConfigBaseOS {
} }
public function __construct() { public function __construct() {
} }
public function exec($cmd, $returncodes_ok = array(), $tries = 1, $retry_codes = null) { public function exec($cmd, $returncodes_ok = array(), $tries = 1, $retry_codes = null) {
...@@ -95,10 +95,10 @@ class ISPConfigBaseOS { ...@@ -95,10 +95,10 @@ class ISPConfigBaseOS {
} }
$tries--; $tries--;
} }
return $result; return $result;
} }
public function passthru($cmd, $returncodes_ok = array(), $tries = 1, $retry_codes = null) { public function passthru($cmd, $returncodes_ok = array(), $tries = 1, $retry_codes = null) {
$result = false; $result = false;
while($result === false && $tries > 0) { while($result === false && $tries > 0) {
...@@ -112,26 +112,26 @@ class ISPConfigBaseOS { ...@@ -112,26 +112,26 @@ class ISPConfigBaseOS {
} }
$tries--; $tries--;
} }
return $result; return $result;
} }
protected function addLines($file, $entries, $add_if_existing = false) { protected function addLines($file, $entries, $add_if_existing = false) {
if(!is_array($entries)) { if(!is_array($entries)) {
$entries = array($entries); $entries = array($entries);
} }
$content = ''; $content = '';
if(is_file($file)) { if(is_file($file)) {
$content = file_get_contents($file); $content = file_get_contents($file);
} }
foreach($entries as $line) { foreach($entries as $line) {
if($add_if_existing === true || !preg_match('/^' . preg_quote($line) . '$/m', $content)) { if($add_if_existing === true || !preg_match('/^' . preg_quote($line) . '$/m', $content)) {
$content .= "\n" . $line . "\n"; $content .= "\n" . $line . "\n";
} }
} }
file_put_contents($file, $content); file_put_contents($file, $content);
return; return;
} }
...@@ -139,28 +139,28 @@ class ISPConfigBaseOS { ...@@ -139,28 +139,28 @@ class ISPConfigBaseOS {
protected function uncommentLines($file, $entries, $commenter = '#') { protected function uncommentLines($file, $entries, $commenter = '#') {
return $this->commentUncommentLines($file, $entries, true, $commenter); return $this->commentUncommentLines($file, $entries, true, $commenter);
} }
protected function commentLines($file, $entries, $commenter = '#') { protected function commentLines($file, $entries, $commenter = '#') {
return $this->commentUncommentLines($file, $entries, false, $commenter); return $this->commentUncommentLines($file, $entries, false, $commenter);
} }
private function commentUncommentLines($file, $entries, $uncomment = false, $commenter = '#') { private function commentUncommentLines($file, $entries, $uncomment = false, $commenter = '#') {
if(!is_array($entries)) { if(!is_array($entries)) {
throw new ISPConfigOSException('Invalid entries array provided.'); throw new ISPConfigOSException('Invalid entries array provided.');
} }
if(!is_file($file)) { if(!is_file($file)) {
throw new ISPConfigOSException('File ' . $file . ' does not exist.'); throw new ISPConfigOSException('File ' . $file . ' does not exist.');
} }
$content = file_get_contents($file); $content = file_get_contents($file);
$active_entry = false; $active_entry = false;
$lines = explode("\n", $content); $lines = explode("\n", $content);
$new_lines = array(); $new_lines = array();
for($l = 0; $l < count($lines); $l++) { for($l = 0; $l < count($lines); $l++) {
$line = $lines[$l]; $line = $lines[$l];
if($active_entry) { if($active_entry) {
if(!isset($active_entry['last_line']) || !$active_entry['last_line']) { if(!isset($active_entry['last_line']) || !$active_entry['last_line']) {
$active_entry = false; $active_entry = false;
...@@ -189,7 +189,7 @@ class ISPConfigBaseOS { ...@@ -189,7 +189,7 @@ class ISPConfigBaseOS {
} }
} }
} }
// not possible using "else" here because last line of active entry might be first of new // not possible using "else" here because last line of active entry might be first of new
if(!$active_entry) { if(!$active_entry) {
for($i = 0; $i < count($entries); $i++) { for($i = 0; $i < count($entries); $i++) {
...@@ -207,7 +207,7 @@ class ISPConfigBaseOS { ...@@ -207,7 +207,7 @@ class ISPConfigBaseOS {
break; break;
} }
} }
if($active_entry && isset($active_entry['add_lines'])) { if($active_entry && isset($active_entry['add_lines'])) {
$add = $active_entry['add_lines']; $add = $active_entry['add_lines'];
if(!is_array($add)) { if(!is_array($add)) {
...@@ -216,14 +216,14 @@ class ISPConfigBaseOS { ...@@ -216,14 +216,14 @@ class ISPConfigBaseOS {
$line .= "\n" . implode("\n", $add); $line .= "\n" . implode("\n", $add);
} }
} }
$new_lines[] = $line; $new_lines[] = $line;
} }
$content = implode("\n", $new_lines); $content = implode("\n", $new_lines);
unset($new_lines); unset($new_lines);
unset($lines); unset($lines);
copy($file, $file . '~' . strftime('%Y%m%d%H%M%S', time())); copy($file, $file . '~' . strftime('%Y%m%d%H%M%S', time()));
file_put_contents($file, $content); file_put_contents($file, $content);
return true; return true;
...@@ -242,7 +242,7 @@ class ISPConfigBaseOS { ...@@ -242,7 +242,7 @@ class ISPConfigBaseOS {
if(!is_array($replacements)) { if(!is_array($replacements)) {
throw new ISPConfigOSException('Invalid replacement array provided.'); throw new ISPConfigOSException('Invalid replacement array provided.');
} }
$content = ''; $content = '';
$matches = array(); $matches = array();
if(is_file($file) == false) { if(is_file($file) == false) {
...@@ -250,7 +250,7 @@ class ISPConfigBaseOS { ...@@ -250,7 +250,7 @@ class ISPConfigBaseOS {
} else { } else {
$content = file_get_contents($file); $content = file_get_contents($file);
} }
foreach($replacements as $search => $replace) { foreach($replacements as $search => $replace) {
$if_not = false; $if_not = false;
if(is_array($replace)) { if(is_array($replace)) {
...@@ -279,14 +279,14 @@ class ISPConfigBaseOS { ...@@ -279,14 +279,14 @@ class ISPConfigBaseOS {
$content = str_replace($search, $replace, $content); $content = str_replace($search, $replace, $content);
} }
} }
if($need_to_add === true) { if($need_to_add === true) {
if($add_to_section) { if($add_to_section) {
$section_found = false; $section_found = false;
$lines = explode("\n", $content); $lines = explode("\n", $content);
$new_lines = array(); $new_lines = array();
$in_section = false; $in_section = false;
for($l = 0; $l < count($lines); $l++) { for($l = 0; $l < count($lines); $l++) {
$line = $lines[$l]; $line = $lines[$l];
...@@ -304,7 +304,7 @@ class ISPConfigBaseOS { ...@@ -304,7 +304,7 @@ class ISPConfigBaseOS {
$content = implode("\n", $new_lines); $content = implode("\n", $new_lines);
unset($lines); unset($lines);
unset($new_lines); unset($new_lines);
if($section_found === false) { if($section_found === false) {
$content .= "\n\n" . '[' . $add_to_section . ']' . "\n" . $replace . "\n"; $content .= "\n\n" . '[' . $add_to_section . ']' . "\n" . $replace . "\n";
} }
...@@ -312,21 +312,21 @@ class ISPConfigBaseOS { ...@@ -312,21 +312,21 @@ class ISPConfigBaseOS {
$content .= "\n" . $replace; $content .= "\n" . $replace;
} }
} }
} }
copy($file, $file . '~' . strftime('%Y%m%d%H%M%S', time())); copy($file, $file . '~' . strftime('%Y%m%d%H%M%S', time()));
file_put_contents($file, $content); file_put_contents($file, $content);
return true; return true;
} }
protected function getInstallCommand($packages) { protected function getInstallCommand($packages) {
if(is_string($packages)) { if(is_string($packages)) {
$packages = array($packages); $packages = array($packages);
} }
$cmd = $this->getUpdateCommand('install'); $cmd = $this->getUpdateCommand('install');
$cmd = str_replace('<PACKAGES>', implode(' ', $packages), $cmd); $cmd = str_replace('<PACKAGES>', implode(' ', $packages), $cmd);
return $cmd; return $cmd;
} }
...@@ -334,17 +334,17 @@ class ISPConfigBaseOS { ...@@ -334,17 +334,17 @@ class ISPConfigBaseOS {
$cmd = $this->getUpdateCommand('prepare'); $cmd = $this->getUpdateCommand('prepare');
return $this->exec($cmd, null, 3, array('100')); return $this->exec($cmd, null, 3, array('100'));
} }
protected function installPackages($packages) { protected function installPackages($packages) {
$cmd = $this->getInstallCommand($packages); $cmd = $this->getInstallCommand($packages);
return $this->exec($cmd, null, 3);//, array('100')); return $this->exec($cmd, null, 3);//, array('100'));
} }
protected function restartService($service_name) { protected function restartService($service_name) {
$cmd = $this->getRestartServiceCommand($service_name); $cmd = $this->getRestartServiceCommand($service_name);
return $this->exec($cmd); return $this->exec($cmd);
} }
protected function startService($service_name) { protected function startService($service_name) {
$cmd = $this->getRestartServiceCommand($service_name, 'start'); $cmd = $this->getRestartServiceCommand($service_name, 'start');
return $this->exec($cmd); return $this->exec($cmd);
...@@ -364,36 +364,36 @@ class ISPConfigBaseOS { ...@@ -364,36 +364,36 @@ class ISPConfigBaseOS {
return true; return true;
} }
} }
protected function getSystemPHPVersion() { protected function getSystemPHPVersion() {
return '7.3'; return '7.3';
} }
protected function afterPackageInstall($section = '') { protected function afterPackageInstall($section = '') {
} }
protected function beforePackageInstall($section = '') { protected function beforePackageInstall($section = '') {
} }
public function getPackageVersion($package) { public function getPackageVersion($package) {
} }
public function getPackageAlias($package) { public function getPackageAlias($package) {
} }
public function getUpdateCommand($mode = 'update') { public function getUpdateCommand($mode = 'update') {
} }
public function getUpdatePackageRegex() { public function getUpdatePackageRegex() {
} }
public function getInstallPackageRegex($mode = '') { public function getInstallPackageRegex($mode = '') {
} }
public function getRestartServiceCommand($service, $command = 'restart') { public function getRestartServiceCommand($service, $command = 'restart') {
} }
public function runPerfectSetup() { public function runPerfectSetup() {
} }
} }
...@@ -43,7 +43,7 @@ class ISPConfigDebian10OS extends ISPConfigDebianOS { ...@@ -43,7 +43,7 @@ class ISPConfigDebian10OS extends ISPConfigDebianOS {
protected function setDefaultPHP() { protected function setDefaultPHP() {
ISPConfigLog::info('Settings default system php version.', true); ISPConfigLog::info('Settings default system php version.', true);
$cmd = 'update-alternatives --set php /usr/bin/php7.3 ; update-alternatives --set php-cgi /usr/bin/php-cgi7.3'; $cmd = 'update-alternatives --set php /usr/bin/php7.3 ; update-alternatives --set php-cgi /usr/bin/php-cgi7.3 ; update-alternatives --set php-fpm.sock /run/php/php7.3-fpm.sock';
$result = $this->exec($cmd); $result = $this->exec($cmd);
if($result === false) { if($result === false) {
throw new ISPConfigOSException('Command ' . $cmd . ' failed.'); throw new ISPConfigOSException('Command ' . $cmd . ' failed.');
......
...@@ -146,7 +146,7 @@ class ISPConfigDebianOS extends ISPConfigBaseOS { ...@@ -146,7 +146,7 @@ class ISPConfigDebianOS extends ISPConfigBaseOS {
protected function setDefaultPHP() { protected function setDefaultPHP() {
ISPConfigLog::info('Settings default system php version.', true); ISPConfigLog::info('Settings default system php version.', true);
$cmd = 'update-alternatives --set php /usr/bin/php7.0 ; update-alternatives --set php-cgi /usr/bin/php-cgi7.0'; $cmd = 'update-alternatives --set php /usr/bin/php7.0 ; update-alternatives --set php-cgi /usr/bin/php-cgi7.0 ; update-alternatives --set php-fpm.sock /run/php/php7.0-fpm.sock';
$result = $this->exec($cmd); $result = $this->exec($cmd);
if($result === false) { if($result === false) {
throw new ISPConfigOSException('Command ' . $cmd . ' failed.'); throw new ISPConfigOSException('Command ' . $cmd . ' failed.');
......
<?php
/**
* Description of class
*
* @author croydon
*/
class ISPConfigUbuntuOS extends ISPConfigDebianOS {
protected function configureApt() {
// enable contrib and non-free
ISPConfigLog::info('Configuring apt repositories.', true);
$contents = '# created by ISPConfig auto installer
deb http://de.archive.ubuntu.com/ubuntu/ focal main restricted
deb http://de.archive.ubuntu.com/ubuntu/ focal-updates main restricted
deb http://de.archive.ubuntu.com/ubuntu/ focal universe
deb http://de.archive.ubuntu.com/ubuntu/ focal-updates universe
deb http://de.archive.ubuntu.com/ubuntu/ focal multiverse
deb http://de.archive.ubuntu.com/ubuntu/ focal-updates multiverse
deb http://de.archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu focal-security main restricted
deb http://security.ubuntu.com/ubuntu focal-security universe
deb http://security.ubuntu.com/ubuntu focal-security multiverse
';
file_put_contents('/etc/apt/sources.list', $contents);
}
protected function beforePackageInstall($section = '') {
$this->stopService('apparmor');
$this->stopService('sendmail');
$cmd = 'update-rc.d -f apparmor remove ; update-rc.d -f sendmail remove ; apt-get -y -qq remove apparmor apparmor-utils';
$result = $this->exec($cmd);
if($result === false) {
throw new ISPConfigOSException('Command ' . $cmd . ' failed.');
}
}
protected function afterPackageInstall($section = '') {
if($section === 'mail') {
$cmd = 'freshclam';
$result = $this->exec($cmd, array(62));
if($result === false) {
throw new ISPConfigOSException('Command ' . $cmd . ' failed.');
}
$this->startService('clamav-daemon');
}
}
protected function addSuryRepo() {
ISPConfigLog::info('Activating sury php repository.', true);
$cmd = 'add-apt-repository -y ppa:ondrej/php';
$result = $this->exec($cmd);
if($result === false) {
throw new ISPConfigOSException('Command ' . $cmd . ' failed.');
}
}
protected function getFail2BanJail() {
$jk_jail = '[pure-ftpd]
enabled = true
port = ftp
filter = pure-ftpd
logpath = /var/log/syslog
maxretry = 3
[dovecot]
enabled = true
filter = dovecot
action = iptables-multiport[name=dovecot-pop3imap, port="pop3,pop3s,imap,imaps", protocol=tcp]
logpath = /var/log/mail.log
maxretry = 5
[postfix-sasl]
enabled = true
port = smtp
filter = postfix
logpath = /var/log/mail.log
maxretry = 3';
return $jk_jail;
}
protected function setDefaultPHP() {
ISPConfigLog::info('Settings default system php version.', true);
$cmd = 'update-alternatives --set php /usr/bin/php7.4 ; update-alternatives --set php-cgi /usr/bin/php-cgi7.4 ; update-alternatives --set php-fpm.sock /run/php/php7.4-fpm.sock';
$result = $this->exec($cmd);
if($result === false) {
throw new ISPConfigOSException('Command ' . $cmd . ' failed.');
}
}
protected function getSystemPHPVersion() {
return '7.4';
}
}
...@@ -23,7 +23,7 @@ deb http://security.ubuntu.com/ubuntu bionic-security multiverse ...@@ -23,7 +23,7 @@ deb http://security.ubuntu.com/ubuntu bionic-security multiverse
'; ';
file_put_contents('/etc/apt/sources.list', $contents); file_put_contents('/etc/apt/sources.list', $contents);
} }
protected function beforePackageInstall($section = '') { protected function beforePackageInstall($section = '') {
$this->stopService('apparmor'); $this->stopService('apparmor');
$this->stopService('sendmail'); $this->stopService('sendmail');
...@@ -34,7 +34,7 @@ deb http://security.ubuntu.com/ubuntu bionic-security multiverse ...@@ -34,7 +34,7 @@ deb http://security.ubuntu.com/ubuntu bionic-security multiverse
throw new ISPConfigOSException('Command ' . $cmd . ' failed.');