Skip to content

Commit b598436

Browse files
author
Marius Burkard
committed
- WIP: add possibilities to hook-in on install/update (for addons)
1 parent bdf0ebd commit b598436

File tree

3 files changed

+141
-2
lines changed

3 files changed

+141
-2
lines changed

install/install.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,46 @@
145145
include_once 'dist/lib/'.$dist['id'].'.lib.php';
146146
include_once 'dist/conf/'.$dist['confid'].'.conf.php';
147147

148+
//** Include addon lib config files
149+
if(is_dir('dist/lib.d')) {
150+
// scheme is: <addon-name>.<distconfid>.conf.php
151+
if(($dir = opendir('dist/lib.d'))) {
152+
while(false !== ($cur = readdir($dir))) {
153+
$curpath = 'dist/lib.d/' . $cur;
154+
if(strpos($curpath, '..') !== false
155+
|| !is_file($curpath)
156+
|| !preg_match('/\.(?:' . preg_quote($dist['id'], '/') . '|' . preg_quote($dist['baseid'], '/') . ')\.lib\.php$/', $cur)) {
157+
158+
// invalid entry or entry not for current distribution
159+
continue;
160+
}
161+
// valid file name and either generic or for current distribution
162+
include_once $curpath;
163+
}
164+
closedir($dir);
165+
}
166+
}
167+
168+
//** Include addon dist config files
169+
if(is_dir('dist/conf.d')) {
170+
// scheme is: <addon-name>.<distconfid>.conf.php
171+
if(($dir = opendir('dist/conf.d'))) {
172+
while(false !== ($cur = readdir($dir))) {
173+
$curpath = 'dist/conf.d/' . $cur;
174+
if(strpos($curpath, '..') !== false
175+
|| !is_file($curpath)
176+
|| !preg_match('/\.' . preg_quote($dist['confid'], '/') . '\.conf\.php$/', $cur)) {
177+
178+
// invalid entry or entry not for current distribution
179+
continue;
180+
}
181+
// valid file name and either generic or for current distribution
182+
include_once $curpath;
183+
}
184+
closedir($dir);
185+
}
186+
}
187+
148188
//****************************************************************************************************
149189
//** Installer Interface
150190
//****************************************************************************************************
@@ -171,7 +211,9 @@
171211
}
172212

173213
//** Detect the installed applications
214+
$this->call_hook('find_installed_apps', false);
174215
$inst->find_installed_apps();
216+
$this->call_hook('find_installed_apps', true);
175217

176218
//** Select the language and set default timezone
177219
$conf['language'] = $inst->simple_query('Select language', array('en', 'de'), 'en','language');
@@ -183,6 +225,7 @@
183225

184226
//** Select installation mode
185227
$install_mode = $inst->simple_query('Installation mode', array('standard', 'expert'), 'standard','install_mode');
228+
$inst->set_install_mode($install_mode);
186229

187230
//** tRNG dependencies
188231
$conf['tRNG']='';
@@ -456,6 +499,8 @@
456499
}
457500
}
458501

