commit | author | age
|
20218c
|
1 |
<?php |
M |
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 |
|
b1a6a5
|
31 |
class installer extends installer_base |
cb8c86
|
32 |
{ |
W |
33 |
public function configure_jailkit() |
b1a6a5
|
34 |
{ |
MC |
35 |
global $conf; |
|
36 |
|
cb8c86
|
37 |
if (is_dir($conf['jailkit']['config_dir'])) |
W |
38 |
{ |
ff1d9a
|
39 |
$jkinit_content = $this->get_template_file($conf['jailkit']['jk_init'], true); //* get contents |
cb8c86
|
40 |
$this->write_config_file($conf['jailkit']['config_dir'] . '/' . $conf['jailkit']['jk_init'], $jkinit_content); |
b1a6a5
|
41 |
|
ff1d9a
|
42 |
$jkchroot_content = $this->get_template_file($conf['jailkit']['jk_chrootsh'], true); //* get contents |
cb8c86
|
43 |
$this->write_config_file($conf['jailkit']['config_dir'] . '/' . $conf['jailkit']['jk_chrootsh'], $jkchroot_content); |
W |
44 |
} |
b1a6a5
|
45 |
|
ff1d9a
|
46 |
$command = 'chown root:root /var/www'; |
W |
47 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
b1a6a5
|
48 |
} |
MC |
49 |
|
cb8c86
|
50 |
public function configure_postfix($options = '') |
b1a6a5
|
51 |
{ |
b51c22
|
52 |
global $conf,$autoinstall; |
b1a6a5
|
53 |
|
MC |
54 |
$cf = $conf['postfix']; |
cb8c86
|
55 |
$config_dir = $cf['config_dir']; |
b1a6a5
|
56 |
|
cb8c86
|
57 |
if(!is_dir($config_dir)){ |
b1a6a5
|
58 |
$this->error("The postfix configuration directory '$config_dir' does not exist."); |
MC |
59 |
} |
|
60 |
|
|
61 |
//* Install virtual mappings |
|
62 |
foreach (glob('tpl/mysql-virtual_*.master') as $filename) { |
|
63 |
$this->process_postfix_config( basename($filename, '.master') ); |
|
64 |
} |
|
65 |
|
ff1d9a
|
66 |
//* Changing mode and group of the new created config files. |
cb8c86
|
67 |
caselog('chmod o= '.$config_dir.'/mysql-virtual_*.cf* &> /dev/null', |
b1a6a5
|
68 |
__FILE__, __LINE__, 'chmod on mysql-virtual_*.cf*', 'chmod on mysql-virtual_*.cf* failed'); |
MC |
69 |
caselog('chgrp '.$cf['group'].' '.$config_dir.'/mysql-virtual_*.cf* &> /dev/null', |
|
70 |
__FILE__, __LINE__, 'chgrp on mysql-virtual_*.cf*', 'chgrp on mysql-virtual_*.cf* failed'); |
|
71 |
|
ff1d9a
|
72 |
//* Creating virtual mail user and group |
cb8c86
|
73 |
$command = 'groupadd -g '.$cf['vmail_groupid'].' '.$cf['vmail_groupname']; |
W |
74 |
if (!is_group($cf['vmail_groupname'])) { |
|
75 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
76 |
} |
20218c
|
77 |
|
cb8c86
|
78 |
$command = 'useradd -g '.$cf['vmail_groupname'].' -u '.$cf['vmail_userid'].' '.$cf['vmail_username'].' -d '.$cf['vmail_mailbox_base'].' -m'; |
W |
79 |
if (!is_user($cf['vmail_username'])) { |
b1a6a5
|
80 |
caselog("$command &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
cb8c86
|
81 |
} |
20218c
|
82 |
|
b67344
|
83 |
//* These postconf commands will be executed on installation and update |
badfbe
|
84 |
$server_ini_rec = $this->db->queryOneRecord("SELECT config FROM ?? WHERE server_id = ?", $conf["mysql"]["database"].'.server', $conf['server_id']); |
20f478
|
85 |
$server_ini_array = ini_to_array(stripslashes($server_ini_rec['config'])); |
D |
86 |
unset($server_ini_rec); |
|
87 |
|
|
88 |
//* If there are RBL's defined, format the list and add them to smtp_recipient_restrictions to prevent removeal after an update |
|
89 |
$rbl_list = ''; |
|
90 |
if (@isset($server_ini_array['mail']['realtime_blackhole_list']) && $server_ini_array['mail']['realtime_blackhole_list'] != '') { |
|
91 |
$rbl_hosts = explode(",", str_replace(" ", "", $server_ini_array['mail']['realtime_blackhole_list'])); |
|
92 |
foreach ($rbl_hosts as $key => $value) { |
|
93 |
$rbl_list .= ", reject_rbl_client ". $value; |
|
94 |
} |
|
95 |
} |
|
96 |
unset($rbl_hosts); |
|
97 |
|
|
98 |
//* If Postgrey is installed, configure it |
|
99 |
$greylisting = ''; |
|
100 |
if($conf['postgrey']['installed'] == true) { |
|
101 |
$greylisting = ', check_recipient_access mysql:/etc/postfix/mysql-virtual_policy_greylist.cf'; |
|
102 |
} |
|
103 |
|
|
104 |
$reject_sender_login_mismatch = ''; |
|
105 |
if(isset($server_ini_array['mail']['reject_sender_login_mismatch']) && ($server_ini_array['mail']['reject_sender_login_mismatch'] == 'y')) { |
|
106 |
$reject_sender_login_mismatch = ', reject_authenticated_sender_login_mismatch'; |
|
107 |
} |
|
108 |
unset($server_ini_array); |
|
109 |
|
b1a6a5
|
110 |
$postconf_placeholders = array('{config_dir}' => $config_dir, |
MC |
111 |
'{vmail_mailbox_base}' => $cf['vmail_mailbox_base'], |
|
112 |
'{vmail_userid}' => $cf['vmail_userid'], |
|
113 |
'{vmail_groupid}' => $cf['vmail_groupid'], |
20f478
|
114 |
'{rbl_list}' => $rbl_list, |
D |
115 |
'{greylisting}' => $greylisting, |
|
116 |
'{reject_slm}' => $reject_sender_login_mismatch, |
|
117 |
); |
b1a6a5
|
118 |
|
MC |
119 |
$postconf_tpl = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/gentoo_postfix.conf.master', 'tpl/gentoo_postfix.conf.master'); |
|
120 |
$postconf_tpl = strtr($postconf_tpl, $postconf_placeholders); |
|
121 |
$postconf_commands = array_filter(explode("\n", $postconf_tpl)); // read and remove empty lines |
|
122 |
|
b67344
|
123 |
//* These postconf commands will be executed on installation only |
T |
124 |
if($this->is_update == false) { |
b1a6a5
|
125 |
$postconf_commands = array_merge($postconf_commands, array( |
MC |
126 |
'myhostname = '.$conf['hostname'], |
|
127 |
'mydestination = '.$conf['hostname'].', localhost, localhost.localdomain', |
|
128 |
'mynetworks = 127.0.0.0/8 [::1]/128' |
|
129 |
)); |
b67344
|
130 |
} |
b1a6a5
|
131 |
|
ff1d9a
|
132 |
//* Create the header and body check files |
cb8c86
|
133 |
touch($config_dir.'/header_checks'); |
W |
134 |
touch($config_dir.'/mime_header_checks'); |
|
135 |
touch($config_dir.'/nested_header_checks'); |
|
136 |
touch($config_dir.'/body_checks'); |
b1a6a5
|
137 |
|
MC |
138 |
|
ff1d9a
|
139 |
//* Make a backup copy of the main.cf file |
cb8c86
|
140 |
copy($config_dir.'/main.cf', $config_dir.'/main.cf~'); |
b1a6a5
|
141 |
|
ff1d9a
|
142 |
//* Executing the postconf commands |
cb8c86
|
143 |
foreach($postconf_commands as $cmd) { |
W |
144 |
$command = "postconf -e '$cmd'"; |
ff1d9a
|
145 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, 'EXECUTED: '.$command, 'Failed to execute the command '.$command); |
cb8c86
|
146 |
} |
b1a6a5
|
147 |
|
ff1d9a
|
148 |
//* Create the SSL certificate |
b1a6a5
|
149 |
if (!stristr($options, 'dont-create-certs')) |
cb8c86
|
150 |
{ |
b04e82
|
151 |
if(AUTOINSTALL){ |
TB |
152 |
$command = 'cd '.$config_dir.'; ' |
35846d
|
153 |
."openssl req -new -subj '/C=".escapeshellcmd($autoinstall['ssl_cert_country'])."/ST=".escapeshellcmd($autoinstall['ssl_cert_state'])."/L=".escapeshellcmd($autoinstall['ssl_cert_locality'])."/O=".escapeshellcmd($autoinstall['ssl_cert_organisation'])."/OU=".escapeshellcmd($autoinstall['ssl_cert_organisation_unit'])."/CN=".escapeshellcmd($autoinstall['ssl_cert_common_name'])."' -outform PEM -out smtpd.cert -newkey rsa:4096 -nodes -keyout smtpd.key -keyform PEM -days 3650 -x509"; |
b04e82
|
154 |
} else { |
TB |
155 |
$command = 'cd '.$config_dir.'; ' |
35846d
|
156 |
.'openssl req -new -outform PEM -out smtpd.cert -newkey rsa:4096 -nodes -keyout smtpd.key -keyform PEM -days 3650 -x509'; |
b04e82
|
157 |
} |
cb8c86
|
158 |
exec($command); |
b1a6a5
|
159 |
|
cb8c86
|
160 |
$command = 'chmod o= '.$config_dir.'/smtpd.key'; |
W |
161 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, 'EXECUTED: '.$command, 'Failed to execute the command '.$command); |
|
162 |
} |
b1a6a5
|
163 |
|
ff1d9a
|
164 |
//* We have to change the permissions of the courier authdaemon directory to make it accessible for maildrop. |
W |
165 |
$command = 'chmod 755 /var/lib/courier/authdaemon/'; |
|
166 |
if (is_dir('/var/lib/courier/authdaemon')) { |
|
167 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, 'EXECUTED: '.$command, 'Failed to execute the command '.$command); |
|
168 |
} |
b1a6a5
|
169 |
|
ff1d9a
|
170 |
//* Changing maildrop lines in posfix master.cf |
cb8c86
|
171 |
$configfile = $config_dir.'/master.cf'; |
W |
172 |
$content = rf($configfile); |
|
173 |
|
b1a6a5
|
174 |
$content = preg_replace('/^#?maildrop/m', 'maildrop', $content); |
MC |
175 |
$content = preg_replace('/^#?(\s+)flags=DRhu user=vmail argv=\/usr\/bin\/maildrop -d/m', |
|
176 |
'$1flags=DRhu user=vmail argv=/usr/bin/maildrop -d vmail \${extension} \${recipient} \${user} \${nexthop} \${sender}', |
|
177 |
$content); |
|
178 |
|
cb8c86
|
179 |
$this->write_config_file($configfile, $content); |
b1a6a5
|
180 |
|
ff1d9a
|
181 |
//* Writing the Maildrop mailfilter file |
615a0a
|
182 |
$content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/mailfilter.master', 'tpl/mailfilter.master'); |
cb8c86
|
183 |
$content = str_replace('{dist_postfix_vmail_mailbox_base}', $cf['vmail_mailbox_base'], $content); |
b1a6a5
|
184 |
|
cb8c86
|
185 |
$this->write_config_file($cf['vmail_mailbox_base'].'/.mailfilter', $content); |
b1a6a5
|
186 |
|
ff1d9a
|
187 |
//* Create the directory for the custom mailfilters |
b1a6a5
|
188 |
if (!is_dir($cf['vmail_mailbox_base'].'/mailfilters')) |
cb8c86
|
189 |
{ |
W |
190 |
$command = 'mkdir '.$cf['vmail_mailbox_base'].'/mailfilters'; |
ff1d9a
|
191 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
cb8c86
|
192 |
} |
ec5716
|
193 |
|
T |
194 |
//* postfix-dkim |
|
195 |
$full_file_name=$config_dir.'/tag_as_originating.re'; |
|
196 |
if(is_file($full_file_name)) { |
|
197 |
copy($full_file_name, $config_dir.$configfile.'~'); |
b1a6a5
|
198 |
} |
MC |
199 |
$this->write_config_file($full_file_name, '/^/ FILTER amavis:[127.0.0.1]:10026'); |
ec5716
|
200 |
|
b1a6a5
|
201 |
$full_file_name=$config_dir.'/tag_as_foreign.re'; |
MC |
202 |
if(is_file($full_file_name)) { |
|
203 |
copy($full_file_name, $config_dir.$configfile.'~'); |
|
204 |
} |
|
205 |
$this->write_config_file($full_file_name, '/^/ FILTER amavis:[127.0.0.1]:10024'); |
|
206 |
|
ff1d9a
|
207 |
//* Chmod and chown the .mailfilter file |
cb8c86
|
208 |
$command = 'chown -R '.$cf['vmail_username'].':'.$cf['vmail_groupname'].' '.$cf['vmail_mailbox_base'].'/.mailfilter'; |
W |
209 |
caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
b1a6a5
|
210 |
|
cb8c86
|
211 |
$command = 'chmod -R 600 '.$cf['vmail_mailbox_base'].'/.mailfilter'; |
W |
212 |
caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
b1a6a5
|
213 |
|
cb8c86
|
214 |
} |
b1a6a5
|
215 |
|
MC |
216 |
public function configure_saslauthd() |
cb8c86
|
217 |
{ |
W |
218 |
global $conf; |
b1a6a5
|
219 |
|
ff1d9a
|
220 |
$content = $this->get_template_file('sasl_smtpd.conf', true, true); //* get contents & insert db cred |
cb8c86
|
221 |
$this->write_config_file($conf['saslauthd']['config_dir'].'/smtpd.conf', $content); |
b1a6a5
|
222 |
|
ff1d9a
|
223 |
//* Edit the file saslauthd config file |
W |
224 |
$content = rf($conf['saslauthd']['config_file']); |
cb8c86
|
225 |
$content = preg_replace('/(?<=\n)SASLAUTHD_OPTS="\$\{SASLAUTHD_OPTS\}[^"]+"/', 'SASLAUTHD_OPTS="${SASLAUTHD_OPTS} -a pam -r -c -s 128 -t 30 -n 5"', $content); |
b1a6a5
|
226 |
|
ff1d9a
|
227 |
$this->write_config_file($conf['saslauthd']['config_file'], $content); |
cb8c86
|
228 |
} |
b1a6a5
|
229 |
|
cb8c86
|
230 |
public function configure_courier() |
b1a6a5
|
231 |
{ |
MC |
232 |
global $conf; |
|
233 |
|
ff1d9a
|
234 |
//* authmysqlrc |
W |
235 |
$content = $this->get_template_file('authmysqlrc', true, true); //* get contents & insert db cred |
cb8c86
|
236 |
$this->write_config_file($conf['courier']['config_dir'].'/authmysqlrc', $content); |
b1a6a5
|
237 |
|
ff1d9a
|
238 |
//* authdaemonrc |
cb8c86
|
239 |
$configfile = $conf['courier']['config_dir'].'/authdaemonrc'; |
W |
240 |
|
|
241 |
$content = rf($configfile); |
|
242 |
$content = preg_replace('/(?<=\n)authmodulelist="[^"]+"/', "authmodulelist=\"authmysql\"", $content); |
|
243 |
$this->write_config_file($configfile, $content); |
b1a6a5
|
244 |
|
ff1d9a
|
245 |
//* create certificates |
W |
246 |
$command = 'mkimapdcert'; |
|
247 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
b1a6a5
|
248 |
|
ff1d9a
|
249 |
$command = 'mkpop3dcert'; |
cb8c86
|
250 |
caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
b1a6a5
|
251 |
} |
MC |
252 |
|
|
253 |
public function configure_dovecot() |
|
254 |
{ |
|
255 |
global $conf; |
|
256 |
|
a8aad2
|
257 |
$virtual_transport = 'dovecot'; |
DM |
258 |
|
|
259 |
// check if virtual_transport must be changed |
|
260 |
if ($this->is_update) { |
cc7a82
|
261 |
$tmp = $this->db->queryOneRecord("SELECT * FROM ?? WHERE server_id = ?", $conf["mysql"]["database"].".server", $conf['server_id']); |
a8aad2
|
262 |
$ini_array = ini_to_array(stripslashes($tmp['config'])); |
DM |
263 |
// ini_array needs not to be checked, because already done in update.php -> updateDbAndIni() |
|
264 |
|
|
265 |
if(isset($ini_array['mail']['mailbox_virtual_uidgid_maps']) && $ini_array['mail']['mailbox_virtual_uidgid_maps'] == 'y') { |
|
266 |
$virtual_transport = 'lmtp:unix:private/dovecot-lmtp'; |
|
267 |
} |
|
268 |
} |
|
269 |
|
b1a6a5
|
270 |
$config_dir = $conf['dovecot']['config_dir']; |
MC |
271 |
|
|
272 |
$configfile = $conf['postfix']['config_dir'].'/master.cf'; |
|
273 |
|
|
274 |
if(is_file($configfile)) { |
ff1d9a
|
275 |
copy($configfile, $configfile.'~2'); |
W |
276 |
} |
|
277 |
if(is_file($configfile.'~2')) { |
|
278 |
chmod($configfile.'~2', 0400); |
|
279 |
} |
b1a6a5
|
280 |
|
MC |
281 |
//* Configure master.cf and add a line for deliver |
ff1d9a
|
282 |
$content = rf($configfile); |
b1a6a5
|
283 |
|
MC |
284 |
if(!stristr($content, 'dovecot/deliver')) { |
013ae4
|
285 |
$deliver_content = 'dovecot unix - n n - - pipe'."\n".' flags=DROhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${user}@${nexthop}'; |
b1a6a5
|
286 |
af($conf['postfix']['config_dir'].'/master.cf', $deliver_content); |
ff1d9a
|
287 |
} |
W |
288 |
unset($content); |
|
289 |
unset($deliver_content); |
|
290 |
unset($configfile); |
b1a6a5
|
291 |
|
ff1d9a
|
292 |
//* Reconfigure postfix to use dovecot authentication |
W |
293 |
$postconf_commands = array ( |
b1a6a5
|
294 |
'dovecot_destination_recipient_limit = 1', |
a8aad2
|
295 |
'virtual_transport = '.$virtual_transport, |
b1a6a5
|
296 |
'smtpd_sasl_type = dovecot', |
MC |
297 |
'smtpd_sasl_path = private/auth' |
ff1d9a
|
298 |
); |
b1a6a5
|
299 |
|
ff1d9a
|
300 |
//* Make a backup copy of the main.cf file |
b1a6a5
|
301 |
copy($conf['postfix']['config_dir'].'/main.cf', $conf['postfix']['config_dir'].'/main.cf~3'); |
MC |
302 |
|
|
303 |
//* Executing the postconf commands |
|
304 |
foreach($postconf_commands as $cmd) |
ff1d9a
|
305 |
{ |
W |
306 |
$command = "postconf -e '$cmd'"; |
|
307 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
308 |
} |
b1a6a5
|
309 |
|
ff1d9a
|
310 |
//* copy dovecot.conf |
W |
311 |
$configfile = $config_dir.'/dovecot.conf'; |
|
312 |
$content = $this->get_template_file('dovecot.conf', true); |
|
313 |
$this->write_config_file($configfile, $content); |
b1a6a5
|
314 |
|
ff1d9a
|
315 |
//* dovecot-sql.conf |
W |
316 |
$configfile = $config_dir.'/dovecot-sql.conf'; |
|
317 |
$content = $this->get_template_file('debian_dovecot-sql.conf', true, true); |
|
318 |
$this->write_config_file($configfile, $content); |
b1a6a5
|
319 |
} |
MC |
320 |
|
cb8c86
|
321 |
public function configure_spamassassin() |
b1a6a5
|
322 |
{ |
cb8c86
|
323 |
return true; |
b1a6a5
|
324 |
} |
MC |
325 |
|
cb8c86
|
326 |
public function configure_getmail() |
b1a6a5
|
327 |
{ |
cb8c86
|
328 |
global $conf; |
b1a6a5
|
329 |
|
cb8c86
|
330 |
$config_dir = $conf['getmail']['config_dir']; |
b1a6a5
|
331 |
|
cb8c86
|
332 |
if (!is_dir($config_dir)) { |
ff1d9a
|
333 |
exec('mkdir -p '.escapeshellcmd($config_dir)); |
cb8c86
|
334 |
} |
W |
335 |
|
|
336 |
$command = "useradd -d $config_dir ".$conf['getmail']['user']; |
|
337 |
if (!is_user('getmail')) { |
|
338 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
339 |
} |
b1a6a5
|
340 |
|
cb8c86
|
341 |
$command = "chown -R getmail $config_dir"; |
W |
342 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
b1a6a5
|
343 |
|
cb8c86
|
344 |
$command = "chmod -R 700 $config_dir"; |
W |
345 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
b1a6a5
|
346 |
|
ff1d9a
|
347 |
//* Getmail will be run from cron. In order to have access to cron the getmail user needs to be part of the cron group. |
cb8c86
|
348 |
$command = "gpasswd -a getmail " . $conf['cron']['group']; |
W |
349 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
350 |
} |
b1a6a5
|
351 |
|
MC |
352 |
public function configure_amavis() |
|
353 |
{ |
cb8c86
|
354 |
global $conf; |
b1a6a5
|
355 |
|
ff1d9a
|
356 |
//* Amavisd-new user config file |
cb8c86
|
357 |
$conf_file = 'amavisd-ispconfig.conf'; |
W |
358 |
$conf_path = dirname($conf['amavis']['config_file']) . '/' . $conf_file; |
b1a6a5
|
359 |
|
ff1d9a
|
360 |
$content = $this->get_template_file($conf_file, true, true); //* get contents & insert db cred |
cb8c86
|
361 |
$this->write_config_file($conf_path, $content); |
b1a6a5
|
362 |
|
ff1d9a
|
363 |
//* Activate config directory in default file |
cb8c86
|
364 |
$amavis_conf = rf($conf['amavis']['config_file']); |
b1a6a5
|
365 |
if (stripos($amavis_conf, $conf_path) === false) |
cb8c86
|
366 |
{ |
ff1d9a
|
367 |
$amavis_conf = preg_replace('/^(1;.*)$/m', "include_config_files('$conf_path');\n$1", $amavis_conf); |
cb8c86
|
368 |
$this->write_config_file($conf['amavis']['config_file'], $amavis_conf); |
W |
369 |
} |
b1a6a5
|
370 |
|
ff1d9a
|
371 |
//* Adding the amavisd commands to the postfix configuration |
cb8c86
|
372 |
$postconf_commands = array ( |
W |
373 |
'content_filter = amavis:[127.0.0.1]:10024', |
|
374 |
'receive_override_options = no_address_mappings' |
|
375 |
); |
b1a6a5
|
376 |
|
MC |
377 |
foreach($postconf_commands as $cmd) { |
cb8c86
|
378 |
$command = "postconf -e '$cmd'"; |
ff1d9a
|
379 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
cb8c86
|
380 |
} |
b1a6a5
|
381 |
|
44ae08
|
382 |
// Append the configuration for amavisd to the master.cf file |
ff1d9a
|
383 |
$content = rf($conf['postfix']['config_dir'].'/master.cf'); |
44ae08
|
384 |
// Only add the content if we had not addded it before |
f0bed3
|
385 |
if(!preg_match('/^amavis\s+unix\s+/m', $content)) { |
cb8c86
|
386 |
unset($content); |
ff1d9a
|
387 |
$content = $this->get_template_file('master_cf_amavis', true); |
W |
388 |
af($conf['postfix']['config_dir'].'/master.cf', $content); |
44ae08
|
389 |
$content = rf($conf['postfix']['config_dir'].'/master.cf'); |
F |
390 |
} |
8100f2
|
391 |
if(!preg_match('/^127.0.0.1:10025\s+/m', $content)) { |
44ae08
|
392 |
unset($content); |
F |
393 |
$content = $this->get_template_file('master_cf_amavis10025', true); |
|
394 |
af($conf['postfix']['config_dir'].'/master.cf', $content); |
|
395 |
$content = rf($conf['postfix']['config_dir'].'/master.cf'); |
|
396 |
} |
8100f2
|
397 |
if(!preg_match('/^127.0.0.1:10027\s+/m', $content)) { |
44ae08
|
398 |
unset($content); |
F |
399 |
$content = $this->get_template_file('master_cf_amavis10027', true); |
|
400 |
af($conf['postfix']['config_dir'].'/master.cf', $content); |
cb8c86
|
401 |
} |
W |
402 |
unset($content); |
b1a6a5
|
403 |
|
ff1d9a
|
404 |
//* Add the clamav user to the amavis group |
cb8c86
|
405 |
exec('usermod -a -G amavis clamav'); |
b1a6a5
|
406 |
} |
MC |
407 |
|
|
408 |
public function configure_pureftpd() |
|
409 |
{ |
cb8c86
|
410 |
global $conf; |
b1a6a5
|
411 |
|
cb8c86
|
412 |
//* configure pure-ftpd for MySQL authentication against the ispconfig database |
ff1d9a
|
413 |
$content = $this->get_template_file('pureftpd_mysql.conf', true, true); //* get contents & insert db cred |
W |
414 |
$content = str_replace('{server_id}', $conf['server_id'], $content); |
b1a6a5
|
415 |
|
cb8c86
|
416 |
$this->write_config_file($conf['pureftpd']['mysql_config_file'], $content, 600, 'root', 'root'); |
b1a6a5
|
417 |
|
ff1d9a
|
418 |
//* enable pure-ftpd and server settings |
cb8c86
|
419 |
$content = rf($conf["pureftpd"]["config_file"]); |
b1a6a5
|
420 |
|
cb8c86
|
421 |
$content = preg_replace('/#?IS_CONFIGURED="(?:yes|no)"/', 'IS_CONFIGURED="yes"', $content); |
W |
422 |
$content = str_replace('AUTH="-l unix"', 'AUTH="-l mysql:'.$conf['pureftpd']['mysql_config_file'].'"', $content); |
b1a6a5
|
423 |
|
ff1d9a
|
424 |
//* Logging defaults to syslog's ftp facility. Override this behaviour for better compatibility with debian/ubuntu |
W |
425 |
//* and specify the format. |
cb8c86
|
426 |
$logdir = '/var/log/pure-ftpd'; |
W |
427 |
if (!is_dir($logdir)) { |
|
428 |
mkdir($logdir, 0755, true); |
|
429 |
} |
b1a6a5
|
430 |
|
ff1d9a
|
431 |
/** |
cb8c86
|
432 |
* @link http://download.pureftpd.org/pub/pure-ftpd/doc/README |
W |
433 |
* -b brokenclientscompatibility |
|
434 |
* -A chrooteveryone |
|
435 |
* -E noanonymous |
|
436 |
* -O altlog <format>:<log file> |
|
437 |
* -Z customerproof (Add safe guards against common customer mistakes ie. like chmod 0 on their own files) |
b1a6a5
|
438 |
* -D displaydotfiles |
ff1d9a
|
439 |
* -H dontresolve |
cb8c86
|
440 |
*/ |
b1a6a5
|
441 |
|
MC |
442 |
|
ff1d9a
|
443 |
$content = preg_replace('/MISC_OTHER="[^"]+"/', 'MISC_OTHER="-b -A -E -Z -D -H -O clf:'.$logdir.'/transfer.log"', $content); |
b1a6a5
|
444 |
|
ff1d9a
|
445 |
$this->write_config_file($conf['pureftpd']['config_file'], $content); |
b1a6a5
|
446 |
} |
MC |
447 |
|
|
448 |
public function configure_powerdns() |
cb8c86
|
449 |
{ |
W |
450 |
global $conf; |
b1a6a5
|
451 |
|
cb8c86
|
452 |
//* Create the database |
cc7a82
|
453 |
if(!$this->db->query('CREATE DATABASE IF NOT EXISTS ?? DEFAULT CHARACTER SET ?', $conf['powerdns']['database'], $conf['mysql']['charset'])) { |
cb8c86
|
454 |
$this->error('Unable to create MySQL database: '.$conf['powerdns']['database'].'.'); |
W |
455 |
} |
b1a6a5
|
456 |
|
cb8c86
|
457 |
//* Create the ISPConfig database user in the local database |
cc7a82
|
458 |
$query = 'GRANT ALL ON ??.* TO ?@?'; |
MC |
459 |
if(!$this->db->query($query, $conf['powerdns']['database'], $conf['mysql']['ispconfig_user'], 'localhost')) { |
cb8c86
|
460 |
$this->error('Unable to create user for powerdns database Error: '.$this->db->errorMessage); |
W |
461 |
} |
b1a6a5
|
462 |
|
cb8c86
|
463 |
//* Reload database privelages |
W |
464 |
$this->db->query('FLUSH PRIVILEGES;'); |
b1a6a5
|
465 |
|
cb8c86
|
466 |
//* load the powerdns databse dump |
W |
467 |
if($conf['mysql']['admin_password'] == '') { |
b1a6a5
|
468 |
caselog("mysql --default-character-set=".$conf['mysql']['charset']." -h '".$conf['mysql']['host']."' -u '".$conf['mysql']['admin_user']."' '".$conf['powerdns']['database']."' < '".ISPC_INSTALL_ROOT."/install/sql/powerdns.sql' &> /dev/null", |
MC |
469 |
__FILE__, __LINE__, 'read in ispconfig3.sql', 'could not read in powerdns.sql'); |
cb8c86
|
470 |
} else { |
b1a6a5
|
471 |
caselog("mysql --default-character-set=".$conf['mysql']['charset']." -h '".$conf['mysql']['host']."' -u '".$conf['mysql']['admin_user']."' -p'".$conf['mysql']['admin_password']."' '".$conf['powerdns']['database']."' < '".ISPC_INSTALL_ROOT."/install/sql/powerdns.sql' &> /dev/null", |
MC |
472 |
__FILE__, __LINE__, 'read in ispconfig3.sql', 'could not read in powerdns.sql'); |
cb8c86
|
473 |
} |
b1a6a5
|
474 |
|
cb8c86
|
475 |
//* Create the powerdns config file |
ff1d9a
|
476 |
$content = $this->get_template_file('pdns.local', true, true); //* get contents & insert db cred |
cb8c86
|
477 |
$content = str_replace('{powerdns_database}', $conf['powerdns']['database'], $content); |
b1a6a5
|
478 |
|
cb8c86
|
479 |
$this->write_config_file($conf["powerdns"]["config_dir"].'/'.$conf["powerdns"]["config_file"], $content, 600, 'root', 'root'); |
W |
480 |
|
ff1d9a
|
481 |
//* Create symlink to init script to start the correct config file |
cb8c86
|
482 |
if( !is_link($conf['init_scripts'].'/'.$conf['powerdns']['init_script']) ) { |
W |
483 |
symlink($conf['init_scripts'].'/pdns', $conf['init_scripts'].'/'.$conf['powerdns']['init_script']); |
|
484 |
} |
|
485 |
} |
b1a6a5
|
486 |
|
d090db
|
487 |
public function configure_bind() { |
W |
488 |
global $conf; |
|
489 |
|
b1a6a5
|
490 |
//* Check if the zonefile directory has a slash at the end |
MC |
491 |
$content=$conf['bind']['bind_zonefiles_dir']; |
|
492 |
if(substr($content, -1, 1) != '/') { |
|
493 |
$content .= '/'; |
d090db
|
494 |
} |
b1a6a5
|
495 |
|
d090db
|
496 |
//* New default format of named.conf uses views. Check which version the system is using and include our zones file. |
W |
497 |
$named_conf = rf($conf['bind']['named_conf_path']); |
b1a6a5
|
498 |
if (stripos($named_conf, 'include "'.$conf['bind']['named_conf_local_path'].'";') === false) |
d090db
|
499 |
{ |
W |
500 |
preg_match_all("/(?<=\n)view \"(?:public|internal)\" in \{.*\n\};/Us", $named_conf, $views); |
|
501 |
if (count($views[0]) == 2) { |
|
502 |
foreach ($views[0] as $view) { |
|
503 |
$named_conf = str_replace($view, substr($view, 0, -2)."include \"{$conf['bind']['named_conf_local_path']}\";\n};", $named_conf); |
|
504 |
} |
b1a6a5
|
505 |
|
d090db
|
506 |
wf($conf['bind']['named_conf_path'], $named_conf); |
W |
507 |
} |
|
508 |
else { |
|
509 |
af($conf['bind']['named_conf_path'], 'include "'.$conf['bind']['named_conf_local_path'].'";'); |
|
510 |
} |
|
511 |
} |
|
512 |
} |
b1a6a5
|
513 |
|
cb8c86
|
514 |
public function configure_apache() |
b1a6a5
|
515 |
{ |
cb8c86
|
516 |
global $conf; |
b1a6a5
|
517 |
|
91324a
|
518 |
if($conf['apache']['installed'] == false) return; |
ff1d9a
|
519 |
//* Create the logging directory for the vhost logfiles |
W |
520 |
if (!is_dir($conf['ispconfig_log_dir'].'/httpd')) { |
|
521 |
mkdir($conf['ispconfig_log_dir'].'/httpd', 0755, true); |
cb8c86
|
522 |
} |
b1a6a5
|
523 |
|
MC |
524 |
if (is_file($conf['suphp']['config_file'])) |
cb8c86
|
525 |
{ |
W |
526 |
$content = rf($conf['suphp']['config_file']); |
b1a6a5
|
527 |
|
ff1d9a
|
528 |
if (!preg_match('|^x-httpd-suphp=php:/usr/bin/php-cgi$|m', $content)) |
W |
529 |
{ |
b1a6a5
|
530 |
$content = preg_replace('/;Handler for php-scripts/', ";Handler for php-scripts\nx-httpd-suphp=php:/usr/bin/php-cgi", $content); |
MC |
531 |
$content = preg_replace('/;?umask=\d+/', 'umask=0022', $content); |
ff1d9a
|
532 |
} |
b1a6a5
|
533 |
|
cb8c86
|
534 |
$this->write_config_file($conf['suphp']['config_file'], $content); |
W |
535 |
} |
b1a6a5
|
536 |
|
ff1d9a
|
537 |
//* Enable ISPConfig default vhost settings |
cb8c86
|
538 |
$default_vhost_path = $conf['apache']['vhost_conf_dir'].'/'.$conf['apache']['vhost_default']; |
b1a6a5
|
539 |
if (is_file($default_vhost_path)) |
cb8c86
|
540 |
{ |
W |
541 |
$content = rf($default_vhost_path); |
b1a6a5
|
542 |
|
cb8c86
|
543 |
$content = preg_replace('/^#?\s*NameVirtualHost.*$/m', 'NameVirtualHost *:80', $content); |
W |
544 |
$content = preg_replace('/<VirtualHost[^>]+>/', '<VirtualHost *:80>', $content); |
b1a6a5
|
545 |
|
cb8c86
|
546 |
$this->write_config_file($default_vhost_path, $content); |
W |
547 |
} |
b1a6a5
|
548 |
|
ff1d9a
|
549 |
//* Generate default ssl certificates |
cb8c86
|
550 |
if (!is_dir($conf['apache']['ssl_dir'])) { |
W |
551 |
mkdir($conf['apache']['ssl_dir']); |
|
552 |
} |
b1a6a5
|
553 |
|
MC |
554 |
if ($conf['services']['mail'] == true) |
cb8c86
|
555 |
{ |
W |
556 |
copy($conf['postfix']['config_dir']."/smtpd.key", $conf['apache']['ssl_dir']."/server.key"); |
|
557 |
copy($conf['postfix']['config_dir']."/smtpd.cert", $conf['apache']['ssl_dir']."/server.crt"); |
|
558 |
} |
|
559 |
else |
|
560 |
{ |
|
561 |
if (!is_file($conf['apache']['ssl_dir'] . '/server.crt')) { |
|
562 |
exec("openssl req -new -outform PEM -out {$conf['apache']['ssl_dir']}/server.crt -newkey rsa:2048 -nodes -keyout {$conf['apache']['ssl_dir']}/server.key -keyform PEM -days 365 -x509"); |
|
563 |
} |
|
564 |
} |
b1a6a5
|
565 |
|
MC |
566 |
|
|
567 |
|
ff1d9a
|
568 |
//* Copy the ISPConfig configuration include |
ccbf14
|
569 |
$tpl = new tpl('apache_ispconfig.conf.master'); |
TB |
570 |
$tpl->setVar('apache_version',getapacheversion()); |
|
571 |
|
2af58c
|
572 |
$records = $this->db->queryAllRecords("SELECT * FROM ?? WHERE server_id = ? AND virtualhost = 'y'", $conf['mysql']['master_database'] . '.server_ip', $conf['server_id']); |
ccbf14
|
573 |
$ip_addresses = array(); |
TB |
574 |
|
|
575 |
if(is_array($records) && count($records) > 0) { |
|
576 |
foreach($records as $rec) { |
|
577 |
if($rec['ip_type'] == 'IPv6') { |
|
578 |
$ip_address = '['.$rec['ip_address'].']'; |
|
579 |
} else { |
|
580 |
$ip_address = $rec['ip_address']; |
|
581 |
} |
|
582 |
$ports = explode(',', $rec['virtualhost_port']); |
|
583 |
if(is_array($ports)) { |
|
584 |
foreach($ports as $port) { |
|
585 |
$port = intval($port); |
|
586 |
if($port > 0 && $port < 65536 && $ip_address != '') { |
|
587 |
$ip_addresses[] = array('ip_address' => $ip_address, 'port' => $port); |
|
588 |
} |
|
589 |
} |
|
590 |
} |
|
591 |
} |
|
592 |
} |
855547
|
593 |
|
3de838
|
594 |
if(count($ip_addresses) > 0) $tpl->setLoop('ip_adresses',$ip_addresses); |
ccbf14
|
595 |
|
TB |
596 |
wf($conf['apache']['vhost_conf_dir'].'/000-ispconfig.conf', $tpl->grab()); |
|
597 |
unset($tpl); |
b1a6a5
|
598 |
|
ff1d9a
|
599 |
//* Gentoo by default does not include .vhost files. Add include line to config file. |
cb8c86
|
600 |
$content = rf($conf['apache']['config_file']); |
W |
601 |
if ( strpos($content, 'Include /etc/apache2/vhosts.d/*.vhost') === false ) { |
b1a6a5
|
602 |
$content = preg_replace('|(Include /etc/apache2/vhosts.d/\*.conf)|', "$1\nInclude /etc/apache2/vhosts.d/*.vhost", $content); |
cb8c86
|
603 |
} |
b1a6a5
|
604 |
|
cb8c86
|
605 |
$this->write_config_file($conf['apache']['config_file'], $content); |
b1a6a5
|
606 |
|
ff1d9a
|
607 |
//* make sure that webalizer finds its config file when it is directly in /etc |
b1a6a5
|
608 |
if(is_file('/etc/webalizer.conf') && !is_dir('/etc/webalizer')) |
cb8c86
|
609 |
{ |
W |
610 |
mkdir('/etc/webalizer', 0755); |
|
611 |
symlink('/etc/webalizer.conf', '/etc/webalizer/webalizer.conf'); |
|
612 |
} |
b1a6a5
|
613 |
|
MC |
614 |
if(is_file('/etc/webalizer/webalizer.conf')) //* Change webalizer mode to incremental |
|
615 |
{ |
|
616 |
replaceLine('/etc/webalizer/webalizer.conf', '#IncrementalName', 'IncrementalName webalizer.current', 0, 0); |
|
617 |
replaceLine('/etc/webalizer/webalizer.conf', '#Incremental', 'Incremental yes', 0, 0); |
|
618 |
replaceLine('/etc/webalizer/webalizer.conf', '#HistoryName', 'HistoryName webalizer.hist', 0, 0); |
cb8c86
|
619 |
} |
b1a6a5
|
620 |
|
ff1d9a
|
621 |
//* add a sshusers group |
b1a6a5
|
622 |
if (!is_group('sshusers')) |
cb8c86
|
623 |
{ |
W |
624 |
$command = 'groupadd sshusers'; |
|
625 |
caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
626 |
} |
b1a6a5
|
627 |
} |
MC |
628 |
|
|
629 |
public function configure_apps_vhost() |
cb8c86
|
630 |
{ |
W |
631 |
global $conf; |
b1a6a5
|
632 |
|
cb8c86
|
633 |
//* Create the ispconfig apps vhost user and group |
165152
|
634 |
if($conf['apache']['installed'] == true){ |
91324a
|
635 |
$apps_vhost_user = escapeshellcmd($conf['web']['apps_vhost_user']); |
F |
636 |
$apps_vhost_group = escapeshellcmd($conf['web']['apps_vhost_group']); |
|
637 |
$install_dir = escapeshellcmd($conf['web']['website_basedir'].'/apps'); |
b1a6a5
|
638 |
|
91324a
|
639 |
$command = 'groupadd '.$apps_vhost_user; |
F |
640 |
if ( !is_group($apps_vhost_group) ) { |
|
641 |
caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
642 |
} |
b1a6a5
|
643 |
|
91324a
|
644 |
$command = "useradd -g '$apps_vhost_group' -d $install_dir $apps_vhost_group"; |
F |
645 |
if ( !is_user($apps_vhost_user) ) { |
|
646 |
caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
647 |
} |
b1a6a5
|
648 |
|
91324a
|
649 |
$command = 'adduser '.$conf['apache']['user'].' '.$apps_vhost_group; |
F |
650 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
b1a6a5
|
651 |
|
99b55b
|
652 |
if(!@is_dir($install_dir)){ |
91324a
|
653 |
mkdir($install_dir, 0755, true); |
99b55b
|
654 |
} else { |
F |
655 |
chmod($install_dir, 0755); |
91324a
|
656 |
} |
F |
657 |
chown($install_dir, $apps_vhost_user); |
|
658 |
chgrp($install_dir, $apps_vhost_group); |
b1a6a5
|
659 |
|
91324a
|
660 |
//* Copy the apps vhost file |
F |
661 |
$vhost_conf_dir = $conf['apache']['vhost_conf_dir']; |
|
662 |
$vhost_conf_enabled_dir = $conf['apache']['vhost_conf_enabled_dir']; |
|
663 |
$apps_vhost_servername = ($conf['web']['apps_vhost_servername'] == '') ? '' : 'ServerName '.$conf['web']['apps_vhost_servername']; |
b1a6a5
|
664 |
|
91324a
|
665 |
//* Dont just copy over the virtualhost template but add some custom settings |
F |
666 |
$content = $this->get_template_file('apache_apps.vhost', true); |
b1a6a5
|
667 |
|
91324a
|
668 |
$content = str_replace('{apps_vhost_ip}', $conf['web']['apps_vhost_ip'], $content); |
F |
669 |
$content = str_replace('{apps_vhost_port}', $conf['web']['apps_vhost_port'], $content); |
|
670 |
$content = str_replace('{apps_vhost_dir}', $conf['web']['website_basedir'].'/apps', $content); |
|
671 |
$content = str_replace('{website_basedir}', $conf['web']['website_basedir'], $content); |
|
672 |
$content = str_replace('{apps_vhost_servername}', $apps_vhost_servername, $content); |
b1a6a5
|
673 |
|
91324a
|
674 |
//* comment out the listen directive if port is 80 or 443 |
F |
675 |
if($conf['web']['apps_vhost_ip'] == 80 or $conf['web']['apps_vhost_ip'] == 443) { |
|
676 |
$content = str_replace('{vhost_port_listen}', '#', $content); |
|
677 |
} else { |
|
678 |
$content = str_replace('{vhost_port_listen}', '', $content); |
|
679 |
} |
b1a6a5
|
680 |
|
91324a
|
681 |
$this->write_config_file("$vhost_conf_dir/apps.vhost", $content); |
b1a6a5
|
682 |
|
MC |
683 |
//if ( !is_file($conf['web']['website_basedir'].'/php-fcgi-scripts/apps/.php-fcgi-starter') ) |
cc6568
|
684 |
//{ |
b1a6a5
|
685 |
$content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/apache_apps_fcgi_starter.master', 'tpl/apache_apps_fcgi_starter.master'); |
MC |
686 |
$content = str_replace('{fastcgi_bin}', $conf['fastcgi']['fastcgi_bin'], $content); |
|
687 |
$content = str_replace('{fastcgi_phpini_path}', $conf['fastcgi']['fastcgi_phpini_path'], $content); |
|
688 |
mkdir($conf['web']['website_basedir'].'/php-fcgi-scripts/apps', 0755, true); |
|
689 |
//copy('tpl/apache_apps_fcgi_starter.master',$conf['web']['website_basedir'].'/php-fcgi-scripts/apps/.php-fcgi-starter'); |
|
690 |
wf($conf['web']['website_basedir'].'/php-fcgi-scripts/apps/.php-fcgi-starter', $content); |
|
691 |
exec('chmod +x '.$conf['web']['website_basedir'].'/php-fcgi-scripts/apps/.php-fcgi-starter'); |
|
692 |
exec('chown -R ispapps:ispapps '.$conf['web']['website_basedir'].'/php-fcgi-scripts/apps'); |
|
693 |
|
cc6568
|
694 |
//} |
91324a
|
695 |
} |
165152
|
696 |
if($conf['nginx']['installed'] == true){ |
91324a
|
697 |
$apps_vhost_user = escapeshellcmd($conf['web']['apps_vhost_user']); |
F |
698 |
$apps_vhost_group = escapeshellcmd($conf['web']['apps_vhost_group']); |
|
699 |
$install_dir = escapeshellcmd($conf['web']['website_basedir'].'/apps'); |
|
700 |
|
|
701 |
$command = 'groupadd '.$apps_vhost_user; |
|
702 |
if(!is_group($apps_vhost_group)) caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
703 |
|
|
704 |
$command = 'useradd -g '.$apps_vhost_group.' -d '.$install_dir.' '.$apps_vhost_group; |
|
705 |
if(!is_user($apps_vhost_user)) caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
706 |
|
|
707 |
|
|
708 |
$command = 'adduser '.$conf['nginx']['user'].' '.$apps_vhost_group; |
|
709 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
710 |
|
6e2d48
|
711 |
if(!@is_dir($install_dir)){ |
F |
712 |
mkdir($install_dir, 0755, true); |
|
713 |
} else { |
|
714 |
chmod($install_dir, 0755); |
|
715 |
} |
91324a
|
716 |
chown($install_dir, $apps_vhost_user); |
F |
717 |
chgrp($install_dir, $apps_vhost_group); |
|
718 |
|
|
719 |
//* Copy the apps vhost file |
|
720 |
$vhost_conf_dir = $conf['nginx']['vhost_conf_dir']; |
|
721 |
$vhost_conf_enabled_dir = $conf['nginx']['vhost_conf_enabled_dir']; |
|
722 |
$apps_vhost_servername = ($conf['web']['apps_vhost_servername'] == '')?'_':$conf['web']['apps_vhost_servername']; |
|
723 |
|
|
724 |
// Dont just copy over the virtualhost template but add some custom settings |
615a0a
|
725 |
$content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/nginx_apps.vhost.master', 'tpl/nginx_apps.vhost.master'); |
b1a6a5
|
726 |
|
91324a
|
727 |
if($conf['web']['apps_vhost_ip'] == '_default_'){ |
F |
728 |
$apps_vhost_ip = ''; |
|
729 |
} else { |
|
730 |
$apps_vhost_ip = $conf['web']['apps_vhost_ip'].':'; |
|
731 |
} |
b1a6a5
|
732 |
|
ca0b77
|
733 |
$socket_dir = escapeshellcmd($conf['nginx']['php_fpm_socket_dir']); |
b1a6a5
|
734 |
if(substr($socket_dir, -1) != '/') $socket_dir .= '/'; |
ca0b77
|
735 |
if(!is_dir($socket_dir)) exec('mkdir -p '.$socket_dir); |
F |
736 |
$fpm_socket = $socket_dir.'apps.sock'; |
8ab3cd
|
737 |
$cgi_socket = escapeshellcmd($conf['nginx']['cgi_socket']); |
91324a
|
738 |
|
F |
739 |
$content = str_replace('{apps_vhost_ip}', $apps_vhost_ip, $content); |
|
740 |
$content = str_replace('{apps_vhost_port}', $conf['web']['apps_vhost_port'], $content); |
|
741 |
$content = str_replace('{apps_vhost_dir}', $conf['web']['website_basedir'].'/apps', $content); |
|
742 |
$content = str_replace('{apps_vhost_servername}', $apps_vhost_servername, $content); |
ca0b77
|
743 |
//$content = str_replace('{fpm_port}', ($conf['nginx']['php_fpm_start_port']+1), $content); |
F |
744 |
$content = str_replace('{fpm_socket}', $fpm_socket, $content); |
8ab3cd
|
745 |
$content = str_replace('{cgi_socket}', $cgi_socket, $content); |
91324a
|
746 |
|
F |
747 |
wf($vhost_conf_dir.'/apps.vhost', $content); |
b1a6a5
|
748 |
|
91324a
|
749 |
// PHP-FPM |
F |
750 |
// Dont just copy over the php-fpm pool template but add some custom settings |
615a0a
|
751 |
$content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/apps_php_fpm_pool.conf.master', 'tpl/apps_php_fpm_pool.conf.master'); |
91324a
|
752 |
$content = str_replace('{fpm_pool}', 'apps', $content); |
ca0b77
|
753 |
//$content = str_replace('{fpm_port}', ($conf['nginx']['php_fpm_start_port']+1), $content); |
F |
754 |
$content = str_replace('{fpm_socket}', $fpm_socket, $content); |
91324a
|
755 |
$content = str_replace('{fpm_user}', $apps_vhost_user, $content); |
F |
756 |
$content = str_replace('{fpm_group}', $apps_vhost_group, $content); |
|
757 |
wf($conf['nginx']['php_fpm_pool_dir'].'/apps.conf', $content); |
|
758 |
|
|
759 |
//copy('tpl/nginx_ispconfig.vhost.master', "$vhost_conf_dir/ispconfig.vhost"); |
|
760 |
//* and create the symlink |
7e1cfb
|
761 |
if(@is_link($vhost_conf_enabled_dir.'/apps.vhost')) unlink($vhost_conf_enabled_dir.'/apps.vhost'); |
F |
762 |
if(!@is_link($vhost_conf_enabled_dir.'/000-apps.vhost')) { |
b1a6a5
|
763 |
symlink($vhost_conf_dir.'/apps.vhost', $vhost_conf_enabled_dir.'/000-apps.vhost'); |
91324a
|
764 |
} |
b1a6a5
|
765 |
|
cb8c86
|
766 |
} |
W |
767 |
} |
b1a6a5
|
768 |
|
MC |
769 |
public function install_ispconfig() |
|
770 |
{ |
cb8c86
|
771 |
global $conf; |
b1a6a5
|
772 |
|
cb8c86
|
773 |
$install_dir = $conf['ispconfig_install_dir']; |
b1a6a5
|
774 |
|
MC |
775 |
//* Create the ISPConfig installation directory |
|
776 |
if(!is_dir($install_dir)) |
cb8c86
|
777 |
{ |
W |
778 |
$command = "mkdir $install_dir"; |
|
779 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
780 |
} |
b1a6a5
|
781 |
|
ff1d9a
|
782 |
//* Create a ISPConfig user and group |
b1a6a5
|
783 |
if (!is_group('ispconfig')) |
cb8c86
|
784 |
{ |
W |
785 |
$command = 'groupadd ispconfig'; |
|
786 |
caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
787 |
} |
b1a6a5
|
788 |
|
MC |
789 |
if (!is_user('ispconfig')) |
cb8c86
|
790 |
{ |
W |
791 |
$command = "useradd -g ispconfig -d $install_dir ispconfig"; |
|
792 |
caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
793 |
} |
b1a6a5
|
794 |
|
ff1d9a
|
795 |
//* copy the ISPConfig interface part |
cb8c86
|
796 |
$command = "cp -rf ../interface $install_dir"; |
W |
797 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
b1a6a5
|
798 |
|
ff1d9a
|
799 |
//* copy the ISPConfig server part |
cb8c86
|
800 |
$command = "cp -rf ../server $install_dir"; |
W |
801 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
a13af2
|
802 |
|
fb6c56
|
803 |
//* Make a backup of the security settings |
TB |
804 |
if(is_file('/usr/local/ispconfig/security/security_settings.ini')) copy('/usr/local/ispconfig/security/security_settings.ini','/usr/local/ispconfig/security/security_settings.ini~'); |
|
805 |
|
a13af2
|
806 |
//* copy the ISPConfig security part |
TB |
807 |
$command = 'cp -rf ../security '.$install_dir; |
|
808 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
fb6c56
|
809 |
|
TB |
810 |
//* Apply changed security_settings.ini values to new security_settings.ini file |
|
811 |
if(is_file('/usr/local/ispconfig/security/security_settings.ini~')) { |
|
812 |
$security_settings_old = ini_to_array(file_get_contents('/usr/local/ispconfig/security/security_settings.ini~')); |
|
813 |
$security_settings_new = ini_to_array(file_get_contents('/usr/local/ispconfig/security/security_settings.ini')); |
|
814 |
if(is_array($security_settings_new) && is_array($security_settings_old)) { |
|
815 |
foreach($security_settings_new as $section => $sval) { |
|
816 |
if(is_array($sval)) { |
|
817 |
foreach($sval as $key => $val) { |
|
818 |
if(isset($security_settings_old[$section]) && isset($security_settings_old[$section][$key])) { |
|
819 |
$security_settings_new[$section][$key] = $security_settings_old[$section][$key]; |
|
820 |
} |
|
821 |
} |
|
822 |
} |
|
823 |
} |
|
824 |
file_put_contents('/usr/local/ispconfig/security/security_settings.ini',array_to_ini($security_settings_new)); |
|
825 |
} |
|
826 |
} |
b1a6a5
|
827 |
|
MC |
828 |
|
ff1d9a
|
829 |
//* Create the config file for ISPConfig interface |
cb8c86
|
830 |
$configfile = 'config.inc.php'; |
ff1d9a
|
831 |
$content = $this->get_template_file($configfile, true, true); //* get contents & insert db cred |
b1a6a5
|
832 |
|
cb8c86
|
833 |
$content = str_replace('{mysql_master_server_ispconfig_user}', $conf['mysql']['master_ispconfig_user'], $content); |
W |
834 |
$content = str_replace('{mysql_master_server_ispconfig_password}', $conf['mysql']['master_ispconfig_password'], $content); |
|
835 |
$content = str_replace('{mysql_master_server_database}', $conf['mysql']['master_database'], $content); |
|
836 |
$content = str_replace('{mysql_master_server_host}', $conf['mysql']['master_host'], $content); |
82e9b9
|
837 |
$content = str_replace('{mysql_master_server_port}', $conf['mysql']['master_port'], $content); |
b1a6a5
|
838 |
|
cb8c86
|
839 |
$content = str_replace('{server_id}', $conf['server_id'], $content); |
W |
840 |
$content = str_replace('{ispconfig_log_priority}', $conf['ispconfig_log_priority'], $content); |
|
841 |
$content = str_replace('{language}', $conf['language'], $content); |
8cf78b
|
842 |
$content = str_replace('{timezone}', $conf['timezone'], $content); |
41eaa8
|
843 |
$content = str_replace('{theme}', $conf['theme'], $content); |
992797
|
844 |
$content = str_replace('{language_file_import_enabled}', ($conf['language_file_import_enabled'] == true)?'true':'false', $content); |
b1a6a5
|
845 |
|
cb8c86
|
846 |
$this->write_config_file("$install_dir/interface/lib/$configfile", $content); |
b1a6a5
|
847 |
|
ff1d9a
|
848 |
//* Create the config file for ISPConfig server |
cb8c86
|
849 |
$this->write_config_file("$install_dir/server/lib/$configfile", $content); |
b1a6a5
|
850 |
|
fb3a98
|
851 |
//* Create the config file for remote-actions (but only, if it does not exist, because |
T |
852 |
// the value is a autoinc-value and so changed by the remoteaction_core_module |
ff1d9a
|
853 |
if (!file_exists($install_dir.'/server/lib/remote_action.inc.php')) { |
W |
854 |
$content = '<?php' . "\n" . '$maxid_remote_action = 0;' . "\n" . '?>'; |
fb3a98
|
855 |
wf($install_dir.'/server/lib/remote_action.inc.php', $content); |
ff1d9a
|
856 |
} |
b1a6a5
|
857 |
|
MC |
858 |
// Enable the server modules and plugins. |
cb8c86
|
859 |
// TODO: Implement a selector which modules and plugins shall be enabled. |
W |
860 |
$dir = $install_dir.'/server/mods-available/'; |
|
861 |
if (is_dir($dir)) { |
|
862 |
if ($dh = opendir($dir)) { |
|
863 |
while (($file = readdir($dh)) !== false) { |
b1a6a5
|
864 |
if($file != '.' && $file != '..' && substr($file, -8, 8) == '.inc.php') { |
MC |
865 |
include_once $install_dir.'/server/mods-available/'.$file; |
|
866 |
$module_name = substr($file, 0, -8); |
cb8c86
|
867 |
$tmp = new $module_name; |
W |
868 |
if($tmp->onInstall()) { |
ff1d9a
|
869 |
if(!@is_link($install_dir.'/server/mods-enabled/'.$file)) { |
W |
870 |
@symlink($install_dir.'/server/mods-available/'.$file, $install_dir.'/server/mods-enabled/'.$file); |
|
871 |
// @symlink($install_dir.'/server/mods-available/'.$file, '../mods-enabled/'.$file); |
|
872 |
} |
cb8c86
|
873 |
if (strpos($file, '_core_module') !== false) { |
ff1d9a
|
874 |
if(!@is_link($install_dir.'/server/mods-core/'.$file)) { |
W |
875 |
@symlink($install_dir.'/server/mods-available/'.$file, $install_dir.'/server/mods-core/'.$file); |
|
876 |
// @symlink($install_dir.'/server/mods-available/'.$file, '../mods-core/'.$file); |
|
877 |
} |
cb8c86
|
878 |
} |
W |
879 |
} |
|
880 |
unset($tmp); |
|
881 |
} |
|
882 |
} |
|
883 |
closedir($dh); |
|
884 |
} |
|
885 |
} |
ff1d9a
|
886 |
|
cb8c86
|
887 |
$dir = $install_dir.'/server/plugins-available/'; |
W |
888 |
if (is_dir($dir)) { |
|
889 |
if ($dh = opendir($dir)) { |
|
890 |
while (($file = readdir($dh)) !== false) { |
91324a
|
891 |
if($conf['apache']['installed'] == true && $file == 'nginx_plugin.inc.php') continue; |
F |
892 |
if($conf['nginx']['installed'] == true && $file == 'apache2_plugin.inc.php') continue; |
b1a6a5
|
893 |
if($file != '.' && $file != '..' && substr($file, -8, 8) == '.inc.php') { |
MC |
894 |
include_once $install_dir.'/server/plugins-available/'.$file; |
|
895 |
$plugin_name = substr($file, 0, -8); |
cb8c86
|
896 |
$tmp = new $plugin_name; |
b1a6a5
|
897 |
if(method_exists($tmp, 'onInstall') && $tmp->onInstall()) { |
ff1d9a
|
898 |
if(!@is_link($install_dir.'/server/plugins-enabled/'.$file)) { |
W |
899 |
@symlink($install_dir.'/server/plugins-available/'.$file, $install_dir.'/server/plugins-enabled/'.$file); |
|
900 |
} |
cb8c86
|
901 |
if (strpos($file, '_core_plugin') !== false) { |
ff1d9a
|
902 |
if(!@is_link($install_dir.'/server/plugins-core/'.$file)) { |
W |
903 |
@symlink($install_dir.'/server/plugins-available/'.$file, $install_dir.'/server/plugins-core/'.$file); |
|
904 |
} |
cb8c86
|
905 |
} |
W |
906 |
} |
|
907 |
unset($tmp); |
|
908 |
} |
|
909 |
} |
|
910 |
closedir($dh); |
|
911 |
} |
|
912 |
} |
b1a6a5
|
913 |
|
ff1d9a
|
914 |
//* Update the server config |
cb8c86
|
915 |
$mail_server_enabled = ($conf['services']['mail'])?1:0; |
W |
916 |
$web_server_enabled = ($conf['services']['web'])?1:0; |
|
917 |
$dns_server_enabled = ($conf['services']['dns'])?1:0; |
|
918 |
$file_server_enabled = ($conf['services']['file'])?1:0; |
|
919 |
$db_server_enabled = ($conf['services']['db'])?1:0; |
|
920 |
$vserver_server_enabled = ($conf['services']['vserver'])?1:0; |
b1a6a5
|
921 |
|
2af58c
|
922 |
$sql = "UPDATE `server` SET mail_server = ?, web_server = ?, dns_server = ?, file_server = ?, db_server = ?, vserver_server = ? WHERE server_id = ?"; |
b1a6a5
|
923 |
|
2af58c
|
924 |
$this->db->query($sql, $mail_server_enabled, $web_server_enabled, $dns_server_enabled, $file_server_enabled, $db_server_enabled, $vserver_server_enabled, $conf['server_id']); |
cb8c86
|
925 |
if($conf['mysql']['master_slave_setup'] == 'y') { |
2af58c
|
926 |
$this->dbmaster->query($sql, $mail_server_enabled, $web_server_enabled, $dns_server_enabled, $file_server_enabled, $db_server_enabled, $vserver_server_enabled, $conf['server_id']); |
cb8c86
|
927 |
} |
b1a6a5
|
928 |
|
3e0fc8
|
929 |
// chown install dir to root and chmod 755 |
TB |
930 |
$command = 'chown root:root '.$install_dir; |
|
931 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
932 |
$command = 'chmod 755 '.$install_dir; |
cb8c86
|
933 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
W |
934 |
|
fa029b
|
935 |
//* Chmod the files and directories in the install dir |
3e0fc8
|
936 |
$command = 'chmod -R 750 '.$install_dir.'/*'; |
TB |
937 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
938 |
|
|
939 |
//* chown the interface files to the ispconfig user and group |
|
940 |
$command = 'chown -R ispconfig:ispconfig '.$install_dir.'/interface'; |
|
941 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
942 |
|
|
943 |
//* chown the server files to the root user and group |
|
944 |
$command = 'chown -R root:root '.$install_dir.'/server'; |
cb8c86
|
945 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
fa029b
|
946 |
|
TB |
947 |
//* chown the security files to the root user and group |
|
948 |
$command = 'chown -R root:root '.$install_dir.'/security'; |
|
949 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
950 |
|
|
951 |
//* chown the security directory and security_settings.ini to root:ispconfig |
|
952 |
$command = 'chown root:ispconfig '.$install_dir.'/security/security_settings.ini'; |
|
953 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
954 |
$command = 'chown root:ispconfig '.$install_dir.'/security'; |
|
955 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
cb1221
|
956 |
$command = 'chown root:ispconfig '.$install_dir.'/security/ids.whitelist'; |
TB |
957 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
958 |
$command = 'chown root:ispconfig '.$install_dir.'/security/ids.htmlfield'; |
|
959 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
960 |
$command = 'chown root:ispconfig '.$install_dir.'/security/apache_directives.blacklist'; |
cb8c86
|
961 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
b1a6a5
|
962 |
|
ff1d9a
|
963 |
//* Make the global language file directory group writable |
cb8c86
|
964 |
exec("chmod -R 770 $install_dir/interface/lib/lang"); |
b1a6a5
|
965 |
|
ff1d9a
|
966 |
//* Make the temp directory for language file exports writable |
W |
967 |
if(is_dir($install_dir.'/interface/web/temp')) { |
|
968 |
exec("chmod -R 770 $install_dir/interface/web/temp"); |
|
969 |
} |
b1a6a5
|
970 |
|
MC |
971 |
//* Make all interface language file directories group writable |
cb8c86
|
972 |
$handle = @opendir($install_dir.'/interface/web'); |
b1a6a5
|
973 |
while ($file = @readdir($handle)) { |
MC |
974 |
if ($file != '.' && $file != '..') { |
|
975 |
if(@is_dir($install_dir.'/interface/web'.'/'.$file.'/lib/lang')) { |
cb8c86
|
976 |
$handle2 = opendir($install_dir.'/interface/web'.'/'.$file.'/lib/lang'); |
b1a6a5
|
977 |
chmod($install_dir.'/interface/web'.'/'.$file.'/lib/lang', 0770); |
MC |
978 |
while ($lang_file = @readdir($handle2)) { |
cb8c86
|
979 |
if ($lang_file != '.' && $lang_file != '..') { |
b1a6a5
|
980 |
chmod($install_dir.'/interface/web'.'/'.$file.'/lib/lang/'.$lang_file, 0770); |
cb8c86
|
981 |
} |
W |
982 |
} |
|
983 |
} |
|
984 |
} |
|
985 |
} |
b1a6a5
|
986 |
|
477d4e
|
987 |
//* Make the APS directories group writable |
T |
988 |
exec("chmod -R 770 $install_dir/interface/web/sites/aps_meta_packages"); |
|
989 |
exec("chmod -R 770 $install_dir/server/aps_packages"); |
b1a6a5
|
990 |
|
MC |
991 |
//* make sure that the server config file (not the interface one) is only readable by the root user |
bfcdef
|
992 |
chmod($install_dir.'/server/lib/config.inc.php', 0600); |
T |
993 |
chown($install_dir.'/server/lib/config.inc.php', 'root'); |
|
994 |
chgrp($install_dir.'/server/lib/config.inc.php', 'root'); |
b1a6a5
|
995 |
|
bfcdef
|
996 |
//* Make sure thet the interface config file is readable by user ispconfig only |
T |
997 |
chmod($install_dir.'/interface/lib/config.inc.php', 0600); |
|
998 |
chown($install_dir.'/interface/lib/config.inc.php', 'ispconfig'); |
|
999 |
chgrp($install_dir.'/interface/lib/config.inc.php', 'ispconfig'); |
ff1d9a
|
1000 |
|
W |
1001 |
chmod($install_dir.'/server/lib/remote_action.inc.php', 0600); |
|
1002 |
chown($install_dir.'/server/lib/remote_action.inc.php', 'root'); |
|
1003 |
chgrp($install_dir.'/server/lib/remote_action.inc.php', 'root'); |
|
1004 |
|
|
1005 |
if(@is_file($install_dir.'/server/lib/mysql_clientdb.conf')) { |
|
1006 |
chmod($install_dir.'/server/lib/mysql_clientdb.conf', 0600); |
|
1007 |
chown($install_dir.'/server/lib/mysql_clientdb.conf', 'root'); |
|
1008 |
chgrp($install_dir.'/server/lib/mysql_clientdb.conf', 'root'); |
cb8c86
|
1009 |
} |
b1a6a5
|
1010 |
|
8cf78b
|
1011 |
if(is_dir($install_dir.'/interface/invoices')) { |
e94a9f
|
1012 |
exec('chmod -R 770 '.escapeshellarg($install_dir.'/interface/invoices')); |
T |
1013 |
exec('chown -R ispconfig:ispconfig '.escapeshellarg($install_dir.'/interface/invoices')); |
edf806
|
1014 |
} |
980485
|
1015 |
|
TB |
1016 |
exec('chown -R root:root /usr/local/ispconfig/interface/ssl'); |
b1a6a5
|
1017 |
|
cb8c86
|
1018 |
// TODO: FIXME: add the www-data user to the ispconfig group. This is just for testing |
W |
1019 |
// and must be fixed as this will allow the apache user to read the ispconfig files. |
|
1020 |
// Later this must run as own apache server or via suexec! |
63b369
|
1021 |
if($conf['apache']['installed'] == true){ |
F |
1022 |
$command = 'usermod -a -G ispconfig '.$conf['apache']['user']; |
|
1023 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
272aec
|
1024 |
if(is_group('ispapps')){ |
F |
1025 |
$command = 'usermod -a -G ispapps '.$conf['apache']['user']; |
|
1026 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
1027 |
} |
63b369
|
1028 |
} |
F |
1029 |
if($conf['nginx']['installed'] == true){ |
|
1030 |
$command = 'usermod -a -G ispconfig '.$conf['nginx']['user']; |
|
1031 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
272aec
|
1032 |
if(is_group('ispapps')){ |
F |
1033 |
$command = 'usermod -a -G ispapps '.$conf['nginx']['user']; |
|
1034 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
1035 |
} |
63b369
|
1036 |
} |
b1a6a5
|
1037 |
|
ff1d9a
|
1038 |
//* Make the shell scripts executable |
cb8c86
|
1039 |
$command = "chmod +x $install_dir/server/scripts/*.sh"; |
W |
1040 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
b1a6a5
|
1041 |
|
7e1cfb
|
1042 |
if($conf['apache']['installed'] == true && $this->install_ispconfig_interface == true){ |
91324a
|
1043 |
//* Copy the ISPConfig vhost for the controlpanel |
F |
1044 |
$content = $this->get_template_file("apache_ispconfig.vhost", true); |
|
1045 |
$content = str_replace('{vhost_port}', $conf['apache']['vhost_port'], $content); |
b1a6a5
|
1046 |
|
91324a
|
1047 |
//* comment out the listen directive if port is 80 or 443 |
F |
1048 |
if ($conf['apache']['vhost_port'] == 80 or $conf['apache']['vhost_port'] == 443) { |
|
1049 |
$content = str_replace('{vhost_port_listen}', '#', $content); |
|
1050 |
} else { |
|
1051 |
$content = str_replace('{vhost_port_listen}', '', $content); |
|
1052 |
} |
b1a6a5
|
1053 |
|
91324a
|
1054 |
if(is_file($install_dir.'/interface/ssl/ispserver.crt') && is_file($install_dir.'/interface/ssl/ispserver.key')) { |
F |
1055 |
$content = str_replace('{ssl_comment}', '', $content); |
|
1056 |
} else { |
|
1057 |
$content = str_replace('{ssl_comment}', '#', $content); |
|
1058 |
} |
10b4c8
|
1059 |
if(is_file($install_dir.'/interface/ssl/ispserver.crt') && is_file($install_dir.'/interface/ssl/ispserver.key') && is_file($install_dir.'/interface/ssl/ispserver.bundle')) { |
T |
1060 |
$content = str_replace('{ssl_bundle_comment}', '', $content); |
|
1061 |
} else { |
|
1062 |
$content = str_replace('{ssl_bundle_comment}', '#', $content); |
|
1063 |
} |
b1a6a5
|
1064 |
|
91324a
|
1065 |
$vhost_path = $conf['apache']['vhost_conf_dir'].'/ispconfig.vhost'; |
F |
1066 |
$this->write_config_file($vhost_path, $content); |
b1a6a5
|
1067 |
|
526b99
|
1068 |
if(!is_file('/var/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter')) { |
615a0a
|
1069 |
$content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/apache_ispconfig_fcgi_starter.master', 'tpl/apache_ispconfig_fcgi_starter.master'); |
526b99
|
1070 |
$content = str_replace('{fastcgi_bin}', $conf['fastcgi']['fastcgi_bin'], $content); |
T |
1071 |
$content = str_replace('{fastcgi_phpini_path}', $conf['fastcgi']['fastcgi_phpini_path'], $content); |
cc6568
|
1072 |
@mkdir('/var/www/php-fcgi-scripts/ispconfig', 0755, true); |
526b99
|
1073 |
wf('/var/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter', $content); |
91324a
|
1074 |
exec('chmod +x /var/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter'); |
F |
1075 |
chmod('/var/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter', 0755); |
b1a6a5
|
1076 |
@symlink($install_dir.'/interface/web', '/var/www/ispconfig'); |
91324a
|
1077 |
exec('chown -R ispconfig:ispconfig /var/www/php-fcgi-scripts/ispconfig'); |
F |
1078 |
} |
cb8c86
|
1079 |
} |
91324a
|
1080 |
|
7e1cfb
|
1081 |
if($conf['nginx']['installed'] == true && $this->install_ispconfig_interface == true){ |
91324a
|
1082 |
//* Copy the ISPConfig vhost for the controlpanel |
F |
1083 |
$vhost_conf_dir = $conf['nginx']['vhost_conf_dir']; |
|
1084 |
$vhost_conf_enabled_dir = $conf['nginx']['vhost_conf_enabled_dir']; |
|
1085 |
|
|
1086 |
// Dont just copy over the virtualhost template but add some custom settings |
615a0a
|
1087 |
$content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/nginx_ispconfig.vhost.master', 'tpl/nginx_ispconfig.vhost.master'); |
91324a
|
1088 |
$content = str_replace('{vhost_port}', $conf['nginx']['vhost_port'], $content); |
b1a6a5
|
1089 |
|
91324a
|
1090 |
if(is_file($install_dir.'/interface/ssl/ispserver.crt') && is_file($install_dir.'/interface/ssl/ispserver.key')) { |
10b4c8
|
1091 |
$content = str_replace('{ssl_on}', ' on', $content); |
91324a
|
1092 |
$content = str_replace('{ssl_comment}', '', $content); |
F |
1093 |
$content = str_replace('{fastcgi_ssl}', 'on', $content); |
|
1094 |
} else { |
10b4c8
|
1095 |
$content = str_replace('{ssl_on}', ' off', $content); |
91324a
|
1096 |
$content = str_replace('{ssl_comment}', '#', $content); |
F |
1097 |
$content = str_replace('{fastcgi_ssl}', 'off', $content); |
|
1098 |
} |
b1a6a5
|
1099 |
|
ca0b77
|
1100 |
$socket_dir = escapeshellcmd($conf['nginx']['php_fpm_socket_dir']); |
b1a6a5
|
1101 |
if(substr($socket_dir, -1) != '/') $socket_dir .= '/'; |
ca0b77
|
1102 |
if(!is_dir($socket_dir)) exec('mkdir -p '.$socket_dir); |
F |
1103 |
$fpm_socket = $socket_dir.'ispconfig.sock'; |
b1a6a5
|
1104 |
|
ca0b77
|
1105 |
//$content = str_replace('{fpm_port}', $conf['nginx']['php_fpm_start_port'], $content); |
F |
1106 |
$content = str_replace('{fpm_socket}', $fpm_socket, $content); |
91324a
|
1107 |
|
F |
1108 |
wf($vhost_conf_dir.'/ispconfig.vhost', $content); |
b1a6a5
|
1109 |
|
91324a
|
1110 |
unset($content); |
b1a6a5
|
1111 |
|
91324a
|
1112 |
// PHP-FPM |
F |
1113 |
// Dont just copy over the php-fpm pool template but add some custom settings |
615a0a
|
1114 |
$content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/php_fpm_pool.conf.master', 'tpl/php_fpm_pool.conf.master'); |
91324a
|
1115 |
$content = str_replace('{fpm_pool}', 'ispconfig', $content); |
ca0b77
|
1116 |
//$content = str_replace('{fpm_port}', $conf['nginx']['php_fpm_start_port'], $content); |
F |
1117 |
$content = str_replace('{fpm_socket}', $fpm_socket, $content); |
91324a
|
1118 |
$content = str_replace('{fpm_user}', 'ispconfig', $content); |
F |
1119 |
$content = str_replace('{fpm_group}', 'ispconfig', $content); |
|
1120 |
wf($conf['nginx']['php_fpm_pool_dir'].'/ispconfig.conf', $content); |
|
1121 |
|
|
1122 |
//copy('tpl/nginx_ispconfig.vhost.master', $vhost_conf_dir.'/ispconfig.vhost'); |
|
1123 |
//* and create the symlink |
7e1cfb
|
1124 |
if($this->is_update == false) { |
91324a
|
1125 |
if(@is_link($vhost_conf_enabled_dir.'/ispconfig.vhost')) unlink($vhost_conf_enabled_dir.'/ispconfig.vhost'); |
F |
1126 |
if(!@is_link($vhost_conf_enabled_dir.'/000-ispconfig.vhost')) { |
b1a6a5
|
1127 |
symlink($vhost_conf_dir.'/ispconfig.vhost', $vhost_conf_enabled_dir.'/000-ispconfig.vhost'); |
91324a
|
1128 |
} |
F |
1129 |
} |
cb8c86
|
1130 |
} |
b1a6a5
|
1131 |
|
ff1d9a
|
1132 |
//* Install the update script |
b34f99
|
1133 |
if (is_file('/usr/local/bin/ispconfig_update_from_dev.sh')) { |
MC |
1134 |
unlink('/usr/local/bin/ispconfig_update_from_dev.sh'); |
cb8c86
|
1135 |
} |
b1a6a5
|
1136 |
|
b34f99
|
1137 |
chown($install_dir.'/server/scripts/update_from_dev.sh', 'root'); |
MC |
1138 |
chmod($install_dir.'/server/scripts/update_from_dev.sh', 0700); |
ff1d9a
|
1139 |
chown($install_dir.'/server/scripts/update_from_tgz.sh', 'root'); |
W |
1140 |
chmod($install_dir.'/server/scripts/update_from_tgz.sh', 0700); |
|
1141 |
chown($install_dir.'/server/scripts/ispconfig_update.sh', 'root'); |
|
1142 |
chmod($install_dir.'/server/scripts/ispconfig_update.sh', 0700); |
b1a6a5
|
1143 |
|
b34f99
|
1144 |
if (!is_link('/usr/local/bin/ispconfig_update_from_dev.sh')) { |
MC |
1145 |
symlink($install_dir.'/server/scripts/ispconfig_update.sh', '/usr/local/bin/ispconfig_update_from_dev.sh'); |
cb8c86
|
1146 |
} |
b1a6a5
|
1147 |
|
cb8c86
|
1148 |
if (!is_link('/usr/local/bin/ispconfig_update.sh')) { |
ff1d9a
|
1149 |
symlink($install_dir.'/server/scripts/ispconfig_update.sh', '/usr/local/bin/ispconfig_update.sh'); |
cb8c86
|
1150 |
} |
b1a6a5
|
1151 |
|
ff1d9a
|
1152 |
//* Make the logs readable for the ispconfig user |
cb8c86
|
1153 |
if (is_file('/var/log/maillog')) { |
W |
1154 |
exec('chmod +r /var/log/maillog'); |
|
1155 |
} |
|
1156 |
if (is_file('/var/log/messages')) { |
|
1157 |
exec('chmod +r /var/log/messages'); |
|
1158 |
} |
|
1159 |
if (is_file('/var/log/clamav/clamav.log')) { |
|
1160 |
exec('chmod +r /var/log/clamav/clamav.log'); |
|
1161 |
} |
|
1162 |
if (is_file('/var/log/clamav/freshclam.log')) { |
|
1163 |
exec('chmod +r /var/log/clamav/freshclam.log'); |
|
1164 |
} |
b1a6a5
|
1165 |
|
ff1d9a
|
1166 |
//* Create the ispconfig log directory |
e38d14
|
1167 |
if (!is_dir($conf['ispconfig_log_dir'])) { |
J |
1168 |
mkdir($conf['ispconfig_log_dir']); |
cb8c86
|
1169 |
} |
e38d14
|
1170 |
if (!is_file($conf['ispconfig_log_dir'].'/ispconfig.log')) { |
ff1d9a
|
1171 |
touch($conf['ispconfig_log_dir'].'/ispconfig.log'); |
cb8c86
|
1172 |
} |
b1a6a5
|
1173 |
|
0799f8
|
1174 |
//* Create the ispconfig auth log file and set uid/gid |
T |
1175 |
if(!is_file($conf['ispconfig_log_dir'].'/auth.log')) { |
|
1176 |
touch($conf['ispconfig_log_dir'].'/auth.log'); |
|
1177 |
} |
|
1178 |
exec('chown ispconfig:ispconfig '. $conf['ispconfig_log_dir'].'/auth.log'); |
|
1179 |
exec('chmod 660 '. $conf['ispconfig_log_dir'].'/auth.log'); |
b1a6a5
|
1180 |
|
ff1d9a
|
1181 |
rename($install_dir.'/server/scripts/run-getmail.sh', '/usr/local/bin/run-getmail.sh'); |
b1a6a5
|
1182 |
|
ff1d9a
|
1183 |
if (is_user('getmail')) { |
W |
1184 |
chown('/usr/local/bin/run-getmail.sh', 'getmail'); |
|
1185 |
} |
|
1186 |
chmod('/usr/local/bin/run-getmail.sh', 0744); |
b1a6a5
|
1187 |
|
d71bae
|
1188 |
//* Remove Domain module as its functions are available in the client module now |
T |
1189 |
if(@is_dir('/usr/local/ispconfig/interface/web/domain')) exec('rm -rf /usr/local/ispconfig/interface/web/domain'); |
021aec
|
1190 |
|
TB |
1191 |
// Add symlink for patch tool |
|
1192 |
if(!is_link('/usr/local/bin/ispconfig_patch')) exec('ln -s /usr/local/ispconfig/server/scripts/ispconfig_patch /usr/local/bin/ispconfig_patch'); |
c83951
|
1193 |
|
TB |
1194 |
// Change mode of a few files from amavisd |
|
1195 |
if(is_file($conf['amavis']['config_dir'].'/conf.d/50-user')) chmod($conf['amavis']['config_dir'].'/conf.d/50-user', 0640); |
|
1196 |
if(is_file($conf['amavis']['config_dir'].'/50-user~')) chmod($conf['amavis']['config_dir'].'/50-user~', 0400); |
|
1197 |
if(is_file($conf['amavis']['config_dir'].'/amavisd.conf')) chmod($conf['amavis']['config_dir'].'/amavisd.conf', 0640); |
|
1198 |
if(is_file($conf['amavis']['config_dir'].'/amavisd.conf~')) chmod($conf['amavis']['config_dir'].'/amavisd.conf~', 0400); |
|
1199 |
|
b1a6a5
|
1200 |
} |
MC |
1201 |
|
20218c
|
1202 |
} |
M |
1203 |
|
e38d14
|
1204 |
?> |