--- a/htaccess.module +++ b/htaccess.module @@ -119,15 +119,15 @@ function htaccess_generate_default(){ $htaccess_template = file_get_contents(HTACCESS_TEMPLATE_PATH); - $with_www_default = "#RewriteCond %{HTTP_HOST} .\n"; - $with_www_default .= "#RewriteCond %{HTTP_HOST} !^www\. [NC]\n"; - $with_www_default .= "#RewriteRule ^ http%{ENV:protossl}://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]\n"; + $with_www_default = "#RewriteCond %{HTTP_HOST} ." . PHP_EOL; + $with_www_default .= "#RewriteCond %{HTTP_HOST} !^www\. [NC]" . PHP_EOL; + $with_www_default .= "#RewriteRule ^ http%{ENV:protossl}://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]" . PHP_EOL; - $without_www_default = "#RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]\n"; - $without_www_default .= "#RewriteRule ^ http%{ENV:protossl}://%1%{REQUEST_URI} [L,R=301]\n"; + $without_www_default = "#RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]" . PHP_EOL; + $without_www_default .= "#RewriteRule ^ http%{ENV:protossl}://%1%{REQUEST_URI} [L,R=301]" . PHP_EOL; - $search = array("%%%rules_before%%%", "%%%prevent_txt%%%", "%%%symbolic_links%%%", "%%%ssl_force_redirect%%%", "%%%with_www%%%", "%%%without_www%%%", "%%%boost_rules%%%"); - $replace = array("", "", "+FollowSymLinks", "", $with_www_default, $without_www_default, ""); + $search = array("\xEF\xBB\xBF", "\r\n", "%%%rules_before%%%", "%%%prevent_txt%%%", "%%%symbolic_links%%%", "%%%ssl_force_redirect%%%", "%%%with_www%%%", "%%%without_www%%%", "%%%boost_rules%%%"); + $replace = array('', PHP_EOL, "", "", "+FollowSymLinks", "", $with_www_default, $without_www_default, ""); $htaccess_update = str_replace($search, $replace, $htaccess_template); @@ -153,19 +153,15 @@ ->fetchAssoc(); if($htaccess_deployed){ - $htaccess_deployed = $htaccess_deployed['htaccess']; - // Compare the two results - if($htaccess_current === $htaccess_deployed){ - - variable_del('htaccess_altered'); - - } - else{ - - drupal_set_message(t('The htaccess seems to be altered.'), 'warning'); - variable_set('htaccess_altered', true); + // Compare the two results + if($htaccess_current === $htaccess_deployed){ + variable_del('htaccess_altered'); + } + else{ + watchdog('htaccess', t('The htaccess seems to be altered.'), NULL, WATCHDOG_ERROR); + variable_set('htaccess_altered', true); } } } --- a/htaccess.admin.inc +++ b/htaccess.admin.inc @@ -192,6 +192,14 @@ $htaccess_count = count($htaccess); for ($i=0; $i<$htaccess_count; $i++) { + // Check that the profile is not in use + $htaccess_check = db_select('htaccess', 'h') + ->fields('h') + ->condition('deployed', 1, '=') + ->condition('id', array(':id' => $htaccess[$i]->id),'IN') + ->execute() + ->fetchAssoc(); + $form['htaccess_settings_version']['row_' . $i] = array( '#prefix' => '', '#suffix' => '', @@ -199,7 +207,7 @@ $form['htaccess_settings_version']['row_' . $i]['htaccess_settings_version_number'] = array( '#prefix' => '', '#suffix' => '', - '#markup' => $htaccess[$i]->id, + '#markup' => $htaccess[$i]->id . ($htaccess_check? '*' : ''), ); $form['htaccess_settings_version']['row_' . $i]['htaccess_settings_version_created'] = array( '#prefix' => '', @@ -217,7 +225,9 @@ '#markup' => $htaccess[$i]->description, ); $form['htaccess_settings_version']['row_' . $i]['htaccess_settings_version_operation'] = array( - '#markup' => l(t('View'), 'admin/config/system/htaccess/deployment/view/'.$htaccess[$i]->id.'') . ' ' . l(t('Deploy'), 'admin/config/system/htaccess/deployment/deploy/'.$htaccess[$i]->id.'') . ' ' . l(t('Download'), 'admin/config/system/htaccess/deployment/download/'.$htaccess[$i]->id.'') . ' ' . l(t('Delete'), 'admin/config/system/htaccess/deployment/delete/'.$htaccess[$i]->id.''), + '#markup' => l(t('View'), 'admin/config/system/htaccess/deployment/view/'.$htaccess[$i]->id.'') . ' ' . l(t('Deploy'), 'admin/config/system/htaccess/deployment/deploy/'.$htaccess[$i]->id.'') . ' ' . l(t('Download'), 'admin/config/system/htaccess/deployment/download/'.$htaccess[$i]->id.'') . ' ' . + ($htaccess_check? '' : + l(t('Delete'), 'admin/config/system/htaccess/deployment/delete/'.$htaccess[$i]->id.'')), '#prefix' => '', '#suffix' => '', ); @@ -318,12 +328,6 @@ $htaccess_content = $htaccess_get['htaccess']; - // Remove utf8-BOM - $htaccess_content = str_replace("\xEF\xBB\xBF",'', $htaccess_content); - - // Standardize the EOL. - $htaccess_content = str_replace("\r\n", PHP_EOL, $htaccess_content); - // Try to write to the .htaccess file if (file_put_contents($htaccess_path, $htaccess_content)) { drupal_chmod($htaccess_path, 0644); @@ -375,9 +379,6 @@ ->fetchAssoc(); $htaccess_content = $htaccess_get['htaccess']; - - // Remove utf8-BOM - $htaccess_content = str_replace("\xEF\xBB\xBF",'', $htaccess_content); $file_name = $htaccess_get['name'].'.htaccess'; @@ -511,8 +512,9 @@ $prevent_txt_rules .= '' . PHP_EOL; } - $search = array("%%%rules_before%%%", "%%%prevent_txt%%%", "%%%symbolic_links%%%", "%%%ssl_force_redirect%%%", "%%%with_www%%%", "%%%without_www%%%", "%%%boost_rules%%%"); - $replace = array($rules_before_config, $prevent_txt_rules, $symbolic_links_config, $ssl_force_redirect, $with_www_config, $without_www_config, $boot_rules); + // Include removal of any BOM, and standardise EOL. + $search = array("\xEF\xBB\xBF", "\r\n", "%%%rules_before%%%", "%%%prevent_txt%%%", "%%%symbolic_links%%%", "%%%ssl_force_redirect%%%", "%%%with_www%%%", "%%%without_www%%%", "%%%boost_rules%%%"); + $replace = array('', PHP_EOL, $rules_before_config, $prevent_txt_rules, $symbolic_links_config, $ssl_force_redirect, $with_www_config, $without_www_config, $boot_rules); $htaccess = str_replace($search, $replace, $htaccess_template);