502+
$inst->call_hook('configure_webserver_selection', true);
503+
459504
if($install_mode == 'standard' || strtolower($inst->simple_query('Configure Firewall Server', array('y', 'n'), 'y','configure_firewall')) == 'y') {
460505
//* Check for Firewall
461506
if(!$conf['ufw']['installed'] && !$conf['firewall']['installed']) {
@@ -547,7 +592,9 @@
547592
$inst->install_ispconfig_interface = false;
548593
}
549594

595+
$inst->call_hook('install_ispconfig', false);
550596
$inst->install_ispconfig();
597+
$inst->call_hook('install_ispconfig', true);
551598

552599
//* Configure DBServer
553600
swriteln('Configuring DBServer');

install/lib/installer_base.lib.php

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ class installer_base {
3737
public $install_ispconfig_interface = true;
3838
public $is_update = false; // true if it is an update, falsi if it is a new install
3939
public $min_php = '5.3.3'; // minimal php-version for update / install
40-
40+
private $addon_classes = null;
41+
private $install_mode = '';
42+
4143
public function __construct() {
4244
global $conf; //TODO: maybe $conf should be passed to constructor
4345
//$this->conf = $conf;
@@ -56,6 +58,14 @@ public function warning($msg) {
5658
echo 'WARNING: '.$msg."\n";
5759
}
5860

61+
public function set_install_mode($mode) {
62+
$this->install_mode = $mode;
63+
}
64+
65+
public function get_install_mode() {
66+
return $this->install_mode;
67+
}
68+
5969
public function simple_query($query, $answers, $default, $name = '') {
6070
global $autoinstall, $autoupdate;
6171
$finished = false;
@@ -150,7 +160,8 @@ public function get_php_version() {
150160
//** Detect installed applications
151161
public function find_installed_apps() {
152162
global $conf;
153-
163+
164+
$this->call_hook('find_installed_apps', false);
154165
if(is_installed('mysql') || is_installed('mysqld')) $conf['mysql']['installed'] = true;
155166
if(is_installed('postfix')) $conf['postfix']['installed'] = true;
156167
if(is_installed('postgrey')) $conf['postgrey']['installed'] = true;
@@ -180,6 +191,8 @@ public function find_installed_apps() {
180191
if(is_installed('cron') || is_installed('anacron')) $conf['cron']['installed'] = true;
181192

182193
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;
194+
195+
$this->call_hook('find_installed_apps', true);
183196
}
184197

185198
public function force_configure_app($service, $enable_force=true) {
@@ -2816,6 +2829,40 @@ protected function insert_db_credentials($tContents) {
28162829

28172830
return $tContents;
28182831
}
2832+
2833+
public function call_hook($hook_name, $after = true) {
2834+
if(is_null($this->addon_classes)) {
2835+
// load addon libs
2836+
$this->addon_classes = array();
2837+
$libpath = realpath(dirname(__FILE__).'/..') . '/lib.d';
2838+
if(($dir = opendir($libpath))) {
2839+
while(false !== ($cur = readdir($dir))) {
2840+
if(strpos($cur, '..') !== false || !is_file($libpath . '/' . $cur) || substr($cur, -8) !== '.lib.php') {
2841+
continue;
2842+
}
2843+
$class_name = substr($cur, 0, -8) . '_addon_installer';
2844+
include_once $libpath . '/' . $cur;
2845+
if(!class_exists($class_name)) {
2846+
continue;
2847+
}
2848+
2849+
$this->addon_classes[] = new $class_name;
2850+
}
2851+
closedir($dir);
2852+
}
2853+
}
2854+
2855+
$call_method = 'onBefore';
2856+
if($after === true) {
2857+
$call_method = 'onAfter';
2858+
}
2859+
reset($this->addon_classes);
2860+
foreach($this->addon_classes as $cl) {
2861+
if(method_exists($cl, $call_method)) {
2862+
call_user_func(array($cl, $call_method), $hook_name);
2863+
}
2864+
}
2865+
}
28192866

28202867
}
28212868

install/update.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,52 @@
142142
define('AUTOINSTALL', false);
143143
}
144144

145+
145146
//** Include the distribution-specific installer class library and configuration
146147
if(is_file('dist/lib/'.$dist['baseid'].'.lib.php')) include_once 'dist/lib/'.$dist['baseid'].'.lib.php';
147148
include_once 'dist/lib/'.$dist['id'].'.lib.php';
148149
include_once 'dist/conf/'.$dist['confid'].'.conf.php';
149150

151+
//** Include addon lib config files
152+
if(is_dir('dist/lib.d')) {
153+
// scheme is: <addon-name>.<distconfid>.conf.php
154+
if(($dir = opendir('dist/lib.d'))) {
155+
while(false !== ($cur = readdir($dir))) {
156+
$curpath = 'dist/lib.d/' . $cur;
157+
if(strpos($curpath, '..') !== false
158+
|| !is_file($curpath)
159+
|| !preg_match('/\.(?:' . preg_quote($dist['id'], '/') . '|' . preg_quote($dist['baseid'], '/') . ')\.lib\.php$/', $cur)) {
160+
161+
// invalid entry or entry not for current distribution
162+
continue;
163+
}
164+
// valid file name and either generic or for current distribution
165+
include_once $curpath;
166+
}
167+
closedir($dir);
168+
}
169+
}
170+
171+
//** Include addon dist config files
172+
if(is_dir('dist/conf.d')) {
173+
// scheme is: <addon-name>.<distconfid>.conf.php
174+
if(($dir = opendir('dist/conf.d'))) {
175+
while(false !== ($cur = readdir($dir))) {
176+
$curpath = 'dist/conf.d/' . $cur;
177+
if(strpos($curpath, '..') !== false
178+
|| !is_file($curpath)
179+
|| !preg_match('/\.' . preg_quote($dist['confid'], '/') . '\.conf\.php$/', $cur)) {
180+
181+
// invalid entry or entry not for current distribution
182+
continue;
183+
}
184+
// valid file name and either generic or for current distribution
185+
include_once $curpath;
186+
}
187+
closedir($dir);
188+
}
189+
}
190+
150191
//** tRNG dependencies
151192
$conf['tRNG']='';
152193

@@ -299,7 +340,9 @@
299340
/*
300341
* dump the new Database and reconfigure the server.ini
301342
*/
343+
$inst->call_hook('updateDbAndIni', false);
302344
updateDbAndIni();
345+
$inst->call_hook('updateDbAndIni', true);
303346

304347
//** read server config from db into $conf['server_config']
305348
$tmp = $inst->db->queryOneRecord("SELECT config FROM ?? WHERE server_id = ?", $conf["mysql"]["database"] . '.server', $conf['server_id']);
@@ -321,7 +364,9 @@
321364
//}
322365

323366
//** Detect the installed applications
367+
$this->call_hook('find_installed_apps', false);
324368
$inst->find_installed_apps();
369+
$this->call_hook('find_installed_apps', true);
325370

326371
//** Check for current service config state and compare to our results
327372
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']);

0 commit comments

Comments
 (0)