Commit b9401c1a authored by Marius Burkard's avatar Marius Burkard
Browse files

- fixed minor bugs and added color to output of service checks

parent d84fefe1
......@@ -48,10 +48,11 @@ tar -C /tmp/ispconfig-ai/ -xzf /tmp/ispconfig-ai.tar.gz || (echo "Failed extract
rm -f /tmp/ispconfig-ai.tar.gz ;
cd /tmp/ispconfig-ai ;
TTY=$(ps ax | grep ^$$ | head -n 1 | awk '{ print $2 }' 2>/dev/null);
TTY=$(ps ax | grep "^[ ]*"$$ | head -n 1 | awk '{ print $2 }' 2>/dev/null);
if [ "$TTY" != "" ] ; then
${PHP} -q /tmp/ispconfig-ai/ispconfig.ai.php $@ < /dev/${TTY} ;
else
echo "It seems you are not using a TTY. Please add --i-know-what-i-am-doing to the arguments.";
${PHP} -q /tmp/ispconfig-ai/ispconfig.ai.php $@ ;
fi
......
......@@ -25,6 +25,9 @@ class ISPConfig {
public static $WEBSERVER = ISPC_WEBSERVER_APACHE;
private static function init() {
if(!isset($_GET)) {
$_GET = array();
}
if(php_sapi_name() == 'cli') {
self::$is_cli_run = true;
......@@ -151,6 +154,14 @@ class ISPConfig {
}
}
public static function getISPConfigChannel() {
if(isset($_GET['channel']) && $_GET['channel']) {
return $_GET['channel'];
} else {
return 'stable';
}
}
private static function printHelp() {
$message = '
......@@ -166,6 +177,10 @@ This script automatically installs all needed packages for an ISPConfig 3 setup
Possible arguments are:
--help ->Show this help page
--debug ->Enable verbose logging (logs each command with the exit code)
--channel ->Choose the channel to use for ISPConfig. --channel=<stable|dev>
->"stable" is the latest ISPConfig release available on www.ispconfig.org
->"dev" is the latest stable-branch from the ISPConfig git repository: https://git.ispconfig.org/ispconfig/ispconfig3/tree/stable-3.1
-> The dev channel might contain bugs and less-tested features and should only be used in production by very experienced users.
--interactive ->Don\'t install ISPConfig in non-interactive mode. This is needed if you want to use expert mode, e. g. to install a slave server that shall be integrated into an existing multiserver setup.
--use-nginx ->Use nginx webserver instead of apache2
--no-web ->Do not use ISPConfig on this server to manage webserver setting and don\'t install nginx/apache or pureftpd. This will also prevent installing an ISPConfig UI and implies --no-roundcube as well as --no-pma
......@@ -189,9 +204,27 @@ Possible arguments are:
public static function run() {
self::init();
$valid_args = array(
'help', 'debug', 'interactive',
'use-nginx', 'channel',
'no-web', 'no-mail', 'no-dns', 'no-firewall', 'no-roundcube', 'no-pma', 'no-mailman',
'i-know-what-i-am-doing'
);
reset($_GET);
foreach($_GET as $key => $value) {
if(!in_array($key, $valid_args, true)) {
self::printHelp();
exit;
}
}
if(isset($_GET['help']) && $_GET['help']) {
self::printHelp();
exit;
} elseif(isset($_GET['channel']) && !in_array($_GET['channel'], array('stable', 'dev'), true)) {
self::printHelp();
exit;
}
if(!isset($_GET['i-know-what-i-am-doing']) || !$_GET['i-know-what-i-am-doing']) {
......@@ -220,7 +253,7 @@ Possible arguments are:
ISPConfigLog::info('Starting perfect server setup for ' . $os['NAME'], true);
$installer = ISPConfigBaseOS::getOSInstance();
$installer->runPerfectSetup();
ISPConfigLog::warn('Please delete the log files in var/log/setup-* once you don\'t need them anymore because they contain your passwords!', true);
ISPConfigLog::info('<lightred>Warning:</lightred> Please delete the log files in var/log/setup-* once you don\'t need them anymore because they contain your passwords!', true);
} catch(Exception $ex) {
throw $ex;
}
......
......@@ -149,10 +149,12 @@ class ISPConfigBaseOS {
$active_entry = false;
} elseif(preg_match($active_entry['last_line'], $line)) {
$active_entry = false;
if($uncomment === true) {
$line = preg_replace('/^(\s*)' . preg_quote($commenter, '/') . '+[ \t]*/', '$1', $line);
} else {
$line = $commenter . $line;
if(!isset($active_entry['skip_last_line']) || !$active_entry['skip_last_line']) {
if($uncomment === true) {
$line = preg_replace('/^(\s*)' . preg_quote($commenter, '/') . '+[ \t]*/', '$1', $line);
} else {
$line = $commenter . $line;
}
}
} elseif(isset($active_entry['search']) && $active_entry['search']) {
if(!is_array($active_entry['search'])) {
......@@ -161,7 +163,7 @@ class ISPConfigBaseOS {
for($i = 0; $i < count($active_entry['search']); $i++) {
if(preg_match($active_entry['search'][$i], $line)) {
if($uncomment === true) {
$line = preg_replace('/^(\s*)' . preg_quote($commenter, '/') . '+[ \t]/', '$1', $line);
$line = preg_replace('/^(\s*)' . preg_quote($commenter, '/') . '+[ \t]*/', '$1', $line);
} else {
$line = $commenter . $line;
}
......@@ -169,7 +171,10 @@ class ISPConfigBaseOS {
}
}
}
} else {
}
// 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++) {
$entry = $entries[$i];
if(!isset($entry['first_line'])) {
......@@ -177,7 +182,7 @@ class ISPConfigBaseOS {
}
if(preg_match($entry['first_line'], $line)) {
if($uncomment === true) {
$line = preg_replace('/^(\s*)' . preg_quote($commenter, '/') . '+[ \t]/', '$1', $line);
$line = preg_replace('/^(\s*)' . preg_quote($commenter, '/') . '+[ \t]*/', '$1', $line);
} else {
$line = $commenter . $line;
}
......
......@@ -68,7 +68,7 @@ class ISPConfigDebian10OS extends ISPConfigDebianOS {
}
touch('/etc/phpmyadmin/htpasswd.setup');
$cmd = 'chown -R www-data:www-data ' . escapeshellarg('/var/lib/phpmyadmin') . ' ; cd /tmp ; rm -f phpMyAdmin-4.9.0.1-all-languages.tar.gz ; wget "https://files.phpmyadmin.net/phpMyAdmin/4.9.0.1/phpMyAdmin-4.9.0.1-all-languages.tar.gz" 2>/dev/null && tar xfz phpMyAdmin-4.9.0.1-all-languages.tar.gz && mv phpMyAdmin-4.9.0.1-all-languages/* /usr/share/phpmyadmin/ && rm -f phpMyAdmin-4.9.0.1-all-languages.tar.gz && rm -rf phpMyAdmin-4.9.0.1-all-languages';
$cmd = 'chown -R www-data:www-data ' . escapeshellarg('/var/lib/phpmyadmin') . ' ; cd /tmp ; rm -f phpMyAdmin-4.9.0.1-all-languages.tar.gz ; wget "https://files.phpmyadmin.net/phpMyAdmin/4.9.0.1/phpMyAdmin-4.9.0.1-all-languages.tar.gz" 2>/dev/null && tar xfz phpMyAdmin-4.9.0.1-all-languages.tar.gz && cp -a phpMyAdmin-4.9.0.1-all-languages/* /usr/share/phpmyadmin/ && rm -f phpMyAdmin-4.9.0.1-all-languages.tar.gz && rm -rf phpMyAdmin-4.9.0.1-all-languages';
$result = $this->exec($cmd);
if($result === false) {
throw new ISPConfigOSException('Command ' . $cmd . ' failed.');
......
......@@ -269,7 +269,7 @@ maxretry = 3';
if(!ISPConfig::shallInstall('mail') || !ISPConfig::shallInstall('mailman')) {
return;
}
ISPConfigLog::info('Installing Mailman', true);
$cmd = 'echo "mailman mailman/site_languages multiselect de (German), en (English)" | debconf-set-selections 2>&1' . "\n";
......@@ -282,11 +282,13 @@ maxretry = 3';
$package = 'mailman';
$this->installPackages($package);
$listpw = ISPConfigFunctions::generatePassword(12);
$cmd = 'newlist -q -e ' . escapeshellarg($host_name) . ' mailman ' . escapeshellarg('root@' . $host_name) . ' ' . escapeshellarg($listpw);
$result = $this->exec($cmd);
if($result === false) {
throw new ISPConfigOSException('Command ' . $cmd . ' failed.');
if(!is_dir('/var/lib/mailman/lists/mailman')) {
$listpw = ISPConfigFunctions::generatePassword(12);
$cmd = 'newlist -q -e ' . escapeshellarg($host_name) . ' mailman ' . escapeshellarg('root@' . $host_name) . ' ' . escapeshellarg($listpw);
$result = $this->exec($cmd);
if($result === false) {
throw new ISPConfigOSException('Command ' . $cmd . ' failed.');
}
}
$add_content = '## mailman mailing list
......@@ -300,12 +302,22 @@ mailman-owner: "|/var/lib/mailman/mail/mailman owner mailman"
mailman-request: "|/var/lib/mailman/mail/mailman request mailman"
mailman-subscribe: "|/var/lib/mailman/mail/mailman subscribe mailman"
mailman-unsubscribe: "|/var/lib/mailman/mail/mailman unsubscribe mailman"';
$fp = fopen('/etc/aliases', 'a');
$fp = fopen('/etc/aliases', 'r+');
if(!$fp) {
throw new ISPConfigOSException('Opening /etc/aliases failed.');
}
fseek($fp, SEEK_END);
fwrite($fp, "\n\n" . $add_content);
$found = false;
while(!feof($fp)) {
$line = trim(fgets($fp));
if($line === '## mailman mailing list') {
$found = true;
break;
}
}
if($found === false) {
fseek($fp, SEEK_END);
fwrite($fp, "\n\n" . $add_content);
}
fclose($fp);
$cmd = 'newaliases';
......@@ -314,7 +326,9 @@ mailman-unsubscribe: "|/var/lib/mailman/mail/mailman unsubscribe mailman"';
throw new ISPConfigOSException('Command ' . $cmd . ' failed.');
}
symlink('/etc/mailman/apache.conf', '/etc/apache2/conf-enabled/mailman.conf');
if(!is_link('/etc/apache2/conf-enabled/mailman.conf') && !is_file('/etc/apache2/conf-enabled/mailman.conf')) {
symlink('/etc/mailman/apache.conf', '/etc/apache2/conf-enabled/mailman.conf');
}
$this->restartService('postfix');
$this->restartService('mailman');
......@@ -324,6 +338,9 @@ mailman-unsubscribe: "|/var/lib/mailman/mail/mailman unsubscribe mailman"';
}
protected function installPackages($packages) {
if(is_string($packages)) {
$packages = array($packages);
}
ISPConfigLog::info('Installing packages ' . implode(', ', $packages), true);
$result = parent::installPackages($packages);
if($result !== false) {
......@@ -564,6 +581,22 @@ mailman-unsubscribe: "|/var/lib/mailman/mail/mailman unsubscribe mailman"';
if(ISPConfig::shallInstall('mail')) {
ISPConfigLog::info('Configuring postfix.', true);
$entries = array(
array(
'first_line' => '/^submission\s+inet/',
'last_line' => '/^[a-z]/',
'skip_last_line' => true,
'search' => '/^\s+-o/'
),
array(
'first_line' => '/^smtps\s+inet/',
'last_line' => '/^[a-z]/',
'skip_last_line' => true,
'search' => '/^\s+-o/'
)
);
$this->commentLines('/etc/postfix/master.cf', $entries);
$entries = array(
array(
'first_line' => '/^#?submission\s+inet/',
......@@ -834,10 +867,12 @@ mailman-unsubscribe: "|/var/lib/mailman/mail/mailman unsubscribe mailman"';
mkdir('/etc/pure-ftpd/conf', 0755);
}
file_put_contents('/etc/pure-ftpd/conf/TLS', '1');
mkdir('/etc/ssl/private', 0755, true);
if(!is_dir('/etc/ssl/private')) {
mkdir('/etc/ssl/private', 0755, true);
}
$ssl_subject = '/C=DE/ST=None/L=None/O=IT/CN=' . $host_name;
$cmd = 'openssl req -x509 -nodes -days 7300 -newkey rsa:2048 -subj ' . escapeshellarg($ssl_subject) . ' -keyout /etc/ssl/private/pure-ftpd.pem -out /etc/ssl/private/pure-ftpd.pem';
$cmd = 'openssl req -x509 -nodes -days 7300 -newkey rsa:2048 -subj ' . escapeshellarg($ssl_subject) . ' -keyout /etc/ssl/private/pure-ftpd.pem -out /etc/ssl/private/pure-ftpd.pem > /dev/null 2>&1';
$result = $this->exec($cmd);
if($result === false) {
throw new ISPConfigOSException('Command ' . $cmd . ' failed.');
......@@ -997,12 +1032,22 @@ mailman-unsubscribe: "|/var/lib/mailman/mail/mailman unsubscribe mailman"';
$ai_argument = '';
}
$cmd = 'cd /tmp ; rm -rf ispconfig3_install 2>&1 ; wget -O ispconfig.tar.gz "https://www.ispconfig.org/downloads/ISPConfig-3-stable.tar.gz" >/dev/null 2>&1 ; tar xzf ispconfig.tar.gz ; cd ispconfig3_install ; cd install ; php -q install.php ' . $ai_argument . ' 2>&1 ; cd /tmp ; rm -rf ispconfig3_install 2>&1'; // ispconfig.autoinstall.ini removal!
$cmd = 'cd /tmp ; rm -rf ispconfig3_install 2>&1';
if(ISPConfig::getISPConfigChannel() === 'dev') {
$cmd .= ' ; wget -O ispconfig.tar.gz "https://git.ispconfig.org/ispconfig/ispconfig3/-/archive/stable-3.1/ispconfig3-stable-3.1.tar.gz" >/dev/null 2>&1 ; tar xzf ispconfig.tar.gz ; mv ispconfig3-stable-3.1 ispconfig3_install';
} else {
$cmd .= ' ; wget -O ispconfig.tar.gz "https://www.ispconfig.org/downloads/ISPConfig-3-stable.tar.gz" >/dev/null 2>&1 ; tar xzf ispconfig.tar.gz';
}
$cmd .= ' ; cd ispconfig3_install ; cd install ; php -q install.php ' . $ai_argument . ' 2>&1 ; cd /tmp ; rm -rf ispconfig3_install 2>&1';
$result = $this->exec($cmd);
if($result === false) {
throw new ISPConfigOSException('Command ' . $cmd . ' failed.');
}
if(!ISPConfig::wantsInteractive() && is_file('/tmp/ispconfig.autoinstall.ini')) {
unlink('/tmp/ispconfig.autoinstall.ini');
}
if(ISPConfig::shallInstall('web')) {
ISPConfigLog::info('Adding php versions to ISPConfig.', true);
......@@ -1043,7 +1088,7 @@ mailman-unsubscribe: "|/var/lib/mailman/mail/mailman unsubscribe mailman"';
foreach($check_services as $service) {
$status = $this->isServiceRunning($service);
ISPConfigLog::info($service . ' :' . ($status ? 'OK' : 'FAILED'), true);
ISPConfigLog::info($service . ': ' . ($status ? '<green>OK</green>' : '<lightred>FAILED</lightred>'), true);
if(!$status) {
ISPConfigLog::warn($service . ' seems not to be running!', true);
}
......@@ -1052,7 +1097,7 @@ mailman-unsubscribe: "|/var/lib/mailman/mail/mailman unsubscribe mailman"';
ISPConfigLog::info('Installation ready.', true);
if(ISPConfig::shallInstall('mailman')) {
if(ISPConfig::shallInstall('mailman') && $mailman_password != '') {
ISPConfigLog::info('Your Mailman password is: ' . $mailman_password, true);
}
if(ISPConfig::shallInstall('web')) {
......
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