Skip to content

Commit 42a34df

Browse files
author
Marius Burkard
committed
- installer class for addons
- do not install/update addons during install/update of ISPconfig. This only leads to lots of trouble
1 parent e35182f commit 42a34df

File tree

13 files changed

+444
-94
lines changed

13 files changed

+444
-94
lines changed

addons/empty.dir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This empty directory is needed by ISPConfig.

install/install.php

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -145,46 +145,6 @@
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-
188148
//****************************************************************************************************
189149
//** Installer Interface
190150
//****************************************************************************************************
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/**
4+
* Base class for app installer
5+
* This is a stripped down class with only the event method. The full class is only used in /server/lib/classes
6+
*
7+
* @author Marius Burkard
8+
*/
9+
class ispconfig_addon_installer_base {
10+
11+
protected $addon_ident;
12+
13+
public function __construct() {
14+
$this->addon_ident = preg_replace('/_addon_installer$/', '', get_called_class());
15+
}
16+
17+
public function onRaisedInstallerEvent($event_name, $data) {
18+
19+
}
20+
}

install/lib/installer_base.lib.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929
*/
3030

31+
require_once realpath(dirname(__FILE__)) . '/classes/ispconfig_addon_installer.inc.php';
32+
3133
class installer_base {
3234

3335
var $wb = array();
@@ -397,8 +399,6 @@ public function add_database_server_record() {
397399
$this->db->query($sql, $conf['hostname'], $mail_server_enabled, $web_server_enabled, $dns_server_enabled, $file_server_enabled, $db_server_enabled, $server_ini_content, $current_db_version, $proxy_server_enabled, $firewall_server_enabled);
398400
$conf['server_id'] = $this->db->insertID();
399401
}
400-
401-
402402
}
403403

