Hosted application : File permissions , passing arguments from javascript to application - javascript

I am very new to web hosted application area.
I have an exe application. It is a windows console application. It takes some arguments( number and strings) and output some (numbers and string) . I want to make it web hosted.
For simplicity we will consider following case. The exe is add.exe and takes two integer as input. It returns their sum. I want to make add.exe web hosted. I do not want “add.exe” to be readable( downloadable) by the site visitor. I have javascript that will take two numbers as input and and display the output ( obtained from add.exe ) .
Questions:
On the http server what should be the permission of the directory that has javascript file.
What should be the permission of the javascript file.
How do I pass arguments to
What should be relative path of add.exe ( with respect to the javascript files) and permissions of the add.exe, permission of directories appearing in the relative path?
Environment:
Please assume linux hosted. Do not worry about use of “exe” in the question. It can be any executable( and is not specific to windows). You may assume a C++ linux compiled executable( of that is needed for your answer, else please try to keep answer generic)

As far as i'm aware, the .exe will not get executed on the browser. you will need a HTML page to get the values and use C++ in the backend. The .exe file will always get downloaded irrespective of the file permissions. So the basic logic of executing a exe file on the browser is wrong.

Related

Cant open local file by Chrome or Edge for Japanese environment

I'm trying to develop HTML base editor equipped with browsing local files function.
I know basically that is restricted by browser to open local files.
However I found out some method doing this activity.
using path begin from "localexplorer://" it works perfect for English path name.
But when I use Japanese folder name or file name it becomes error.
I tried to convert SJIS format that file names but this is not work.
Here is code.
[![error[![\]\[1\]][1]][1]][1]url = 'localexplorer:' + event.target.innerText;
array = str2array(url);
sjis_array = Encoding.convert(array, "SJIS", "UNICODE");
sjis= Encoding.codeToString(sjis_array);
window.open(url, '_blank');
According to browser security, javascript is only allowed to run in the sandbox, you cannot read or write arbitrary files:
JavaScript and the DOM provide the potential for malicious authors to
deliver scripts to run on a client computer via the Web. Browser
authors minimize this risk using two restrictions. First, scripts run
in a sandbox in which they can only perform Web-related actions, not
general-purpose programming tasks like creating files.
If the user selects a file via <input type="file">, you could try to read the content of the file through FileReader API, like this case: How to open a local disk file with JavaScript?
If you need to interact with files on the user's local device or a user-accessible network file system, you can try to use the File System Access API. And this must be done in a secure context, and must be called from within a user gesture. You can also read this article to learn more about it:The File System Access API: simplifying access to local files.
Thank you for your response, I solved this issue by Forefox plug in extensions, it seems like chrome did not support this functions even if there is plug in extensions.

Can JS read a local file from local web-page?

I'd like to use html+css+js to create an interface for setting up a simulation. The interface is used to create a visualisation of the simulation, and an output parameters file, by using several input files.
This web-page does NOT need to run on a server and is only run locally on the same machine.
I understand why a sever page is not allowed to access a client file, and that a server page may access another server file. Is it possible for a LOCAL web-page to access a local file?
It is possible to view the contents of any file using file:///path/to/file.txt so I presume that it is somehow possible to pull the result into a running page in the form of a string. However I'm having very little success.
If it is possible please could you detail a simple example of how the contents of a txt file could be read into a string?
Thank you very much
node.js is a javascript implementation that can easily do such things because it is a process running on the machine. A web page is running in a browser which does not have access to the file system, so that would not be possible, however you could bundle your web application into an electron application which would be able to access the osand file system, so while it would use html and javascript it would still require an installation.
If you are using Chrome, you can launch it with the --allow-file-access-from-files flag. Then you can do:
fetch('file:///path/to/file.txt')
.then(function(response) {
// do something with it
})

how get list of files in a folder using javascript

