• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python tools.get_global_parameter函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中modoboa.parameters.tools.get_global_parameter函数的典型用法代码示例。如果您正苦于以下问题:Python get_global_parameter函数的具体用法?Python get_global_parameter怎么用?Python get_global_parameter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_global_parameter函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: check_domain

    def check_domain(self, domain, timeout=3, ttl=7200, **options):
        """Check specified domain."""
        mx_list = list(
            models.MXRecord.objects.get_or_create_for_domain(domain, ttl))

        if param_tools.get_global_parameter("enable_mx_checks"):
            self.check_valid_mx(domain, mx_list, **options)

        condition = (
            not param_tools.get_global_parameter("enable_dnsbl_checks") or
            options["no_dnsbl"] is True)
        if condition or not mx_list:
            return

        mx_by_ip = {}
        for mx in mx_list:
            if mx.address not in mx_by_ip:
                mx_by_ip[mx.address] = [mx]
            elif mx not in mx_by_ip[mx.address]:
                mx_by_ip[mx.address].append(mx)

        jobs = [
            gevent.spawn(self.query_dnsbl, mx_by_ip, provider)
            for provider in self.providers]
        gevent.joinall(jobs, timeout)
        for job in jobs:
            if not job.successful():
                continue
            provider, results = job.value
            self.store_dnsbl_result(domain, provider, results, **options)
开发者ID:fyfe,项目名称:modoboa,代码行数:30,代码来源:_mx.py


示例2: get_static_content

