rejetto forum

Как вместо 404 посылать некий файл?

0 Members and 1 Guest are viewing this topic.

Offline Mike Korneev

  • Occasional poster
  • *
    • Posts: 7
    • View Profile
Всем привет!

Мне бы хотелось, в случае, когда запрашиваемый файл не найден и HFS отвечает "Not served: 404 - Not found", посылать некий файл.

Как это, в случай с HFS 2.3k, проще всего сделать?


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
Have you an example about requested file, are you referring to a file sent by a user or to a file that is trying to load a user?

Есть ли у вас пример о запрошенном файле, ссылаетесь ли вы на файл, отправленный пользователем или на файл, который пытается загрузить пользователя?
 
я использую переводчик Google, если возможно, вы можете использовать непосредственно английский, у вас будут более быстрые и точные ответы, спасибо?


A bad request give always  this page
Quote
Not found

go to root
gived by the section
Quote
[not found]
<h1>{.!Not found.}</h1>
<a href="/">{.!go to root.}</a>

if you have some files to hide it is possible to add them as a file mask
VFS Root -> properties --> files Mask --> Don't consider as download (mask)
by default it'is *.htm;*.html;*.css     you can add your mask  and validate
« Last Edit: June 18, 2018, 12:43:04 PM by Mars »


Offline Mike Korneev

  • Occasional poster
  • *
    • Posts: 7
    • View Profile
When someone requests from HFS file which HFS can't find in his VFS, HFS send "Not served: 404 - Not found" error.
And I want to force HFS to send some file instead of 404 error.

What is the simplest way to do this?

Sorry for my bad english :-)
« Last Edit: June 18, 2018, 12:44:03 PM by Mike Korneev »


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
I translated your first message, and I put two possible answers in my previous message, but I understand the goal to reach but not the path,

Let's say that I connect to your server, what should I do for me to display a "NOT FOUND", I have to upload a certain type of file, try to download a file from the server, but supposed to be inaccessible, or when I put a url that does not match any physical file like "xxx.xxx.xxx.xxx./max.txt"

I have very little time in front of me to bring you a solution, be brief and precise


Offline Mike Korneev

  • Occasional poster
  • *
    • Posts: 7
    • View Profile
or when I put a url that does not match any physical file like "xxx.xxx.xxx.xxx./max.txt"

Yes, this is the case. When someone request from HFS file which doesn't exist I want to send some existing file intead of requested file which is not exists.


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
in fact you want the answer is done by sending a file instead of sending a web page, can I know without indiscretion which file you want to send, otherwise it is also simply possible to redirect the user to Home Page


Offline Mike Korneev

  • Occasional poster
  • *
    • Posts: 7
    • View Profile

Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
the solution is based on this principle

Quote
[not found]
<h1>{.!Not found.}</h1>
<a href="/">{.!go to root.}</a>
{.add header|Location:/files.txt.}

if this should only be possible for certain files, it is possible to define tests

Quote
[not found]
<h1>{.!Not found.}</h1>
<a href="/">{.!go to root.}</a>
{. if|
  {.=|%url%|/private/noview.txt.}|
  {.=|%url%|/perso/hidden.dat.}|
 |{:{.add header|Location:/files.txt.}:}/if}

working only if those file don't exists on the server, otherwise it is necessary to put the corresponding file names in the filter of the directory considered

it is possible to manage each request by using the event file in the request section, but it is more difficult to manage,

we can also use a table to avoid a significant number of rows in the previous IF

I'm sorry I have no more time in front of me for now, take the time to detail the list of files you do not want to see loaded and put me in private message I will treat later when I return



Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
Quote
I want HFS to send instead of this NOT EXISTING IN IT'S VFS file some another file - for example d:\HFS\NotFound.txt or even /File3.txt from it's VFS. But I want that HFS sent this file AS IF IT IS A REQUESTED file, and open the  Save as Dialog.

Any ideas?

I'm sorry for this late and fragmentary response, but I could not go further in the technique to use

first you have to use something like this in order to reload a complete web page that will contain the code needed to transfer the file

Quote
[not found]
{.add header|Location:/~Error404.}

[Error404]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript">
  .....
</script>

<body onload="downloadFile("/error_file.txt");">
mince
</body>
</html>

it is probably necessary to perform a relocation because "not found" is the part of the "error-page" section through the variable %content%

the principle is to make hfs believe that it receives a request from the user by using a set based on XMLHttpRequest

I found a lot of examples but nothing that corresponds exactly and allows local to open a window saveas

I put some links that may help to find the magic formula using XMLHttpRequest
https://developer.mozilla.org/ru/docs/Web/API/XMLHttpRequest/Sending_and_Receiving_Binary_Data
https://stackoverflow.com/questions/13752984/html5-file-api-downloading-file-from-server-and-saving-it-in-sandbox
https://gist.github.com/xxd3vin/9632138c49c94b38b2c632c40990f6f8

https://stackoverflow.com/questions/13752984/html5-file-api-downloading-file-from-server-and-saving-it-in-sandbox

do not be afraid of explanations in other languages, you have to look especially at the scripts to put in the template

all this being a little too complex for me, I can not go further for the rest, sorry it will have to wait for someone more competent
« Last Edit: June 18, 2018, 10:14:15 PM by Mars »