commit | author | age
|
532ae5
|
1 |
<?php |
L |
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 mailman_plugin { |
7fe908
|
32 |
|
532ae5
|
33 |
var $plugin_name = 'mailman_plugin'; |
L |
34 |
var $class_name = 'mailman_plugin'; |
7fe908
|
35 |
|
MC |
36 |
|
532ae5
|
37 |
var $mailman_config_dir = '/etc/mailman/'; |
7fe908
|
38 |
|
532ae5
|
39 |
//* This function is called during ispconfig installation to determine |
L |
40 |
// if a symlink shall be created for this plugin. |
|
41 |
function onInstall() { |
|
42 |
global $conf; |
7fe908
|
43 |
|
532ae5
|
44 |
if($conf['services']['mail'] == true) { |
L |
45 |
return true; |
|
46 |
} else { |
|
47 |
return false; |
|
48 |
} |
7fe908
|
49 |
|
532ae5
|
50 |
} |
7fe908
|
51 |
|
532ae5
|
52 |
/* |
L |
53 |
This function is called when the plugin is loaded |
|
54 |
*/ |
7fe908
|
55 |
|
532ae5
|
56 |
function onLoad() { |
L |
57 |
global $app; |
7fe908
|
58 |
|
532ae5
|
59 |
/* |
L |
60 |
Register for the events |
|
61 |
*/ |
7fe908
|
62 |
|
MC |
63 |
$app->plugins->registerEvent('mail_mailinglist_insert', 'mailman_plugin', 'insert'); |
|
64 |
$app->plugins->registerEvent('mail_mailinglist_update', 'mailman_plugin', 'update'); |
|
65 |
$app->plugins->registerEvent('mail_mailinglist_delete', 'mailman_plugin', 'delete'); |
|
66 |
|
|
67 |
|
|
68 |
|
532ae5
|
69 |
} |
7fe908
|
70 |
|
MC |
71 |
function insert($event_name, $data) { |
532ae5
|
72 |
global $app, $conf; |
7fe908
|
73 |
|
532ae5
|
74 |
$this->update_config(); |
7fe908
|
75 |
|
26c0fc
|
76 |
exec("nohup /usr/lib/mailman/bin/newlist -u ".escapeshellcmd($data["new"]["domain"])." -e ".escapeshellcmd($data["new"]["domain"])." ".escapeshellcmd($data["new"]["listname"])." ".escapeshellcmd($data["new"]["email"])." ".escapeshellcmd($data["new"]["password"])." >/dev/null 2>&1 &"); |
3f478f
|
77 |
if(is_file('/var/lib/mailman/data/virtual-mailman')) exec('postmap /var/lib/mailman/data/virtual-mailman'); |
d22542
|
78 |
if(is_file('/var/lib/mailman/data/transport-mailman')) exec('postmap /var/lib/mailman/data/transport-mailman'); |
26c0fc
|
79 |
exec('nohup '.$conf['init_scripts'] . '/' . 'mailman reload >/dev/null 2>&1 &'); |
7fe908
|
80 |
|
cc7a82
|
81 |
$app->db->query("UPDATE mail_mailinglist SET password = '' WHERE mailinglist_id = ?", $data["new"]['mailinglist_id']); |
7fe908
|
82 |
|
532ae5
|
83 |
} |
7fe908
|
84 |
|
532ae5
|
85 |
// The purpose of this plugin is to rewrite the main.cf file |
7fe908
|
86 |
function update($event_name, $data) { |
532ae5
|
87 |
global $app, $conf; |
d22542
|
88 |
|
TB |
89 |
$this->update_config(); |
7fe908
|
90 |
|
5378e9
|
91 |
if($data["new"]["password"] != $data["old"]["password"] && $data["new"]["password"] != '') { |
26c0fc
|
92 |
exec("nohup /usr/lib/mailman/bin/change_pw -l ".escapeshellcmd($data["new"]["listname"])." -p ".escapeshellcmd($data["new"]["password"])." >/dev/null 2>&1 &"); |
T |
93 |
exec('nohup '.$conf['init_scripts'] . '/' . 'mailman reload >/dev/null 2>&1 &'); |
cc7a82
|
94 |
$app->db->query("UPDATE mail_mailinglist SET password = '' WHERE mailinglist_id = ?", $data["new"]['mailinglist_id']); |
5378e9
|
95 |
} |
d22542
|
96 |
|
TB |
97 |
if(is_file('/var/lib/mailman/data/virtual-mailman')) exec('postmap /var/lib/mailman/data/virtual-mailman'); |
|
98 |
if(is_file('/var/lib/mailman/data/transport-mailman')) exec('postmap /var/lib/mailman/data/transport-mailman'); |
532ae5
|
99 |
} |
7fe908
|
100 |
|
MC |
101 |
function delete($event_name, $data) { |
532ae5
|
102 |
global $app, $conf; |
7fe908
|
103 |
|
532ae5
|
104 |
$this->update_config(); |
7fe908
|
105 |
|
26c0fc
|
106 |
exec("nohup /usr/lib/mailman/bin/rmlist -a ".escapeshellcmd($data["old"]["listname"])." >/dev/null 2>&1 &"); |
7fe908
|
107 |
|
26c0fc
|
108 |
exec('nohup '.$conf['init_scripts'] . '/' . 'mailman reload >/dev/null 2>&1 &'); |
d22542
|
109 |
|
TB |
110 |
if(is_file('/var/lib/mailman/data/virtual-mailman')) exec('postmap /var/lib/mailman/data/virtual-mailman'); |
|
111 |
if(is_file('/var/lib/mailman/data/transport-mailman')) exec('postmap /var/lib/mailman/data/transport-mailman'); |
7fe908
|
112 |
|
532ae5
|
113 |
} |
7fe908
|
114 |
|
532ae5
|
115 |
function update_config() { |
L |
116 |
global $app, $conf; |
7fe908
|
117 |
|
86e699
|
118 |
copy($this->mailman_config_dir.'mm_cfg.py', $this->mailman_config_dir.'mm_cfg.py~'); |
7fe908
|
119 |
|
532ae5
|
120 |
// load the server configuration options |
L |
121 |
$app->uses('getconf'); |
|
122 |
$server_config = $app->getconf->get_server_config($conf['server_id'], 'server'); |
7fe908
|
123 |
|
532ae5
|
124 |
// load files |
02bf99
|
125 |
if(file_exists($conf["rootpath"]."/conf-custom/mm_cfg.py.master")) { |
355efb
|
126 |
$content = file_get_contents($conf["rootpath"]."/conf-custom/mm_cfg.py.master"); |
T |
127 |
} else { |
|
128 |
$content = file_get_contents($conf["rootpath"]."/conf/mm_cfg.py.master"); |
|
129 |
} |
532ae5
|
130 |
$old_file = file_get_contents($this->mailman_config_dir."/mm_cfg.py"); |
7fe908
|
131 |
|
532ae5
|
132 |
$old_options = array(); |
7fe908
|
133 |
$lines = explode("\n", $old_file); |
532ae5
|
134 |
foreach ($lines as $line) |
L |
135 |
{ |
|
136 |
if (strlen($line) && substr($line, 0, 1) != '#') |
|
137 |
{ |
|
138 |
list($key, $value) = explode("=", $line); |
86e699
|
139 |
if ($value && $value !== '') |
532ae5
|
140 |
{ |
L |
141 |
$key = rtrim($key); |
|
142 |
$old_options[$key] = trim($value); |
|
143 |
} |
|
144 |
} |
|
145 |
} |
7fe908
|
146 |
|
532ae5
|
147 |
// create virtual_domains list |
L |
148 |
$domainAll = $app->db->queryAllRecords("SELECT domain FROM mail_mailinglist GROUP BY domain"); |
|
149 |
$virtual_domains = ''; |
|
150 |
foreach($domainAll as $domain) |
|
151 |
{ |
|
152 |
if ($domainAll[0]['domain'] == $domain['domain']) |
|
153 |
$virtual_domains .= "'".$domain['domain']."'"; |
|
154 |
else |
|
155 |
$virtual_domains .= ", '".$domain['domain']."'"; |
|
156 |
} |
7fe908
|
157 |
|
532ae5
|
158 |
$content = str_replace('{hostname}', $server_config['hostname'], $content); |
L |
159 |
$content = str_replace('{default_language}', $old_options['DEFAULT_SERVER_LANGUAGE'], $content); |
|
160 |
$content = str_replace('{virtual_domains}', $virtual_domains, $content); |
7fe908
|
161 |
|
532ae5
|
162 |
file_put_contents($this->mailman_config_dir."/mm_cfg.py", $content); |
L |
163 |
} |
|
164 |
|
|
165 |
} // end class |
|
166 |
|
|
167 |
?> |