commit | author | age
|
c9b9f2
|
1 |
<?php |
T |
2 |
|
|
3 |
/* |
|
4 |
Copyright (c) 2009, 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 apps_vhost_plugin { |
7fe908
|
32 |
|
c9b9f2
|
33 |
var $plugin_name = 'apps_vhost_plugin'; |
T |
34 |
var $class_name = 'apps_vhost_plugin'; |
7fe908
|
35 |
|
MC |
36 |
|
c9b9f2
|
37 |
//* This function is called during ispconfig installation to determine |
T |
38 |
// if a symlink shall be created for this plugin. |
|
39 |
function onInstall() { |
|
40 |
global $conf; |
7fe908
|
41 |
|
6882ab
|
42 |
if($conf['services']['web'] == true) { |
T |
43 |
return true; |
|
44 |
} else { |
|
45 |
return false; |
|
46 |
} |
7fe908
|
47 |
|
c9b9f2
|
48 |
} |
7fe908
|
49 |
|
c9b9f2
|
50 |
/* |
T |
51 |
This function is called when the plugin is loaded |
|
52 |
*/ |
7fe908
|
53 |
|
c9b9f2
|
54 |
function onLoad() { |
T |
55 |
global $app; |
7fe908
|
56 |
|
c9b9f2
|
57 |
/* |
T |
58 |
Register for the events |
|
59 |
*/ |
7fe908
|
60 |
|
MC |
61 |
$app->plugins->registerEvent('server_insert', 'apps_vhost_plugin', 'insert'); |
|
62 |
$app->plugins->registerEvent('server_update', 'apps_vhost_plugin', 'update'); |
|
63 |
|
|
64 |
|
c9b9f2
|
65 |
} |
7fe908
|
66 |
|
MC |
67 |
function insert($event_name, $data) { |
c9b9f2
|
68 |
global $app, $conf; |
7fe908
|
69 |
|
MC |
70 |
$this->update($event_name, $data); |
|
71 |
|
c9b9f2
|
72 |
} |
7fe908
|
73 |
|
c9b9f2
|
74 |
// The purpose of this plugin is to rewrite the main.cf file |
7fe908
|
75 |
function update($event_name, $data) { |
c9b9f2
|
76 |
global $app, $conf; |
7fe908
|
77 |
|
c9b9f2
|
78 |
// get the config |
T |
79 |
$app->uses("getconf"); |
|
80 |
$web_config = $app->getconf->get_server_config($conf["server_id"], 'web'); |
7fe908
|
81 |
|
4ffb51
|
82 |
if($web_config['server_type'] == 'apache'){ |
8133de
|
83 |
$app->load('tpl'); |
7fe908
|
84 |
|
8133de
|
85 |
$tpl = new tpl(); |
MC |
86 |
$tpl->newTemplate('apache_apps.vhost.master'); |
|
87 |
|
|
88 |
$tpl->setVar('apache_version', $app->system->getapacheversion()); |
7fe908
|
89 |
|
4ffb51
|
90 |
$vhost_conf_dir = $web_config['vhost_conf_dir']; |
F |
91 |
$vhost_conf_enabled_dir = $web_config['vhost_conf_enabled_dir']; |
|
92 |
$apps_vhost_servername = ($web_config['apps_vhost_servername'] == '')?'':'ServerName '.$web_config['apps_vhost_servername']; |
7fe908
|
93 |
|
4ffb51
|
94 |
$web_config['apps_vhost_port'] = (empty($web_config['apps_vhost_port']))?8081:$web_config['apps_vhost_port']; |
F |
95 |
$web_config['apps_vhost_ip'] = (empty($web_config['apps_vhost_ip']))?'_default_':$web_config['apps_vhost_ip']; |
7fe908
|
96 |
|
8133de
|
97 |
$tpl->setVar('apps_vhost_ip', $web_config['apps_vhost_ip']); |
MC |
98 |
$tpl->setVar('apps_vhost_port', $web_config['apps_vhost_port']); |
|
99 |
$tpl->setVar('apps_vhost_dir', $web_config['website_basedir'].'/apps'); |
|
100 |
$tpl->setVar('apps_vhost_servername', $apps_vhost_servername); |
|
101 |
$tpl->setVar('apps_vhost_basedir', $web_config['website_basedir']); |
|
102 |
|
|
103 |
$vhost_port_listen = ''; |
|
104 |
// comment out the listen directive if port is 80 or 443 |
|
105 |
if($web_config['apps_vhost_port'] == 80 or $web_config['apps_vhost_port'] == 443) { |
|
106 |
$vhost_port_listen = '#'; |
|
107 |
} |
|
108 |
$tpl->setVar('vhost_port_listen', $vhost_port_listen); |
|
109 |
|
|
110 |
$content = $tpl->grab(); |
|
111 |
|
|
112 |
/* for backwards compatibility we replace the old syntax by hand now */ |
4ffb51
|
113 |
$content = str_replace('{apps_vhost_ip}', $web_config['apps_vhost_ip'], $content); |
F |
114 |
$content = str_replace('{apps_vhost_port}', $web_config['apps_vhost_port'], $content); |
|
115 |
$content = str_replace('{apps_vhost_dir}', $web_config['website_basedir'].'/apps', $content); |
|
116 |
$content = str_replace('{apps_vhost_servername}', $apps_vhost_servername, $content); |
|
117 |
$content = str_replace('{apps_vhost_basedir}', $web_config['website_basedir'], $content); |
8133de
|
118 |
$content = str_replace('{vhost_port_listen}', $vhost_port_listen, $content); |
MC |
119 |
/* end of backwards compatibility section */ |
7fe908
|
120 |
|
8133de
|
121 |
$app->system->file_put_contents("$vhost_conf_dir/apps.vhost", $content); |
1dbd0e
|
122 |
|
FS |
123 |
// enabled / disable apps-vhost |
|
124 |
$vhost_symlink = escapeshellcmd($web_config['vhost_conf_enabled_dir'].'/000-apps.vhost'); |
|
125 |
if(is_link($vhost_symlink) && $web_config['apps_vhost_enabled'] == 'n') { |
|
126 |
$app->system->unlink($vhost_symlink); |
|
127 |
} |
|
128 |
if(!@is_link($vhost_conf_enabled_dir.'/000-apps.vhost') && $web_config['apps_vhost_enabled'] == 'y') { |
|
129 |
symlink($vhost_conf_dir.'/apps.vhost', $vhost_conf_enabled_dir.'/000-apps.vhost'); |
|
130 |
} |
|
131 |
|
7fe908
|
132 |
$app->services->restartServiceDelayed('httpd', 'restart'); |
4ffb51
|
133 |
} |
7fe908
|
134 |
|
4ffb51
|
135 |
if($web_config['server_type'] == 'nginx'){ |
F |
136 |
// Dont just copy over the virtualhost template but add some custom settings |
cc6568
|
137 |
if(file_exists($conf["rootpath"]."/conf-custom/nginx_apps.vhost.master")) { |
H |
138 |
$content = file_get_contents($conf["rootpath"]."/conf-custom/nginx_apps.vhost.master"); |
|
139 |
} else { |
|
140 |
$content = file_get_contents($conf["rootpath"]."/conf/nginx_apps.vhost.master"); |
|
141 |
} |
7fe908
|
142 |
|
4ffb51
|
143 |
$vhost_conf_dir = $web_config['nginx_vhost_conf_dir']; |
F |
144 |
$vhost_conf_enabled_dir = $web_config['nginx_vhost_conf_enabled_dir']; |
|
145 |
$apps_vhost_servername = ($web_config['apps_vhost_servername'] == '')?'_':$web_config['apps_vhost_servername']; |
7fe908
|
146 |
|
99b55b
|
147 |
$apps_vhost_user = 'ispapps'; |
F |
148 |
$apps_vhost_group = 'ispapps'; |
7fe908
|
149 |
|
4ffb51
|
150 |
$web_config['apps_vhost_port'] = (empty($web_config['apps_vhost_port']))?8081:$web_config['apps_vhost_port']; |
F |
151 |
$web_config['apps_vhost_ip'] = (empty($web_config['apps_vhost_ip']))?'_default_':$web_config['apps_vhost_ip']; |
7fe908
|
152 |
|
4ffb51
|
153 |
if($web_config['apps_vhost_ip'] == '_default_'){ |
F |
154 |
$apps_vhost_ip = ''; |
|
155 |
} else { |
|
156 |
$apps_vhost_ip = $web_config['apps_vhost_ip'].':'; |
|
157 |
} |
7fe908
|
158 |
|
ca0b77
|
159 |
$socket_dir = escapeshellcmd($web_config['php_fpm_socket_dir']); |
7fe908
|
160 |
if(substr($socket_dir, -1) != '/') $socket_dir .= '/'; |
ca0b77
|
161 |
if(!is_dir($socket_dir)) exec('mkdir -p '.$socket_dir); |
F |
162 |
$fpm_socket = $socket_dir.'apps.sock'; |
8ab3cd
|
163 |
$cgi_socket = escapeshellcmd($web_config['nginx_cgi_socket']); |
7fe908
|
164 |
|
4ffb51
|
165 |
$content = str_replace('{apps_vhost_ip}', $apps_vhost_ip, $content); |
F |
166 |
$content = str_replace('{apps_vhost_port}', $web_config['apps_vhost_port'], $content); |
|
167 |
$content = str_replace('{apps_vhost_dir}', $web_config['website_basedir'].'/apps', $content); |
|
168 |
$content = str_replace('{apps_vhost_servername}', $apps_vhost_servername, $content); |
ca0b77
|
169 |
//$content = str_replace('{fpm_port}', $web_config['php_fpm_start_port']+1, $content); |
F |
170 |
$content = str_replace('{fpm_socket}', $fpm_socket, $content); |
8ab3cd
|
171 |
$content = str_replace('{cgi_socket}', $cgi_socket, $content); |
183c47
|
172 |
if(file_exists('/var/run/php5-fpm.sock')){ |
F |
173 |
$use_tcp = '#'; |
|
174 |
$use_socket = ''; |
|
175 |
} else { |
|
176 |
$use_tcp = ''; |
|
177 |
$use_socket = '#'; |
|
178 |
} |
|
179 |
$content = str_replace('{use_tcp}', $use_tcp, $content); |
|
180 |
$content = str_replace('{use_socket}', $use_socket, $content); |
7fe908
|
181 |
|
99b55b
|
182 |
// PHP-FPM |
F |
183 |
// Dont just copy over the php-fpm pool template but add some custom settings |
cc6568
|
184 |
if(file_exists($conf["rootpath"]."/conf-custom/apps_php_fpm_pool.conf.master")) { |
H |
185 |
$fpm_content = file_get_contents($conf["rootpath"]."/conf-custom/apps_php_fpm_pool.conf.master"); |
|
186 |
} else { |
|
187 |
$fpm_content = file_get_contents($conf["rootpath"]."/conf/apps_php_fpm_pool.conf.master"); |
|
188 |
} |
7fe908
|
189 |
|
99b55b
|
190 |
$fpm_content = str_replace('{fpm_pool}', 'apps', $fpm_content); |
F |
191 |
//$fpm_content = str_replace('{fpm_port}', $web_config['php_fpm_start_port']+1, $fpm_content); |
|
192 |
$fpm_content = str_replace('{fpm_socket}', $fpm_socket, $fpm_content); |
|
193 |
$fpm_content = str_replace('{fpm_user}', $apps_vhost_user, $fpm_content); |
|
194 |
$fpm_content = str_replace('{fpm_group}', $apps_vhost_group, $fpm_content); |
|
195 |
file_put_contents($web_config['php_fpm_pool_dir'].'/apps.conf', $fpm_content); |
7fe908
|
196 |
|
99b55b
|
197 |
file_put_contents("$vhost_conf_dir/apps.vhost", $content); |
1dbd0e
|
198 |
|
FS |
199 |
// enabled / disable apps-vhost |
|
200 |
$vhost_symlink = escapeshellcmd($web_config['vhost_conf_enabled_dir'].'/000-apps.vhost'); |
|
201 |
if(is_link($vhost_symlink) && $web_config['apps_vhost_enabled'] == 'n') { |
|
202 |
$app->system->unlink($vhost_symlink); |
|
203 |
} |
|
204 |
if(!@is_link($vhost_conf_enabled_dir.'/000-apps.vhost') && $web_config['apps_vhost_enabled'] == 'y') { |
|
205 |
symlink($vhost_conf_dir.'/apps.vhost', $vhost_conf_enabled_dir.'/000-apps.vhost'); |
|
206 |
} |
|
207 |
|
7fe908
|
208 |
$app->services->restartServiceDelayed('httpd', 'reload'); |
c9b9f2
|
209 |
} |
T |
210 |
} |
7fe908
|
211 |
|
c9b9f2
|
212 |
|
T |
213 |
} // end class |
|
214 |
|
|
215 |
|
|
216 |
|
7fe908
|
217 |
?> |