Skip to content

Commit f0dfa9f

Browse files
author
Marius Cramer
committed
- added http -> https rewriting
- backported patches
1 parent 8cb6f8f commit f0dfa9f

File tree

10 files changed

+76
-27
lines changed

10 files changed

+76
-27
lines changed

install/sql/incremental/upd_dev_collection.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ ALTER TABLE `directive_snippets` ADD `required_php_snippets` VARCHAR(255) NOT NU
144144
ALTER TABLE `dns_rr` CHANGE `ttl` `ttl` INT(11) UNSIGNED NOT NULL DEFAULT '3600';
145145
ALTER TABLE `dns_soa` CHANGE `minimum` `minimum` INT(11) UNSIGNED NOT NULL DEFAULT '3600', CHANGE `ttl` `ttl` INT(11) UNSIGNED NOT NULL DEFAULT '3600';
146146
ALTER TABLE `client` CHANGE `web_php_options` `web_php_options` VARCHAR(255) NOT NULL DEFAULT 'no,fast-cgi,cgi,mod,suphp,php-fpm,hhvm';
147-
ALTER TABLE `web_domain` ADD COLUMN `enable_pagespeed` ENUM('y','n') NULL DEFAULT 'n' AFTER `directive_snippets_id`;
147+
ALTER TABLE `web_domain` ADD COLUMN `enable_pagespeed` ENUM('y','n') NOT NULL DEFAULT 'n' AFTER `directive_snippets_id`;
148148