def get_static_content(sender, caller, st_type, user, **kwargs):
    """Add extra static content."""
    condition = (
        not param_tools.get_global_parameter("enable_admin_limits") or
        caller not in ["domains", "identities"] or
        user.role in ["SuperAdmins", "SimpleUsers"]
    )
    if condition:
        return ""
    if st_type == "css":
        return """<style>
.resource {
    padding: 10px 15px;
}

.resource .progress {
    margin-bottom: 0px;
}

.resource .progress .bar {
    color: #000000;
}
</style>
"""
    return """
开发者ID:mvb9,项目名称:modoboa,代码行数:25,代码来源:handlers.py


示例3: account_auto_created

def account_auto_created(sender, user, **kwargs):
    """New account has been auto-created, build the rest."""
    if not param_tools.get_global_parameter("auto_create_domain_and_mailbox"):
        return
    localpart, domname = split_mailbox(user.username)
    if user.role != 'SimpleUsers' and domname is None:
        return
    sadmins = core_models.User.objects.filter(is_superuser=True)
    try:
        domain = models.Domain.objects.get(name=domname)
    except models.Domain.DoesNotExist:
        label = lib.check_if_domain_exists(
            domname, [(models.DomainAlias, _("domain alias"))])
        if label is not None:
            return
        domain = models.Domain(
            name=domname, enabled=True, default_mailbox_quota=0)
        domain.save(creator=sadmins[0])
        for su in sadmins[1:]:
            permissions.grant_access_to_object(su, domain)
    qset = models.Mailbox.objects.filter(domain=domain, address=localpart)
    if not qset.exists():
        mb = models.Mailbox(
            address=localpart, domain=domain, user=user, use_domain_quota=True
        )
        mb.set_quota(override_rules=True)
        mb.save(creator=sadmins[0])
        for su in sadmins[1:]:
            permissions.grant_access_to_object(su, mb)
开发者ID:bearstech,项目名称:modoboa,代码行数:29,代码来源:handlers.py


示例4: clean_quota

 def clean_quota(self):
     """Check quota value."""
     if self.cleaned_data["quota"] is None:
         return param_tools.get_global_parameter("default_domain_quota")
     if self.cleaned_data["quota"] < 0:
         raise forms.ValidationError(_("Must be a positive integer"))
     return self.cleaned_data["quota"]
开发者ID:whyscream,项目名称:modoboa,代码行数:7,代码来源:domain.py


示例5: display_pool_usage

def display_pool_usage(user, target, currentpage):
    condition = (
        not param_tools.get_global_parameter("enable_admin_limits") or
        target != "leftcol" or user.is_superuser)
    if condition:
        return []
    if currentpage == "identities":
        names = ["mailboxes", "mailbox_aliases"]
        if user.has_perm("admin.add_domain"):
            names += ["domain_admins"]
    else:
        exceptions = ["domain_admins", "mailboxes", "mailbox_aliases"]
        names = [
            name for name, tpl in utils.get_user_limit_templates()
            if name not in exceptions and
            ("required_role" not in tpl or
             tpl["required_role"] == user.role)
        ]

    limits = user.userobjectlimit_set.filter(name__in=names, max_value__gt=0)
    if len(limits) == 0:
        return []
    return [
        render_to_string("limits/poolusage.html",
                         dict(limits=limits))
    ]
开发者ID:whyscream,项目名称:modoboa,代码行数:26,代码来源:general_callbacks.py


示例6: user_can_set_role

def user_can_set_role(user, role, account=None):
    """Check if the user can still set this role.

    The only interesting case concerns resellers defining new domain
    administrators. We want to check if they are allowed to do this
    operation before any modification is made to :keyword:`account`.

    :param ``User`` user: connected user
    :param ``User`` account: account modified (None on creation)
    :param str newrole: role to check
    """
    condition = (
        not param_tools.get_global_parameter("enable_admin_limits") or
        role != "DomainAdmins")
    if condition:
        return [True]
    lname = "domain_admins"
    condition = (
        user.is_superuser or
        not user.userobjectlimit_set.get(name=lname).is_exceeded()
    )
    if condition:
        return [True]
    if account is not None and account.role == role:
        return [True]
    return [False]
开发者ID:whyscream,项目名称:modoboa,代码行数:26,代码来源:controls.py


示例7: load_from_master_cf

    def load_from_master_cf(self):
        """Load services from the master.cf file.

        Parse the configuration file to update the service table. New
        entries are saved and outdated ones (ie. present in the
        database but not in the file) are removed.
        """
        with open(param_tools.get_global_parameter("master_cf_path")) as fp:
            content = fp.read()
        services = []
        for line in content.split('\n'):
            if not line or line.startswith('#'):
                continue
            parts = line.strip().split()
            if len(parts) != 8:
                continue
            if parts[7] != 'smtp':
                continue
            srv, created = self.get_or_create(name=parts[0])
            services.append(parts[0])
        to_delete = []
        for service in self.all():
            if service.name not in services:
                to_delete.append(service.name)
        Service.objects.filter(name__in=to_delete).delete()
开发者ID:mvb9,项目名称:modoboa,代码行数:25,代码来源:models.py


示例8: fill_domain_instances

def fill_domain_instances(user, domain, instances):
    """Set domain instance for resources form."""
    if not param_tools.get_global_parameter("enable_domain_limits"):
        return
    if not user.has_perm("admin.change_domain"):
        return
    instances["resources"] = domain
开发者ID:whyscream,项目名称:modoboa,代码行数:7,代码来源:general_callbacks.py


示例9: create_new_dkim_key

 def create_new_dkim_key(self, domain):
     """Create a new DKIM key."""
     storage_dir = param_tools.get_global_parameter("dkim_keys_storage_dir")
     pkey_path = os.path.join(storage_dir, "{}.pem".format(domain.name))
     key_size = (
         domain.dkim_key_length if domain.dkim_key_length
         else self.default_key_length)
     code, output = sysutils.exec_cmd(
         "openssl genrsa -out {} {}".format(pkey_path, key_size))
     if code:
         print("Failed to generate DKIM private key for domain {}: {}"
               .format(domain.name, smart_text(output)))
     domain.dkim_private_key_path = pkey_path
     code, output = sysutils.exec_cmd(
         "openssl rsa -in {} -pubout".format(pkey_path))
     if code:
         print("Failed to generate DKIM public key for domain {}: {}"
               .format(domain.name, smart_text(output)))
     public_key = ""
     for cpt, line in enumerate(smart_text(output).splitlines()):
         if cpt == 0 or line.startswith("-----"):
             continue
         public_key += line
     domain.dkim_public_key = public_key
     domain.save(update_fields=["dkim_public_key", "dkim_private_key_path"])
开发者ID:brucewu16899,项目名称:modoboa,代码行数:25,代码来源:_manage_dkim_keys.py


示例10: account_auto_created

def account_auto_created(user):
    from modoboa.core.models import User
    from modoboa.lib.permissions import grant_access_to_object
    from .lib import check_if_domain_exists

    if not param_tools.get_global_parameter("auto_create_domain_and_mailbox"):
        return
    localpart, domname = split_mailbox(user.username)
    if user.role != 'SimpleUsers' and domname is None:
        return
    sadmins = User.objects.filter(is_superuser=True)
    try:
        domain = Domain.objects.get(name=domname)
    except Domain.DoesNotExist:
        label = check_if_domain_exists(
            domname, [(DomainAlias, _('domain alias'))])
        if label is not None:
            return
        domain = Domain(name=domname, enabled=True, quota=0)
        domain.save(creator=sadmins[0])
        for su in sadmins[1:]:
            grant_access_to_object(su, domain)
    try:
        mb = Mailbox.objects.get(domain=domain, address=localpart)
    except Mailbox.DoesNotExist:
        mb = Mailbox(
            address=localpart, domain=domain, user=user, use_domain_quota=True
        )
        mb.set_quota(override_rules=True)
        mb.save(creator=sadmins[0])
        for su in sadmins[1:]:
            grant_access_to_object(su, mb)
开发者ID:whyscream,项目名称:modoboa,代码行数:32,代码来源:callbacks.py


示例11: get_static_content

def get_static_content(caller, st_type, user):
    condition = (
        not param_tools.get_global_parameter("enable_admin_limits") or
        caller not in ["domains", "identities"] or
        user.role in ["SuperAdmins", "SimpleUsers"]
    )
    if condition:
        return []
    if st_type == "css":
        return ["""<style>
.resource {
    padding: 10px 15px;
}

.resource .progress {
    margin-bottom: 0px;
}

.resource .progress .bar {
    color: #000000;
}
</style>
"""]
    return ["""
