File: join.py

package info (click to toggle)
modsecurity-crs 3.3.8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,664 kB
  • sloc: ansic: 727; perl: 443; python: 421; sh: 90; ruby: 69; javascript: 53; makefile: 14
file content (47 lines) | stat: -rwxr-xr-x 1,317 bytes parent folder | download | duplicates (12)
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
#!/usr/bin/env python
#
# This script reads all the rule files passed on the command line,
# and outputs them, with each (multi-line) directive joined as a
# single line.
#
# This can be used to work around a bug in Apache < 2.4.11 in
# parsing long configuration directives.
#
# Usage:
#
#   util/join-multiline-rules/join.py rules/*.conf > rules/rules.conf.joined
#
# This produces a single 'rules.conf.joined' file that can be included
# in buggy Apache versions. It is recommended to keep this file in the
# rules/ directory (because it refers to .data files in that directory)
# but give it a name not ending in .conf (so the file will not be
# included in *.conf and you can re-run the command multiple times
# without including its own output).
#
# Example:
#
#   SecRule &TX:paranoia_level "@eq 0" \
#      "id:901120,\
#      phase:1,\
#      pass,\
#      nolog,\
#      setvar:tx.paranoia_level=1"
#
# will be outputted as:
#
#   SecRule &TX:paranoia_level "@eq 0" "id:901120,phase:1,pass,nolog,setvar:tx.paranoia_level=1"
#

import fileinput, sys

for line in fileinput.input():
    line = line.strip()
    if line == '':
        sys.stdout.write("\n")
        continue

    if line[-1] == '\\':
        sys.stdout.write(line[0:-1])
    else:
        sys.stdout.write(line)
        sys.stdout.write("\n")