Newer
Older
Hj Ahmad Rasyid Hj Ismail
committed
Copyright (c) 2007-2019, Till Brehm, projektfarm GmbH
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of ISPConfig nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
class installer_base {
var $wb = array();
var $language = 'en';
var $db;
public $install_ispconfig_interface = true;
public $is_update = false; // true if it is an update, false if it is a new install
protected $mailman_group = 'list';
public function __construct() {
global $conf; //TODO: maybe $conf should be passed to constructor
}
private function install_acme() {
$install_cmd = 'wget -O - https://get.acme.sh | sh';
$ret = null;
$val = 0;
exec($install_cmd . ' 2>&1', $ret, $val);
return ($val == 0 ? true : false);
}
//: TODO Implement the translation function and language files for the installer.
public function lng($text) {
return $text;
}
public function error($msg) {
die('ERROR: '.$msg."\n");
}
public function warning($msg) {
public function simple_query($query, $answers, $default, $name = '') {
global $autoinstall, $autoupdate;
if($name != '' && $autoinstall[$name] != '') {
if($autoinstall[$name] == 'default') {
$input = $default;
} else {
$input = $autoinstall[$name];
}
Till Brehm
committed
} elseif($name != '' && $autoupdate[$name] != '') {
if($autoupdate[$name] == 'default') {
$input = $default;
} else {
$input = $autoupdate[$name];
}
} else {
$answers_str = implode(',', $answers);
swrite($this->lng($query).' ('.$answers_str.') ['.$default.']: ');
$input = sread();
}
//* Stop the installation
if($input == 'quit') {
swriteln($this->lng("Installation terminated by user.\n"));
die();
}
//* Select the default
if($input == '') {
$answer = $default;
$finished = true;
}
//* Set answer id valid
if(in_array($input, $answers)) {
$answer = $input;
$finished = true;
}
} while ($finished == false);
swriteln();
return $answer;
}
public function free_query($query, $default, $name = '') {
global $autoinstall, $autoupdate;
if($name != '' && $autoinstall[$name] != '') {
if($autoinstall[$name] == 'default') {
$input = $default;
} else {
$input = $autoinstall[$name];
}
Till Brehm
committed
} elseif($name != '' && $autoupdate[$name] != '') {
if($autoupdate[$name] == 'default') {
$input = $default;
} else {
$input = $autoupdate[$name];
}
} else {
swrite($this->lng($query).' ['.$default.']: ');
$input = sread();
}
//* Stop the installation
if($input == 'quit') {
swriteln($this->lng("Installation terminated by user.\n"));
die();
}
$answer = ($input == '') ? $default : $input;
swriteln();
return $answer;
}
/*
// TODO: this function is not used atmo I think - pedro
function request_language(){
swriteln(lng('Enter your language'));
swriteln(lng('de, en'));
public function set_immutable($path, $enable = true) {
if($path != '' && $path != '/' && strlen($path) > 6 && strpos($path, '..') === false && (is_file($path) || is_dir($path))) {
if($enable) {
exec('chattr +i ' . escapeshellarg($path));
} else {
exec('chattr -i ' . escapeshellarg($path));
}
}
}
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
public function crypt_password($cleartext_password, $charset = 'UTF-8') {
if($charset != 'UTF-8') {
$cleartext_password = mb_convert_encoding($cleartext_password, $charset, 'UTF-8');
}
if(defined('CRYPT_SHA512') && CRYPT_SHA512 == 1) {
$salt = '$6$rounds=5000$';
$salt_length = 16;
} elseif(defined('CRYPT_SHA256') && CRYPT_SHA256 == 1) {
$salt = '$5$rounds=5000$';
$salt_length = 16;
} else {
$salt = '$1$';
$salt_length = 12;
}
if(function_exists('openssl_random_pseudo_bytes')) {
$salt .= substr(bin2hex(openssl_random_pseudo_bytes($salt_length)), 0, $salt_length);
} else {
$base64_alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789./';
for($n = 0; $n < $salt_length; $n++) {
$salt .= $base64_alphabet[mt_rand(0, 63)];
}
}
$salt .= "$";
return crypt($cleartext_password, $salt);
}
//** Detect installed applications
public function find_installed_apps() {
global $conf;
if(is_installed('mysql') || is_installed('mysqld')) $conf['mysql']['installed'] = true;
if(is_installed('postfix')) $conf['postfix']['installed'] = true;
if(is_installed('postgrey')) $conf['postgrey']['installed'] = true;
Florian Schaal
committed
if(is_installed('mailman') || is_installed('mmsitepass')) $conf['mailman']['installed'] = true;
Falko Timme
committed
if(is_installed('apache') || is_installed('apache2') || is_installed('httpd') || is_installed('httpd2')) $conf['apache']['installed'] = true;
if(is_installed('getmail')) $conf['getmail']['installed'] = true;
if(is_installed('courierlogger')) $conf['courier']['installed'] = true;
Loading full blame...