<script type="text/javascript">
$(document).ready(function() {
    $(".progress").tooltip();
});
</script>
"""]
开发者ID:whyscream,项目名称:modoboa,代码行数:30,代码来源:general_callbacks.py


示例12: decrypt

def decrypt(ciph):
    obj = AES.new(
        param_tools.get_global_parameter(
            "secret_key", app="core"), AES.MODE_ECB
    )
    ciph = base64.b64decode(ciph)
    clear = obj.decrypt(ciph)
    return clear.rstrip(' ')
开发者ID:bearstech,项目名称:modoboa,代码行数:8,代码来源:cryptutils.py


示例13: make_password

def make_password():
    """Create a random password."""
    length = int(
        param_tools.get_global_parameter("random_password_length", app="core")
    )
    return "".join(
        random.SystemRandom().choice(
            string.ascii_letters + string.digits) for _ in range(length))
开发者ID:brucewu16899,项目名称:modoboa,代码行数:8,代码来源:lib.py


示例14: _crypt_password

    def _crypt_password(self, raw_value):
        """Crypt the local password using the appropriate scheme.

        In case we don't find the scheme (for example when the
        management framework is used), we load the parameters and try
        one more time.

        """
        scheme = param_tools.get_global_parameter(
            "password_scheme", raise_exception=False)
        if scheme is None:
            from modoboa.core.apps import load_core_settings
            load_core_settings()
            scheme = param_tools.get_global_parameter(
                "password_scheme", raise_exception=False)
        raw_value = smart_bytes(raw_value)
        return get_password_hasher(scheme.upper())().encrypt(raw_value)
开发者ID:bearstech,项目名称:modoboa,代码行数:17,代码来源:models.py


示例15: get_dns_resolver

def get_dns_resolver():
    """Return a DNS resolver object."""
    dns_server = param_tools.get_global_parameter("custom_dns_server")
    if dns_server:
        resolver = dns.resolver.Resolver()
        resolver.nameservers = [dns_server]
    else:
        resolver = dns.resolver
    return resolver
开发者ID:brucewu16899,项目名称:modoboa,代码行数:9,代码来源:lib.py


示例16: fill_domain_instances

def fill_domain_instances(sender, user, domain, **kwargs):
    """Set domain instance for resources form."""
    condition = (
        not param_tools.get_global_parameter("enable_domain_limits") or
        not user.has_perm("admin.change_domain")
    )
    if condition:
        return {}
    return {"resources": domain}
开发者ID:mvb9,项目名称:modoboa,代码行数:9,代码来源:handlers.py


示例17: rename_dir

 def rename_dir(self, old_mail_home):
     """Rename local directory if needed."""
     hm = param_tools.get_global_parameter(
         "handle_mailboxes", raise_exception=False)
     if not hm:
         return
     MailboxOperation.objects.create(
         mailbox=self, type="rename", argument=old_mail_home
     )
开发者ID:whyscream,项目名称:modoboa,代码行数:9,代码来源:mailbox.py


示例18: handle

 def handle(self, *args, **options):
     """Entry point."""
     self.default_key_length = param_tools.get_global_parameter(
         "dkim_default_key_length")
     qset = models.Domain.objects.filter(
         enable_dkim=True, dkim_private_key_path="")
     for domain in qset:
         self.create_new_dkim_key(domain)
     if qset.exists():
         signals.new_dkim_keys.send(sender=self.__class__, domains=qset)
开发者ID:brucewu16899,项目名称:modoboa,代码行数:10,代码来源:_manage_dkim_keys.py


示例19: check_object_limit

def check_object_limit(sender, context, **kwargs):
    """Check if user can create a new object."""
    if context.__class__.__name__ == "User":
        if not param_tools.get_global_parameter("enable_admin_limits"):
            return
        if context.is_superuser:
            return True
        ct = ContentType.objects.get_for_model(kwargs.get("klass"))
        limits = context.userobjectlimit_set.filter(content_type=ct)
    elif context.__class__.__name__ == "Domain":
        if not param_tools.get_global_parameter("enable_domain_limits"):
            return
        object_type = kwargs.get("object_type")
        limits = context.domainobjectlimit_set.filter(name=object_type)
    else:
        raise NotImplementedError
    for limit in limits:
        if limit.is_exceeded(kwargs.get("count", 1), kwargs.get("instance")):
            raise lib.LimitReached(limit)
开发者ID:mvb9,项目名称:modoboa,代码行数:19,代码来源:handlers.py


示例20: encrypt

def encrypt(clear):
    key = param_tools.get_global_parameter("secret_key", app="core")
    obj = AES.new(key, AES.MODE_ECB)
    if type(clear) is unicode:
        clear = clear.encode("utf-8")
    if len(clear) % AES.block_size:
        clear += " " * (AES.block_size - len(clear) % AES.block_size)
    ciph = obj.encrypt(clear)
    ciph = base64.b64encode(ciph)
    return ciph
开发者ID:mvb9,项目名称:modoboa,代码行数:10,代码来源:cryptutils.py



注:本文中的modoboa.parameters.tools.get_global_parameter函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python modshogun.RealFeatures类代码示例发布时间:2022-05-27
下一篇:
Python webutils.render_to_json_response函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap