Exemplo n.º 1
0
Arquivo: views.py Projeto: a740122/pcp
def changePasswdBox(request, eid):
    eid = int(eid)
    u = request.session.get('switched_user', request.user)
    superuser = request.user

    try:
        e = Email.objects.get(domain__in=u.email_domain_set.all(), id=eid)
    except Email.DoesNotExist:
        e = None

    if request.method == 'POST':
        form = EmailPasswd(request.POST, instance=e)
        if form.is_valid():
            email = form.save(commit=False)
            email.password = crypt.crypt(form.cleaned_data["password1"], email.login*2)
            email.save()
            messages.add_message(request, messages.SUCCESS, _('Password has been changed'))
            return HttpResponseRedirect(reverse("mailbox_list"))
    else:
        form = EmailPasswd(instance=e)

    helper = RostiFormHelper()
    helper.form_action = reverse("wsgiadmin.emails.views.changePasswdBox", args=[e.id])

    return render_to_response('universal.html',
            {
            "form": form,
            "form_helper": helper,
            "title": _("Change password for e-mail box"),
            "u": u,
            "superuser": superuser,
            "menu_active": "emails",
            },
        context_instance=RequestContext(request)
    )
Exemplo n.º 2
0
def add(request, dbtype):
    """
    DB create
    """
    u = request.session.get('switched_user', request.user)
    superuser = request.user

    form_class = MysqlForm if dbtype == 'mysql' else PgsqlForm

    if request.method == 'POST':
        form = form_class(request.POST)
        orig_dbname = form.data['dbname']
        old = form.data
        form.data._mutable = True
        form.data['dbname'] = "%s_%s" % (u.parms.prefix(), form.data['dbname'])
        form.data._mutable = old

        if form.is_valid():
            db_obj = form.save(commit=False)
            db_obj.owner = u
            db_obj.save()

            if dbtype == 'mysql':
                mr = MySQLRequest(u, u.parms.mysql_machine)
            elif dbtype == 'pgsql':
                mr = PostgreSQLRequest(u, u.parms.pgsql_machine)
            else:
                return HttpResponseBadRequest(_('Unknown database type'))
            mr.add_db(db_obj.dbname, form.cleaned_data["password1"])

            return HttpResponseRedirect(reverse("db_list", kwargs=dict(dbtype=dbtype)))
        else:
            form.data['dbname'] = orig_dbname
    else:
        form = form_class()
        form.owner = u


    helper = RostiFormHelper()

    helper.form_action = reverse("db_add", kwargs=dict(dbtype=dbtype))

    return render_to_response('universal.html',
            {
            "form": form,
            "form_helper": RostiFormHelper(),
            "title": _("Create %s database" % dbtype),
            "u": u,
            "superuser": superuser,
            "menu_active": "dbs",
            },
        context_instance=RequestContext(request)
    )
Exemplo n.º 3
0
def add(request, dbtype):
    """
    DB create
    """
    u = request.session.get('switched_user', request.user)
    superuser = request.user

    form_class = MysqlForm if dbtype == 'mysql' else PgsqlForm

    if request.method == 'POST':
        form = form_class(request.POST)
        orig_dbname = form.data['dbname']
        old = form.data
        form.data._mutable = True
        form.data['dbname'] = "%s_%s" % (u.parms.prefix(), form.data['dbname'])
        form.data._mutable = old

        if form.is_valid():
            db_obj = form.save(commit=False)
            db_obj.owner = u
            db_obj.save()

            if dbtype == 'mysql':
                mr = MySQLRequest(u, u.parms.mysql_machine)
            elif dbtype == 'pgsql':
                mr = PostgreSQLRequest(u, u.parms.pgsql_machine)
            else:
                return HttpResponseBadRequest(_('Unknown database type'))
            mr.add_db(db_obj.dbname, form.cleaned_data["password1"])

            return HttpResponseRedirect(
                reverse("db_list", kwargs=dict(dbtype=dbtype)))
        else:
            form.data['dbname'] = orig_dbname
    else:
        form = form_class()
        form.owner = u

    helper = RostiFormHelper()

    helper.form_action = reverse("db_add", kwargs=dict(dbtype=dbtype))

    return render_to_response('universal.html', {
        "form": form,
        "form_helper": RostiFormHelper(),
        "title": _("Create %s database" % dbtype),
        "u": u,
        "superuser": superuser,
        "menu_active": "dbs",
    },
                              context_instance=RequestContext(request))
Exemplo n.º 4
0
def ftp_upsert(request, ftp_id=0):
    u = request.session.get('switched_user', request.user)
    superuser = request.user

    try:
        ftp = Ftp.objects.get(pk=ftp_id)
    except Ftp.DoesNotExist:
        ftp = None

    if request.method == 'POST':
        if ftp:
            form = FTPUpdateForm(request.POST, user=u, instance=ftp)
        else:
            form = FTPForm(request.POST, user=u)

        if form.is_valid():
            iftp = form.save(commit=False)
            iftp.uid = u.parms.uid
            iftp.gid = u.parms.gid
            iftp.owner = u
            if "password1" in form.cleaned_data:
                iftp.password = crypt.crypt(form.cleaned_data["password1"],
                                            iftp.owner.username)
            iftp.save()

            messages.add_message(
                request, messages.SUCCESS,
                _('FTP account has been %s') %
                _("changed") if ftp else _("added"))
            return HttpResponseRedirect(reverse("ftp_list"))
    else:
        if ftp:
            form = FTPUpdateForm(user=u, instance=ftp)
        else:
            form = FTPForm(user=u)

    helper = RostiFormHelper()
    helper.form_action = reverse("ftp_upsert", kwargs={'ftp_id': ftp_id})

    return render_to_response(
        'universal.html', {
            "form": form,
            "form_helper": RostiFormHelper(),
            "title": _("FTP account"),
            "note": [_("* Username will be prefixed with `%s_`" % u.username)],
            "u": u,
            "superuser": superuser,
            "menu_active": "ftps",
        },
        context_instance=RequestContext(request))
Exemplo n.º 5
0
def ftp_upsert(request, ftp_id=0):
    u = request.session.get('switched_user', request.user)
    superuser = request.user

    try:
        ftp = Ftp.objects.get(pk=ftp_id)
    except Ftp.DoesNotExist:
        ftp = None

    if request.method == 'POST':
        if ftp:
            form = FTPUpdateForm(request.POST, user=u, instance=ftp)
        else:
            form = FTPForm(request.POST, user=u)

        if form.is_valid():
            iftp = form.save(commit=False)
            iftp.uid = u.parms.uid
            iftp.gid = u.parms.gid
            iftp.owner = u
            if "password1" in form.cleaned_data: iftp.password = crypt.crypt(form.cleaned_data["password1"], iftp.owner.username)
            iftp.save()

            messages.add_message(request, messages.SUCCESS, _('FTP account has been %s') % _("changed") if ftp else _("added"))
            return HttpResponseRedirect(reverse("ftp_list"))
    else:
        if ftp:
            form = FTPUpdateForm(user=u, instance=ftp)
        else:
            form = FTPForm(user=u)

    helper = RostiFormHelper()
    helper.form_action = reverse("ftp_upsert", kwargs={'ftp_id': ftp_id})

    return render_to_response('universal.html',
            {
            "form": form,
            "form_helper": RostiFormHelper(),
            "title": _("FTP account"),
            "note": [_("* Username will be prefixed with `%s_`" % u.username)],
            "u": u,
            "superuser": superuser,
            "menu_active": "ftps",
            },
        context_instance=RequestContext(request)
    )
Exemplo n.º 6
0
def changeRedirect(request, rid):
    u = request.session.get('switched_user', request.user)
    superuser = request.user
    rid = int(rid)

    r = get_object_or_404(EmailRedirect, id=rid)
    if r.domain.user != u:
        return HttpResponseForbidden(ugettext("Forbidden operation"))

    domains = [(x.name, x.name) for x in u.email_domain_set.filter()]
    if request.method == 'POST':
        form = FormRedirect(request.POST, instance=r)
        form.fields["_domain"].choices = domains
        if form.is_valid():
            fredirect = form.save(commit=False)
            fredirect.domain = get_object_or_404(
                u.email_domain_set, name=form.cleaned_data["_domain"])
            fredirect.save()
            messages.add_message(request, messages.SUCCESS,
                                 _('Redirect has been changed'))
            return HttpResponseRedirect(reverse("redirect_list"))
    else:
        form = FormRedirect(instance=r)
        form.fields["_domain"].choices = domains

    helper = RostiFormHelper()
    helper.form_action = reverse("wsgiadmin.emails.views.changeRedirect",
                                 args=[rid])

    return render_to_response('universal.html', {
        "form": form,
        "form_helper": helper,
        "title": _("Modify email alias"),
        "submit": _("Save changes"),
        "u": u,
        "superuser": superuser,
        "menu_active": "emails",
    },
                              context_instance=RequestContext(request))