I am working on project for desktop application. I am using Qt controls with visual c++.
I am loading an html file in the QWebView as,
m_pWebView->load(QUrl("../../../demo/index_Splash_Screen.html"));
Now, what i want is, say, I have some .zip files in my location "c:\demo", I want list (or array of file names) of the files present in that directory.
How can i do this through javascript ?
PS: I went through this link, but it didnt match my requirement. I have not worked with of html, javascript and jquery. Please help me.
I'm afraid you cannot access local files or directories using javascript due to security issues.
Edit: I hadn't thought about the file api so thought for a moment this might not be true, but without some user input to give permission, this still cannot be done.
This question has a good response from PhilNicholas:
I'm afraid I may be the bearer of bad news for your design: The action
you are requesting expressly violates the security model as specified
in the File API spec. The client implementation of FileReader() must
make sure that "all files that are being read by FileReader objects
have first been selected by the user." (W3C File API , 13. Security
Considerations: http://www.w3.org/TR/FileAPI/#security-discussion).
It would be a huge security risk of browser scripts could just
arbitrarily open and read any file from a path without any user
interaction. No browser manufacturer would allow unfettered access to
the entire file system like that.
Thinking about it however, if it is all being run locally, you could use ajax to query a server side script that could return the directory you request.
If it is a Windows application then you could access the local filesystem by using ActiveX objects. You might have a look at this link Reading a txt file from Javascript
Note that activeX usage is possible only when using IE as browser/engine; I used to need it a while ago for developing an HTML application (.hta files).

JS Filesystem API: accessing JS FileEntry's on local system?

I'm testing some of the new JS filesystem abilities, i.e. creating an empty text file in the local filesystem. I'm running the HTML & JS files from a local path (file:///). For this purpose I launched Google Chrome with the --allow-file-access-from-files flag from the CLI. The filesystem request is PERSISTENT (and works).
I have read up on different posts about the filesystem, copied and modified some of the code in the tutorials; When I launch the HTML file, my custom success/ failure messages are outputted in the console;
This is the result:
Opened file system:/ // this is the root path of the JS Filesystem.
/wtf.txt // this is the name and path of the text file I created+ it's a success
However, when I look at my directory's (both system and application root), there's no .txt file with the name I assigned to it. How can I know where Javascript really wrote this file? In what "root" (since the 'root' cannot be assigned)? What does it mean that the FileSystem is a 'sandbox'? That I cannot access the (virtual?) contents of it on my local drive, but only with JS? If this is the case, is there a way to prompt the user to save the file?
Thanks in advance for your answers
It seems you're expecting the File System API to work locally similar to an OS file system. The client doesn't work like that. In fact, and API is designed to be your interface, as a programmer, to the files and directories -- the client itself (e.g., Chrome, etc.) will handle the rest on the local level. The API is not designed by which you can create a file via the browser and easily access it via the operating system.
How can I know where Javascript really wrote this file? In what "root" (since the 'root' cannot be assigned)?
Technically speaking, each client can store locally as it chooses. So while you can go to the local file system to look for the file, something is wrong with your approach if you're attempting to do so; the File System API is not meant for that. To your question, you can assume that if there's content the client's storage area (e.g., for Chrome it's something like "C:\Users\USERNAME\AppData\Local\Google\Chrome\User Data\Default\File System\") then you can assume that the JavaScript wrote it. But again, it's not set up for user friendly browsing on the local system.
What does it mean that the FileSystem is a 'sandbox'?
Sandbox simply means an area created and set aside for a specific purpose, outside of which the client cannot see/access. See this from Mozilla: https://developer.mozilla.org/en-US/docs/WebGuide/API/File_System/Introduction#virtual
That I cannot access the (virtual?) contents of it on my local drive, but only with JS?
That is correct, and by design.
If this is the case, is there a way to prompt the user to save the file?
If I understand your question right, you're asking if there is a way to provide a specific file to the user and have it prompt them to save it locally. Well, of course if you provide a link to the file (or push it, a different discussion) then the client will prompt the user to save/store it if their platform allows them to do so. But you have no control over where they save it locally nor can you later get it it. If I've misunderstood your question, comment below and I'll follow up.

How to read and run files on hard drive from a webpage?

Here's the gist of what I'm trying to do:
A user will have to match his fingerprint (captured image) with an image stored in the server. I've implemented the image matching program in OpenCV and it's a .exe on disk. The output of this is flag.txt.
Basically if the value of flag.txt is non-zero the user may gain access to the next webpage.
The question is - how to I run the .exe and read the contents of the resultant text file (saved on the hard-drive) from a webpage?
EDIT - please note, I am not sure under which tags this falls.
You need to implement kind of web service which will execute you .exe files and do other logic and access this web service from web page. Browser won't allow web page do such actions because of security reasons

Categories