404404
public function detect_ips(){
@@ -2183,7 +2183,7 @@ public function install_ispconfig() {
21832183
// TODO: Implement a selector which modules and plugins shall be enabled.
21842184
$dir = $install_dir.'/server/mods-available/';
21852185
if (is_dir($dir)) {
2186-
if ($dh = opendir($dir)) {
2186+
if (($dh = opendir($dir))) {
21872187
while (($file = readdir($dh)) !== false) {
21882188
if($file != '.' && $file != '..' && substr($file, -8, 8) == '.inc.php') {
21892189
include_once $install_dir.'/server/mods-available/'.$file;
@@ -2210,7 +2210,7 @@ public function install_ispconfig() {
22102210

22112211
$dir = $install_dir.'/server/plugins-available/';
22122212
if (is_dir($dir)) {
2213-
if ($dh = opendir($dir)) {
2213+
if (($dh = opendir($dir))) {
22142214
while (($file = readdir($dh)) !== false) {
22152215
if($conf['apache']['installed'] == true && $file == 'nginx_plugin.inc.php') continue;
22162216
if($conf['nginx']['installed'] == true && $file == 'apache2_plugin.inc.php') continue;
@@ -2828,7 +2828,7 @@ protected function insert_db_credentials($tContents) {
28282828
}
28292829

28302830
private function loadAddonClasses($path) {
2831-
$libpath = $conf['ispconfig_install_dir'] . '/addons';
2831+
$libpath = $path;
28322832
if(($dir = opendir($libpath))) {
28332833
while(false !== ($cur = readdir($dir))) {
28342834
if($cur === '.' || $cur === '..' || strpos($cur, '..') !== false || !is_dir($libpath . '/' . $cur)) {
@@ -2867,15 +2867,12 @@ public function raiseEvent($event_name) {
28672867
if(is_null($this->addon_classes)) {
28682868
// load addon libs
28692869
$this->addon_classes = array();
2870-
$addonpath = $conf['ispconfig_install_dir'] . '/addons';
2871-
$this->loadAddonClasses($addonpath);
28722870

2873-
// check for addon libs in install dir
2874-
$addonpath = realpath(dirname(__FILE__) . '/..') . '/addons';
2871+
$addonpath = $conf['ispconfig_install_dir'] . '/addons';
28752872
$this->loadAddonClasses($addonpath);
28762873
}
28772874

2878-
$call_method = 'onRaisedEvent';
2875+
$call_method = 'onRaisedInstallerEvent';
28792876
reset($this->addon_classes);
28802877
foreach($this->addon_classes as $cl) {
28812878
if(method_exists($cl, $call_method)) {

install/sql/incremental/upd_dev_collection.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,12 @@ UPDATE `spamfilter_policy` SET `rspamd_spam_kill_level` = '8.00' WHERE id = 6;
142142
UPDATE `spamfilter_policy` SET `rspamd_spam_kill_level` = '20.00' WHERE id = 7;
143143
-- end of rspamd
144144

145+
CREATE TABLE IF NOT EXISTS `addons` (
146+
`addon_id` int(11) NOT NULL AUTO_INCREMENT,
147+
`addon_ident` VARCHAR(100) NOT NULL DEFAULT '',
148+
`addon_version` VARCHAR(20) NOT NULL DEFAULT '',
149+
`addon_name` VARCHAR(255) NOT NULL DEFAULT '',
150+
`db_version` INT(6) NOT NULL DEFAULT '0',
151+
PRIMARY KEY (`addon_id`),
152+
UNIQUE KEY `ident` (`addon_ident`)
153+
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;

install/sql/ispconfig3.sql

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,22 @@ SET FOREIGN_KEY_CHECKS = 0;
5353
-- --------------------------------------------------------
5454
-- --------------------------------------------------------
5555

56+
--
57+
-- Table structure for table `addons`
58+
--
59+
60+
CREATE TABLE IF NOT EXISTS `addons` (
61+
`addon_id` int(11) NOT NULL AUTO_INCREMENT,
62+
`addon_ident` VARCHAR(100) NOT NULL DEFAULT '',
63+
`addon_version` VARCHAR(20) NOT NULL DEFAULT '',
64+
`addon_name` VARCHAR(255) NOT NULL DEFAULT '',
65+
`db_version` INT(6) NOT NULL DEFAULT '0',
66+
PRIMARY KEY (`addon_id`),
67+
UNIQUE KEY `ident` (`addon_ident`)
68+
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;
69+
70+
-- --------------------------------------------------------
71+
5672
--
5773
-- Table structure for table `aps_instances`
5874
--

install/update.php

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -148,45 +148,11 @@
148148
include_once 'dist/lib/'.$dist['id'].'.lib.php';
149149
include_once 'dist/conf/'.$dist['confid'].'.conf.php';
150150

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-
}
151+
$inst = new installer();
152+
if (!$inst->get_php_version()) die('ISPConfig requieres PHP '.$inst->min_php."\n");
153+
$inst->is_update = true;
170154

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-
}
155+
$inst->raiseEvent('set_dist_config', $dist);
190156

191157
//** tRNG dependencies
192158
$conf['tRNG']='';
@@ -228,10 +194,6 @@
228194
$conf['server_id'] = intval($conf_old["server_id"]);
229195
$conf['ispconfig_log_priority'] = $conf_old["log_priority"];
230196

231-
$inst = new installer();
232-
if (!$inst->get_php_version()) die('ISPConfig requieres PHP '.$inst->min_php."\n");
233-
$inst->is_update = true;
234-
235197
echo "This application will update ISPConfig 3 on your server.\n\n";
236198

237199
//* Make a backup before we start the update

interface/web/tools/resync.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,19 @@ function onSubmit() {
599599
}
600600
$msg .= '<br>';
601601
}
602+
603+
$entries = $app->plugin->raiseEvent('tools:resync:get_resync_entries', $this->dataRecord, true);
604+
if(is_array($entries) && !empty($entries)) {
605+
foreach($entries as $entry) {
606+
if(!isset($entry['db_table']) || !isset($entry['db_table']) || !isset($entry['db_table']) || !isset($entry['db_table']) || !isset($entry['db_table']) || !isset($entry['db_table'])) {
607+
continue;
608+
}
609+
if(!isset($entry['active'])) {
610+
$entry['active'] = true;
611+
}
612+
$msg .= $this->do_resync($entry['db_table'], $entry['index_field'], $entry['server_type'], $entry['server_id'], $entry['msg_field'], $entry['wordbook'], $entry['active']);
613+
}
614+
}
602615

603616
echo $msg;
604617
} //* end onSumbmit

interface/web/tools/templates/resync.htm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ <h1><tmpl_var name="list_head_txt"></h1>
122122
<div class="col-sm-3"><select name="firewall_server_id" id="firewall_server_id" class="form-control">{tmpl_var name='firewall_server_id'}</select></div>
123123
</div>
124124
</tmpl_if>
125+
126+
{tmpl_hook name="end_form"}
125127

126128
<div class="form-group">
127129
<label for="resync_client" class="col-sm-2 control-label control-label-plain">{tmpl_var name="resync_client_txt"}</label>

0 commit comments

Comments
 (0)