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

- updated for ubuntu 20.04

parent 3f497245
......@@ -6,9 +6,9 @@
*/
class ISPConfigBaseOS {
private $ispc_config = false;
private static $os_data = null;
/**
* @return array
* @throws ISPConfigOSException
......@@ -38,14 +38,14 @@ class ISPConfigBaseOS {
throw new ISPConfigOSException('Version ' . $os['VERSION_ID'] . ' is not supported for ' . $os['ID']);
}
} 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']);
}
} else {
// cannot be reached, but just to be on the safe side ...
throw new ISPConfigOSException($os['ID'] . ' is not a supported distribution.');
}
self::$os_data = array(
'ID' => $os['ID'],
'VERSION' => $os['VERSION_ID'],
......@@ -55,10 +55,10 @@ class ISPConfigBaseOS {
throw new ISPConfigOSException('Unknown or unsupported OS.');
}
}
return self::$os_data;
}
/**
* @return ISPConfigBaseOS
* @throws Exception
......@@ -66,11 +66,11 @@ class ISPConfigBaseOS {
public static function getOSInstance() {
try {
$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')) {
$class_name = 'ISPConfig' . ucfirst($os['ID']) . 'OS';
}
return new $class_name;
} catch(Exception $ex) {
throw $ex;
......@@ -78,7 +78,7 @@ class ISPConfigBaseOS {
}
public function __construct() {
}
public function exec($cmd, $returncodes_ok = array(), $tries = 1, $retry_codes = null) {
......@@ -95,10 +95,10 @@ class ISPConfigBaseOS {
}
$tries--;
}
return $result;
}
public function passthru($cmd, $returncodes_ok = array(), $tries = 1, $retry_codes = null) {
$result = false;
while($result === false && $tries > 0) {
......@@ -112,26 +112,26 @@ class ISPConfigBaseOS {
}
$tries--;
}
return $result;
}
protected function addLines($file, $entries, $add_if_existing = false) {
if(!is_array($entries)) {
$entries = array($entries);
}
$content = '';
if(is_file($file)) {
$content = file_get_contents($file);
}
foreach($entries as $line) {
if($add_if_existing === true || !preg_match('/^' . preg_quote($line) . '$/m', $content)) {
$content .= "\n" . $line . "\n";
}
}
file_put_contents($file, $content);
return;
}
......@@ -139,28 +139,28 @@ class ISPConfigBaseOS {
protected function uncommentLines($file, $entries, $commenter = '#') {
return $this->commentUncommentLines($file, $entries, true, $commenter);
}
protected function commentLines($file, $entries, $commenter = '#') {
return $this->commentUncommentLines($file, $entries, false, $commenter);
}
private function commentUncommentLines($file, $entries, $uncomment = false, $commenter = '#') {
if(!is_array($entries)) {
throw new ISPConfigOSException('Invalid entries array provided.');
}
if(!is_file($file)) {
throw new ISPConfigOSException('File ' . $file . ' does not exist.');
}
$content = file_get_contents($file);
$active_entry = false;
$lines = explode("\n", $content);
$new_lines = array();
for($l = 0; $l < count($lines); $l++) {
$line = $lines[$l];
if($active_entry) {
if(!isset($active_entry['last_line']) || !$active_entry['last_line']) {
$active_entry = false;
......@@ -189,7 +189,7 @@ class ISPConfigBaseOS {
}
}
}
// not possible using "else" here because last line of active entry might be first of new
if(!$active_entry) {
for($i = 0; $i < count($entries); $i++) {
......@@ -207,7 +207,7 @@ class ISPConfigBaseOS {
break;
}
}
if($active_entry && isset($active_entry['add_lines'])) {
$add = $active_entry['add_lines'];
if(!is_array($add)) {
......@@ -216,14 +216,14 @@ class ISPConfigBaseOS {
$line .= "\n" . implode("\n", $add);
}
}
$new_lines[] = $line;
}
$content = implode("\n", $new_lines);
unset($new_lines);
unset($lines);
copy($file, $file . '~' . strftime('%Y%m%d%H%M%S', time()));
file_put_contents($file, $content);
return true;
......@@ -242,7 +242,7 @@ class ISPConfigBaseOS {
if(!is_array($replacements)) {
throw new ISPConfigOSException('Invalid replacement array provided.');
}
$content = '';
$matches = array();
if(is_file($file) == false) {
......@@ -250,7 +250,7 @@ class ISPConfigBaseOS {
} else {
$content = file_get_contents($file);
}
foreach($replacements as $search => $replace) {
$if_not = false;
if(is_array($replace)) {
......@@ -279,14 +279,14 @@ class ISPConfigBaseOS {
$content = str_replace($search, $replace, $content);
}
}
if($need_to_add === true) {
if($add_to_section) {
$section_found = false;
$lines = explode("\n", $content);
$new_lines = array();
$in_section = false;
for($l = 0; $l < count($lines); $l++) {
$line = $lines[$l];
......@@ -304,7 +304,7 @@ class ISPConfigBaseOS {
$content = implode("\n", $new_lines);
unset($lines);
unset($new_lines);
if($section_found === false) {
$content .= "\n\n" . '[' . $add_to_section . ']' . "\n" . $replace . "\n";
}
......@@ -312,21 +312,21 @@ class ISPConfigBaseOS {
$content .= "\n" . $replace;
}
}
}
copy($file, $file . '~' . strftime('%Y%m%d%H%M%S', time()));
file_put_contents($file, $content);
return true;
}
protected function getInstallCommand($packages) {
if(is_string($packages)) {
$packages = array($packages);
}
$cmd = $this->getUpdateCommand('install');
$cmd = str_replace('<PACKAGES>', implode(' ', $packages), $cmd);
return $cmd;
}
......@@ -334,17 +334,17 @@ class ISPConfigBaseOS {
$cmd = $this->getUpdateCommand('prepare');
return $this->exec($cmd, null, 3, array('100'));
}
protected function installPackages($packages) {
$cmd = $this->getInstallCommand($packages);
return $this->exec($cmd, null, 3);//, array('100'));
}
protected function restartService($service_name) {
$cmd = $this->getRestartServiceCommand($service_name);
return $this->exec($cmd);
}
protected function startService($service_name) {
$cmd = $this->getRestartServiceCommand($service_name, 'start');
return $this->exec($cmd);
......@@ -364,36 +364,36 @@ class ISPConfigBaseOS {
return true;
}
}
protected function getSystemPHPVersion() {
return '7.3';
}
protected function afterPackageInstall($section = '') {
}
protected function beforePackageInstall($section = '') {
}
public function getPackageVersion($package) {
}
public function getPackageAlias($package) {
}
public function getUpdateCommand($mode = 'update') {
}
public function getUpdatePackageRegex() {
}
public function getInstallPackageRegex($mode = '') {
}
public function getRestartServiceCommand($service, $command = 'restart') {
}
public function runPerfectSetup() {
}
}
......@@ -43,7 +43,7 @@ class ISPConfigDebian10OS extends ISPConfigDebianOS {
protected function setDefaultPHP() {
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);
if($result === false) {
throw new ISPConfigOSException('Command ' . $cmd . ' failed.');
......
......@@ -146,7 +146,7 @@ class ISPConfigDebianOS extends ISPConfigBaseOS {
protected function setDefaultPHP() {
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);
if($result === false) {
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
';
file_put_contents('/etc/apt/sources.list', $contents);
}
protected function beforePackageInstall($section = '') {
$this->stopService('apparmor');
$this->stopService('sendmail');
......@@ -34,7 +34,7 @@ deb http://security.ubuntu.com/ubuntu bionic-security multiverse
throw new ISPConfigOSException('Command ' . $cmd . ' failed.');
}
}
protected function afterPackageInstall($section = '') {
if($section === 'mail') {
$cmd = 'freshclam';
......@@ -42,21 +42,21 @@ deb http://security.ubuntu.com/ubuntu bionic-security multiverse
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
......@@ -83,15 +83,15 @@ maxretry = 3';
protected function setDefaultPHP() {
ISPConfigLog::info('Settings default system php version.', true);
$cmd = 'update-alternatives --set php /usr/bin/php7.2 ; update-alternatives --set php-cgi /usr/bin/php-cgi7.2';
$cmd = 'update-alternatives --set php /usr/bin/php7.2 ; update-alternatives --set php-cgi /usr/bin/php-cgi7.2 ; update-alternatives --set php-fpm.sock /run/php/php7.2-fpm.sock';
$result = $this->exec($cmd);
if($result === false) {
throw new ISPConfigOSException('Command ' . $cmd . ' failed.');
}
}
protected function getSystemPHPVersion() {
return '7.2';
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment