Using ColdFusion to prevent history from being taken - coldfusion

I'm fairly new to ColdFusion and am currently creating a system for which users can view PDF files. As well, I have it so some users can upload replacements for the current PDF if need be. The problem is, at least when using Firefox, when the user views the PDF file, it goes into their history cache to improve loading times I assume, and if a user replaces the PDF with a more updated one, users with the original PDF in their history cache will just see the old file and not the new one.
Now, I'm not going to just tell users to clear their history, so here's where my question comes in: Is there either a way to prevent the PDF from going into their history cache or is there a way to remove the page from the history? Any help would be greatly appreciated! :)

In PDF link add timestamp using gettickcount() to make URL unique and this prevent caching pdf.
http://mywebsite/pdfname.pdf?123249329323

Rather than link directly to the PDF, link to a .cfm that has this code:
<cfheader name="expires" value="#getHttpTimeString(now())#">
<cfheader name="pragma" value="no-cache">
<cfheader name="cache-control" value="no-cache, no-store, must-revalidate">
<cfcontent file="#path_to_pdf_file#" type="application/pdf">

Related

Amazon AWS S3 Site Update

I've looked through just about every related question on here that I can find and none of the suggested solutions seem to resolve my problem.
I'm currently hosting a website on Amazon AWS using strictly the S3 and Route 53 tools to host a static website and re-route from a couple of different URL queries to our site. This morning I attempted to update the CSS files being used to style the webpage, as well as a bunch of new image files and some minor updates to the HTML pages, and noticed that all of my changes showed up immediately on the webpage except the changes I had made to my CSS file. I've checked, and the version of the file on the S3 is the correct/updated version, but when I attempt to use the Developer Tools in my web browser to inspect the webpage displayed, it's still showing an older version of the css file. This doesn't make any sense to me, as all of the other changes show up immediately except for this particular file. Does anyone have any thoughts on how to fix this/what could be going wrong?
NOTE: I'm not using AWS CloudFront on this webpage at all so I don't believe that any of the "invalidation" suggested elsewhere will help me. In the past, I've updated the files and seen immediate changes when loading my webpage.
You already know this is a browser cache issue - which you can clear the cache, but if you want to force everyone to automatically get the new CSS, what I usually do is add a query parameter to the file include, i.e. instead of
<link href="~/css/plugins/thickbox/thickbox.css" rel="stylesheet" />
do this:
<link href="~/css/plugins/thickbox/thickbox.css?v=1001" rel="stylesheet" />
and you can up the 1001 each time you push out an update - the browser will automatically grab the new file.
Google 'cache-busting' for other options.

How to turn a Django webpage into a PDF

I would like to add a feature to my Django website where the user can click on a link saying "Save as PDF". I would like this link to 1) produce a slightly different version of the page the user is currently on and 2) generate a PDF file in a separate window that the user can then save to wherever he or she wants.
All of the PDF functions I came across related to Django assumed that you already had a PDF that you wanted to render. In this case though, I want to create a PDF based on the content of the current page. Any idea how to do this? Thank you.
You can try this tool WeasyPrint. You can use it with Django
Any webpage is just a HTML basically so any html to pdf library would work. But this one is specifically built for django. Hope this helps.
Documentation for django-wkhtmltopdf

CfContent restricted to a folder

The application keeps the daily reports in a shared path. Our application generates the URL linking it to the excels like
http://application/ExcelTask/Index.cfm?type=Report&fileName=Report_Mar2014.xlsx
with the cfm code as
<cfif FileExists("#filePath#")>
<cfheader name="Content-Disposition" value="inline; filename=""#URL.fileName#""">
<cfcontent type="application/vnd.ms-excel" file="#filePath#">
</cfif>
What we have found out if the users are aware of our directory structure the cfm files can be downloaded using the URL injection like
http://application/ExcelTask/Index.cfm?type=../ExcelTask&fileName=Index.cfm
I can add a condition to only allow files of type xls and xlsx only but that looks like a Plan B.
Any ideas how to restrict the folder access?
Use basic data sanitization skills to both clean and validate your URL.type and URL.filename.
some replaceAll code to eliminate ../, or
try isValid("regex", some regex pattern...)
You can also validate against the session whether the current logged in user has the write to view/download the file for extra protection.

Django - Upload file without using form

I have a small email client. I would like to be able to upload files without having to submit a form. So, I have my email form. I would like to, whenever I use the file input button on my form, that file would be uploaded without any reload of the page. The goal is to be able to upload multiple files without a reload of the page, something similar to what happens in GMail.
Every time you click the file input and choose a file, a small progress bar appears with the upload progress, and the page is not reloaded.
I am guessing some JS/Ajax library might help me achieve this? I am using HTML5.
Thank you
Blueimp has a great jQuery-based throttling file uploader.

What might cause the images from rendering properly in PDF generation?

I am using ColdFusion 8.
I have a perfectly formatted HTML page that I want to convert into PDF. It takes ColdFusion about 250 milliseconds to create this content. The code is tried and true and works in every respect with no problem, except for in creating a PDF.
I create the PageContent variable like this:
<!--- CREATE PAGE AS CONTENT --->
<cfsavecontent variable="PageContent">
<html>
<head></head>
<body>
<cfoutput>
// PAGE CONTENT IS HERE
<cfoutput>
</body>
</html>
</cfsavecontent>
I can display this PageContent perfectly as HTML in a browser, open it in Word or Excel. I try to create a PDF like this:
<cfdocument format="pdf">
<cfoutput>
#PageContent#
</cfoutput>
</cfdocument>
The page content has inline styles, images, divs, and tables. If I remove the image path and file with an empty string, the document works. Here's the
I think that the PDF generator is choking ob the image path, although the paths seem perfect to me and render well everywhere else. The img tag is being fed the full HTTP path, which is totally valid. Here's one that isn't working:
http://dev.iqcatalogs.com/avcat/IMAGES/products/spotlight/ef17_40_4lu_c2_186x279.gif
What might cause the images from rendering properly in PDF?
(From the comments above) I am guessing you have looked into the usual suspects already?
ie 2) If your server is behind firewall. As we mentioned earlier, CF
server needs to send an HTTP request for the images. If the firewall
prevents any outgoing connection from the server, CF will not be able
to retrieve them and will show a red-x in place of them. You will need
to setup your firewall in such a way that server can send an HTTP
request to itself.
Remember that for Cfdocument to work it doesn't matter whether you can pull up the image in your browser. It only matters if the server can pull it up. The most likely cause for this is simply domain resolution - where the server cannot get the right IP address - or where it is blocked from retrieving the content. See this post.
resolution and cfdocument