Server side: detecting if a user is downloading (save as...) or visualizing a file in the browser - apache

I'm writing an apache2 module
by default and when viewed in a web browser, the module would only print the first lines of a large file and convert them to HTML.
if the user choose to 'download as...', the whole raw file would be downloaded.
Is it possible to detect this choice on the server side ? (for example is there a specific http header set ?).
note: I would like to avoid any parameter in the GET url (e.g: "http://example.org/file?mode=raw" )
Pierre

added my own answer to close the question: as said #alexeyten there is no difference. I ended by a javascript code the alter the index.html file generated by apache.

Related

smarty migration website doesn't work. Error 500

I've got to transfer a website from an hoster to another (MelbourneIT).
So I've done as usual with my favorite FileZilla, just copy the html website (without DB) to the other url.
So this one work for the first page ( http://www.lmhceramics.com/) because it's an html one but all my other pages doesn't work!
I've check the folders of my website and I found that this one worked with "Smarty" who is apparently a third party application.
I tried for 5 hours different things as : create an .htaccess to launch index.php instead of index.html, change the configuration on my site_globals.php but it didn't work. It looks like only the first page : index.html is loading.
I can give the access to the ftp if anyone could help it will be sweet as it's one website of my company!
Thanks guys.
Cheers
Initially I tested whether PHP was working, then when I was sure I looked at the error log. The overriding issue was a required library not being found because of a broken path, and PHP's display_errors setting was disabled so it resulted in a white screen.
The site main pages now function.
In site_globals.php, there were two paths that begun with a forward slash. This results in the code looking in the root directory of the server for a particular folder of files (the Smarty library, and the Smarty templates), which likely worked on the old server but not on the new shared hosting environment. New code italicised:
define( "SMARTYPATH", _$_SERVER['DOCUMENT_ROOT'] ._ "/deldridge_smarty/" );
define( "TEMPLATEPATH", _$_SERVER['DOCUMENT_ROOT'] ._ '/smarty/' );
Once that was fixed the code library and templates could be loaded and the rest of the configuration file continued to load. It then dies on:
$db_interface = new DBInterface;
$db_interface->connect( '172.20.254.1' , 'ampnet', 'cable05' );
This is an attempt to connect to a database. I haven't investigated what the database was for yet (that'd require looking through the PHP files in depth) but I'm assuming it was the login system or some such. Almost all of the pages in the site function with those two lines commented out, which I've done for now so that the majority of the content is available again. There's another reference to database connection details further down but they were already commented out.
One other area of particular interest is this:
// different dir structure on secure domain, make ammends
// ensure trailing slash if directory present
define( "SECURE_DIR", 'buildersbollards/' );
if ( $_SERVER['DOCUMENT_ROOT'] == '/home/deldridge/secure.4mation.com.au' )
{
$site_path = '/' . SECURE_DIR;
}
Hop that helps!
It's difficult to know with so little information. Enable error reporting in php or just look at the php error log in your server. One probable cause for the error 500 may be that some key folders don't have CHMOD permission to write; In smarty, for example, templates_c must be writable

Make file readable by CGI but not web browser

I have a text file "data.txt", and based on input to an html form I want to display a single line from that file. My result is delivered by a CGI script which needs to access data.txt, but I don't want a user to be able to type in "data.txt" into their web browser and see the whole file. Is there a simple way to make "data.txt" readable by the CGI script but not accessible by loading it with the browser?
I'm using standard apache on ubuntu. I believe the suexec module can do this, but I'm hoping for a simpler solution just using fancy permissions, chowns, etc. Thanks-
Store your datafile outside of the webserver filetree (for apache, check the DocumentRoot).

Enable the use of SSI

Using HostGator, I can't seem to get SSI to work on my server. I'm using Dreamweaver to build the site and the everything works just fine in the preview. But when I actually upload the pages to my server, any elements that are includes files don't appear. Does anyone know how I can enable SSI on my web server?
Your last comment gave me the information I need. The issue is that the file is not in the same directory as the file you're trying to add the footer.inc file to. Try this code:
<!--#include virtual= "includes/footer.inc" -->
when using the file= parameter, the file you're including must be in the same directory. If the file you're including is not in the same directory, then you will have to use virtual. See this page for more information: SSI: The Include Command.
And here, from the source, is pretty much the rule of thumb: Use file= when the included file is within the same directory as the page that wants it. Use virtual= when it isn't.
EDIT: I think I got it now. Copy and paste the above code and it should work for you. Make sure you follow these guideline: after <!--, there is no space between the last - and #. Additionally, there is a space between the closing " and the first -. These rules must be adhered to. You can view more information here: Server Side Includes Not Working

Make Indexed File Downloadable In Apache Solr

I am trying to indexed pdf file to Solr which I have done successfully using the command
curl "http://localhost:8983/solr/update/extract?literal.id=id=true"-F myfile=#filename.pdf"
I am able to see the file contents and search, but when I try to click on file name it shows
HTTP ERROR 404
Problem accessing /solr/collection1/id. Reason:
not found
What I want is to have a link which allows downloading the file, I know Solr merely indexes the file and stores it. I was wondering if there is a way by which I can add attribute location like you have done and proceed from there, can you please share with me what you have done, if you want any more clarity regarding my problem do ask.
We have the actual files hosted through a separate web application to be download from with auditing and additional security.
you can always directly host these files through http server.
If you are having the file names with id, it is as easy as appending the id.extension to the fixed http hosted url.
Else index the path of the file with an additional parameter e.g. literal.url.
The url will the solr field which will now be available with the Solr response.

How to use relative URL's in website with two base URL's

I have our basic corporate static html website installed in our web root directory and our billing software installed in /portal. I have integrated the websites to look like a single site by including the /menu.tpl smarty template file in the /portal/header.tpl file. However, if I use relative URL's, the menu sysem doesnt work as the base url for the billing script is /portal. i.e. if I create a link to faq.php in the menu.tpl and I load a page on the portal site, the link in the menu back to the faq page is now /portal/faq.php whereby if I load a page off the root site the link is just /faq.php as it should be.
The obvious answer is to just use absolute URL's, but I need the site to be portable as I have many developers who need to install and test it.
I cant find anyway to resolve this. Any ideas?
I ran into the same problem as you a while ago, and after trying a lot of dead ends, I finally ended up with the following solution:
For any URL you need to be a chamelion, i.e. change its path depending on the environment, insert a PHP function that writes out the correct URL.
If you include the PHP function from a single central file, then you can change all of the URL's in the entire site automatically, based on a setting, or some pre-detected switch such as the current domain name, etc.
Example:
<?php print_base_url_plus("/menu.php"); ?>
... where print_base_url_plus() is a function which appends the base URL onto the output.
You may find that you have to change some of the URL's to be php, so they are preprocessed by the PHP engine, or, you can alter the web settings so that standard .htm files are piped through the PHP engine, just like .php files.