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 { |
|
32 |
|
|
33 |
var $plugin_name = 'apps_vhost_plugin'; |
|
34 |
var $class_name = 'apps_vhost_plugin'; |
|
35 |
|
|
36 |
|
|
37 |
//* This function is called during ispconfig installation to determine |
|
38 |
// if a symlink shall be created for this plugin. |
|
39 |
function onInstall() { |
|
40 |
global $conf; |
|
41 |
|
d06c20
|
42 |
if($conf['services']['web'] == true) { |
T |
43 |
return true; |
|
44 |
} else { |
|
45 |
return false; |
|
46 |
} |
c9b9f2
|
47 |
|
T |
48 |
} |
|
49 |
|
|
50 |
/* |
|
51 |
This function is called when the plugin is loaded |
|
52 |
*/ |
|
53 |
|
|
54 |
function onLoad() { |
|
55 |
global $app; |
|
56 |
|
|
57 |
/* |
|
58 |
Register for the events |
|
59 |
*/ |
|
60 |
|
|
61 |
$app->plugins->registerEvent('server_insert','apps_vhost_plugin','insert'); |
|
62 |
$app->plugins->registerEvent('server_update','apps_vhost_plugin','update'); |
|
63 |
|
|
64 |
|
|
65 |
} |
|
66 |
|
|
67 |
function insert($event_name,$data) { |
|
68 |
global $app, $conf; |
|
69 |
|
|
70 |
$this->update($event_name,$data); |
|
71 |
|
|
72 |
} |
|
73 |
|
|
74 |
// The purpose of this plugin is to rewrite the main.cf file |
|
75 |
function update($event_name,$data) { |
|
76 |
global $app, $conf; |
1d8123
|
77 |
|
c9b9f2
|
78 |
// get the config |
T |
79 |
$app->uses("getconf"); |
|
80 |
$web_config = $app->getconf->get_server_config($conf["server_id"], 'web'); |
|
81 |
|
4ffb51
|
82 |
if($web_config['server_type'] == 'apache'){ |
F |
83 |
// Dont just copy over the virtualhost template but add some custom settings |
|
84 |
$content = file_get_contents($conf["rootpath"]."/conf/apache_apps.vhost.master"); |
c9b9f2
|
85 |
|
4ffb51
|
86 |
$vhost_conf_dir = $web_config['vhost_conf_dir']; |
F |
87 |
$vhost_conf_enabled_dir = $web_config['vhost_conf_enabled_dir']; |
|
88 |
$apps_vhost_servername = ($web_config['apps_vhost_servername'] == '')?'':'ServerName '.$web_config['apps_vhost_servername']; |
c9b9f2
|
89 |
|
4ffb51
|
90 |
$web_config['apps_vhost_port'] = (empty($web_config['apps_vhost_port']))?8081:$web_config['apps_vhost_port']; |
F |
91 |
$web_config['apps_vhost_ip'] = (empty($web_config['apps_vhost_ip']))?'_default_':$web_config['apps_vhost_ip']; |
df8a46
|
92 |
|
4ffb51
|
93 |
$content = str_replace('{apps_vhost_ip}', $web_config['apps_vhost_ip'], $content); |
F |
94 |
$content = str_replace('{apps_vhost_port}', $web_config['apps_vhost_port'], $content); |
|
95 |
$content = str_replace('{apps_vhost_dir}', $web_config['website_basedir'].'/apps', $content); |
|
96 |
$content = str_replace('{apps_vhost_servername}', $apps_vhost_servername, $content); |
|
97 |
$content = str_replace('{apps_vhost_basedir}', $web_config['website_basedir'], $content); |
c9b9f2
|
98 |
|
T |
99 |
|
4ffb51
|
100 |
// comment out the listen directive if port is 80 or 443 |
F |
101 |
if($web_config['apps_vhost_ip'] == 80 or $web_config['apps_vhost_ip'] == 443) { |
|
102 |
$content = str_replace('{vhost_port_listen}', '#', $content); |
|
103 |
} else { |
|
104 |
$content = str_replace('{vhost_port_listen}', '', $content); |
|
105 |
} |
99b55b
|
106 |
|
F |
107 |
file_put_contents("$vhost_conf_dir/apps.vhost", $content); |
|
108 |
$app->services->restartServiceDelayed('httpd','restart'); |
4ffb51
|
109 |
} |
F |
110 |
|
|
111 |
if($web_config['server_type'] == 'nginx'){ |
|
112 |
// Dont just copy over the virtualhost template but add some custom settings |
|
113 |
$content = file_get_contents($conf["rootpath"]."/conf/nginx_apps.vhost.master"); |
|
114 |
|
|
115 |
$vhost_conf_dir = $web_config['nginx_vhost_conf_dir']; |
|
116 |
$vhost_conf_enabled_dir = $web_config['nginx_vhost_conf_enabled_dir']; |
|
117 |
$apps_vhost_servername = ($web_config['apps_vhost_servername'] == '')?'_':$web_config['apps_vhost_servername']; |
99b55b
|
118 |
|
F |
119 |
$apps_vhost_user = 'ispapps'; |
|
120 |
$apps_vhost_group = 'ispapps'; |
4ffb51
|
121 |
|
F |
122 |
$web_config['apps_vhost_port'] = (empty($web_config['apps_vhost_port']))?8081:$web_config['apps_vhost_port']; |
|
123 |
$web_config['apps_vhost_ip'] = (empty($web_config['apps_vhost_ip']))?'_default_':$web_config['apps_vhost_ip']; |
|
124 |
|
|
125 |
if($web_config['apps_vhost_ip'] == '_default_'){ |
|
126 |
$apps_vhost_ip = ''; |
|
127 |
} else { |
|
128 |
$apps_vhost_ip = $web_config['apps_vhost_ip'].':'; |
|
129 |
} |
ca0b77
|
130 |
|
F |
131 |
$socket_dir = escapeshellcmd($web_config['php_fpm_socket_dir']); |
|
132 |
if(substr($socket_dir,-1) != '/') $socket_dir .= '/'; |
|
133 |
if(!is_dir($socket_dir)) exec('mkdir -p '.$socket_dir); |
|
134 |
$fpm_socket = $socket_dir.'apps.sock'; |
94a7e1
|
135 |
$cgi_socket = escapeshellcmd($web_config['nginx_cgi_socket']); |
4ffb51
|
136 |
|
F |
137 |
$content = str_replace('{apps_vhost_ip}', $apps_vhost_ip, $content); |
|
138 |
$content = str_replace('{apps_vhost_port}', $web_config['apps_vhost_port'], $content); |
|
139 |
$content = str_replace('{apps_vhost_dir}', $web_config['website_basedir'].'/apps', $content); |
|
140 |
$content = str_replace('{apps_vhost_servername}', $apps_vhost_servername, $content); |
ca0b77
|
141 |
//$content = str_replace('{fpm_port}', $web_config['php_fpm_start_port']+1, $content); |
F |
142 |
$content = str_replace('{fpm_socket}', $fpm_socket, $content); |
94a7e1
|
143 |
$content = str_replace('{cgi_socket}', $cgi_socket, $content); |
99b55b
|
144 |
|
F |
145 |
// PHP-FPM |
|
146 |
// Dont just copy over the php-fpm pool template but add some custom settings |
|
147 |
$fpm_content = file_get_contents($conf["rootpath"]."/conf/apps_php_fpm_pool.conf.master"); |
|
148 |
$fpm_content = str_replace('{fpm_pool}', 'apps', $fpm_content); |
|
149 |
//$fpm_content = str_replace('{fpm_port}', $web_config['php_fpm_start_port']+1, $fpm_content); |
|
150 |
$fpm_content = str_replace('{fpm_socket}', $fpm_socket, $fpm_content); |
|
151 |
$fpm_content = str_replace('{fpm_user}', $apps_vhost_user, $fpm_content); |
|
152 |
$fpm_content = str_replace('{fpm_group}', $apps_vhost_group, $fpm_content); |
|
153 |
file_put_contents($web_config['php_fpm_pool_dir'].'/apps.conf', $fpm_content); |
|
154 |
|
|
155 |
file_put_contents("$vhost_conf_dir/apps.vhost", $content); |
|
156 |
$app->services->restartServiceDelayed('httpd','reload'); |
c9b9f2
|
157 |
} |
T |
158 |
} |
|
159 |
|
|
160 |
|
|
161 |
} // end class |
|
162 |
|
|
163 |
|
|
164 |
|
|
165 |
?> |