Exemple #1
0
def rm(request):
    #try:
    user = request.session.get('switched_user', request.user)

    domain = get_object_or_404(user.domain_set, id=request.POST['object_id'])
    print domain
    if domain.owner == user:
        logging.info(_("Deleting domain %s") % domain.name)

        print "subdomains"
        for subdomain in Domain.objects.filter(parent=domain):
            print subdomain
            for app in subdomain.apps():
                print app
                if app.domains_count <= 1:
                    print "remove preparations"
                    remove_app_preparation(app, remove_domains=False)
                    print "delete"
                    app.delete()
            subdomain.delete()

        print "apps"
        for app in domain.apps():
            if app.domains_count <= 1:
                remove_app_preparation(app)
                app.delete()

        print "dns"
        if config.handle_dns and domain.dns:
            pri_br = BindRequest(user, "master")
            pri_br.remove_zone(domain)
            pri_br.mod_config()
            pri_br.reload()

            if config.handle_dns_secondary:
                sec_br = BindRequest(user, "slave")
                sec_br.mod_config()
                sec_br.reload()

        domain.delete()

    return JsonResponse("OK", {1: ugettext("Domain was successfuly deleted")})
Exemple #2
0
def add(request):
    """
    Add domain of customer
    """
    u = request.session.get('switched_user', request.user)
    superuser = request.user

    if request.method == 'POST':
        form = FormDomain(request.POST)
        if form.is_valid():
            name = form.cleaned_data["name"]

            object = form.save(commit=False)
            object.owner = u
            object.save()

            if config.handle_dns and object.dns:
                pri_br = BindRequest(u, "master")
                pri_br.mod_zone(object)
                pri_br.mod_config()
                pri_br.reload()
                if config.handle_dns_secondary:
                    sec_br = BindRequest(u, "slave")
                    sec_br.mod_config()
                    sec_br.reload()

            logging.info(_("Added domain %s ") % name)
            message = _("Domain %s has been successfuly added") % name
            send_mail(_('Added new domain: %s') % name, message, settings.EMAIL_FROM, [mail for (name, mail) in settings.ADMINS if mail], fail_silently=True)

            messages.add_message(request, messages.SUCCESS, _('Domain has been added'))
            return HttpResponseRedirect(reverse("subdomains", args=(object.id, )))
    else:
        form = FormDomain()

    return render_to_response('universal.html',
            {
            "form": form,
            'form_helper': RostiFormHelper(),
            "title": _("Add domain"),
            "u": u,
            "superuser": superuser,
            "menu_active": "domains",
            },
        context_instance=RequestContext(request)
    )
Exemple #3
0
def rm(request):

    try:
        u = request.session.get('switched_user', request.user)

        d = get_object_or_404(Domain, id=request.POST['object_id'])
        if d.owner == u:
            logging.info(_("Deleting domain %s") % d.name)

            if config.handle_dns and d.dns:
                pri_br = BindRequest(u, "master")
                pri_br.remove_zone(d)
                pri_br.mod_config()
                pri_br.reload()

                sec_br = BindRequest(u, "slave")
                sec_br.mod_config()
                sec_br.reload()

            d.delete()

        return JsonResponse("OK", {1: ugettext("Domain was successfuly deleted")})
    except Exception, e:
        return JsonResponse("KO", {1: ugettext("Error deleting domain")})
Exemple #4
0
def add(request):
    """
    Add domain of customer
    """
    u = request.session.get('switched_user', request.user)
    superuser = request.user

    if request.method == 'POST':
        form = RegistrationRequestForm(request.POST)
        if form.is_valid():
            name = form.cleaned_data["domain"]

            instance, created = Domain.objects.get_or_create(name=name, owner=u)

            if config.handle_dns and instance.dns:
                pri_br = BindRequest(u, "master")
                pri_br.mod_zone(instance)
                pri_br.mod_config()
                pri_br.reload()
                sec_br = BindRequest(u, "slave")
                sec_br.mod_config()
                sec_br.reload()

            logging.info(_("Added domain %s ") % name)
            message = _("Domain %s has been successfuly added") % name
            send_mail(_('Added new domain: %s') % name, message, settings.EMAIL_FROM, [mail for (name, mail) in settings.ADMINS if mail], fail_silently=True)

            messages.add_message(request, messages.SUCCESS, _('Domain has been added'))
            return HttpResponseRedirect(reverse("domains_list"))
    else:
        form = RegistrationRequestForm()

    return render_to_response('universal.html',
            {
            "form": form,
            "title": _("Add domain"),
            "submit": _("Save domain"),
            "action": reverse("wsgiadmin.domains.views.add"),
            "u": u,
            "superuser": superuser,
            "menu_active": "domains",
            },
        context_instance=RequestContext(request)
    )
