def remove_site(request): u = request.session.get('switched_user', request.user) try: object_id = request.POST['object_id'] s = get_object_or_404(UserSite, id=object_id) if s.owner != u: raise Exception("Forbidden operation") s.removed = True s.end_date = date.today() s.save() #Signal restart_master(config.mode, u) ur = UWSGIRequest(u, u.parms.web_machine) ur.stop(s) ur.mod_config() # calculate! u.parms.pay_for_sites(use_cache=False) return JsonResponse("OK", {1: ugettext("Site was successfuly removed")}) except Exception, e: return JsonResponse("KO", {1: ugettext("Error deleting site")})
def app_wsgi(request, app_id=0): u = request.session.get('switched_user', request.user) superuser = request.user try: site = UserSite.objects.get(id=app_id, owner=u) except UserSite.DoesNotExist: site = None if request.method == 'POST': form = FormWsgi(request.POST, user=u, instance=site) site_errors = domain_check(request, form, site) if not site_errors and form.is_valid(): site = form.save(commit=False) site.owner = u site.type = 'uwsgi' site.save() if site.type == "uwsgi": ur = UWSGIRequest(u, u.parms.web_machine) ur.mod_config() ur.restart(site) #Signal restart_master(config.mode, u) # calculate! u.parms.pay_for_sites(use_cache=False) messages.add_message(request, messages.SUCCESS, _('App has been %s') % (_('changed') if site else _('added'))) messages.add_message(request, messages.INFO, _('Changes will be performed in few minutes')) return HttpResponseRedirect(reverse("app_list")) else: form = FormWsgi(user=u, instance=site) site_errors = () dynamic_refreshs = ( (reverse("refresh_wsgi"), 'id_script'), (reverse("refresh_venv"), 'id_virtualenv'), ) return render_to_response('add_site.html', { "dynamic_refreshs": dynamic_refreshs, "siteErrors": site_errors, "form": form, "title": _("%s WSGI application") % _('Modify') if site else _('Add'), "submit": _("Save changes"), "action": reverse("app_wsgi", args=[app_id]), "u": u, "superuser": superuser, "menu_active": "webapps", }, context_instance=RequestContext(request) )
def app_wsgi(request, app_id=0): u = request.session.get('switched_user', request.user) superuser = request.user try: site = u.usersite_set.get(id=app_id) except UserSite.DoesNotExist: site = None domains = domains_list(u, used=used_domains(u, site)) if request.method == 'POST': form = FormWsgi(request.POST, user=u, instance=site) form.fields["main_domain"].choices = [(x.id, x.domain_name) for x in domains] form.fields["misc_domains"].choices = [(x.id, x.domain_name) for x in domains] if form.is_valid(): site = form.save(commit=False) site.owner = u site.type = 'uwsgi' site.save() for sd in SiteDomain.objects.filter(user_site=site): sd.delete() for domain in form.cleaned_data['misc_domains']: SiteDomain.objects.create(domain=domain, user_site=site) if site.type == "uwsgi": ur = UWSGIRequest(u, u.parms.web_machine) ur.mod_config() ur.restart(site) #Signal restart_master(config.mode, u) # calculate! u.parms.pay_for_sites(use_cache=False) messages.add_message(request, messages.SUCCESS, _('App has been %s') % (_('changed') if site else _('added'))) messages.add_message(request, messages.INFO, _('Changes will be performed in few minutes')) return HttpResponseRedirect(reverse("app_list")) else: form = FormWsgi(user=u, instance=site) form.fields["main_domain"].choices = [(x.id, x.domain_name) for x in domains] form.fields["misc_domains"].choices = [(x.id, x.domain_name) for x in domains] form.helper.form_action = reverse("app_wsgi", args=[app_id]) return render_to_response('add_site.html', { "form": form, "title": _("%s WSGI application") % _('Modify') if site else _('Add'), "u": u, "superuser": superuser, "menu_active": "webapps", }, context_instance=RequestContext(request) )
def app_static(request, app_type="static", app_id=0): if app_type not in ("static", "php"): return HttpResponseForbidden(ugettext("Invalid type of application")) u = request.session.get('switched_user', request.user) superuser = request.user try: site = u.usersite_set.get(id=app_id) except UserSite.DoesNotExist: site = None domains = domains_list(u, used=used_domains(u, site)) if request.method == 'POST': form = FormStatic(request.POST, user=u, instance=site) form.fields["main_domain"].choices = [(x.id, x.domain_name) for x in domains] form.fields["misc_domains"].choices = [(x.id, x.domain_name) for x in domains] if form.is_valid(): isite = form.save(commit=False) isite.type = app_type isite.owner = u isite.save() for sd in SiteDomain.objects.filter(user_site=isite): sd.delete() for domain in form.cleaned_data['misc_domains']: SiteDomain.objects.create(domain=domain, user_site=isite) # Requests restart_master(config.mode, u) # calculate! u.parms.pay_for_sites(use_cache=False) messages.add_message(request, messages.SUCCESS, _('Site has been %s') % (_('changed') if site else _('added'))) messages.add_message(request, messages.INFO, _('Changes will be performed in few minutes')) return HttpResponseRedirect(reverse("app_list")) else: form = FormStatic(user=u, instance=site) form.fields["main_domain"].choices = [(x.id, x.domain_name) for x in domains] form.fields["misc_domains"].choices = [(x.id, x.domain_name) for x in domains] form.helper.form_action = reverse("app_static", kwargs={'app_type': app_type, 'app_id': app_id}) return render_to_response('add_site.html', { "form": form, "title": {'static': _("Static website"), 'php': _("PHP website")}[app_type], "u": u, "superuser": superuser, "menu_active": "webapps", }, context_instance=RequestContext(request) )
def app_static(request, app_type="static", app_id=0): if app_type not in ("static", "php"): return HttpResponseForbidden(ugettext("Invalid type of application")) u = request.session.get('switched_user', request.user) superuser = request.user choices = [(d, d) for d in user_directories(u, use_cache=True)] try: site = UserSite.objects.get(id=app_id, owner=u) except UserSite.DoesNotExist: site = None if request.method == 'POST': form = FormStatic(request.POST, user=u, instance=site) site_errors = domain_check(request, form, this_site=site) if not site_errors and form.is_valid(): isite = form.save(commit=False) isite.type = app_type isite.owner = u isite.save() # Requests restart_master(config.mode, u) # calculate! u.parms.pay_for_sites(use_cache=False) messages.add_message(request, messages.SUCCESS, _('Site has been %s') % (_('changed') if site else _('added'))) messages.add_message(request, messages.INFO, _('Changes will be performed in few minutes')) return HttpResponseRedirect(reverse("app_list")) else: form = FormStatic(user=u, instance=site) site_errors = () dynamic_refreshs = ( (reverse("refresh_userdirs"), 'id_document_root'), ) return render_to_response('add_site.html', { "dynamic_refreshs": dynamic_refreshs, "siteErrors": site_errors, "form": form, "title": {'static': _("Static website"), 'php': _("PHP website")}[app_type], "submit": _("Add website") if not site else _("Modify website"), "action": reverse("app_static", kwargs={'app_type': app_type, 'app_id': app_id}), "u": u, "superuser": superuser, "menu_active": "webapps", }, context_instance=RequestContext(request) )
def restart(request, sid): u = request.session.get('switched_user', request.user) sid = int(sid) s = get_object_or_404(UserSite, id=sid) #Signal if s.type in ("uwsgi", "modwsgi"): ur = UWSGIRequest(u, u.parms.web_machine) ur.mod_config() ur.restart(s) else: restart_master(config.mode, u) messages.add_message(request, messages.SUCCESS, _('Request for restarting has been sent')) messages.add_message(request, messages.INFO, _('It will be performed in few minutes')) return HttpResponseRedirect(reverse("app_list"))
def handle(self, *args, **options): total_credit = 0.0 apache_reload = False guarding = [] print "Username".ljust(40), print "Credit".ljust(15), print "cr./day".ljust(10), print "Days left".ljust(10), print "Low level act.".ljust(15), print "Last notif.".ljust(15) for user in self.get_users(): parms = user.parms print user.username.ljust(40), print ("%.2f cr." % parms.credit).ljust(15), print ("%.2f cr." % parms.pay_total_day()).ljust(10), print ("%.2f" % parms.days_left).ljust(10), print (parms.low_level_credits).ljust(15), print (parms.last_notification.strftime("%d.%m.%Y")).ljust(15) if parms.last_notification else "--".ljust(15), if not parms.guard_enable: print "Guarding disabled", if parms.credit < 0: total_credit += parms.credit if not parms.last_notification or (parms.last_notification and (datetime.date.today() - parms.last_notification).days >= 7): if parms.guard_enable: guarding.append(user) print "Be guarded", print print "Total: %.2f" % total_credit if raw_input("Do you agree? (yes/NO) ") == "yes": for user in guarding: with transaction.commit_on_success(): apache_reload = self.process(user) if apache_reload: restart_master(config.mode, user) print "Apache restarted"
def app_static(request, app_type="static", app_id=0): if app_type not in ("static", "php"): return HttpResponseForbidden(ugettext("Invalid type of application")) u = request.session.get('switched_user', request.user) superuser = request.user try: site = u.usersite_set.get(id=app_id) except UserSite.DoesNotExist: site = None domains = domains_list(u, used=used_domains(u, site)) if request.method == 'POST': form = FormStatic(request.POST, user=u, instance=site) form.fields["main_domain"].choices = [(x.id, x.domain_name) for x in domains] form.fields["misc_domains"].choices = [(x.id, x.domain_name) for x in domains] if form.is_valid(): isite = form.save(commit=False) isite.type = app_type isite.owner = u isite.save() for sd in SiteDomain.objects.filter(user_site=isite): sd.delete() for domain in form.cleaned_data['misc_domains']: SiteDomain.objects.create(domain=domain, user_site=isite) # Requests restart_master(config.mode, u) # calculate! u.parms.pay_for_sites(use_cache=False) messages.add_message( request, messages.SUCCESS, _('Site has been %s') % (_('changed') if site else _('added'))) messages.add_message(request, messages.INFO, _('Changes will be performed in few minutes')) return HttpResponseRedirect(reverse("app_list")) else: form = FormStatic(user=u, instance=site) form.fields["main_domain"].choices = [(x.id, x.domain_name) for x in domains] form.fields["misc_domains"].choices = [(x.id, x.domain_name) for x in domains] form.helper.form_action = reverse("app_static", kwargs={ 'app_type': app_type, 'app_id': app_id }) return render_to_response('add_site.html', { "form": form, "title": { 'static': _("Static website"), 'php': _("PHP website") }[app_type], "u": u, "superuser": superuser, "menu_active": "webapps", }, context_instance=RequestContext(request))
def app_wsgi(request, app_id=0): u = request.session.get('switched_user', request.user) superuser = request.user try: site = u.usersite_set.get(id=app_id) except UserSite.DoesNotExist: site = None domains = domains_list(u, used=used_domains(u, site)) if request.method == 'POST': form = FormWsgi(request.POST, user=u, instance=site) form.fields["main_domain"].choices = [(x.id, x.domain_name) for x in domains] form.fields["misc_domains"].choices = [(x.id, x.domain_name) for x in domains] if form.is_valid(): site = form.save(commit=False) site.owner = u site.type = 'uwsgi' site.save() for sd in SiteDomain.objects.filter(user_site=site): sd.delete() for domain in form.cleaned_data['misc_domains']: SiteDomain.objects.create(domain=domain, user_site=site) if site.type == "uwsgi": ur = UWSGIRequest(u, u.parms.web_machine) ur.mod_config() ur.restart(site) #Signal restart_master(config.mode, u) # calculate! u.parms.pay_for_sites(use_cache=False) messages.add_message( request, messages.SUCCESS, _('App has been %s') % (_('changed') if site else _('added'))) messages.add_message(request, messages.INFO, _('Changes will be performed in few minutes')) return HttpResponseRedirect(reverse("app_list")) else: form = FormWsgi(user=u, instance=site) form.fields["main_domain"].choices = [(x.id, x.domain_name) for x in domains] form.fields["misc_domains"].choices = [(x.id, x.domain_name) for x in domains] form.helper.form_action = reverse("app_wsgi", args=[app_id]) return render_to_response( 'add_site.html', { "form": form, "title": _("%s WSGI application") % _('Modify') if site else _('Add'), "u": u, "superuser": superuser, "menu_active": "webapps", }, context_instance=RequestContext(request))