149149
ALTER TABLE openvz_template ADD COLUMN `features` varchar(255) DEFAULT NULL AFTER `capability`;
150150
ALTER TABLE openvz_vm ADD COLUMN `features` TEXT DEFAULT NULL AFTER `capability`;
@@ -165,3 +165,4 @@ CREATE TABLE `server_ip_map` (
165165
PRIMARY KEY (`server_ip_map_id`)
166166
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
167167

168+
ALTER TABLE `web_domain` ADD COLUMN `rewrite_to_https` ENUM('y','n') NOT NULL DEFAULT 'n' AFTER `seo_redirect`;

install/sql/ispconfig3.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1884,6 +1884,7 @@ CREATE TABLE `web_domain` (
18841884
`redirect_type` varchar(255) default NULL,
18851885
`redirect_path` varchar(255) default NULL,
18861886
`seo_redirect` varchar(255) default NULL,
1887+
`rewrite_to_https` ENUM('y','n') NOT NULL DEFAULT 'n',
18871888
`ssl` enum('n','y') NOT NULL default 'n',
18881889
`ssl_state` varchar(255) NULL,
18891890
`ssl_locality` varchar(255) NULL,
@@ -1924,7 +1925,7 @@ CREATE TABLE `web_domain` (
19241925
`added_date` date NOT NULL DEFAULT '0000-00-00',
19251926
`added_by` varchar(255) DEFAULT NULL,
19261927
`directive_snippets_id` int(11) unsigned NOT NULL default '0',
1927-
`enable_pagespeed` ENUM('y','n') NULL DEFAULT 'n',
1928+
`enable_pagespeed` ENUM('y','n') NOT NULL DEFAULT 'n',
19281929
`http_port` int(11) unsigned NOT NULL DEFAULT '80',
19291930
`https_port` int(11) unsigned NOT NULL DEFAULT '443',
19301931
PRIMARY KEY (`domain_id`),

interface/web/sites/form/web_vhost_domain.tform.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,15 @@
400400
'width' => '30',
401401
'maxlength' => '255'
402402
),
403+
'rewrite_to_https' => array (
404+
'datatype' => 'VARCHAR',
405+
'formtype' => 'CHECKBOX',
406+
'default' => 'n',
407+
'value' => array (
408+
0 => 'n',
409+
1 => 'y'
410+
)
411+
),
403412
//#################################
404413
// ENDE Datatable fields
405414
//#################################

interface/web/sites/templates/web_vhost_domain_redirect.htm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ <h1><tmpl_var name="list_head_txt"></h1>
3333
<label for="rewrite_rules" class="col-sm-3 control-label">{tmpl_var name='rewrite_rules_txt'}</label>
3434
<div class="col-sm-9"><textarea class="form-control" name="rewrite_rules" id="rewrite_rules" rows='10' cols='50'>{tmpl_var name='rewrite_rules'}</textarea></div>&nbsp;<b>{tmpl_var name="allowed_rewrite_rule_directives_txt"}</b><br><br>&nbsp;break<br>&nbsp;if<br>&nbsp;return<br>&nbsp;rewrite<br>&nbsp;set<br><br>&nbsp;<a href="http://wiki.nginx.org/HttpRewriteModule" target="_blank">http://wiki.nginx.org/HttpRewriteModule</a>
3535
</div>
36+
<div class="form-group">
37+
<label class="col-sm-3 control-label">{tmpl_var name='rewrite_to_https_txt'}</label>
38+
<div class="col-sm-9">
39+
{tmpl_var name="rewrite_to_https"}
40+
</div>
41+
</div>
3642

3743

3844
<input type="hidden" name="id" value="{tmpl_var name='id'}">

server/conf/nginx_vhost.conf.master

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ server {
3333
rewrite ^<tmpl_var name='local_redirect_exclude'>(.*)$ <tmpl_var name='local_redirect_target'>$2 <tmpl_var name='local_redirect_type'>;
3434
}
3535
</tmpl_loop>
36+
<tmpl_if name='ssl_enabled'>
37+
<tmpl_if name='rewrite_to_https' op='==' value='y'>
38+
if ($scheme != "https") {
39+
rewrite ^ https://$http_host$request_uri? permanent;
40+
}
41+
</tmpl_if>
42+
</tmpl_if>
3643

3744
<tmpl_loop name="own_redirects">
3845
<tmpl_if name='use_rewrite'>

server/conf/vhost.conf.master

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,12 @@
412412
RewriteRule ^/(.*)$ <tmpl_var name='rewrite_target'><tmpl_if name="rewrite_add_path" op="==" value="y">$1</tmpl_if> <tmpl_var name='rewrite_type'>
413413

414414
</tmpl_loop>
415+
<tmpl_if name='ssl_enabled'>
416+
<tmpl_if name='rewrite_to_https' op='==' value='y'>
417+
RewriteCond %{HTTPS} off
418+
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
419+
</tmpl_if>
420+
</tmpl_if>
415421
</tmpl_if>
416422

417423
# add support for apache mpm_itk

server/lib/classes/cron.d/150-awstats.inc.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ public function onRunJob() {
117117
}
118118

119119
if(!@is_dir($statsdir)) mkdir($statsdir);
120+
$username = escapeshellcmd($rec['system_user']);
121+
$groupname = escapeshellcmd($rec['system_group']);
122+
chown($statsdir, $username);
123+
chgrp($statsdir, $groupname);
120124
if(is_link('/var/log/ispconfig/httpd/'.$domain.'/yesterday-access.log')) unlink('/var/log/ispconfig/httpd/'.$domain.'/yesterday-access.log');
121125
symlink($logfile, '/var/log/ispconfig/httpd/'.$domain.'/yesterday-access.log');
122126

@@ -174,6 +178,7 @@ public function onRunJob() {
174178
chgrp($rec['document_root']."/".$web_folder."/stats/index.php", $rec['system_group']);
175179
}
176180

181+
exec('chown -R '.$username.':'.$groupname.' '.$statsdir);
177182
}
178183

179184

server/lib/classes/cron.d/150-webalizer.inc.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function setConfigVar( $filename, $varName, $varValue, $append = 0 ) {
7979
}
8080

8181

82-
$sql = "SELECT domain_id, domain, document_root, web_folder, type, parent_domain_id FROM web_domain WHERE (type = 'vhost' or type = 'vhostsubdomain' or type = 'vhostalias') and stats_type = 'webalizer' AND server_id = ?";
82+
$sql = "SELECT domain_id, domain, document_root, web_folder, type, parent_domain_id, system_user, system_group FROM web_domain WHERE (type = 'vhost' or type = 'vhostsubdomain' or type = 'vhostalias') and stats_type = 'webalizer' AND server_id = ?";
8383
$records = $app->db->queryAllRecords($sql, $conf['server_id']);
8484

8585
foreach($records as $rec) {
@@ -122,7 +122,13 @@ function setConfigVar( $filename, $varName, $varValue, $append = 0 ) {
122122

123123

124124
if(!@is_dir($statsdir)) mkdir($statsdir);
125+
$username = escapeshellcmd($rec['system_user']);
126+
$groupname = escapeshellcmd($rec['system_group']);
127+
chown($statsdir, $username);
128+
chgrp($statsdir, $groupname);
125129
exec("$webalizer -c $webalizer_conf -n $domain -s $domain -r $domain -q -T -p -o $statsdir $logfile");
130+
131+
exec('chown -R '.$username.':'.$groupname.' '.$statsdir);
126132
}
127133

128134

server/plugins-available/apache2_plugin.inc.php

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,7 @@ function update($event_name, $data) {
650650

651651
if(!is_dir($data['new']['document_root'].'/' . $web_folder)) $app->system->mkdirpath($data['new']['document_root'].'/' . $web_folder);
652652
if(!is_dir($data['new']['document_root'].'/' . $web_folder . '/error') and $data['new']['errordocs']) $app->system->mkdirpath($data['new']['document_root'].'/' . $web_folder . '/error');
653+
if(!is_dir($data['new']['document_root'].'/' . $web_folder . '/stats')) $app->system->mkdirpath($data['new']['document_root'].'/' . $web_folder . '/stats');
653654
//if(!is_dir($data['new']['document_root'].'/'.$log_folder)) exec('mkdir -p '.$data['new']['document_root'].'/'.$log_folder);
654655
if(!is_dir($data['new']['document_root'].'/ssl')) $app->system->mkdirpath($data['new']['document_root'].'/ssl');
655656
if(!is_dir($data['new']['document_root'].'/cgi-bin')) $app->system->mkdirpath($data['new']['document_root'].'/cgi-bin');
@@ -771,27 +772,31 @@ function update($event_name, $data) {
771772
}
772773

773774
if (file_exists($conf['rootpath'] . '/conf-custom/index/standard_index.html_'.substr(escapeshellcmd($conf['language']), 0, 2))) {
774-
exec('cp ' . $conf['rootpath'] . '/conf-custom/index/standard_index.html_'.substr(escapeshellcmd($conf['language']), 0, 2).' '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html');
775+
if(!file_exists(escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html')) exec('cp ' . $conf['rootpath'] . '/conf-custom/index/standard_index.html_'.substr(escapeshellcmd($conf['language']), 0, 2).' '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html');
775776

776777
if(is_file($conf['rootpath'] . '/conf-custom/index/favicon.ico')) {
777-
exec('cp ' . $conf['rootpath'] . '/conf-custom/index/favicon.ico '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
778+
if(!file_exists(escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/favicon.ico')) exec('cp ' . $conf['rootpath'] . '/conf-custom/index/favicon.ico '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
778779
}
779780
if(is_file($conf['rootpath'] . '/conf-custom/index/robots.txt')) {
780-
exec('cp ' . $conf['rootpath'] . '/conf-custom/index/robots.txt '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
781+
if(!file_exists(escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/robots.txt')) exec('cp ' . $conf['rootpath'] . '/conf-custom/index/robots.txt '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
781782
}
782783
if(is_file($conf['rootpath'] . '/conf-custom/index/.htaccess')) {
783-
exec('cp ' . $conf['rootpath'] . '/conf-custom/index/.htaccess '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
784+
if(!file_exists(escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/.htaccess')) exec('cp ' . $conf['rootpath'] . '/conf-custom/index/.htaccess '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
784785
}
785-
}
786-
else {
786+
} else {
787787
if (file_exists($conf['rootpath'] . '/conf-custom/index/standard_index.html')) {
788-
exec('cp ' . $conf['rootpath'] . '/conf-custom/index/standard_index.html '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html');
789-
}
790-
else {
791-
exec('cp ' . $conf['rootpath'] . '/conf/index/standard_index.html_'.substr(escapeshellcmd($conf['language']), 0, 2).' '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html');
792-
if(is_file($conf['rootpath'] . '/conf/index/favicon.ico')) exec('cp ' . $conf['rootpath'] . '/conf/index/favicon.ico '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
793-
if(is_file($conf['rootpath'] . '/conf/index/robots.txt')) exec('cp ' . $conf['rootpath'] . '/conf/index/robots.txt '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
794-
if(is_file($conf['rootpath'] . '/conf/index/.htaccess')) exec('cp ' . $conf['rootpath'] . '/conf/index/.htaccess '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
788+
if(!file_exists(escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html')) exec('cp ' . $conf['rootpath'] . '/conf-custom/index/standard_index.html '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html');
789+
} else {
790+
if(!file_exists(escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html')) exec('cp ' . $conf['rootpath'] . '/conf/index/standard_index.html_'.substr(escapeshellcmd($conf['language']), 0, 2).' '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html');
791+
if(is_file($conf['rootpath'] . '/conf/index/favicon.ico')){
792+
if(!file_exists(escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/favicon.ico')) exec('cp ' . $conf['rootpath'] . '/conf/index/favicon.ico '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
793+
}
794+
if(is_file($conf['rootpath'] . '/conf/index/robots.txt')){
795+
if(!file_exists(escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/robots.txt')) exec('cp ' . $conf['rootpath'] . '/conf/index/robots.txt '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
796+
}
797+
if(is_file($conf['rootpath'] . '/conf/index/.htaccess')){
798+
if(!file_exists(escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/.htaccess')) exec('cp ' . $conf['rootpath'] . '/conf/index/.htaccess '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
799+
}
795800
}
796801
}
797802
exec('chmod -R a+r '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');

server/plugins-available/nginx_plugin.inc.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ function update($event_name, $data) {
531531

532532
if(!is_dir($data['new']['document_root'].'/' . $web_folder)) $app->system->mkdirpath($data['new']['document_root'].'/' . $web_folder);
533533
if(!is_dir($data['new']['document_root'].'/' . $web_folder . '/error') and $data['new']['errordocs']) $app->system->mkdirpath($data['new']['document_root'].'/' . $web_folder . '/error');
534+
if(!is_dir($data['new']['document_root'].'/' . $web_folder . '/stats')) $app->system->mkdirpath($data['new']['document_root'].'/' . $web_folder . '/stats');
534535
//if(!is_dir($data['new']['document_root'].'/'.$log_folder)) exec('mkdir -p '.$data['new']['document_root'].'/'.$log_folder);
535536
if(!is_dir($data['new']['document_root'].'/ssl')) $app->system->mkdirpath($data['new']['document_root'].'/ssl');
536537
if(!is_dir($data['new']['document_root'].'/cgi-bin')) $app->system->mkdirpath($data['new']['document_root'].'/cgi-bin');
@@ -652,26 +653,28 @@ function update($event_name, $data) {
652653
}
653654

654655
if (file_exists($conf['rootpath'] . '/conf-custom/index/standard_index.html_'.substr(escapeshellcmd($conf['language']), 0, 2))) {
655-
exec('cp ' . $conf['rootpath'] . '/conf-custom/index/standard_index.html_'.substr(escapeshellcmd($conf['language']), 0, 2).' '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html');
656+
if(!file_exists(escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html')) exec('cp ' . $conf['rootpath'] . '/conf-custom/index/standard_index.html_'.substr(escapeshellcmd($conf['language']), 0, 2).' '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html');
656657

657658
if(is_file($conf['rootpath'] . '/conf-custom/index/favicon.ico')) {
658-
exec('cp ' . $conf['rootpath'] . '/conf-custom/index/favicon.ico '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
659+
if(!file_exists(escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/favicon.ico')) exec('cp ' . $conf['rootpath'] . '/conf-custom/index/favicon.ico '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
659660
}
660661
if(is_file($conf['rootpath'] . '/conf-custom/index/robots.txt')) {
661-
exec('cp ' . $conf['rootpath'] . '/conf-custom/index/robots.txt '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
662+
if(!file_exists(escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/robots.txt')) exec('cp ' . $conf['rootpath'] . '/conf-custom/index/robots.txt '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
662663
}
663664
//if(is_file($conf['rootpath'] . '/conf-custom/index/.htaccess')) {
664665
// exec('cp ' . $conf['rootpath'] . '/conf-custom/index/.htaccess '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
665666
//}
666-
}
667-
else {
667+
} else {
668668
if (file_exists($conf['rootpath'] . '/conf-custom/index/standard_index.html')) {
669-
exec('cp ' . $conf['rootpath'] . '/conf-custom/index/standard_index.html '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html');
670-
}
671-
else {
672-
exec('cp ' . $conf['rootpath'] . '/conf/index/standard_index.html_'.substr(escapeshellcmd($conf['language']), 0, 2).' '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html');
673-
if(is_file($conf['rootpath'] . '/conf/index/favicon.ico')) exec('cp ' . $conf['rootpath'] . '/conf/index/favicon.ico '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
674-
if(is_file($conf['rootpath'] . '/conf/index/robots.txt')) exec('cp ' . $conf['rootpath'] . '/conf/index/robots.txt '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
669+
if(!file_exists(escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html')) exec('cp ' . $conf['rootpath'] . '/conf-custom/index/standard_index.html '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html');
670+
} else {
671+
if(!file_exists(escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html')) exec('cp ' . $conf['rootpath'] . '/conf/index/standard_index.html_'.substr(escapeshellcmd($conf['language']), 0, 2).' '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html');
672+
if(is_file($conf['rootpath'] . '/conf/index/favicon.ico')){
673+
if(!file_exists(escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/favicon.ico')) exec('cp ' . $conf['rootpath'] . '/conf/index/favicon.ico '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
674+
}
675+
if(is_file($conf['rootpath'] . '/conf/index/robots.txt')){
676+
if(!file_exists(escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/robots.txt')) exec('cp ' . $conf['rootpath'] . '/conf/index/robots.txt '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
677+
}
675678
//if(is_file($conf['rootpath'] . '/conf/index/.htaccess')) exec('cp ' . $conf['rootpath'] . '/conf/index/.htaccess '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
676679
}
677680
}

0 commit comments

Comments
 (0)