예제 #1
0
파일: utils.py 프로젝트: donzpixelz/modoboa
def check_for_updates(request):
    """Check if a new version of Modoboa is available."""
    local_config = models.LocalConfig.objects.first()
    client = ModoAPIClient()
    extensions = exts_pool.list_all()
    extensions = [{
        "label": "Modoboa",
        "name": "modoboa",
        "description": _("The core part of Modoboa"),
        "version": client.local_core_version
    }] + extensions
    update_avail = False
    for extension in extensions:
        pkgname = extension["name"].replace("_", "-")
        for api_extension in local_config.api_versions:
            if api_extension["name"] != pkgname:
                continue
            extension["last_version"] = api_extension["version"]
            if (parse_version(api_extension["version"]) > parse_version(
                    extension["version"])):
                extension["update"] = True
                extension["changelog_url"] = api_extension["url"]
                update_avail = True
                break
    return update_avail, extensions
예제 #2
0
def check_for_updates(request):
    """Check if a new version of Modoboa is available."""
    local_config = models.LocalConfig.objects.first()
    client = ModoAPIClient()
    extensions = exts_pool.list_all()
    extensions = [{
        "label": "Modoboa",
        "name": "modoboa",
        "description": _("The core part of Modoboa"),
        "version": client.local_core_version
    }] + extensions
    update_avail = False
    for extension in extensions:
        pkgname = extension["name"].replace("_", "-")
        for api_extension in local_config.api_versions:
            if api_extension["name"] != pkgname:
                continue
            extension["last_version"] = api_extension["version"]
            if (
                parse_version(api_extension["version"]) >
                parse_version(extension["version"])
            ):
                extension["update"] = True
                extension["changelog_url"] = api_extension["url"]
                update_avail = True
                break
    return update_avail, extensions
    def handle(self, *args, **options):
        """Command entry point."""
        local_config = (
            models.LocalConfig.objects.select_related("site").first())
        if not local_config.parameters.get_value("enable_api_communication"):
            return
        self.client = api_client.ModoAPIClient()
        if not local_config.api_pk:
            pk = self.client.register_instance(local_config.site.domain)
            if pk is None:
                raise CommandError("Instance registration failed.")
            local_config.api_pk = pk

        if local_config.parameters.get_value("check_new_versions"):
            versions = self.client.versions()
            if versions is None:
                raise CommandError("Failed to retrieve versions from the API.")
            local_config.api_versions = versions

        local_config.save()

        if not local_config.parameters.get_value("send_statistics"):
            return
        extensions = [ext["name"] for ext in exts_pool.list_all()]
        data = {
            "hostname": local_config.site.domain,
            "known_version": self.client.local_core_version,
            "domain_counter": admin_models.Domain.objects.count(),
            "domain_alias_counter": admin_models.DomainAlias.objects.count(),
            "mailbox_counter": admin_models.Mailbox.objects.count(),
            "alias_counter": (
                admin_models.Alias.objects.filter(internal=False).count()),
            "extensions": extensions
        }
        self.client.update_instance(local_config.api_pk, data)
예제 #4
0
def enabled_applications():
    """Return the list of installed extensions."""
    from modoboa.core.extensions import exts_pool

    result = [("user", "user")]
    for extension in exts_pool.list_all():
        result.append((extension["name"], extension["name"]))
    return sorted(result, key=lambda e: e[0])
예제 #5
0
파일: admin.py 프로젝트: kaxdev/modoboa
def viewextensions(request, tplname='core/extensions.html'):
    """List available extensions."""
    from modoboa.core.extensions import exts_pool

    exts = exts_pool.list_all()
    return render_to_json_response({
        "callback": "extensions",
        "content": _render_to_string(request, tplname, {"extensions": exts})
    })
예제 #6
0
def enabled_applications():
    """Return the list of installed extensions."""
    from modoboa.core.extensions import exts_pool

    result = [("user", _("User profile"))]
    for extension in exts_pool.list_all():
        if "topredirection_url" not in extension:
            continue
        result.append((extension["name"], extension["label"]))
    return sorted(result, key=lambda e: e[0])
