Skip to content

Commit e35182f

Browse files
author
Marius Burkard
committed
- added new hooks/actions/events for addons to hook into the core
- TODO: the server services plugin is not capable of enabling and disabling addon plugins, yet
1 parent c02b7e4 commit e35182f

20 files changed

+291
-261
lines changed

install/install.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@
211211
}
212212

213213
//** Detect the installed applications
214-
$this->call_hook('find_installed_apps', false);
214+
$inst->raiseEvent('find_installed_apps::before');
215215
$inst->find_installed_apps();
216-
$this->call_hook('find_installed_apps', true);
216+
$inst->raiseEvent('find_installed_apps::after');
217217

218218
//** Select the language and set default timezone
219219
$conf['language'] = $inst->simple_query('Select language', array('en', 'de'), 'en','language');
@@ -499,7 +499,7 @@
499499
}
500500
}
501501

502-
$inst->call_hook('configure_webserver_selection', true);
502+
$inst->raiseEvent('configure_webserver_selection::after');
503503

504504
if($install_mode == 'standard' || strtolower($inst->simple_query('Configure Firewall Server', array('y', 'n'), 'y','configure_firewall')) == 'y') {
505505
//* Check for Firewall
@@ -592,9 +592,9 @@
592592
$inst->install_ispconfig_interface = false;
593593
}
594594

595-
$inst->call_hook('install_ispconfig', false);
595+
$inst->raiseEvent('install_ispconfig::before');
596596
$inst->install_ispconfig();
597-
$inst->call_hook('install_ispconfig', true);
597+
$inst->raiseEvent('install_ispconfig::after');
598598

599599
//* Configure DBServer
600600
swriteln('Configuring DBServer');

install/lib/installer_base.lib.php

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2827,40 +2827,61 @@ protected function insert_db_credentials($tContents) {
28272827
return $tContents;
28282828
}
28292829

