Skip to content

Commit 00fad68

Browse files
committed
Added basic module processing to the server part.
1 parent 45f11e2 commit 00fad68

File tree

4 files changed

+240
-39
lines changed

4 files changed

+240
-39
lines changed

config/amavis/amavis_sql.conf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
$sql_select_policy =
2+
'SELECT *,spamfilter_users.id'.
3+
' FROM spamfilter_users LEFT JOIN spamfilter_policy ON spamfilter_users.policy_id=spamfilter_policy.id'.
4+
' WHERE spamfilter_users.email IN (%k) ORDER BY spamfilter_users.priority DESC';
5+
6+
7+
$sql_select_white_black_list = 'SELECT wb FROM spamfilter_wblist'.
8+
' WHERE (spamfilter_wblist.rid=?) AND (spamfilter_wblist.email IN (%k))' .
9+
' ORDER BY spamfilter_wblist.priority DESC';

server/lib/classes/modules.inc.php

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php
2+
3+
/*
4+
Copyright (c) 2007, Till Brehm, projektfarm Gmbh
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without modification,
8+
are permitted provided that the following conditions are met:
9+
10+
* Redistributions of source code must retain the above copyright notice,
11+
this list of conditions and the following disclaimer.
12+
* Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
* Neither the name of ISPConfig nor the names of its contributors
16+
may be used to endorse or promote products derived from this software without
17+
specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22+
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
class modules {
32+
33+
var $notification_hooks = array();
34+
35+
/*
36+
This function is called to load the modules from the mods-available folder
37+
*/
38+
39+
function loadModules() {
40+
global $app;
41+
42+
}
43+
44+
/*
45+
This function is called by the modules to register for a specific
46+
table change notification
47+
*/
48+
49+
function registerTableHook($table_name,$module_name,$function_name) {
50+
$this->notification_hooks[$table_name][] = array('module' => $module_name, 'function' => $function_name);
51+
}
52+
53+
/*
54+
This function goes through all new records in the
55+
sys_datalog table and and calls the function in the
56+
modules that hooked on to the table change.
57+
*/
58+
59+
function processDatalog() {
60+
global $app;
61+
62+
// TODO: process only new entries.
63+
$sql = "SELECT * FROM sys_datalog WHERE 1";
64+
$records = $app->db->queryAllRecords($sql);
65+
foreach($records as $rec) {
66+
$data = unserialize(stripslashes($rec["data"]));
67+
$this->raiseTableHook($rec["dbtable"],$rec["action"],$data);
68+
}
69+
}
70+
71+
function raiseTableHook($table_name,$action,$data) {
72+
global $app;
73+
74+
// Get the hooks for this table
75+
$hooks = $this->notification_hooks[$table_name];
76+
77+
if(is_array($hooks)) {
78+
foreach($hooks as $hook) {
79+
$module_name = $hook["module"];
80+
$function_name = $hook["function"];
81+
// Claa the processing function of the module
82+
call_user_method($function_name,$app->$module_name,$table_name,$action,$data);
83+
unset($module_name);
84+
unset($function_name);
85+
}
86+
}
87+
unset($hook);
88+
unset($hooks);
89+
}
90+
91+
}
92+
93+
?>
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<?php
2+
3+
/*
4+
Copyright (c) 2007, Till Brehm, projektfarm Gmbh
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without modification,
8+
are permitted provided that the following conditions are met:
9+
10+
* Redistributions of source code must retain the above copyright notice,
11+
this list of conditions and the following disclaimer.
12+
* Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
* Neither the name of ISPConfig nor the names of its contributors
16+
may be used to endorse or promote products derived from this software without
17+
specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22+
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
class mail_module {
32+
33+
var $module_name = 'mail';
34+
var $class_name = 'mail_module';
35+
var $actions_available = array( 'mail_domain_insert',
36+
'mail_domain_update',
37+
'mail_domain_delete',
38+
'mail_user_insert',
39+
'mail_user_update',
40+
'mail_user_delete',
41+
'mail_access_insert',
42+
'mail_access_update',
43+
'mail_access_delete',
44+
'mail_forwarding_insert',
45+
'mail_forwarding_update',
46+
'mail_forwarding_delete',
47+
'mail_transport_insert',
48+
'mail_transport_update',
49+
'mail_transport_delete');
50+
51+
/*
52+
This function is called when the module is loaded
53+
*/
54+
55+
function onLoad() {
56+
57+
/*
58+
Annonce the actions that where provided by this module, so plugins
59+
can register on them.
60+
*/
61+
62+
$app->plugins->registerEvents($this->module_name,$this->actions_available);
63+
64+
/*
65+
As we want to get notified of any changes on several database tables,
66+
we register for them.
67+
68+
The following function registers the function "functionname"
69+
to be executed when a record for the table "dbtable" is
70+
processed in the sys_datalog. "classname" is the name of the
71+
class that contains the function functionname.
72+
*/
73+
74+
$app->modules->registerTableHook('mail_access','mail_module','process');
75+
$app->modules->registerTableHook('mail_domain','mail_module','process');
76+
$app->modules->registerTableHook('mail_forwarding','mail_module','process');
77+
$app->modules->registerTableHook('mail_transport','mail_module','process');
78+
$app->modules->registerTableHook('mail_user','mail_module','process');
79+
80+
}
81+
82+
/*
83+
This function is called when a change in one of the registered tables is detected.
84+
The function then raises the events for the plugins.
85+
*/
86+
87+
function process($tablename,$action,$data) {
88+
global $app;
89+
90+
switch ($tablename) {
91+
case 'mail_access':
92+
if($action == 'i') $app->plugins->raiseEvent('mail_access_insert',$data);
93+
if($action == 'u') $app->plugins->raiseEvent('mail_access_update',$data);
94+
if($action == 'd') $app->plugins->raiseEvent('mail_access_delete',$data);
95+
break;
96+
case 'mail_domain':
97+
if($action == 'i') $app->plugins->raiseEvent('mail_domain_insert',$data);
98+
if($action == 'u') $app->plugins->raiseEvent('mail_domain_update',$data);
99+
if($action == 'd') $app->plugins->raiseEvent('mail_domain_delete',$data);
100+
break;
101+
case 'mail_forwarding':
102+
if($action == 'i') $app->plugins->raiseEvent('mail_forwarding_insert',$data);
103+
if($action == 'u') $app->plugins->raiseEvent('mail_forwarding_update',$data);
104+
if($action == 'd') $app->plugins->raiseEvent('mail_forwarding_delete',$data);
105+
break;
106+
case 'mail_transport':
107+
if($action == 'i') $app->plugins->raiseEvent('mail_transport_insert',$data);
108+
if($action == 'u') $app->plugins->raiseEvent('mail_transport_update',$data);
109+
if($action == 'd') $app->plugins->raiseEvent('mail_transport_delete',$data);
110+
break;
111+
case 'mail_user':
112+
if($action == 'i') $app->plugins->raiseEvent('mail_user_insert',$data);
113+
if($action == 'u') $app->plugins->raiseEvent('mail_user_update',$data);
114+
if($action == 'd') $app->plugins->raiseEvent('mail_user_delete',$data);
115+
break;
116+
} // end switch
117+
} // end function
118+
119+
} // end class
120+
121+
?>

