コード例 #1
0
def admin_purge(request):
    if request.method == 'POST':
        url = request.POST['url']
        expr = request.POST['expr']
        xkey = request.POST['xkey']
        l = len([_f for _f in [url, expr, xkey] if _f])
        if l == 0:
            # Nothing specified
            return HttpResponseRedirect('.')
        elif l > 1:
            messages.error(
                request, "Can only specify one of url, expression and xkey!")
            return HttpResponseRedirect('.')

        if url:
            varnish_purge(url)
        elif expr:
            varnish_purge_expr(expr)
        else:
            varnish_purge_xkey(xkey)

        messages.info(request, "Purge added.")
        return HttpResponseRedirect('.')

    # Fetch list of latest purges
    curs = connection.cursor()
    curs.execute(
        "SELECT added, completed, consumer, CASE WHEN mode = 'K' THEN 'XKey' WHEN mode='P' THEN 'URL' ELSE 'Expression' END, expr FROM varnishqueue.queue q LEFT JOIN varnishqueue.consumers c ON c.consumerid=q.consumerid ORDER BY added DESC"
    )
    latest = curs.fetchall()

    return render(request, 'core/admin_purge.html', {
        'latest_purges': latest,
    })
コード例 #2
0
def uploadftp(request):
    if request.method != 'PUT':
        raise PermissionDenied("Invalid method")
    if not request.META['REMOTE_ADDR'] in settings.FTP_MASTERS:
        raise PermissionDenied("Invalid client address")
    # We have the data in request.body. Attempt to load it as
    # a pickle to make sure it's properly formatted
    pickle.loads(request.body)

    # Next, check if it's the same as the current file
    f = open(settings.FTP_PICKLE, "rb")
    x = f.read()
    f.close()
    if x == request.body:
        # Don't rewrite the file or purge any data if nothing changed
        return HttpResponse("NOT CHANGED", content_type="text/plain")

    # File has changed - let's write it!
    f = open("%s.new" % settings.FTP_PICKLE, "wb")
    f.write(request.body)
    f.close()
    os.rename("%s.new" % settings.FTP_PICKLE, settings.FTP_PICKLE)

    # Purge it out of varnish so we start responding right away
    varnish_purge("/ftp")

    # Finally, indicate to the client that we're happy
    return HttpResponse("OK", content_type="text/plain")
コード例 #3
0
def uploadyum(request):
    if request.method != 'PUT':
        raise PermissionDenied("Invalid method")
    if not request.META['REMOTE_ADDR'] in settings.FTP_MASTERS:
        raise PermissionDenied("Invalid client address")
    # We have the data in request.body. Attempt to load it as
    # json to ensure correct format.
    json.loads(request.body.decode('utf8'))

    # Next, check if it's the same as the current file
    if os.path.isfile(settings.YUM_JSON):
        with open(settings.YUM_JSON, "r") as f:
            if f.read() == request.body:
                # Don't rewrite the file or purge any data if nothing changed
                return HttpResponse("NOT CHANGED", content_type="text/plain")

    # File has changed - let's write it!
    with open("%s.new" % settings.YUM_JSON, "w") as f:
        f.write(request.body.decode('utf8'))

    os.rename("%s.new" % settings.YUM_JSON, settings.YUM_JSON)

    # Purge it out of varnish so we start responding right away
    varnish_purge("/download/js/yum.js")

    # Finally, indicate to the client that we're happy
    return HttpResponse("OK", content_type="text/plain")