2830-
public function call_hook($hook_name, $after = true) {
2831-
if(is_null($this->addon_classes)) {
2832-
// load addon libs
2833-
$this->addon_classes = array();
2834-
$libpath = realpath(dirname(__FILE__).'/..') . '/lib.d';
2835-
if(($dir = opendir($libpath))) {
2836-
while(false !== ($cur = readdir($dir))) {
2837-
if(strpos($cur, '..') !== false || !is_file($libpath . '/' . $cur) || substr($cur, -8) !== '.lib.php') {
2838-
continue;
2839-
}
2840-
$class_name = substr($cur, 0, -8) . '_addon_installer';
2841-
include_once $libpath . '/' . $cur;
2842-
if(!class_exists($class_name)) {
2843-
continue;
2844-
}
2845-
2846-
$this->addon_classes[] = new $class_name;
2830+
private function loadAddonClasses($path) {
2831+
$libpath = $conf['ispconfig_install_dir'] . '/addons';
2832+
if(($dir = opendir($libpath))) {
2833+
while(false !== ($cur = readdir($dir))) {
2834+
if($cur === '.' || $cur === '..' || strpos($cur, '..') !== false || !is_dir($libpath . '/' . $cur)) {
2835+
continue;
2836+
}
2837+
$addon_file = $libpath . '/' . $cur . '/' . $cur . '.addon.php';
2838+
if(!is_file($addon_file)) {
2839+
continue;
2840+
}
2841+
2842+
$class_name = $cur . '_addon_installer';
2843+
2844+
if(isset($this->addon_classes[$class_name]) && is_object($this->addon_classes[$class_name])) {
2845+
// don't override
2846+
continue;
2847+
}
2848+
2849+
include_once $addon_file;
2850+
if(!class_exists($class_name)) {
2851+
continue;
2852+
}
2853+
2854+
if(!is_array($this->addon_classes)) {
2855+
$this->addon_classes = array();
28472856
}
2848-
closedir($dir);
2857+
2858+
$this->addon_classes[$class_name] = new $class_name;
28492859
}
2860+
closedir($dir);
28502861
}
2862+
}
2863+
2864+
public function raiseEvent($event_name) {
2865+
global $conf;
28512866

2852-
$call_method = 'onBefore';
2853-
if($after === true) {
2854-
$call_method = 'onAfter';
2867+
if(is_null($this->addon_classes)) {
2868+
// load addon libs
2869+
$this->addon_classes = array();
2870+
$addonpath = $conf['ispconfig_install_dir'] . '/addons';
2871+
$this->loadAddonClasses($addonpath);
2872+
2873+
// check for addon libs in install dir
2874+
$addonpath = realpath(dirname(__FILE__) . '/..') . '/addons';
2875+
$this->loadAddonClasses($addonpath);
28552876
}
2877+
2878+
$call_method = 'onRaisedEvent';
28562879
reset($this->addon_classes);
28572880
foreach($this->addon_classes as $cl) {
28582881
if(method_exists($cl, $call_method)) {
2859-
call_user_func(array($cl, $call_method), $hook_name);
2882+
call_user_func(array($cl, $call_method), $event_name);
28602883
}
28612884
}
28622885
}
28632886

28642887
}
2865-
2866-
?>

install/lib/update.lib.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -434,11 +434,16 @@ function setDefaultServers(){
434434
* @param $servicename string the name of the Database-Field in "servers" for this service
435435
* @param $detected_value boolean The result of service detection
436436
*/
437-
function check_service_config_state($servicename, $detected_value) {
438-
global $current_svc_config, $inst, $conf;
437+
function check_service_config_state($servicename, $detected_value, $use_current_config = null) {
438+
global $current_svc_config, $inst;
439439

440-
if ($current_svc_config[$servicename] == 1) $current_state = 1;
441-
else $current_state = 0;
440+
if(is_array($use_current_config)) {
441+
if ($use_current_config[$servicename] == 1) $current_state = 1;
442+
else $current_state = 0;
443+
} else {
444+
if ($current_svc_config[$servicename] == 1) $current_state = 1;
445+
else $current_state = 0;
446+
}
442447

443448
if ($detected_value) $detected_value = 1;
444449
else $detected_value = 0;

install/update.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,9 @@
340340
/*
341341
* dump the new Database and reconfigure the server.ini
342342
*/
343-
$inst->call_hook('updateDbAndIni', false);
343+
$inst->raiseEvent('updateDbAndIni::before');
344344
updateDbAndIni();
345-
$inst->call_hook('updateDbAndIni', true);
345+
$inst->raiseEvent('updateDbAndIni::after');
346346

347347
//** read server config from db into $conf['server_config']
348348
$tmp = $inst->db->queryOneRecord("SELECT config FROM ?? WHERE server_id = ?", $conf["mysql"]["database"] . '.server', $conf['server_id']);
@@ -364,11 +364,12 @@
364364
//}
365365

366366
//** Detect the installed applications
367-
$this->call_hook('find_installed_apps', false);
367+
$inst->raiseEvent('find_installed_apps::before');
368368
$inst->find_installed_apps();
369-
$this->call_hook('find_installed_apps', true);
369+
$inst->raiseEvent('find_installed_apps::after');
370370

371371
//** Check for current service config state and compare to our results
372+
$inst->raiseEvent('check_service_config_state::before');
372373
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']);
373374
else $current_svc_config = $inst->db->queryOneRecord("SELECT mail_server,web_server,dns_server,firewall_server,db_server FROM ?? WHERE server_id=?", $conf["mysql"]["database"] . '.server', $conf['server_id']);
374375
$conf['services']['mail'] = check_service_config_state('mail_server', $conf['postfix']['installed']);
@@ -377,6 +378,7 @@
377378
$conf['services']['firewall'] = check_service_config_state('firewall_server', ($conf['ufw']['installed'] || $conf['firewall']['installed']));
378379
$conf['services']['db'] = check_service_config_state('db_server', true); /* Will always offer as MySQL is of course installed on this host as it's a requirement for ISPC to work... */
379380
unset($current_svc_config);
381+
$inst->raiseEvent('check_service_config_state::after');
380382

381383
//** Write new decisions into DB
382384
$sql = "UPDATE ?? SET mail_server = '{$conf['services']['mail']}', web_server = '{$conf['services']['web']}', dns_server = '{$conf['services']['dns']}', file_server = '{$conf['services']['file']}', db_server = '{$conf['services']['db']}', proxy_server = '{$conf['services']['proxy']}', firewall_server = '$firewall_server_enabled' WHERE server_id = ?";
@@ -539,7 +541,9 @@
539541
}
540542
}
541543

544+
$inst->raiseEvent('install_ispconfig::before');
542545
$inst->install_ispconfig();
546+
$inst->raiseEvent('install_ispconfig::after');
543547

544548
// Cleanup
545549
$inst->cleanup_ispconfig();

interface/lib/classes/functions.inc.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,12 @@ public function suggest_ips($type = 'IPv4'){
253253
}
254254
}
255255
}
256+
257+
$tmp_ips = $app->plugin->raiseEvent('get_server_ips', 0, true);
258+
if(is_array($tmp_ips) && !empty($tmp_ips)) {
259+
$ips = array_merge($ips, $tmp_ips);
260+
}
261+
256262

257263
$results = $groupid != 1 ? $app->db->queryAllRecords("SELECT database_name as name,remote_ips as ip FROM web_database WHERE remote_ips != '' AND sys_groupid = ?", $groupid) : $results = $app->db->queryAllRecords("SELECT database_name as name,remote_ips as ip FROM web_database WHERE remote_ips != ''");
258264

interface/lib/classes/listform.inc.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,70 @@ public function loadListDef($file, $module = '')
6666

6767
$this->wordbook = $wb;
6868

69+
$module = (isset($_SESSION['s']['module']['name']) ? $_SESSION['s']['module']['name'] : '');
70+
71+
// load wordbook/lang files from addons
72+
if($module == '') {
73+
$lng_path = 'lib/lang.d';
74+
} else {
75+
$lng_path = '../' . $module . '/lib/lang.d';
76+
}
77+
if(($dir = opendir($lng_path))) {
78+
$fallback_files = array();
79+
$use_files = array();
80+
while(false !== ($cur = readdir($dir))) {
81+
$lng_file = $lng_path . '/' . $cur;
82+
if(is_file($lng_file) && substr($cur, -strlen('.'.$app->listform->listDef["name"].".lng")) === '.'.$app->listform->listDef["name"].".lng") {
83+
if(substr($cur, 0, 3) === 'en_') {
84+
$fallback_files[] = $cur;
85+
} elseif(substr($cur, 0, 3) === $app->functions->check_language($_SESSION["s"]["language"]) . '_') {
86+
$use_files[] = $cur;
87+
}
88+
}
89+
}
90+
closedir($dir);
91+
92+
foreach($fallback_files as $cur) {
93+
$cur_lng = $app->functions->check_language($_SESSION["s"]["language"]) . '_' . substr($cur, 3);
94+
if(in_array($cur_lng, $use_files, true) == false) {
95+
$use_files[] = $cur;
96+
}
97+
}
98+
unset($fallback_files);
99+
100+
reset($use_files);
101+
foreach($use_files as $cur) {
102+
$lng_file = $lng_path . '/' . $cur;
103+
104+
include $lng_file;
105+
if(isset($wb) && is_array($wb)) {
106+
$this->wordbook = $app->functions->array_merge($this->wordbook, $wb);
107+
}
108+
}
109+
unset($use_files);
110+
}
111+
112+
113+
if($module) {
114+
// load list files from addons
115+
$listform_path = '../' . $module . '/lib/form.d';
116+
if(($dir = opendir($listform_path))) {
117+
$items = null;
118+
while(false !== ($cur = readdir($dir))) {
119+
$listform_file = $listform_path . '/' . $cur;
120+
if(is_file($listform_file) && substr($cur, -strlen('.'.$app->listform->listDef["name"].".list.php")) === '.'.$app->listform->listDef["name"].".list.php") {
121+
unset($items); // just in case someone does not create a new array in the list file
122+
include($listform_file);
123+
if(isset($items) && is_array($items) && !empty($items)) {
124+
$this->listDef['item'] = array_merge($this->listDef['item'], $items);
125+
}
126+
}
127+
}
128+
closedir($dir);
129+
}
130+
}
131+
132+
69133
return true;
70134
}
71135

interface/lib/classes/plugin.inc.php

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,35 @@ public function raiseEvent($event_name, $data, $return_data = false) {
124124
$tmp_event = $sub_events[2];
125125
if($this->debug) $app->log("Called Event '$tmp_event'", LOGLEVEL_DEBUG);
126126
$tmpresult = $this->callPluginEvent($tmp_event, $data, $return_data);
127-
if($return_data == true && $tmpresult) $result .= $tmpresult;
127+
if($return_data == true && $tmpresult) {
128+
if(is_array($tmpresult) && (!$result || is_array($result))) {
129+
$result = array_merge($result, $tmpresult);
130+
} elseif(!is_array($tmpresult)) {
131+
$result .= $tmpresult;
132+
}
133+
}
128134

129135
$tmp_event = $sub_events[0].':'.$sub_events[2];
130136
if($this->debug) $app->log("Called Event '$tmp_event'", LOGLEVEL_DEBUG);
131137
$tmpresult = $this->callPluginEvent($tmp_event, $data, $return_data);
132-
if($return_data == true && $tmpresult) $result .= $tmpresult;
138+
if($return_data == true && $tmpresult) {
139+
if(is_array($tmpresult) && (!$result || is_array($result))) {
140+
$result = array_merge($result, $tmpresult);
141+
} elseif(!is_array($tmpresult)) {
142+
$result .= $tmpresult;
143+
}
144+
}
133145

134146
$tmp_event = $sub_events[0].':'.$sub_events[1].':'.$sub_events[2];
135147
if($this->debug) $app->log("Called Event '$tmp_event'", LOGLEVEL_DEBUG);
136148
$tmpresult = $this->callPluginEvent($tmp_event, $data, $return_data);
137-
if($return_data == true && $tmpresult) $result .= $tmpresult;
149+
if($return_data == true && $tmpresult) {
150+
if(is_array($tmpresult) && (!$result || is_array($result))) {
151+
$result = array_merge($result, $tmpresult);
152+
} elseif(!is_array($tmpresult)) {
153+
$result .= $tmpresult;
154+
}
155+
}
138156

139157
/*$sub_events = array_reverse($sub_events);
140158
$tmp_event = '';
@@ -147,7 +165,13 @@ public function raiseEvent($event_name, $data, $return_data = false) {
147165
} else {
148166
if($this->debug) $app->log("Called Event '$sub_events[0]'", LOGLEVEL_DEBUG);
149167
$tmpresult = $this->callPluginEvent($sub_events[0], $data, $return_data);
150-
if($return_data == true && $tmpresult) $result .= $tmpresult;
168+
if($return_data == true && $tmpresult) {
169+
if(is_array($tmpresult) && (!$result || is_array($result))) {
170+
$result = array_merge($result, $tmpresult);
171+
} elseif(!is_array($tmpresult)) {
172+
$result .= $tmpresult;
173+
}
174+
}
151175
}
152176
}
153177

@@ -187,7 +211,13 @@ private function callPluginEvent($event_name, $data, $return_data = false) {
187211
// call_user_method($function_name,$app->loaded_plugins[$plugin_name],$event_name,$data);
188212

189213
$tmpresult = call_user_func(array($app->loaded_plugins[$plugin_name], $function_name), $event_name, $data);
190-
if($return_data == true && $tmpresult) $result .= $tmpresult;
214+
if($return_data == true && $tmpresult) {
215+
if(is_array($tmpresult) && (!$result || is_array($result))) {
216+
$result = array_merge($result, $tmpresult);
217+
} elseif(!is_array($tmpresult)) {
218+
$result .= $tmpresult;
219+
}
220+
}
191221
}
192222
}
193223

interface/lib/classes/remote.d/server.inc.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ public function server_get_serverid_by_name($session_id, $server_name)
203203
global $app;
204204
if(!$this->checkPerm($session_id, 'server_get')) {
205205
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
206-
return false;
207206
}
208207
if (!empty($session_id) && !empty($server_name)) {
209208
$sql = "SELECT server_id FROM server WHERE server_name = ?";
@@ -225,12 +224,22 @@ public function server_get_functions($session_id, $server_id)
225224
global $app;
226225
if(!$this->checkPerm($session_id, 'server_get')) {
227226
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
228-
return false;
229227
}
230228
if (!empty($session_id) && !empty($server_id)) {
231-
$sql = "SELECT mail_server, web_server, dns_server, file_server, db_server, proxy_server, firewall_server, mirror_server_id FROM server WHERE server_id = ?";
229+
$sql = "SELECT * FROM server WHERE server_id = ?";
232230
$all = $app->db->queryOneRecord($sql, $server_id);
233-
return $all;
231+
if(empty($all)) return false;
232+
233+
$func = array();
234+
foreach($all as $key => $value) {
235+
if($key === 'mirror_server_id' || substr($key, -7) === '_server') {
236+
if($value == 0 || $value == 1) {
237+
$func[$key] = $value;
238+
}
239+
}
240+
}
241+
242+
return $func;
234243
} else {
235244
return false;
236245
}
@@ -241,7 +250,6 @@ public function server_get_app_version($session_id, $server_id = 0)
241250
global $app;
242251
if(!$this->checkPerm($session_id, 'server_get')) {
243252
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
244-
return false;
245253
}
246254
if (!empty($session_id)) {
247255
if($server_id == 0) $ispc_app_version = array('ispc_app_version' => ISPC_APP_VERSION);

0 commit comments

Comments
 (0)