How to save data locally on a locally running website? - javascript

I'm here because I have a very particular problem, but first a piece of background information:
I'm setting up a website that isn't made to run online on a server.
It just should run locally on the client's computer being saved on the clients stick, because I wanna avoid being dependent on the internet. Added to that I don't wanna save data using cookies or smth. similar, because I cannot be dependent on the browser or the computer (as already said above: the website is saved on someones stick).
So there's the problem that I want to save user-data in a text-file via javascript. Coming of Java I thought there would be not problem doing that.
But after some research I heard that this isn't possible due to security problems (which sounded logically).
But in my case these security problems are not really relevant in view of the facts that it runs locally and is made for a very small group of trusting people (10-15 people).
So is there a way to just put some small user-data in a text-file (theoretically the file could already be created, but empty) in the folder of the website?

Running a small HTTP server is a working possibility. Name the html file index.html. On Linux, python has a built in HTTP server with python, python -m SimpleHTTPServer. On the Windows systems, I include an HTTP server exe, like HFS, in the same folder. The website can be connected to using localhost. Something like localStorage would work then.
There's probably something better than this, but it worked.
http://www.rejetto.com/hfs/

Related

Make a game written in Javascript available online

I've just finished a simple game in Adobe Animate using the HTML5 Canvas. I now have .fla, .html and .js files. Can I now put these somewhere on my website to make the game available to play? If so, where? If not, what else do I need? Thanks.
Clicking on the HTML file opens it in a browser, but I can't interact with it.
Thanks.
You're stepping in to a whole new world of hosting and deployments. To have a functioning website you need:
A host server
A domain name
Web files (which you have)
The host server will serve up your web files and allow incoming traffic from the web.
The domain name is optional, but helps with visibility. Without it you'll have to connect directly to the IP address of the host server.
I'd recommend finding a host like HostGator, GoDaddy, or Amazon S3 if you want to host a static website. It can be pretty intimidating at first, but you'll need to put in the time reading documentation to fully understand the process.
Alternatively, if you just want to get it running locally and not on the internet you can install a simple http server on your machine. I use NodeJS so I'll test with http-server alot. Hope this helps!

I am trying to use a locally hosted Django webserver's HTML button to execute a python script that's on my local machine and I'm stumped

So, I'm pretty new to Django, python, and javascript.
I have a partially functional Django webserver that, while developing it, I host locally on my machine.
I've made a button with HTML which I've figured out can be tied to a javascript script. The next step for me was to make this button "execute" a python script that's sitting on my machine, particularly on the /desktop directory. I can of course move the script though, but the important part is that I want that python script (let's call it django_test_script.py) to open its own window on my machine. It's just a file that says "hi" in stdout, then closes after 5 seconds, but due to the plan for this whole project, I want that to happen. I want to have my website open on my machine, click that button, then have the script's console pop up on my desktop and run/finish.
The eventual goal is to control an LED strip that's plugged into my raspberry pi. I want colored buttons on the website that, when clicked, run appropriate python scripts that turn the lights to that color. It wouldn't take me long to write up the python scripts themselves that would change colors, but I need to bridge the gap between "button causes a py script to run" and the python script actually running.
I see a ton of questions similar to this, but they all seem to involve running the python scripts WITHIN the webserver, like internal files that do everything and then return something to the server via an HttpResponse.
I don't need an HttpResponse. Literally all I want to do for right now is figure out how to make a script that's stored on the machine run.
I've done some reading on AJAX and I'm guessing that's involved, however everything I've tried has failed with AJAX in terms of actually getting the server to RUN a script. I've been scouring the internet for over an hour now and have found basically nothing useful (as far as I can tell) so I figured I may as well ask for help. Can someone please point me in the right direction in terms of what I'll need to do?
I'm afraid that's not possible. The browser doesn't allow to execute local scripts since everything is (for security reasons) in a sandbox.
If you want to execute something you could do one of the following:
Use a http server which executes the script and call it via AJAX
You build it into an exectron / nodejs app which opens more possibilities to access the system. See this example
But from your requirement I assume the website will be opened on another device to remote control the Pi led? If you you'll need to use some sort of http server as otherwise you can't run the script on the pi itself.

Opening file folder present in a FTP site in file explorer on the client-side

