1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
| #!/bin/awk
# Time-stamp: <2013/01/22 10:40:33 jack-ft>
# <Location /toto/ >
# ProxyPass http://m.toto.com/ retry=0
# ProxyPassReverse http://m.toto.com/
# ProxyPassReverseCookiePath / /toto/
# ProxyPassReverseCookieDomain .toto.com
# SetOutputFilter INFLATE;proxy-html;DEFLATE
# ProxyHTMLLogVerbose On
# ProxyHTMLExtended On
# ProxyHTMLURLMap / /toto/
# ProxyHTMLURLMap href="m.toto.com/" href="/toto/"
# ProxyHTMLURLMap http://m.toto.com/ /toto/
# ProxyHTMLURLMap m.toto.com
# </Location>
# <Location /titi/ >
# ProxyPass http://m.titi.com/ retry=0
# ProxyPassReverse http://m.titi.com/
# ProxyPassReverseCookiePath / /titi/
# </Location>
# =>
# ProxyPass /toto/ http://m.toto.com/ retry=0
# ProxyPassReverse /toto/ http://m.toto.com/
# <Location /toto/ >
# ProxyPassReverseCookiePath / /toto/
# ProxyPassReverseCookieDomain .toto.com
# SetOutputFilter INFLATE;proxy-html;DEFLATE
# ProxyHTMLLogVerbose On
# ProxyHTMLExtended On
# ProxyHTMLURLMap / /toto/
# ProxyHTMLURLMap href="m.toto.com/" href="/toto/"
# ProxyHTMLURLMap http://m.toto.com/ /toto/
# ProxyHTMLURLMap m.toto.com
# </Location>
# ProxyPass /titi/ http://m.titi.com/ retry=0
# ProxyPassReverse /titi/ http://m.titi.com/
# <Location /titi/ >
# ProxyPassReverseCookiePath / /titi/
# </Location>
# Begin:
# - On démarre avec état := "extérieur"
# Quand on rencontre une balise ouvrante,
# - on stocke le nom associé à la balise (par exemple /toto/)
# - on passe à état := "intérieur"
# - on initialise le num-ligne := 0
# - on stocke la ligne courante (à la position num-ligne++)
# - next
# Quand on rencontre une balise fermante,
# - on stocke la ligne courante (à la position num-ligne++)
# - on affiche le ProxyPass modifié, le ProxyPassReverse modifié et toutes les lignes stockées dans le tableau
# - on passe à état := "extérieur"
# - next
# Quand on rencontre ProxyPass,
# - on vérifie que état == "intérieur"
# - on le stocke dans ProxyPass
# - next
# Quand on rencontre ProxyPassReverse,
# - on vérifie que état == "intérieur"
# - on le stocke dans ProxyPassReverse
# - next
# Pour toute ligne,
# - si état == "extérieur"
# alors afficher la ligne telle quelle
# sinon on stocke la ligne courante (à la position num-ligne++)
# End:
# - on vérifie que état == "extérieur"
BEGIN { state = "out" }
/<Location/ {
state = "in";
name = $2;
nl = 0;
Lines[++nl] = $0;
next;
}
/Location>/ {
Lines[++nl] = $0;
gsub("http", name " http", PP);
gsub("http", name " http", PPR);
print(PP);
print(PPR);
for(n=1; n<=nl; n++) { print Lines[n] ; };
state = "out";
next;
}
{
if (state == "out") { print $0; next; }
else if ($1 == "ProxyPass") { PP = $0; next; }
else if ($1 == "ProxyPassReverse") { PPR = $0; next; }
else { Lines[++nl] = $0; }
} |
Partager