mirror of https://github.com/jumpserver/jumpserver
[Update] 修改cmd filter rules pattern
parent
e52178811c
commit
ce530e417c
|
@ -7,6 +7,7 @@ from django.db import models
|
||||||
from django.core.validators import MinValueValidator, MaxValueValidator
|
from django.core.validators import MinValueValidator, MaxValueValidator
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
from common.utils import lazyproperty
|
||||||
from orgs.mixins.models import OrgModelMixin
|
from orgs.mixins.models import OrgModelMixin
|
||||||
|
|
||||||
|
|
||||||
|
@ -57,25 +58,30 @@ class CommandFilterRule(OrgModelMixin):
|
||||||
date_updated = models.DateTimeField(auto_now=True)
|
date_updated = models.DateTimeField(auto_now=True)
|
||||||
created_by = models.CharField(max_length=128, blank=True, default='', verbose_name=_('Created by'))
|
created_by = models.CharField(max_length=128, blank=True, default='', verbose_name=_('Created by'))
|
||||||
|
|
||||||
__pattern = None
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ('-priority', 'action')
|
ordering = ('-priority', 'action')
|
||||||
verbose_name = _("Command filter rule")
|
verbose_name = _("Command filter rule")
|
||||||
|
|
||||||
@property
|
@lazyproperty
|
||||||
def _pattern(self):
|
def _pattern(self):
|
||||||
if self.__pattern:
|
|
||||||
return self.__pattern
|
|
||||||
if self.type == 'command':
|
if self.type == 'command':
|
||||||
regex = []
|
regex = []
|
||||||
for cmd in self.content.split('\r\n'):
|
content = self.content.replace('\r\n', '\n')
|
||||||
cmd = cmd.replace(' ', '\s+')
|
for cmd in content.split('\n'):
|
||||||
regex.append(r'\b{0}\b'.format(cmd))
|
cmd = re.escape(cmd)
|
||||||
self.__pattern = re.compile(r'{}'.format('|'.join(regex)))
|
cmd = cmd.replace('\\ ', '\s+')
|
||||||
|
if cmd[-1].isalpha():
|
||||||
|
regex.append(r'\b{0}\b'.format(cmd))
|
||||||
|
else:
|
||||||
|
regex.append(r'\b{0}'.format(cmd))
|
||||||
|
s = r'{}'.format('|'.join(regex))
|
||||||
else:
|
else:
|
||||||
self.__pattern = re.compile(r'{0}'.format(self.content))
|
s = r'{0}'.format(self.content)
|
||||||
return self.__pattern
|
try:
|
||||||
|
_pattern = re.compile(s)
|
||||||
|
except:
|
||||||
|
_pattern = ''
|
||||||
|
return _pattern
|
||||||
|
|
||||||
def match(self, data):
|
def match(self, data):
|
||||||
found = self._pattern.search(data)
|
found = self._pattern.search(data)
|
||||||
|
|
|
@ -140,6 +140,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function initTree() {
|
function initTree() {
|
||||||
|
$('#assetTree').html("{% trans 'Loading' %}" + '..');
|
||||||
if (systemUserId) {
|
if (systemUserId) {
|
||||||
url = treeUrl + '&system_user=' + systemUserId
|
url = treeUrl + '&system_user=' + systemUserId
|
||||||
} else {
|
} else {
|
||||||
|
@ -365,4 +366,4 @@
|
||||||
execute()
|
execute()
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Loading…
Reference in New Issue