I have a folder structure in FTP, that I am trying to access and open in file explorer on the client-side using javascript in my asp.net application. Using window.open("ftp://192.168.1.10/clients/112"); opens the folder in the web browser how do I make it open in the file explorer.
The real answer is that you do not understand what you, in any way, are doing. You are trying to cross standards which is prevented inherently, but by your lack of technical knowledge, you don't know help when you see it. The part below shows ways to possibly handle it.
For a machine to connect to an ftp server, they need to authenticate and do so over the correct protocol. That is not the protocol that browsers use.
Now, that is not to say that I can't go in my browser, type ftp://... and see a directory. But that is totally different. Your browser switches protocols based on your url. That can't just happen when your a webpage in a clients browser.
Your web server can conduct ftp traffic though. You can read that structure and show it to your user. https://msdn.microsoft.com/en-us/library/ms229716(v=vs.110).aspx
A clever guy can make this happen. It used to be easy in flash/flex, but.. progress.

Can I open a Windows Explorer window from a web app?

I built a CRM for a client of mine, and now they've requested an interesting feature:
For each customer record, they have a matching directory of files on their local computer. They want the ability to open that folder in Windows Explorer directly from within the web app (the app doesn't need access to the directory/files; it just has to launch Windows Explorer so that the user can interact with their files).
This is obviously not possible with regular JavaScript running in the browser (thankfully). I thought there might be some way to accomplish this by building a Chrome extension for this purpose, but it seems Chrome extensions/apps can only access a sandboxed filesystem, which doesn't serve my needs at all. Building an NPAPI plugin in out of the question since Chrome is discontinuing support for NPAPI.
File URIs don't solve this problem either. Their display is ugly, there's no drag-and-drop, no big icons/thumbnails, no sorting etc. They want the full capability of the Windows Explorer.
The only viable option I thought of is to create a local node.js server, make a localhost CORS request to that server, and then run an exec command from node.
Any better idea?
One possibility is to register a custom URI protocol handler with the user's operating system, and then your web page can contain links using your custom protocol, such as openfolder://c/path/to/folder This sort of customization is probably most commonly seen in practice with itunes:// links.
A quick Google search led me to this decent looking tutorial: https://support.shotgunsoftware.com/hc/en-us/articles/200213756-How-to-launch-external-applications-using-custom-protocols-rock-instead-of-http-
The downside is that the user will have to run a small installer of some sort in order to set the correct registry entries (or whatever the non-Windows equivalent is for other OSes) and to drop a small script on disk. That would be much lighter-weight than running a node.js server like you proposed, though.
The linked tutorial uses a Python script, but even that is probably overkill for your needs. A batch file would likely suffice.
EDIT: One additional note, please be aware of the security implications of implementing a custom handler like this. Any webpage in any browser can potentially take advantage of your custom protocol, and an attacker would be able to pass arbitrary data to your script. You should take steps to ensure that the script will not accidentally execute arbitrary commands that may be injected by a malicious web page, and that it will only open a folder and nothing else.
That would require each customer to run a node.js server, which seems unrealistic in your case.
You could use File URIs.
Browsers will refuse to open them by default. However, as suggested in this answer, you could ask your customers to install LocalLinks.

How can I edit a js file sent by the server before it gets to my browser?

During a normal browsing session I want to edit a specific javascript file before the browser receives since once it gets there it's impossible to edit. Is there are any tool for this? For what I need it I can't just save it and edit it on my disk.
I'm ready to learn how to program it myself but if anyone can point out more or less what I have to do I'd be very grateful. I'd have to intercept the packets until I have the whole file while blocking the browser from receiving it any part of it, then edit it manually and forward it to the same port.
I don't think I can do this by just using pcap, I've read a bit about scapy but I'm not sure if it can help me either.
Thanks in advance.
You'd need to implement some sort of proxy, or hook into an existing one, and intercept the file as it's being downloaded and replace it.
Not trivial for a beginner, but a good learning project.
If you are happy to, rather then editing a file, replace it with a local one, then I would* use Charles and its Map To Local function.
Actually, "did". This helped me debug a problem with a browser and a JS file I couldn't edit yesterday.
You can probably achieve whatever it is you are wanting to do by using the firefox firebug plugin, chrome's development tools or the firefox greasemonkey plugin.
Or you could enter the files domain into your hosts file and point that domain to your local machine (running a web server), edit & save that javascript file locally and serve it from your own web server.

Categories