Commit b5984360 authored by Marius Burkard's avatar Marius Burkard

- WIP: add possibilities to hook-in on install/update (for addons)

parent bdf0ebdc
......@@ -145,6 +145,46 @@ if(is_file('dist/lib/'.$dist['baseid'].'.lib.php')) include_once 'dist/lib/'.$di
include_once 'dist/lib/'.$dist['id'].'.lib.php';
include_once 'dist/conf/'.$dist['confid'].'.conf.php';
//** Include addon lib config files
if(is_dir('dist/lib.d')) {
// scheme is: <addon-name>.<distconfid>.conf.php
if(($dir = opendir('dist/lib.d'))) {
while(false !== ($cur = readdir($dir))) {
$curpath = 'dist/lib.d/' . $cur;
if(strpos($curpath, '..') !== false
|| !is_file($curpath)
|| !preg_match('/\.(?:' . preg_quote($dist['id'], '/') . '|' . preg_quote($dist['baseid'], '/') . ')\.lib\.php$/', $cur)) {
// invalid entry or entry not for current distribution
continue;
}
// valid file name and either generic or for current distribution
include_once $curpath;
}
closedir($dir);
}
}
//** Include addon dist config files
if(is_dir('dist/conf.d')) {
// scheme is: <addon-name>.<distconfid>.conf.php
if(($dir = opendir('dist/conf.d'))) {
while(false !== ($cur = readdir($dir))) {
$curpath = 'dist/conf.d/' . $cur;
if(strpos($curpath, '..') !== false
|| !is_file($curpath)
|| !preg_match('/\.' . preg_quote($dist['confid'], '/') . '\.conf\.php$/', $cur)) {
// invalid entry or entry not for current distribution
continue;
}
// valid file name and either generic or for current distribution
include_once $curpath;
}
closedir($dir);
}
}
//****************************************************************************************************
//** Installer Interface
//****************************************************************************************************
......@@ -171,7 +211,9 @@ if(is_dir('/usr/local/ispconfig')) {
}
//** Detect the installed applications
$this->call_hook('find_installed_apps', false);
$inst->find_installed_apps();
$this->call_hook('find_installed_apps', true);
//** Select the language and set default timezone
$conf['language'] = $inst->simple_query('Select language', array('en', 'de'), 'en','language');
......@@ -183,6 +225,7 @@ $conf['language_file_import_enabled'] = true;
//** Select installation mode
$install_mode = $inst->simple_query('Installation mode', array('standard', 'expert'), 'standard','install_mode');
$inst->set_install_mode($install_mode);
//** tRNG dependencies
$conf['tRNG']='';
......@@ -456,6 +499,8 @@ if($install_mode == 'standard' || strtolower($inst->simple_query('Configure Web
}
}
$inst->call_hook('configure_webserver_selection', true);
if($install_mode == 'standard' || strtolower($inst->simple_query('Configure Firewall Server', array('y', 'n'), 'y','configure_firewall')) == 'y') {
//* Check for Firewall
if(!$conf['ufw']['installed'] && !$conf['firewall']['installed']) {
......@@ -547,7 +592,9 @@ if($install_mode == 'standard' || strtolower($inst->simple_query('Install ISPCon
$inst->install_ispconfig_interface = false;
}
$inst->call_hook('install_ispconfig', false);
$inst->install_ispconfig();
$inst->call_hook('install_ispconfig', true);
//* Configure DBServer
swriteln('Configuring DBServer');
......
......@@ -37,7 +37,9 @@ class installer_base {
public $install_ispconfig_interface = true;
public $is_update = false; // true if it is an update, falsi if it is a new install
public $min_php = '5.3.3'; // minimal php-version for update / install
private $addon_classes = null;
private $install_mode = '';
public function __construct() {
global $conf; //TODO: maybe $conf should be passed to constructor
//$this->conf = $conf;
......@@ -56,6 +58,14 @@ class installer_base {
echo 'WARNING: '.$msg."\n";
}
public function set_install_mode($mode) {
$this->install_mode = $mode;
}
public function get_install_mode() {
return $this->install_mode;
}
public function simple_query($query, $answers, $default, $name = '') {
global $autoinstall, $autoupdate;
$finished = false;
......@@ -150,7 +160,8 @@ class installer_base {
//** Detect installed applications
public function find_installed_apps() {
global $conf;
$this->call_hook('find_installed_apps', false);
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;
......@@ -180,6 +191,8 @@ class installer_base {
if(is_installed('cron') || is_installed('anacron')) $conf['cron']['installed'] = true;
if (($conf['apache']['installed'] && is_file($conf['apache']["vhost_conf_enabled_dir"]."/000-ispconfig.vhost")) || ($conf['nginx']['installed'] && is_file($conf['nginx']["vhost_conf_enabled_dir"]."/000-ispconfig.vhost"))) $this->ispconfig_interface_installed = true;
$this->call_hook('find_installed_apps', true);
}
public function force_configure_app($service, $enable_force=true) {
......@@ -2816,6 +2829,40 @@ class installer_base {
return $tContents;
}
public function call_hook($hook_name, $after = true) {
if(is_null($this->addon_classes)) {
// load addon libs
$this->addon_classes = array();
$libpath = realpath(dirname(__FILE__).'/..') . '/lib.d';
if(($dir = opendir($libpath))) {
while(false !== ($cur = readdir($dir))) {
if(strpos($cur, '..') !== false || !is_file($libpath . '/' . $cur) || substr($cur, -8) !== '.lib.php') {
continue;
}
$class_name = substr($cur, 0, -8) . '_addon_installer';
include_once $libpath . '/' . $cur;
if(!class_exists($class_name)) {
continue;
}
$this->addon_classes[] = new $class_name;
}
closedir($dir);
}
}
$call_method = 'onBefore';
if($after === true) {
$call_method = 'onAfter';
}
reset($this->addon_classes);
foreach($this->addon_classes as $cl) {
if(method_exists($cl, $call_method)) {
call_user_func(array($cl, $call_method), $hook_name);
}
}
}
}
......
......@@ -142,11 +142,52 @@ if(isset($cmd_opt['autoinstall']) && is_file($cmd_opt['autoinstall'])) {
define('AUTOINSTALL', false);
}
//** Include the distribution-specific installer class library and configuration
if(is_file('dist/lib/'.$dist['baseid'].'.lib.php')) include_once 'dist/lib/'.$dist['baseid'].'.lib.php';
include_once 'dist/lib/'.$dist['id'].'.lib.php';
include_once 'dist/conf/'.$dist['confid'].'.conf.php';
//** Include addon lib config files
if(is_dir('dist/lib.d')) {
// scheme is: <addon-name>.<distconfid>.conf.php
if(($dir = opendir('dist/lib.d'))) {
while(false !== ($cur = readdir($dir))) {
$curpath = 'dist/lib.d/' . $cur;
if(strpos($curpath, '..') !== false
|| !is_file($curpath)
|| !preg_match('/\.(?:' . preg_quote($dist['id'], '/') . '|' . preg_quote($dist['baseid'], '/') . ')\.lib\.php$/', $cur)) {
// invalid entry or entry not for current distribution
continue;
}
// valid file name and either generic or for current distribution
include_once $curpath;
}
closedir($dir);
}
}
//** Include addon dist config files
if(is_dir('dist/conf.d')) {
// scheme is: <addon-name>.<distconfid>.conf.php
if(($dir = opendir('dist/conf.d'))) {
while(false !== ($cur = readdir($dir))) {
$curpath = 'dist/conf.d/' . $cur;
if(strpos($curpath, '..') !== false
|| !is_file($curpath)
|| !preg_match('/\.' . preg_quote($dist['confid'], '/') . '\.conf\.php$/', $cur)) {
// invalid entry or entry not for current distribution
continue;
}
// valid file name and either generic or for current distribution
include_once $curpath;
}
closedir($dir);
}
}
//** tRNG dependencies
$conf['tRNG']='';
......@@ -299,7 +340,9 @@ checkDbHealth();
/*
* dump the new Database and reconfigure the server.ini
*/
$inst->call_hook('updateDbAndIni', false);
updateDbAndIni();
$inst->call_hook('updateDbAndIni', true);
//** read server config from db into $conf['server_config']
$tmp = $inst->db->queryOneRecord("SELECT config FROM ?? WHERE server_id = ?", $conf["mysql"]["database"] . '.server', $conf['server_id']);
......@@ -321,7 +364,9 @@ if($reconfigure_master_database_rights_answer == 'yes') {
//}
//** Detect the installed applications
$this->call_hook('find_installed_apps', false);
$inst->find_installed_apps();
$this->call_hook('find_installed_apps', true);
//** Check for current service config state and compare to our results
if ($conf['mysql']['master_slave_setup'] == 'y') $current_svc_config = $inst->dbmaster->queryOneRecord("SELECT mail_server,web_server,dns_server,firewall_server,db_server FROM ?? WHERE server_id=?", $conf['mysql']['master_database'] . '.server', $conf['server_id']);
......
Markdown is supported
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