Skip to content
This repository was archived by the owner on Jun 22, 2022. It is now read-only.

Commit f03bb92

Browse files
authored
Merge pull request #39 from jumpserver/dev
Dev
2 parents e86fdf0 + d86264d commit f03bb92

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

jms/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# -*- coding: utf-8 -*-
33
#
44

5-
__version__ = '0.0.63'
5+
__version__ = '0.0.64'

jms/models.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
from hashlib import md5
77
import re
88

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__)
1012

1113

1214
class Decoder:
@@ -264,7 +266,7 @@ class CommandFilterRule(Decoder):
264266
action = {}
265267
__pattern = None
266268

267-
DENY, ALLOW, UNKNOWN = range(3)
269+
DENY, ALLOW, UNKNOWN, ERROR = range(4)
268270

269271
def __init__(self, **kwargs):
270272
super().__init__(**kwargs)
@@ -275,7 +277,8 @@ def _pattern(self):
275277
return self.__pattern
276278
if self.type['value'] == 'command':
277279
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'):
279282
cmd = cmd.replace(' ', '\s+')
280283
regex.append(r'\b{0}\b'.format(cmd))
281284
self.__pattern = re.compile(r'{}'.format('|'.join(regex)))
@@ -284,7 +287,12 @@ def _pattern(self):
284287
return self.__pattern
285288

286289
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+
288296
if not found:
289297
return self.UNKNOWN, ''
290298

0 commit comments

Comments
 (0)