2017-03-09 06:55:33 +00:00
|
|
|
# ~*~ coding: utf-8 ~*~
|
2022-11-11 11:20:17 +00:00
|
|
|
import uuid
|
2018-03-30 14:03:43 +00:00
|
|
|
|
2017-03-09 06:55:33 +00:00
|
|
|
from django.db import models
|
2022-05-07 08:20:12 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2017-12-10 16:29:25 +00:00
|
|
|
|
2022-10-08 08:55:14 +00:00
|
|
|
from common.utils import get_logger
|
2022-11-29 11:44:12 +00:00
|
|
|
from orgs.mixins.models import JMSOrgBaseModel
|
2017-03-09 06:55:33 +00:00
|
|
|
|
2022-11-29 11:44:12 +00:00
|
|
|
__all__ = ["AdHoc"]
|
2017-03-09 06:55:33 +00:00
|
|
|
|
2017-12-22 13:42:12 +00:00
|
|
|
logger = get_logger(__file__)
|
2017-03-09 06:55:33 +00:00
|
|
|
|
|
|
|
|
2022-11-29 11:44:12 +00:00
|
|
|
class AdHoc(JMSOrgBaseModel):
|
2022-11-11 11:20:17 +00:00
|
|
|
class Modules(models.TextChoices):
|
|
|
|
shell = 'shell', _('Shell')
|
|
|
|
winshell = 'win_shell', _('Powershell')
|
|
|
|
|
|
|
|
id = models.UUIDField(default=uuid.uuid4, primary_key=True)
|
|
|
|
name = models.CharField(max_length=128, verbose_name=_('Name'))
|
2022-10-08 08:55:14 +00:00
|
|
|
pattern = models.CharField(max_length=1024, verbose_name=_("Pattern"), default='all')
|
2022-11-11 11:20:17 +00:00
|
|
|
module = models.CharField(max_length=128, choices=Modules.choices, default=Modules.shell,
|
|
|
|
verbose_name=_('Module'))
|
2022-10-08 08:55:14 +00:00
|
|
|
args = models.CharField(max_length=1024, default='', verbose_name=_('Args'))
|
2022-11-29 11:44:12 +00:00
|
|
|
creator = models.ForeignKey('users.User', verbose_name=_("Creator"), on_delete=models.SET_NULL, null=True)
|
2022-11-29 11:52:48 +00:00
|
|
|
comment = models.CharField(max_length=1024, default='', verbose_name=_('Comment'), null=True, blank=True)
|
|
|
|
|
2022-11-11 11:20:17 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def row_count(self):
|
|
|
|
if len(self.args) == 0:
|
|
|
|
return 0
|
|
|
|
count = str(self.args).count('\n')
|
|
|
|
return count + 1
|
2022-10-08 11:12:04 +00:00
|
|
|
|
2022-11-11 11:20:17 +00:00
|
|
|
@property
|
|
|
|
def size(self):
|
|
|
|
return len(self.args)
|
2017-12-21 18:08:29 +00:00
|
|
|
|
2017-12-15 07:50:15 +00:00
|
|
|
def __str__(self):
|
2022-10-08 08:55:14 +00:00
|
|
|
return "{}: {}".format(self.module, self.args)
|