Commit 039a16fe authored by Falko Timme's avatar Falko Timme
Browse files

- Added nginx rewrite rules field to vhostsubdomains.

parent 38b49844
......@@ -305,6 +305,14 @@ $form["tabs"]['redirect'] = array (
'default' => '',
'value' => array('' => 'no_redirect_txt', 'non_www_to_www' => 'domain.tld => www.domain.tld', 'www_to_non_www' => 'www.domain.tld => domain.tld', '*_domain_tld_to_domain_tld' => '*.doman.tld => domain.tld', '*_domain_tld_to_www_domain_tld' => '*.domain.tld => www.domain.tld', '*_to_domain_tld' => '* => domain.tld', '*_to_www_domain_tld' => '* => www.domain.tld')
),
'rewrite_rules' => array (
'datatype' => 'TEXT',
'formtype' => 'TEXT',
'default' => '',
'value' => '',
'width' => '30',
'maxlength' => '255'
),
##################################
# ENDE Datatable fields
##################################
......
......@@ -115,5 +115,9 @@ $wb['available_apache_directive_snippets_txt'] = 'Verfügbare Apache Direktiven
$wb['available_nginx_directive_snippets_txt'] = 'Verfügbare nginx Direktiven Schnipsel:';
$wb['proxy_directives_txt'] = 'Proxy Direktiven';
$wb['available_proxy_directive_snippets_txt'] = 'Verfügbare Proxy Direktiven Schnipsel:';
$wb['rewrite_rules_txt'] = 'Rewrite Rules';
$wb['invalid_rewrite_rules_txt'] = 'Unzulässige Rewrite Rules';
$wb['allowed_rewrite_rule_directives_txt'] = 'Erlaubte Direktiven:';
$wb['configuration_error_txt'] = 'KONFIGURATIONSFEHLER';
?>
......@@ -116,4 +116,8 @@ $wb['available_apache_directive_snippets_txt'] = 'Available Apache Directive Sni
$wb['available_nginx_directive_snippets_txt'] = 'Available nginx Directive Snippets:';
$wb['proxy_directives_txt'] = 'Proxy Directives';
$wb['available_proxy_directive_snippets_txt'] = 'Available Proxy Directive Snippets:';
$wb['rewrite_rules_txt'] = 'Rewrite Rules';
$wb['invalid_rewrite_rules_txt'] = 'Invalid Rewrite Rules';
$wb['allowed_rewrite_rule_directives_txt'] = 'Allowed Directives:';
$wb['configuration_error_txt'] = "CONFIGURATION ERROR";
?>
\ No newline at end of file
......@@ -20,6 +20,10 @@
<select name="seo_redirect" id="seo_redirect" class="selectInput formLengthHalf">
{tmpl_var name='seo_redirect'}
</select>
</div>
<div class="ctrlHolder nginx">
<label for="rewrite_rules">{tmpl_var name='rewrite_rules_txt'}</label>
<textarea name="rewrite_rules" id="rewrite_rules" rows='10' cols='50' style="width:400px;">{tmpl_var name='rewrite_rules'}</textarea>&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>
</div>
</fieldset>
......
......@@ -482,6 +482,62 @@ class page_action extends tform_actions {
$app->tform->errorMessage .= $app->tform->lng("error_php_fpm_pm_settings_txt").'<br>';
}
}
// Check rewrite rules
$server_type = $web_config['server_type'];
if($server_type == 'nginx' && isset($this->dataRecord['rewrite_rules']) && trim($this->dataRecord['rewrite_rules']) != '') {
$rewrite_rules = trim($this->dataRecord['rewrite_rules']);
$rewrites_are_valid = true;
// use this counter to make sure all curly brackets are properly closed
$if_level = 0;
// Make sure we only have Unix linebreaks
$rewrite_rules = str_replace("\r\n", "\n", $rewrite_rules);
$rewrite_rules = str_replace("\r", "\n", $rewrite_rules);
$rewrite_rule_lines = explode("\n", $rewrite_rules);
if(is_array($rewrite_rule_lines) && !empty($rewrite_rule_lines)){
foreach($rewrite_rule_lines as $rewrite_rule_line){
// ignore comments
if(substr(ltrim($rewrite_rule_line),0,1) == '#') continue;
// empty lines
if(trim($rewrite_rule_line) == '') continue;
// rewrite
if(preg_match('@^\s*rewrite\s+(^/)?\S+(\$)?\s+\S+(\s+(last|break|redirect|permanent|))?\s*;\s*$@', $rewrite_rule_line)) continue;
// if
if(preg_match('@^\s*if\s+\(\s*\$\S+(\s+(\!?(=|~|~\*))\s+(\S+|\".+\"))?\s*\)\s*\{\s*$@', $rewrite_rule_line)){
$if_level += 1;
continue;
}
// if - check for files, directories, etc.
if(preg_match('@^\s*if\s+\(\s*\!?-(f|d|e|x)\s+\S+\s*\)\s*\{\s*$@', $rewrite_rule_line)){
$if_level += 1;
continue;
}
// break
if(preg_match('@^\s*break\s*;\s*$@', $rewrite_rule_line)){
continue;
}
// return code [ text ]
if(preg_match('@^\s*return\s+\d\d\d.*;\s*$@', $rewrite_rule_line)) continue;
// return code URL
// return URL
if(preg_match('@^\s*return(\s+\d\d\d)?\s+(http|https|ftp)\://([a-zA-Z0-9\.\-]+(\:[a-zA-Z0-9\.&%\$\-]+)*\@)*((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|localhost|([a-zA-Z0-9\-]+\.)*[a-zA-Z0-9\-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\?\'\\\+&%\$#\=~_\-]+))*\s*;\s*$@', $rewrite_rule_line)) continue;
// set
if(preg_match('@^\s*set\s+\$\S+\s+\S+\s*;\s*$@', $rewrite_rule_line)) continue;
// closing curly bracket
if(trim($rewrite_rule_line) == '}'){
$if_level -= 1;
continue;
}
$rewrites_are_valid = false;
break;
}
}
if(!$rewrites_are_valid || $if_level != 0){
$app->tform->errorMessage .= $app->tform->lng("invalid_rewrite_rules_txt").'<br>';
}
}
parent::onSubmit();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment