@@ -45,7 +45,7 @@ class UninitializedCryptoFilter(Exception):
45
45
class CryptoFilter (object ):
46
46
"""Class to control cryptographic logging."""
47
47
48
- def __init__ (self , regex = None , field_list = None ):
48
+ def __init__ (self , regex = None , field_list = None , delete_list = None ):
49
49
"""
50
50
Args:
51
51
regex: re.compile(r'(?P<A>)(?P<B>)) object, with
@@ -56,13 +56,14 @@ def __init__(self, regex=None, field_list=None):
56
56
if regex :
57
57
self .SetRegex (regex )
58
58
if field_list :
59
- self .SetFields (field_list )
59
+ self .SetFields (field_list , delete_list )
60
60
61
61
def SetRegex (self , regex ):
62
62
self ._regex = regex
63
63
64
- def SetFields (self , field_list ):
64
+ def SetFields (self , field_list , delete_list ):
65
65
self ._field_list = field_list
66
+ self ._delete_list = delete_list
66
67
67
68
def IsInitialized (self ):
68
69
return self ._regex and self ._field_list
@@ -87,6 +88,7 @@ def EncryptSingleLogEntry(self, log_entry):
87
88
if not results :
88
89
raise LogParseError ("Log format does not match regex." )
89
90
split_log = list (results .groups ())
91
+
90
92
# TODO(dtauerbach): this is inefficient but regex
91
93
# doesn't seem quite powerful enough to avoid it
92
94
# by being able to bulk replace named groups.
@@ -105,6 +107,9 @@ def EncryptSingleLogEntry(self, log_entry):
105
107
# could legitimately be empty
106
108
continue
107
109
split_log [split_log .index (res )] = self .EncryptField (res , 6 )
110
+ for field in self ._delete_list :
111
+ res = results .group (field )
112
+ split_log [split_log .index (res )] = ''
108
113
return '%s\n ' % ('' .join (split_log ))
109
114
110
115
def EncryptField (self , field , hashed_size ):
@@ -124,6 +129,10 @@ def EncryptField(self, field, hashed_size):
124
129
dest = 'entities' ,
125
130
default = 'IP' ,
126
131
help = 'comma-separated list of entities to filter' )
132
+ parser .add_argument ('-s' ,
133
+ action = 'store_true' ,
134
+ dest = 'strip_uas_and_refs' ,
135
+ default = False )
127
136
args = parser .parse_args ()
128
137
129
138
log_file = None
@@ -135,9 +144,16 @@ def EncryptField(self, field, hashed_size):
135
144
p = Popen (args .command , stdin = PIPE , shell = True )
136
145
137
146
entities = args .entities .split (',' )
138
-
139
147
regex = re .compile (r'(?P<IP>\d\d?\d?\.\d\d?\d?\.\d\d?\d?\.\d\d?\d?)( )(?P<OTHER>.*)' )
140
- cryptor = CryptoFilter (regex , entities )
148
+ apache_regex = re .compile (r'(?P<IP>\d\d?\d?\.\d\d?\d?\.\d\d?\d?\.\d\d?\d?)(?P<SAVE> - - \[.*\] ".*" \d* \d* )(?P<OTHER>.*)' )
149
+ delete_list = []
150
+
151
+ # hack for pound logs
152
+ if args .strip_uas_and_refs :
153
+ regex = apache_regex
154
+ delete_list = ['OTHER' ]
155
+
156
+ cryptor = CryptoFilter (regex , entities , delete_list )
141
157
142
158
log = stdin .readline ()
143
159
while (log ):
0 commit comments