コード例 #4
0
ファイル: views.py プロジェクト: jkatz/pgweb
def uploadftp(request):
    if request.method != 'PUT':
        return HttpServerError(request, "Invalid method")
    if not request.META['REMOTE_ADDR'] in settings.FTP_MASTERS:
        return HttpServerError(request, "Invalid client address")
    # We have the data in request.body. Attempt to load it as
    # a pickle to make sure it's properly formatted
    pickle.loads(request.body)

    # Next, check if it's the same as the current file
    f = open(settings.FTP_PICKLE, "rb")
    x = f.read()
    f.close()
    if x == request.body:
        # Don't rewrite the file or purge any data if nothing changed
        return HttpResponse("NOT CHANGED", content_type="text/plain")

    # File has changed - let's write it!
    f = open("%s.new" % settings.FTP_PICKLE, "wb")
    f.write(request.body)
    f.close()
    os.rename("%s.new" % settings.FTP_PICKLE, settings.FTP_PICKLE)

    # Purge it out of varnish so we start responding right away
    varnish_purge("/ftp")

    # Finally, indicate to the client that we're happy
    return HttpResponse("OK", content_type="text/plain")
コード例 #5
0
ファイル: views.py プロジェクト: jkatz/pgweb
def uploadyum(request):
    if request.method != 'PUT':
        return HttpServerError(request, "Invalid method")
    if not request.META['REMOTE_ADDR'] in settings.FTP_MASTERS:
        return HttpServerError(request, "Invalid client address")
    # We have the data in request.body. Attempt to load it as
    # json to ensure correct format.
    json.loads(request.body.decode('utf8'))

    # Next, check if it's the same as the current file
    if os.path.isfile(settings.YUM_JSON):
        with open(settings.YUM_JSON, "r") as f:
            if f.read() == request.body:
                # Don't rewrite the file or purge any data if nothing changed
                return HttpResponse("NOT CHANGED", content_type="text/plain")

    # File has changed - let's write it!
    with open("%s.new" % settings.YUM_JSON, "w") as f:
        f.write(request.body.decode('utf8'))

    os.rename("%s.new" % settings.YUM_JSON, settings.YUM_JSON)

    # Purge it out of varnish so we start responding right away
    varnish_purge("/download/js/yum.js")

    # Finally, indicate to the client that we're happy
    return HttpResponse("OK", content_type="text/plain")
コード例 #6
0
ファイル: views.py プロジェクト: jkatz/pgweb
def admin_purge(request):
    if request.method == 'POST':
        url = request.POST['url']
        expr = request.POST['expr']
        xkey = request.POST['xkey']
        l = len([_f for _f in [url, expr, xkey] if _f])
        if l == 0:
            # Nothing specified
            return HttpResponseRedirect('.')
        elif l > 1:
            messages.error(request, "Can only specify one of url, expression and xkey!")
            return HttpResponseRedirect('.')

        if url:
            varnish_purge(url)
        elif expr:
            varnish_purge_expr(expr)
        else:
            varnish_purge_xkey(xkey)

        messages.info(request, "Purge added.")
        return HttpResponseRedirect('.')

    # Fetch list of latest purges
    curs = connection.cursor()
    curs.execute("SELECT added, completed, consumer, CASE WHEN mode = 'K' THEN 'XKey' WHEN mode='P' THEN 'URL' ELSE 'Expression' END, expr FROM varnishqueue.queue q LEFT JOIN varnishqueue.consumers c ON c.consumerid=q.consumerid ORDER BY added DESC")
    latest = curs.fetchall()

    return render(request, 'core/admin_purge.html', {
        'latest_purges': latest,
    })
