This repository was archived by the owner on Jun 22, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Original file line number Diff line number Diff line change 2
2
# -*- coding: utf-8 -*-
3
3
#
4
4
5
- __version__ = '0.0.63 '
5
+ __version__ = '0.0.64 '
Original file line number Diff line number Diff line change 6
6
from hashlib import md5
7
7
import re
8
8
9
- from .utils import ssh_key_string_to_obj
9
+ from .utils import ssh_key_string_to_obj , get_logger
10
+
11
+ logger = get_logger (__file__ )
10
12
11
13
12
14
class Decoder :
@@ -264,7 +266,7 @@ class CommandFilterRule(Decoder):
264
266
action = {}
265
267
__pattern = None
266
268
267
- DENY , ALLOW , UNKNOWN = range (3 )
269
+ DENY , ALLOW , UNKNOWN , ERROR = range (4 )
268
270
269
271
def __init__ (self , ** kwargs ):
270
272
super ().__init__ (** kwargs )
@@ -275,7 +277,8 @@ def _pattern(self):
275
277
return self .__pattern
276
278
if self .type ['value' ] == 'command' :
277
279
regex = []
278
- for cmd in self .content .split ('\r \n ' ):
280
+ content = self .content .replace ('\r \n ' , '\n ' )
281
+ for cmd in content .split ('\n ' ):
279
282
cmd = cmd .replace (' ' , '\s+' )
280
283
regex .append (r'\b{0}\b' .format (cmd ))
281
284
self .__pattern = re .compile (r'{}' .format ('|' .join (regex )))
@@ -284,7 +287,12 @@ def _pattern(self):
284
287
return self .__pattern
285
288
286
289
def match (self , data ):
287
- found = self ._pattern .search (data )
290
+ try :
291
+ found = self ._pattern .search (data )
292
+ except Exception as e :
293
+ logger .error (e )
294
+ return self .ERROR , ''
295
+
288
296
if not found :
289
297
return self .UNKNOWN , ''
290
298
You can’t perform that action at this time.
0 commit comments