Created
November 25, 2013 23:56
-
-
Save zzamboni/7651063 to your computer and use it in GitHub Desktop.
Update/add <Directory> sections in an Apache config file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| body common control | |
| { | |
| bundlesequence => { "test" }; | |
| inputs => { | |
| "lib/3.5/common.cf", | |
| "lib/3.5/files.cf", | |
| }; | |
| } | |
| bundle agent test | |
| { | |
| files: | |
| "/tmp/apache.conf" | |
| edit_line => insert_apache_lines; | |
| } | |
| body select_region apache_directory(dir) | |
| { | |
| select_start => "\<Directory \"$(dir)\"\>"; | |
| select_end => "\</Directory\>"; | |
| } | |
| bundle edit_line insert_apache_lines | |
| { | |
| vars: | |
| # Parameters to add in each section | |
| "line[/home/modification][Options]" string => "None"; | |
| "line[/home/modification][AllowOverride]" string => "AuthConfig"; | |
| "line[/home/modification][Order]" string => "allow,deny"; | |
| "line[/home/modification][Allow]" string => "from all"; | |
| "line[/home/php/version][Options]" string => "None"; | |
| "line[/home/php/version][AllowOverride]" string => "AuthConfig"; | |
| "line[/home/php/version][Order]" string => "deny,allow"; | |
| "line[/home/php/version][Allow]" string => "from all"; | |
| # Options | |
| "index" slist => { "Options", "AllowOverride", "Order", "Allow" }; | |
| "dir" slist => getindices("line"); | |
| "cdir[$(dir)]" string => canonify("$(dir)"); | |
| classes: | |
| # Detect which directories already have blocks | |
| "has_$(cdir[$(dir)])" expression => regline("\<Directory\s+\"$(dir)\"\>", "$(edit.filename)"); | |
| replace_patterns: | |
| # Replace existing values within the blocks with the correct ones | |
| "^\s*$(index)\s+(?!$(line[$(dir)][$(index)])).*" | |
| select_region => apache_directory("$(dir)"), | |
| replace_with => value(" $(index) $(line[$(dir)][$(index)])"), | |
| classes => always("replace_done_$(cdir[$(dir)])_$(index)"); | |
| insert_lines: | |
| # Insert new, empty block if it doesn't exist already. | |
| "<Directory \"$(dir)\"> | |
| </Directory>" | |
| insert_type => "preserve_block", | |
| ifvarclass => "!has_$(cdir[$(dir)])"; | |
| # Insert missing lines into the blocks | |
| " $(index) $(line[$(dir)][$(index)])" | |
| select_region => apache_directory("$(dir)"), | |
| ifvarclass => "replace_done_$(cdir[$(dir)])_$(index)"; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment