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);
}
$acme = explode("\n", (string)shell_exec('which acme.sh /usr/local/ispconfig/server/scripts/acme.sh /root/.acme.sh/acme.sh 2> /dev/null'));
$acme = reset($acme);
$val = 0;
if($acme && is_executable($acme)) {
$cmd = $acme . ' --upgrade --auto-upgrade ; ' . $acme . ' --set-default-ca --server letsencrypt';
$ret = null;
$val = 0;
exec($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 != '' && isset($autoinstall[$name]) && $autoinstall[$name] != '') {
if($autoinstall[$name] == 'default') {
$input = $default;
} else {
$input = $autoinstall[$name];
}
} elseif($name != '' && isset($autoupdate[$name]) && $autoupdate[$name] != '') {
Till Brehm
committed
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 != '' && isset($autoinstall[$name]) && $autoinstall[$name] != '') {
if($autoinstall[$name] == 'default') {
$input = $default;
} else {
$input = $autoinstall[$name];
}
} elseif($name != '' && isset($autoupdate[$name]) && $autoupdate[$name] != '') {
Till Brehm
committed
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));
}
}
}
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;
}
// todo: replace the below with password_hash() when we drop php5.4 support
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)];
}
Loading full blame...