コード例 #7
0
ファイル: views.py プロジェクト: tpud/pgweb
def admin_purge(request):
    if request.method == 'POST':
        url = request.POST['url']
        expr = request.POST['expr']
        template = request.POST['template']
        xkey = request.POST['xkey']
        l = len([_f for _f in [url, expr, template, xkey] if _f])
        if l == 0:
            # Nothing specified
            return HttpResponseRedirect('.')
        elif l > 1:
            messages.error(
                request,
                "Can only specify one of url, expression, template and xkey!")
            return HttpResponseRedirect('.')

        if url:
            varnish_purge(url)
        elif expr:
            varnish_purge_expr(expr)
        elif template:
            path = os.path.abspath(
                os.path.join(settings.PROJECT_ROOT, '../templates', template))
            if not os.path.isfile(path):
                messages.error(request,
                               "Template {} does not exist!".format(template))
                return HttpResponseRedirect('.')
            # Calculate the xkey
            xkey = "pgwt_{}".format(
                hashlib.md5(template.encode('ascii')).hexdigest())
            varnish_purge_xkey(xkey)
        else:
            varnish_purge_xkey(xkey)

        messages.info(request, "Purge added.")
        return HttpResponseRedirect('.')

    # Fetch list of latest purges
    curs = connection.cursor()
    curs.execute(
        "SELECT added, completed, consumer, CASE WHEN mode = 'K' THEN 'XKey' WHEN mode='P' THEN 'URL' ELSE 'Expression' END, expr FROM varnishqueue.queue q LEFT JOIN varnishqueue.consumers c ON c.consumerid=q.consumerid ORDER BY added DESC"
    )
    latest = curs.fetchall()

    return render(request, 'core/admin_purge.html', {
        'latest_purges': latest,
    })
コード例 #8
0
def admin_purge(request):
	if request.method == 'POST':
		url = request.POST['url']
		if url == '':
			return HttpResponseRedirect('.')
		varnish_purge(url)
		messages.info(request, "Purge completed: '^%s'" % url)
		return HttpResponseRedirect('.')

	# Fetch list of latest purges
	curs = connection.cursor()
	curs.execute("SELECT added, completed, consumer, mode, expr FROM varnishqueue.queue q LEFT JOIN varnishqueue.consumers c ON c.consumerid=q.consumerid ORDER BY added DESC")
	latest = curs.fetchall()

	return render_to_response('core/admin_purge.html', {
			'latest_purges': latest,
			}, RequestContext(request))
コード例 #9
0
def admin_purge(request):
	if request.method == 'POST':
		url = request.POST['url']
		if url == '':
			return HttpResponseRedirect('.')
		varnish_purge(url)
		messages.info(request, "Purge completed: '^%s'" % url)
		return HttpResponseRedirect('.')

	# Fetch list of latest purges
	curs = connection.cursor()
	curs.execute("SELECT added, completed, consumer, mode, expr FROM varnishqueue.queue q LEFT JOIN varnishqueue.consumers c ON c.consumerid=q.consumerid ORDER BY added DESC")
	latest = curs.fetchall()

	return render_to_response('core/admin_purge.html', {
			'latest_purges': latest,
			}, RequestContext(request))
コード例 #10
0
def vote(request, surveyid):
    surv = get_object_or_404(Survey, pk=surveyid)

    # Check that we have a valid answer number
    try:
        ansnum = int(request.POST['answer'])
        if ansnum < 1 or ansnum > 8:
            return HttpSimpleResponse(request, "Response error",
                                      "Invalid answer")
    except Exception as e:
        # When no answer is given, redirect to results instead
        return HttpResponseRedirect("/community/survey/%s-%s" %
                                    (surv.id, slugify(surv.question)))
    attrname = "tot%s" % ansnum

    # Do IP based locking...
    addr = get_client_ip(request)

    # Clean out any old junk
    curs = connection.cursor()
    curs.execute(
        "DELETE FROM survey_surveylock WHERE (\"time\" + '15 minutes') < now()"
    )

    # Check if we are locked
    lock = SurveyLock.objects.filter(ipaddr=addr)
    if len(lock) > 0:
        return HttpSimpleResponse(
            request, "Rate limited",
            "Too many requests from your IP in the past 15 minutes")

    # Generate a new lock item, and store it
    lock = SurveyLock(ipaddr=addr)
    lock.save()

    answers = SurveyAnswer.objects.get_or_create(survey=surv)[0]
    setattr(answers, attrname, getattr(answers, attrname) + 1)
    answers.save()

    # Do explicit varnish purge, since it seems that the model doesn't
    # do it properly. Possibly because of the cute stuff we do with
    # getattr/setattr above.
    varnish_purge("/community/survey/%s/" % surveyid)

    return HttpResponseRedirect("/community/survey/%s/" % surveyid)