예제 #7
0
def enabled_applications():
    """Return the list of installed extensions."""
    from modoboa.core.extensions import exts_pool

    result = [("user", _("User profile"))]
    for extension in exts_pool.list_all():
        if "topredirection_url" not in extension:
            continue
        result.append((extension["name"], extension["label"]))
    return sorted(result, key=lambda e: e[0])
예제 #8
0
def viewextensions(request, tplname='core/extensions.html'):
    """List available extensions."""
    from modoboa.core.extensions import exts_pool

    exts = exts_pool.list_all()
    return render_to_json_response({
        "callback":
        "extensions",
        "content":
        _render_to_string(request, tplname, {"extensions": exts})
    })
예제 #9
0
def enabled_applications():
    """Return the list of installed extensions.

    We check if the table exists before trying to fetch activated
    extensions because the admin module is always imported by Django,
    even before the database exists (example: the first ``syncdb``).

    :return: a list
    """
    from modoboa.core.extensions import exts_pool

    result = [("user", "user")]
    for extension in exts_pool.list_all():
        result.append((extension["name"], extension["name"]))
    return sorted(result, key=lambda e: e[0])
예제 #10
0
def enabled_applications():
    """Return the list of installed extensions.

    We check if the table exists before trying to fetch activated
    extensions because the admin module is always imported by Django,
    even before the database exists (example: the first ``syncdb``).

    :return: a list
    """
    from modoboa.core.extensions import exts_pool

    result = [("user", "user")]
    for extension in exts_pool.list_all():
        result.append((extension["name"], extension["name"]))
    return sorted(result, key=lambda e: e[0])
예제 #11
0
파일: admin.py 프로젝트: simonkern/modoboa
def viewextensions(request, tplname="core/extensions.html"):
    from modoboa.core.extensions import exts_pool

    exts = exts_pool.list_all()
    for ext in exts:
        try:
            dbext = Extension.objects.get(name=ext["id"])
            ext["selection"] = dbext.enabled
        except Extension.DoesNotExist:
            dbext = Extension()
            dbext.name = ext["id"]
            dbext.enabled = False
            dbext.save()
            ext["selection"] = False

    tbl = ExtensionsTable(request, exts)
    return ajax_simple_response({"status": "ok", "content": _render_to_string(request, tplname, {"extensions": tbl})})
예제 #12
0
파일: admin.py 프로젝트: masbog/modoboa
def viewextensions(request, tplname='core/extensions.html'):
    from modoboa.core.extensions import exts_pool

    exts = exts_pool.list_all()
    for ext in exts:
        try:
            dbext = Extension.objects.get(name=ext["id"])
            ext["selection"] = dbext.enabled
        except Extension.DoesNotExist:
            dbext = Extension()
            dbext.name = ext["id"]
            dbext.enabled = False
            dbext.save()
            ext["selection"] = False

    tbl = ExtensionsTable(request, exts)
    return render_to_json_response(
        {"content": _render_to_string(request, tplname, {"extensions": tbl})})
예제 #13
0
    def handle(self, *args, **options):
        """Command entry point."""
        local_config = (
            models.LocalConfig.objects.select_related("site").first())
        if not local_config.parameters.get_value("enable_api_communication"):
            return
        self.client = api_client.ModoAPIClient()
        if not local_config.api_pk:
            pk = self.client.register_instance(local_config.site.domain)
            if pk is None:
                raise CommandError("Instance registration failed.")
            local_config.api_pk = pk

        if local_config.parameters.get_value("check_new_versions"):
            versions = self.client.versions()
            if versions is None:
                raise CommandError("Failed to retrieve versions from the API.")
            local_config.api_versions = versions

        local_config.save()

        if not local_config.parameters.get_value("send_statistics"):
            return
        extensions = [ext["name"] for ext in exts_pool.list_all()]
        data = {
            "hostname":
            local_config.site.domain,
            "known_version":
            self.client.local_core_version,
            "domain_counter":
            admin_models.Domain.objects.count(),
            "domain_alias_counter":
            admin_models.DomainAlias.objects.count(),
            "mailbox_counter":
            admin_models.Mailbox.objects.count(),
            "alias_counter":
            (admin_models.Alias.objects.filter(internal=False).count()),
            "extensions":
            extensions
        }
        if not self.client.update_instance(local_config.api_pk, data):
            raise CommandError("Failed to update instance.")