Exemplo n.º 7
0
Arquivo: views.py Projeto: a740122/pcp
def changeRedirect(request, rid):
    u = request.session.get('switched_user', request.user)
    superuser = request.user
    rid = int(rid)

    r = get_object_or_404(EmailRedirect, id=rid)
    if r.domain.user != u:
        return HttpResponseForbidden(ugettext("Forbidden operation"))

    domains = [(x.name, x.name) for x in u.email_domain_set.filter()]
    if request.method == 'POST':
        form = FormRedirect(request.POST, instance=r)
        form.fields["_domain"].choices = domains
        if form.is_valid():
            fredirect = form.save(commit=False)
            fredirect.domain = get_object_or_404(u.email_domain_set, name=form.cleaned_data["_domain"])
            fredirect.save()
            messages.add_message(request, messages.SUCCESS, _('Redirect has been changed'))
            return HttpResponseRedirect(reverse("redirect_list"))
    else:
        form = FormRedirect(instance=r)
        form.fields["_domain"].choices = domains

    helper = RostiFormHelper()
    helper.form_action = reverse("wsgiadmin.emails.views.changeRedirect", args=[rid])

    return render_to_response('universal.html',
            {
            "form": form,
            "form_helper": helper,
            "title": _("Modify email alias"),
            "submit": _("Save changes"),
            "u": u,
            "superuser": superuser,
            "menu_active": "emails",
            },
        context_instance=RequestContext(request)
    )
Exemplo n.º 8
0
Arquivo: views.py Projeto: a740122/pcp
def addRedirect(request):
    u = request.session.get('switched_user', request.user)
    superuser = request.user

    domains = [(x.name, x.name) for x in u.email_domain_set.filter()]
    if request.method == 'POST':
        form = FormRedirect(request.POST)
        form.fields["_domain"].choices = domains
        if form.is_valid():
            redirect = form.save(commit=False)
            redirect.alias = form.cleaned_data["alias"]
            redirect.domain = get_object_or_404(u.email_domain_set, name=form.cleaned_data["_domain"])
            redirect.pub_date = date.today()
            redirect.save()

            messages.add_message(request, messages.SUCCESS, _('Redirect has been added'))
            return HttpResponseRedirect(reverse("redirect_list"))
    else:
        form = FormRedirect()
        form.fields["_domain"].choices = domains

    helper = RostiFormHelper()
    helper.form_action = reverse("add_redirect")

    return render_to_response('universal.html',
            {
            "form": form,
            "form_helper": helper,
            "title": _("Add email redirect"),
            "submit": _("Add redirect"),
            "u": u,
            "superuser": superuser,
            "menu_active": "emails",
            },
        context_instance=RequestContext(request)
    )
Exemplo n.º 9
0
def addRedirect(request):
    u = request.session.get('switched_user', request.user)
    superuser = request.user

    domains = [(x.name, x.name) for x in u.email_domain_set.filter()]
    if request.method == 'POST':
        form = FormRedirect(request.POST)
        form.fields["_domain"].choices = domains
        if form.is_valid():
            redirect = form.save(commit=False)
            redirect.alias = form.cleaned_data["alias"]
            redirect.domain = get_object_or_404(
                u.email_domain_set, name=form.cleaned_data["_domain"])
            redirect.pub_date = date.today()
            redirect.save()

            messages.add_message(request, messages.SUCCESS,
                                 _('Redirect has been added'))
            return HttpResponseRedirect(reverse("redirect_list"))
    else:
        form = FormRedirect()
        form.fields["_domain"].choices = domains

    helper = RostiFormHelper()
    helper.form_action = reverse("add_redirect")

    return render_to_response('universal.html', {
        "form": form,
        "form_helper": helper,
        "title": _("Add email redirect"),
        "submit": _("Add redirect"),
        "u": u,
        "superuser": superuser,
        "menu_active": "emails",
    },
                              context_instance=RequestContext(request))
Exemplo n.º 10
0
def changePasswdBox(request, eid):
    eid = int(eid)
    u = request.session.get('switched_user', request.user)
    superuser = request.user

    try:
        e = Email.objects.get(domain__in=u.email_domain_set.all(), id=eid)
    except Email.DoesNotExist:
        e = None

    if request.method == 'POST':
        form = PassCheckModelForm(request.POST, instance=e)
        if form.is_valid():
            email = form.save(commit=False)
            email.password = crypt.crypt(form.cleaned_data["password1"],
                                         email.login)
            email.save()
            messages.add_message(request, messages.SUCCESS,
                                 _('Password has been changed'))
            return HttpResponseRedirect(reverse("mailbox_list"))
    else:
        form = PassCheckModelForm(instance=e)

    helper = RostiFormHelper()
    helper.form_action = reverse("wsgiadmin.emails.views.changePasswdBox",
                                 args=[e.id])

    return render_to_response('universal.html', {
        "form": form,
        "form_helper": helper,
        "title": _("Change password for e-mail box"),
        "u": u,
        "superuser": superuser,
        "menu_active": "emails",
    },
                              context_instance=RequestContext(request))