From cf2017a8636763781e499ba19e241c0837e20fae Mon Sep 17 00:00:00 2001 From: Brice Waegeneire Date: Tue, 12 Jan 2021 17:31:27 +0100 Subject: [PATCH] Finally working --- convert.pl | 20 ++++++++++---------- migrate.sh | 29 ++++++++++++++++++++--------- snippets | 17 ++++++++++++++++- 3 files changed, 46 insertions(+), 20 deletions(-) diff --git a/convert.pl b/convert.pl index 8afdeaf..a78b2e9 100644 --- a/convert.pl +++ b/convert.pl @@ -4,7 +4,7 @@ # securly migrate to apache 2.2 to 2.4. This script only migrate most # common pattern. -#use re "debug"; +# use re "debug"; use strict; use warnings; @@ -20,14 +20,17 @@ use warnings; # Regex for spaces bettwen word (including comment character) my $s = '[#\s]*'; -while () { +while (<>) { # ** Order # Default of mod_access_compat next if /Order${s}deny,allow/i; if (/(Order${s}Allow,Deny)/i) { - $_ .= ; + $_ .= <> unless eof; + # NOTE We replace with dpreceated directive, because they are + # replaced with the current one down the line. s/${1}${s}(Deny${s}from${s}all)/$1/i; + s/${1}${s}(Allow${s}from${s}localhost.*)/$1/i; }; # ** Satisfy @@ -36,15 +39,13 @@ while () { # ** Misc if (/(Require${s}valid-user)/i) { - $_ .= ..; + $_ .= <>.<>.<> unless eof; s/(${1})${s}Order${s}Deny,Allow${s}Deny${s}from${s}all/$1/i; }; # ** Deny if (/(Deny${s}from${s}all)/i) { - # unless (eof(ARGV)) { - $_ .= ; - # }; + $_ .= <> unless eof; s/${1}${s}Allow${s}from/Require ip/i; s/Deny${s}from${s}all/Require all denied/i; }; @@ -53,11 +54,10 @@ while () { # ** Allow s/Allow${s}from${s}all/Require all granted/i; + s/Allow${s}from${s}localhost.*/Require ip local/i; s/Allow${s}from/Require ip/i; - print ARGV; + print; } # close $fh; - -# print 'END THIS SHIT!!!!\n'; diff --git a/migrate.sh b/migrate.sh index e8a40eb..2e8abbd 100644 --- a/migrate.sh +++ b/migrate.sh @@ -1,13 +1,24 @@ #!/bin/sh -newline="\n[[:blank:]]" +set -e -# 2.2 Directives -all_denied="s/Order deny,allow${newline}Deny from all/Require all denied/" -- -## Last -deny_from_env="s/Deny from env=/Require not env /" -allow_all="s/Allow from all/Require all granted/" +inventory=$1 -# Mixed directives -mix_allow_all_require_all="s/Allow from all${newline}Require all granted/Require all granted/" +tmp_dir=/tmp/apache-require +inventory=$tmp_dir/inventory +to_convert=$tmp_dir/to_convert + +# Create a backup of the FILE specific for this project +backup() { + file=$1 + + cp "$file" "$file".apreq.bak +} + +awk '{ print $1 }' "$inventory" > "$to_convert" + +while IFS= read -r file; do + echo $file + backup "$file" + perl -i ~bwaegeneire/convert.pl "$file" +done < "$to_convert" diff --git a/snippets b/snippets index 14d3ba4..f2600fb 100644 --- a/snippets +++ b/snippets @@ -1,4 +1,19 @@ Order deny,allow Deny from all + + Satisfy any + + + Allow from 127.0.0.1 - Include /etc/apache2/ipaddr_whitelist.conf + + + + +Deny from env=bar + + + +foo bar + +Include /etc/apache2/ipaddr_whitelist.conf