server/server.php

Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/*
4-
Copyright (c) 2006, Till Brehm, projektfarm Gmbh
4+
Copyright (c) 2007, Till Brehm, projektfarm Gmbh
55
All rights reserved.
66
77
Redistribution and use in source and binary forms, with or without modification,
@@ -62,52 +62,30 @@
6262
@touch($conf["temppath"].$conf["fs_div"].".ispconfig_lock");
6363
$app->log("Set Lock: ".$conf["temppath"].$conf["fs_div"].".ispconfig_lock");
6464

65+
// Load required base-classes
66+
$this->uses('ini_parser,modules,plugins');
67+
6568
// Get server configuration
66-
$this->uses('ini_parser');
6769
$conf["serverconfig"] = $app->ini_parser->parse_ini_string(stripslashes($server_db_record["config"]));
6870

69-
// Run the configuration modules
70-
if($server_db_record["mail_server"] == 1) {
71-
$app->load('mod_mail_base');
72-
$mail_module_name = 'mod_mail_'.$conf["serverconfig"]["mail"]["module"];
73-
$app->uses($mail_module_name);
74-
$app->$mail_module_name->write_config();
75-
}
71+
/*
72+
Load the modules that are im the mods-enabled folder
73+
*/
7674

77-
if($server_db_record["web_server"] == 1) {
78-
$app->load('mod_web_base');
79-
$web_module_name = 'mod_web_'.$conf["serverconfig"]["web"]["module"];
80-
$app->uses($web_module_name);
81-
$app->$web_module_name->write_config();
82-
}
75+
$this->modules->loadModules();
8376

84-
if($server_db_record["dns_server"] == 1) {
85-
$app->load('mod_dns_base');
86-
$dns_module_name = 'mod_dns_'.$conf["serverconfig"]["dns"]["module"];
87-
$app->uses($dns_module_name);
88-
$app->$dns_module_name->write_config();
89-
}
9077

91-
if($server_db_record["file_server"] == 1) {
92-
$app->load('mod_file_base');
93-
$file_module_name = 'mod_file_'.$conf["serverconfig"]["file"]["module"];
94-
$app->uses($file_module_name);
95-
$app->$file_module_name->write_config();
96-
}
78+
/*
79+
Load the plugins that are in the plugins-enabled folder
80+
*/
9781

98-
if($server_db_record["db_server"] == 1) {
99-
$app->load('mod_db_base');
100-
$db_module_name = 'mod_db_'.$conf["serverconfig"]["db"]["module"];
101-
$app->uses($db_module_name);
102-
$app->$db_module_name->write_config();
103-
}
82+
$this->plugins->loadPlugins();
10483

105-
if($server_db_record["vserver_server"] == 1) {
106-
$app->load('mod_vserver_base');
107-
$vserver_module_name = 'mod_vserver_'.$conf["serverconfig"]["vserver"]["module"];
108-
$app->uses($vserver_module_name);
109-
$app->$vserver_module_name->write_config();
110-
}
84+
/*
85+
Go trough the sys_datalog table and call the processing functions
86+
in the modules that are hooked on to the table actions
87+
*/
88+
$this->modules->processDatalog();
11189

11290
// Remove lock
11391
@unlink($conf["temppath"].$conf["fs_div"].".ispconfig_lock");

0 commit comments

Comments
 (0)