Author Topic: Как вместо 404 посылать некий файл?  (Read 300 times)

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
  • Insane poster
  • *****
  • Posts: 1828
    • View Profile
Re: Как вместо 404 посылать некий файл?
« Reply #1 on: June 18, 2018, 12:33:46 PM »
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 »
FRENCH MEMBER : Si vous comprenez la langue française,  n'hésitez pas à l'utiliser pour une meilleure aide de ma part

Offline Mike Korneev

  • Occasional poster
  • *
  • Posts: 7
    • View Profile
Re: Как вместо 404 посылать некий файл?
« Reply #2 on: June 18, 2018, 12:39:50 PM »
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
  • Insane poster
  • *****
  • Posts: 1828
    • View Profile
Re: Как вместо 404 посылать некий файл?
« Reply #3 on: June 18, 2018, 12:48:15 PM »
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
FRENCH MEMBER : Si vous comprenez la langue française,  n'hésitez pas à l'utiliser pour une meilleure aide de ma part

Offline Mike Korneev

  • Occasional poster
  • *
  • Posts: 7
    • View Profile
Re: Как вместо 404 посылать некий файл?
« Reply #4 on: June 18, 2018, 12:54:37 PM »
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
  • Insane poster
  • *****
  • Posts: 1828
    • View Profile
Re: Как вместо 404 посылать некий файл?
« Reply #5 on: June 18, 2018, 01:00:29 PM »
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
FRENCH MEMBER : Si vous comprenez la langue française,  n'hésitez pas à l'utiliser pour une meilleure aide de ma part

Offline Mike Korneev

  • Occasional poster
  • *
  • Posts: 7
    • View Profile
Re: Как вместо 404 посылать некий файл?
« Reply #6 on: June 18, 2018, 01:03:31 PM »
Just some file on my computer. For example "x:/xxx/xxxx/xxx.xxx"

Offline Mars

  • Operator
  • Insane poster
  • *****
  • Posts: 1828
    • View Profile
Re: Как вместо 404 посылать некий файл?
« Reply #7 on: June 18, 2018, 01:22:11 PM »
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
FRENCH MEMBER : Si vous comprenez la langue française,  n'hésitez pas à l'utiliser pour une meilleure aide de ma part

Offline Mike Korneev

  • Occasional poster
  • *
  • Posts: 7
    • View Profile
Re: Как вместо 404 посылать некий файл?
« Reply #8 on: June 18, 2018, 01:23:52 PM »
Ok.
Thank you very much!

Offline Mars

  • Operator
  • Insane poster
  • *****
  • Posts: 1828
    • View Profile
Re: Как вместо 404 посылать некий файл?
« Reply #9 on: June 18, 2018, 10:09:45 PM »
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 »
FRENCH MEMBER : Si vous comprenez la langue française,  n'hésitez pas à l'utiliser pour une meilleure aide de ma part