Exemple #5
0
def rm(request):

    try:
        u = request.session.get('switched_user', request.user)

        d = get_object_or_404(Domain, id=request.POST['object_id'])
        if d.owner == u:
            logging.info(_("Deleting domain %s") % d.name)

            if config.handle_dns and d.dns:
                pri_br = BindRequest(u, "master")
                pri_br.remove_zone(d)
                pri_br.mod_config()
                pri_br.reload()

                sec_br = BindRequest(u, "slave")
                sec_br.mod_config()
                sec_br.reload()

            d.delete()

        return JsonResponse("OK", {1: ugettext("Domain was successfuly deleted")})
    except Exception, e:
        return JsonResponse("KO", {1: ugettext("Error deleting domain")})
Exemple #6
0
def add(request):
    """
    Add domain of customer
    """
    u = request.session.get('switched_user', request.user)
    superuser = request.user

    if request.method == 'POST':
        form = FormDomain(request.POST)
        if form.is_valid():
            name = form.cleaned_data["name"]

            object = form.save(commit=False)
            object.owner = u
            object.save()

            if config.handle_dns and object.dns:
                pri_br = BindRequest(u, "master")
                pri_br.mod_zone(object)
                pri_br.mod_config()
                pri_br.reload()
                if config.handle_dns_secondary:
                    sec_br = BindRequest(u, "slave")
                    sec_br.mod_config()
                    sec_br.reload()

            logging.info(_("Added domain %s ") % name)
            message = _("Domain %s has been successfuly added") % name
            send_mail(_('Added new domain: %s') % name,
                      message,
                      settings.EMAIL_FROM,
                      [mail for (name, mail) in settings.ADMINS if mail],
                      fail_silently=True)

            messages.add_message(request, messages.SUCCESS,
                                 _('Domain has been added'))
            return HttpResponseRedirect(
                reverse("subdomains", args=(object.id, )))
    else:
        form = FormDomain()

    return render_to_response('universal.html', {
        "form": form,
        'form_helper': RostiFormHelper(),
        "title": _("Add domain"),
        "u": u,
        "superuser": superuser,
        "menu_active": "domains",
    },
                              context_instance=RequestContext(request))
Exemple #7
0
def rm(request):
    #try:
    user = request.session.get('switched_user', request.user)

    domain = get_object_or_404(user.domain_set, id=request.POST['object_id'])
    print domain
    if domain.owner == user:
        logging.info(_("Deleting domain %s") % domain.name)

        print "subdomains"
        for subdomain in Domain.objects.filter(parent=domain):
            print subdomain
            for app in subdomain.apps():
                print app
                if app.domains_count <= 1:
                    print "remove preparations"
                    remove_app_preparation(app, remove_domains=False)
                    print "delete"
                    app.delete()
            subdomain.delete()

        print "apps"
        for app in domain.apps():
            if app.domains_count <= 1:
                remove_app_preparation(app)
                app.delete()

        print "dns"
        if config.handle_dns and domain.dns:
            pri_br = BindRequest(user, "master")
            pri_br.remove_zone(domain)
            pri_br.mod_config()
            pri_br.reload()

            if config.handle_dns_secondary:
                sec_br = BindRequest(user, "slave")
                sec_br.mod_config()
                sec_br.reload()

        domain.delete()

    return JsonResponse("OK", {1: ugettext("Domain was successfuly deleted")})