コード例 #11
0
ファイル: views.py プロジェクト: a1exsh/pgweb
def admin_purge(request):
	if request.method == 'POST':
		url = request.POST['url']
		if url == '':
			return HttpResponseRedirect('.')
		varnish_purge(url)
		transaction.commit_unless_managed()
		completed = '^%s' % url
	else:
		completed = None

	# Fetch list of latest purges
	curs = connection.cursor()
	curs.execute("SELECT ev_time, ev_data FROM pgq.event_1 WHERE ev_type='P' ORDER BY ev_time DESC LIMIT 20")
	latest = [{'t': r[0], 'u': r[1]} for r in curs.fetchall()]

	return render_to_response('core/admin_purge.html', {
			'purge_completed': completed,
			'latest_purges': latest,
			})
コード例 #12
0
ファイル: views.py プロジェクト: ChristophBerg/pgweb
def vote(request, surveyid):
	surv = get_object_or_404(Survey, pk=surveyid)

	# Check that we have a valid answer number
	try:
		ansnum = int(request.POST['answer'])
		if ansnum < 1 or ansnum > 8:
			return HttpServerError("Invalid answer")
	except:
		# When no answer is given, redirect to results instead
		return HttpResponseRedirect("/community/survey/%s-%s" % (surv.id, slugify(surv.question)))
	attrname = "tot%s" % ansnum

	# Do IP based locking...
	addr = get_client_ip(request)

	# Clean out any old junk
	curs = connection.cursor()
	curs.execute("DELETE FROM survey_surveylock WHERE (\"time\" + '15 minutes') < now()")

	# Check if we are locked
	lock = SurveyLock.objects.filter(ipaddr=addr)
	if len(lock) > 0:
		return HttpServerError("Too many requests from your IP in the past 15 minutes")

	# Generate a new lock item, and store it
	lock = SurveyLock(ipaddr=addr)
	lock.save()

	answers = SurveyAnswer.objects.get_or_create(survey=surv)[0]
	setattr(answers, attrname, getattr(answers, attrname)+1)
	answers.save()

	# Do explicit varnish purge, since it seems that the model doesn't
	# do it properly. Possibly because of the cute stuff we do with
	# getattr/setattr above.
	varnish_purge("/community/survey/%s/" % surveyid)
	transaction.commit_unless_managed()

	return HttpResponseRedirect("/community/survey/%s/" % surveyid)
コード例 #13
0
ファイル: views.py プロジェクト: yh453926638/pgweb
def admin_purge(request):
    if request.method == "POST":
        url = request.POST["url"]
        if url == "":
            return HttpResponseRedirect(".")
        varnish_purge(url)
        transaction.commit_unless_managed()
        completed = "^%s" % url
    else:
        completed = None

        # Fetch list of latest purges
    curs = connection.cursor()
    curs.execute(
        "SELECT ev_time, ev_type, ev_data FROM pgq.event_%s WHERE ev_type IN ('P', 'X') ORDER BY ev_time DESC LIMIT 20"
        % settings.VARNISH_QUEUE_ID
    )
    latest = [{"t": r[0], "ty": r[1], "u": r[2]} for r in curs.fetchall()]

    return render_to_response(
        "core/admin_purge.html", {"purge_completed": completed, "latest_purges": latest}, RequestContext(request)
    )
コード例 #14
0
ファイル: models.py プロジェクト: kleopatra999/pgweb
	def purge_related(self):
		if self.purgepattern:
			varnish_purge(self.purgepattern)
コード例 #15
0
ファイル: models.py プロジェクト: Venkata16924B/pgweb
 def purge_related(self):
     if self.purgepattern:
         varnish_purge(self.purgepattern)