예제 #14
0
    def handle(self, *args, **options):
        """Command entry point."""
        if parameters.get_admin("ENABLE_API_COMMUNICATION") == "no":
            return
        self.client = api_client.ModoAPIClient()
        local_config = (
            models.LocalConfig.objects.select_related("site").first())
        if not local_config.api_pk:
            pk = self.client.register_instance(local_config.site.domain)
            if pk is None:
                raise CommandError("Instance registration failed.")
            local_config.api_pk = pk

        if parameters.get_admin("CHECK_NEW_VERSIONS") == "yes":
            versions = self.client.versions()
            if versions is None:
                raise CommandError("Failed to retrieve versions from the API.")
            local_config.api_versions = versions

        local_config.save()

        if parameters.get_admin("SEND_STATISTICS") == "no":
            return
        extensions = [ext["name"] for ext in exts_pool.list_all()]
        data = {
            "hostname":
            local_config.site.domain,
            "known_version":
            self.client.local_core_version,
            "domain_counter":
            admin_models.Domain.objects.count(),
            "domain_alias_counter":
            admin_models.DomainAlias.objects.count(),
            "mailbox_counter":
            admin_models.Mailbox.objects.count(),
            "alias_counter":
            (admin_models.Alias.objects.filter(internal=False).count()),
            "extensions":
            extensions
        }
        if not self.client.update_instance(local_config.api_pk, data):
            raise CommandError("Failed to update instance.")
예제 #15
0
def check_for_updates(request):
    """Check if a new version of Modoboa is available."""
    if parameters.get_admin("CHECK_NEW_VERSIONS") == "no":
        return False, []
    client = ModoAPIClient()
    extensions = exts_pool.list_all(True)
    extensions = [{
        "label": "Modoboa",
        "description": _("The core part of Modoboa"),
        "update": client.new_core_version(get_current_site(request)),
        "last_version": client.latest_core_version,
        "changelog_url": client.changelog_url,
        "version": client.local_core_version
    }] + extensions
    update_avail = False
    for extension in extensions:
        if extension.get("update"):
            update_avail = True
            break
    return update_avail, extensions
예제 #16
0
파일: admin.py 프로젝트: finid/modoboa
def viewextensions(request, tplname='core/extensions.html'):
    """List available extensions."""
    from modoboa.core.extensions import exts_pool

    exts = exts_pool.list_all()
    for ext in exts:
        try:
            dbext = Extension.objects.get(name=ext["id"])
            ext["selection"] = dbext.enabled
        except Extension.DoesNotExist:
            dbext = Extension()
            dbext.name = ext["id"]
            dbext.enabled = False
            dbext.save()
            ext["selection"] = False

    return render_to_json_response({
        "callback": "extensions",
        "content": _render_to_string(request, tplname, {"extensions": exts})
    })
예제 #17
0
    def handle(self, *args, **options):
        """Command entry point."""
        if parameters.get_admin("ENABLE_API_COMMUNICATION") == "no":
            return
        self.client = api_client.ModoAPIClient()
        local_config = (
            models.LocalConfig.objects.select_related("site").first())
        if not local_config.api_pk:
            pk = self.client.register_instance(local_config.site.domain)
            if pk is None:
                raise CommandError("Instance registration failed.")
            local_config.api_pk = pk

        if parameters.get_admin("CHECK_NEW_VERSIONS") == "yes":
            versions = self.client.versions()
            if versions is None:
                raise CommandError("Failed to retrieve versions from the API.")
            local_config.api_versions = versions

        local_config.save()

        if parameters.get_admin("SEND_STATISTICS") == "no":
            return
        extensions = [ext["name"] for ext in exts_pool.list_all()]
        data = {
            "hostname": local_config.site.domain,
            "known_version": self.client.local_core_version,
            "domain_counter": admin_models.Domain.objects.count(),
            "domain_alias_counter": admin_models.DomainAlias.objects.count(),
            "mailbox_counter": admin_models.Mailbox.objects.count(),
            "alias_counter": (
                admin_models.Alias.objects.filter(internal=False).count()),
            "extensions": extensions
        }
        if not self.client.update_instance(local_config.api_pk, data):
            raise CommandError("Failed to update instance.")