Skip to content

Commit 5f96909

Browse files
author
Marius Burkard
committed
- manually ported merge request !963
1 parent e08d9e4 commit 5f96909

File tree

2 files changed

+108
-90
lines changed

2 files changed

+108
-90
lines changed

server/plugins-available/apache2_plugin.inc.php

Lines changed: 56 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function onLoad() {
7373
$app->plugins->registerEvent('server_ip_insert', $this->plugin_name, 'server_ip');
7474
$app->plugins->registerEvent('server_ip_update', $this->plugin_name, 'server_ip');
7575
$app->plugins->registerEvent('server_ip_delete', $this->plugin_name, 'server_ip');
76-
76+
7777
$app->plugins->registerEvent('server_insert', $this->plugin_name, 'server_ip');
7878
$app->plugins->registerEvent('server_update', $this->plugin_name, 'server_ip');
7979

@@ -97,14 +97,14 @@ function onLoad() {
9797

9898
private function get_master_php_ini_content($web_data) {
9999
global $app, $conf;
100-
100+
101101
$app->uses('getconf');
102102
$web_config = $app->getconf->get_server_config($conf['server_id'], 'web');
103103
$fastcgi_config = $app->getconf->get_server_config($conf['server_id'], 'fastcgi');
104-
104+
105105
$php_ini_content = '';
106106
$master_php_ini_path = '';
107-
107+
108108
if($web_data['php'] == 'mod') {
109109
$master_php_ini_path = $web_config['php_ini_path_apache'];
110110
} else {
@@ -135,7 +135,7 @@ private function get_master_php_ini_content($web_data) {
135135
}
136136
}
137137
}
138-
138+
139139
// Resolve inconsistant path settings
140140
if($master_php_ini_path != '' && is_dir($master_php_ini_path) && is_file($master_php_ini_path.'/php.ini')) {
141141
$master_php_ini_path .= '/php.ini';
@@ -145,7 +145,7 @@ private function get_master_php_ini_content($web_data) {
145145
if($master_php_ini_path != '' && substr($master_php_ini_path, -7) == 'php.ini' && is_file($master_php_ini_path)) {
146146
$php_ini_content .= $app->system->file_get_contents($master_php_ini_path)."\n";
147147
}
148-
148+
149149
return $php_ini_content;
150150
}
151151

@@ -200,11 +200,11 @@ function php_ini_changed($event_name, $data) {
200200
$custom_php_ini_dir .= '_' . $web_folder;
201201
}
202202
if(!is_dir($web_config['website_basedir'].'/conf')) $app->system->mkdir($web_config['website_basedir'].'/conf');
203-
203+
204204
if(!is_dir($custom_php_ini_dir)) $app->system->mkdir($custom_php_ini_dir);
205-
205+
206206
$php_ini_content = $this->get_master_php_ini_content($web_data);
207-
207+
208208
if(intval($web_data['directive_snippets_id']) > 0){
209209
$snippet = $app->db->queryOneRecord("SELECT * FROM directive_snippets WHERE directive_snippets_id = ? AND type = 'apache' AND active = 'y' AND customer_viewable = 'y'", intval($web_data['directive_snippets_id']));
210210
if(isset($snippet['required_php_snippets']) && trim($snippet['required_php_snippets']) != ''){
@@ -223,7 +223,7 @@ function php_ini_changed($event_name, $data) {
223223
}
224224
}
225225
}
226-
226+
227227
$php_ini_content .= str_replace("\r", '', trim($web_data['custom_php_ini']));
228228
$app->system->file_put_contents($custom_php_ini_dir.'/php.ini', $php_ini_content);
229229
$app->log('Info: rewrote custom php.ini for web ' . $web_data['domain_id'] . ' (' . $web_data['domain'] . ').', LOGLEVEL_DEBUG);
@@ -329,8 +329,16 @@ function ssl($event_name, $data) {
329329
[ req_attributes ]
330330
";//challengePassword = A challenge password";
331331

332+
$ext_cnf = "
333+
subjectAltName = @alt_names
334+
335+
[alt_names]
336+
DNS.1 = .$domain";
337+
332338
$ssl_cnf_file = $ssl_dir.'/openssl.conf';
333339
$app->system->file_put_contents($ssl_cnf_file, $ssl_cnf);
340+
$ssl_ext_file = $ssl_dir.'/v3.ext';
341+
$app->system->file_put_contents($ssl_ext_file, $ext_cnf);
334342

335343
$rand_file = $rand_file;
336344
$key_file2 = $key_file2;
@@ -356,10 +364,10 @@ function ssl($event_name, $data) {
356364

357365
if(file_exists($web_config['CA_path'].'/openssl.cnf'))
358366
{
359-
$app->system->exec_safe("openssl ca -batch -out ? -config ? -passin pass:? -in ?", $openssl_cmd_crt_file, $web_config['CA_path']."/openssl.cnf", $web_config['CA_pass'], $openssl_cmd_csr_file);
367+
$app->system->exec_safe("openssl ca -batch -out ? -config ? -passin pass:? -in ? -extfile ?", $openssl_cmd_crt_file, $web_config['CA_path']."/openssl.cnf", $web_config['CA_pass'], $openssl_cmd_csr_file, $ssl_ext_file);
360368
$app->log("Creating CA-signed SSL Cert for: $domain", LOGLEVEL_DEBUG);
361369
if(filesize($crt_file) == 0 || !file_exists($crt_file)) {
362-
$app->log("CA-Certificate signing failed. openssl ca -out $openssl_cmd_crt_file -config " . $web_config['CA_path'] . "/openssl.cnf -passin pass:" . $web_config['CA_pass'] . " -in $openssl_cmd_csr_file", LOGLEVEL_ERROR);
370+
$app->log("CA-Certificate signing failed. openssl ca -out $openssl_cmd_crt_file -config " . $web_config['CA_path'] . "/openssl.cnf -passin pass:" . $web_config['CA_pass'] . " -in $openssl_cmd_csr_file -extfile $ssl_ext_file", LOGLEVEL_ERROR);
363371
}
364372
};
365373
if (@filesize($crt_file)==0 || !file_exists($crt_file)){
@@ -373,6 +381,7 @@ function ssl($event_name, $data) {
373381
$app->system->chmod($key_file, 0400);
374382
@$app->system->unlink($config_file);
375383
@$app->system->unlink($rand_file);
384+
@$app->system->unlink($ssl_ext_file);
376385
$ssl_request = $app->system->file_get_contents($csr_file);
377386
$ssl_cert = $app->system->file_get_contents($crt_file);
378387
$ssl_key = $app->system->file_get_contents($key_file);
@@ -383,23 +392,23 @@ function ssl($event_name, $data) {
383392
$app->dbmaster->query("UPDATE web_domain SET ssl_request = ?, ssl_cert = ?, ssl_key = ? WHERE domain = ?", $ssl_request, $ssl_cert, $ssl_key, $data['new']['domain']);
384393
$app->dbmaster->query("UPDATE web_domain SET ssl_action = '' WHERE domain = ?", $data['new']['domain']);
385394
}
386-
395+
387396
//* Check that the SSL key is not password protected
388397
if($data["new"]["ssl_action"] == 'save') {
389398
if(stristr($data["new"]["ssl_key"],'Proc-Type: 4,ENCRYPTED')) {
390399
$data["new"]["ssl_action"] = '';
391-
400+
392401
$app->log('SSL Certificate not saved. The SSL key is encrypted.', LOGLEVEL_WARN);
393402
$app->dbmaster->datalogError('SSL Certificate not saved. The SSL key is encrypted.');
394-
403+
395404
/* Update the DB of the (local) Server */
396405
$app->db->query("UPDATE web_domain SET ssl_action = '' WHERE domain = ?", $data['new']['domain']);
397406

398407
/* Update also the master-DB of the Server-Farm */
399408
$app->dbmaster->query("UPDATE web_domain SET ssl_action = '' WHERE domain = ?", $data['new']['domain']);
400409
}
401410
}
402-
411+
403412
//* and check that SSL cert does not contain subdomain of domain acme.invalid
404413
if($data["new"]["ssl_action"] == 'save') {
405414
$tmp = array();
@@ -409,10 +418,10 @@ function ssl($event_name, $data) {
409418
$crt_data = implode("\n",$tmp);
410419
if(stristr($crt_data,'.acme.invalid')) {
411420
$data["new"]["ssl_action"] = '';
412-
421+
413422
$app->log('SSL Certificate not saved. The SSL cert contains domain acme.invalid.', LOGLEVEL_WARN);
414423
$app->dbmaster->datalogError('SSL Certificate not saved. The SSL cert contains domain acme.invalid.');
415-
424+
416425
/* Update the DB of the (local) Server */
417426
$app->db->query("UPDATE web_domain SET ssl_action = '' WHERE domain = ?", $data['new']['domain']);
418427

@@ -570,7 +579,7 @@ function update($event_name, $data) {
570579
$web_folder = $data['new']['web_folder'];
571580
$log_folder .= '/' . $subdomain_host;
572581
unset($tmp);
573-
582+
574583
if(isset($data['old']['parent_domain_id'])) {
575584
// old one
576585
$tmp = $app->db->queryOneRecord('SELECT `domain` FROM web_domain WHERE domain_id = ?', $data['old']['parent_domain_id']);
@@ -666,7 +675,7 @@ function update($event_name, $data) {
666675
$app->system->rename($data['new']['document_root'], $data['new']['document_root'].'_bak_'.date('Y_m_d_H_i_s'));
667676
$app->log('Renaming existing directory in new docroot location. mv '.$data['new']['document_root'].' '.$data['new']['document_root'].'_bak_'.date('Y_m_d_H_i_s'), LOGLEVEL_DEBUG);
668677
}
669-
678+
670679
//* Unmount the old log directory bfore we move the log dir
671680
$app->system->exec_safe('umount ?', $data['old']['document_root'].'/log');
672681

@@ -702,19 +711,19 @@ function update($event_name, $data) {
702711
$fstab_line = '/var/log/ispconfig/httpd/'.$data['old']['domain'].' '.$data['old']['document_root'].'/'.$old_log_folder.' none bind,nobootwait';
703712
$app->system->removeLine('/etc/fstab', $fstab_line);
704713
*/
705-
714+
706715
$fstab_line_old = '/var/log/ispconfig/httpd/'.$data['old']['domain'].' '.$data['old']['document_root'].'/'.$old_log_folder.' none bind';
707-
716+
708717
if($web_config['network_filesystem'] == 'y') {
709718
$fstab_line = '/var/log/ispconfig/httpd/'.$data['new']['domain'].' '.$data['new']['document_root'].'/'.$log_folder.' none bind,nofail,_netdev 0 0';
710719
$app->system->replaceLine('/etc/fstab', $fstab_line_old, $fstab_line, 0, 1);
711720
} else {
712721
$fstab_line = '/var/log/ispconfig/httpd/'.$data['new']['domain'].' '.$data['new']['document_root'].'/'.$log_folder.' none bind,nofail 0 0';
713722
$app->system->replaceLine('/etc/fstab', $fstab_line_old, $fstab_line, 0, 1);
714723
}
715-
724+
716725
$app->system->exec_safe('mount --bind ? ?', '/var/log/ispconfig/httpd/'.$data['new']['domain'], $data['new']['document_root'].'/'.$log_folder);
717-
726+
718727
}
719728

720729
//print_r($data);
@@ -729,7 +738,7 @@ function update($event_name, $data) {
729738
if(!is_dir($data['new']['document_root'].'/cgi-bin')) $app->system->mkdirpath($data['new']['document_root'].'/cgi-bin');
730739
if(!is_dir($data['new']['document_root'].'/tmp')) $app->system->mkdirpath($data['new']['document_root'].'/tmp');
731740
if(!is_dir($data['new']['document_root'].'/webdav')) $app->system->mkdirpath($data['new']['document_root'].'/webdav');
732-
741+
733742
if(!is_dir($data['new']['document_root'].'/.ssh')) {
734743
$app->system->mkdirpath($data['new']['document_root'].'/.ssh');
735744
$app->system->chmod($data['new']['document_root'].'/.ssh', 0700);
@@ -1115,10 +1124,10 @@ function update($event_name, $data) {
11151124
if(trim($data['new']['custom_php_ini']) != '') {
11161125
$has_custom_php_ini = true;
11171126
if(!is_dir($custom_php_ini_dir)) $app->system->mkdirpath($custom_php_ini_dir);
1118-
1127+
11191128
$php_ini_content = $this->get_master_php_ini_content($data['new']);
11201129
$php_ini_content .= str_replace("\r", '', trim($data['new']['custom_php_ini']));
1121-
1130+
11221131
if(intval($data['new']['directive_snippets_id']) > 0){
11231132
$snippet = $app->db->queryOneRecord("SELECT * FROM directive_snippets WHERE directive_snippets_id = ? AND type = 'apache' AND active = 'y' AND customer_viewable = 'y'", intval($data['new']['directive_snippets_id']));
11241133
if(isset($snippet['required_php_snippets']) && trim($snippet['required_php_snippets']) != ''){
@@ -1137,7 +1146,7 @@ function update($event_name, $data) {
11371146
}
11381147
}
11391148
}
1140-
1149+
11411150
$app->system->file_put_contents($custom_php_ini_dir.'/php.ini', $php_ini_content);
11421151
} else {
11431152
$has_custom_php_ini = false;
@@ -1179,7 +1188,7 @@ function update($event_name, $data) {
11791188
'{DOCROOT_CLIENT}' => $vhost_data['web_document_root']
11801189
);
11811190
$vhost_data['apache_directives'] = strtr($vhost_data['apache_directives'], $trans);
1182-
1191+
11831192
$app->uses('letsencrypt');
11841193
// Check if a SSL cert exists
11851194
$tmp = $app->letsencrypt->get_website_certificate_paths($data);
@@ -1190,7 +1199,7 @@ function update($event_name, $data) {
11901199
$crt_file = $tmp['crt'];
11911200
$bundle_file = $tmp['bundle'];
11921201
unset($tmp);
1193-
1202+
11941203
$data['new']['ssl_domain'] = $domain;
11951204
$vhost_data['ssl_domain'] = $domain;
11961205
$vhost_data['ssl_crt_file'] = $crt_file;
@@ -1222,7 +1231,7 @@ function update($event_name, $data) {
12221231
$app->dbmaster->query("UPDATE web_domain SET `ssl` = ?, `ssl_letsencrypt` = ? WHERE `domain` = ? AND `server_id` = ?", $data['new']['ssl'], 'n', $data['new']['domain'], $conf['server_id']);
12231232
}
12241233
}
1225-
1234+
12261235
// Use separate bundle file only for apache versions < 2.4.8
12271236
if(@is_file($bundle_file) && version_compare($app->system->getapacheversion(true), '2.4.8', '<')) $vhost_data['has_bundle_cert'] = 1;
12281237

@@ -1425,7 +1434,7 @@ function update($event_name, $data) {
14251434
} else {
14261435
$tpl->setVar('alias', '');
14271436
}
1428-
1437+
14291438
if (count($rewrite_wildcard_rules) > 0) $rewrite_rules = array_merge($rewrite_rules, $rewrite_wildcard_rules); // Append wildcard rules to the end of rules
14301439

14311440
if(count($rewrite_rules) > 0 || $vhost_data['seo_redirect_enabled'] > 0 || count($alias_seo_redirects) > 0 || $data['new']['rewrite_to_https'] == 'y') {
@@ -1568,7 +1577,7 @@ function update($event_name, $data) {
15681577
$pool_name = 'web'.$data['new']['domain_id'];
15691578
$socket_dir = $web_config['php_fpm_socket_dir'];
15701579
if(substr($socket_dir, -1) != '/') $socket_dir .= '/';
1571-
1580+
15721581
if($data['new']['php_fpm_use_socket'] == 'y'){
15731582
$use_tcp = 0;
15741583
$use_socket = 1;
@@ -2051,9 +2060,9 @@ function delete($event_name, $data) {
20512060
} else {
20522061
$app->system->exec_safe('umount ? 2>/dev/null', $data['old']['document_root'].'/'.$log_folder);
20532062
}
2054-
2063+
20552064
// remove letsencrypt if it exists (renew will always fail otherwise)
2056-
2065+
20572066
$old_domain = $data['old']['domain'];
20582067
if(substr($old_domain, 0, 2) === '*.') {
20592068
// wildcard domain not yet supported by letsencrypt!
@@ -2588,7 +2597,7 @@ function web_folder_update($event_name, $data) {
25882597
$app->system->chown($new_folder_path.'.htaccess', $website['system_user']);
25892598
$app->system->chgrp($new_folder_path.'.htaccess', $website['system_group']);
25902599
$app->log('Created/modified file '.$new_folder_path.'.htaccess', LOGLEVEL_DEBUG);
2591-
2600+
25922601
//* Create empty .htpasswd file, if it does not exist
25932602
if(!is_file($folder_path.'.htpasswd')) {
25942603
$app->system->touch($new_folder_path.'.htpasswd');
@@ -2964,7 +2973,7 @@ private function awstats_delete ($data, $web_config) {
29642973

29652974
private function hhvm_update($data, $web_config) {
29662975
global $app, $conf;
2967-
2976+
29682977
if(file_exists($conf['rootpath'] . '/conf-custom/hhvm_starter.master')) {
29692978
$content = file_get_contents($conf['rootpath'] . '/conf-custom/hhvm_starter.master');
29702979
} else {
@@ -2975,7 +2984,7 @@ private function hhvm_update($data, $web_config) {
29752984
} else {
29762985
$monit_content = file_get_contents($conf['rootpath'] . '/conf/hhvm_monit.master');
29772986
}
2978-
2987+
29792988
if($data['new']['php'] == 'hhvm' && $data['old']['php'] != 'hhvm' || ($data['new']['php'] == 'hhvm' && isset($data['old']['custom_php_ini']) && $data['new']['custom_php_ini'] != $data['old']['custom_php_ini'])) {
29802989

29812990
// Custom php.ini settings
@@ -3012,22 +3021,22 @@ private function hhvm_update($data, $web_config) {
30123021
$app->system->exec_safe('chmod +x ? >/dev/null 2>&1', '/etc/init.d/hhvm_' . $data['new']['system_user']);
30133022
$app->system->exec_safe('/usr/sbin/update-rc.d ? defaults >/dev/null 2>&1', 'hhvm_' . $data['new']['system_user']);
30143023
$app->system->exec_safe('? restart >/dev/null 2>&1', '/etc/init.d/hhvm_' . $data['new']['system_user']);
3015-
3024+
30163025
if(is_dir('/etc/monit/conf.d')){
30173026
$monit_content = str_replace('{SYSTEM_USER}', $data['new']['system_user'], $monit_content);
30183027
file_put_contents('/etc/monit/conf.d/00-hhvm_' . $data['new']['system_user'], $monit_content);
30193028
if(is_file('/etc/monit/conf.d/hhvm_' . $data['new']['system_user'])) unlink('/etc/monit/conf.d/hhvm_' . $data['new']['system_user']);
30203029
exec('/etc/init.d/monit restart >/dev/null 2>&1');
30213030
}
3022-
3031+
30233032
} elseif($data['new']['php'] != 'hhvm' && $data['old']['php'] == 'hhvm') {
30243033
if($data['old']['system_user'] != ''){
30253034
$app->system->exec_safe('? stop >/dev/null 2>&1', '/etc/init.d/hhvm_' . $data['old']['system_user']);
30263035
$app->system->exec_safe('/usr/sbin/update-rc.d ? remove >/dev/null 2>&1', 'hhvm_' . $data['old']['system_user']);
30273036
unlink('/etc/init.d/hhvm_' . $data['old']['system_user']);
30283037
if(is_file('/etc/hhvm/'.$data['old']['system_user'].'.ini')) unlink('/etc/hhvm/'.$data['old']['system_user'].'.ini');
30293038
}
3030-
3039+
30313040
if(is_file('/etc/monit/conf.d/hhvm_' . $data['old']['system_user']) || is_file('/etc/monit/conf.d/00-hhvm_' . $data['old']['system_user'])){
30323041
if(is_file('/etc/monit/conf.d/hhvm_' . $data['old']['system_user'])){
30333042
unlink('/etc/monit/conf.d/hhvm_' . $data['old']['system_user']);
@@ -3066,7 +3075,7 @@ private function php_fpm_pool_update ($data, $web_config, $pool_dir, $pool_name,
30663075

30673076
$app->uses("getconf");
30683077
$web_config = $app->getconf->get_server_config($conf["server_id"], 'web');
3069-
3078+
30703079
$php_fpm_reload_mode = ($web_config['php_fpm_reload_mode'] == 'reload')?'reload':'restart';
30713080

30723081
if($data['new']['php'] != 'php-fpm'){
@@ -3089,7 +3098,7 @@ private function php_fpm_pool_update ($data, $web_config, $pool_dir, $pool_name,
30893098
$tpl = new tpl();
30903099
$tpl->newTemplate('php_fpm_pool.conf.master');
30913100
$tpl->setVar('apache_version', $app->system->getapacheversion());
3092-
3101+
30933102
if($data['new']['php_fpm_use_socket'] == 'y'){
30943103
$use_tcp = 0;
30953104
$use_socket = 1;
@@ -3142,7 +3151,7 @@ private function php_fpm_pool_update ($data, $web_config, $pool_dir, $pool_name,
31423151
// Custom php.ini settings
31433152
$final_php_ini_settings = array();
31443153
$custom_php_ini_settings = trim($data['new']['custom_php_ini']);
3145-
3154+
31463155
if(intval($data['new']['directive_snippets_id']) > 0){
31473156
$snippet = $app->db->queryOneRecord("SELECT * FROM directive_snippets WHERE directive_snippets_id = ? AND type = 'apache' AND active = 'y' AND customer_viewable = 'y'", intval($data['new']['directive_snippets_id']));
31483157
if(isset($snippet['required_php_snippets']) && trim($snippet['required_php_snippets']) != ''){
@@ -3161,7 +3170,7 @@ private function php_fpm_pool_update ($data, $web_config, $pool_dir, $pool_name,
31613170
}
31623171
}
31633172
}
3164-
3173+
31653174
$custom_session_save_path = false;
31663175
if($custom_php_ini_settings != ''){
31673176
// Make sure we only have Unix linebreaks
@@ -3249,10 +3258,10 @@ private function php_fpm_pool_update ($data, $web_config, $pool_dir, $pool_name,
32493258
//* Delete the PHP-FPM pool configuration file
32503259
private function php_fpm_pool_delete ($data, $web_config) {
32513260
global $app, $conf;
3252-
3261+
32533262
$app->uses("getconf");
32543263
$web_config = $app->getconf->get_server_config($conf["server_id"], 'web');
3255-
3264+
32563265
$php_fpm_reload_mode = ($web_config['php_fpm_reload_mode'] == 'reload')?'reload':'restart';
32573266

32583267
if(trim($data['old']['fastcgi_php_version']) != '' && $data['old']['php'] == 'php-fpm'){

0 commit comments

Comments
 (0)