Can I run programs/CLI using a PWA? - javascript

I heard PWA is capable of more things than a regular web app when it comes to client side operations.
As a disclaimer, I'd like to note that the PWA I've been working on is a privately used project, it has no malicious intent to harm any system.
What I want to do is I want to be able to use cec-client to turn the TV on/off on the system, so I want to be able to either run a pre-written bash script, or access CLI on the system. Is it somehow possible using a PWA? Currently the client system has a simple nodejs app that's listening to a call on localhost from the web app, which in turn turns the TV on. I want to change it to a more sophisticated solution, hence I'm wondering if PWA can run scripts on the client's system.

The system that you are currently using (server side code with access to the necessary API) is likely the best method.
Progressive Web Apps are just websites with some extra features to persist state and emulate some functions available to system apps, and the security risks that would be involved if they could execute arbitrary system code would be enormous.

Related

How to connect to MS-SQL database via JavaScript?

I understand this is not best practice but I am operating within a limited realm and, as far as I can tell, this is the only solution to this problem.
I am trying to connect to an MS-SQL database both to get data and to put data onto the database. I cannot seem to do it through JavaScript.
ActiveXObject is, from my understanding, now depreciated so that is not working, which eliminates every functional solution that I could find recommended in the past.
Please note: I am not a web developer and I have no access to any of the standard web development tools for this task.
This is the question has been asked multiple times in various forums - Can my client-side Javascript (running in a browser) connect to a database server and fetch data?
The short answer is - not recommended in general, not feasible without breaching security and without using outdated technologies. Let us dig into it.
It is possible to connect to remote database from a browser using outdated technologies
There are two pieces of technologies from Java and .Net worlds - Applet and ActiveX that run on the browser and can communicate to a remote database. The Java Applet is hardly used by anyone nowadays and browsers are stopping to support it. ActiveX is discontinued by Microsoft in their newer browser Edge. So, you have to enforce your target users to use old insecure browsers if you want to go with these options.
Do not use this.
Use databases embedded in the browser and sync with a remote database
You may use the database locally available in the browser and perform all read/write operations. Periodically sync this database with a remote one. Here are the options:
MongoDB and use change stream to sync with a remote MongoDB
PouchDB and sync with a remote CouchDB or even a MySQL database
Use this only for offline storage temporarily in the browser.
The traditional and secure approach to connect to a remote Database
Use a server-side technology to develop an app that your client-side code (Javascript, HTML) talks to. The app may provide RESTful APIs to interact from the client-side. Then the app that is running in a web server connects and interacts with the database. There are plenty of server-side technologies such as Java, PHP, Python, NodeJS (Javascript based), .Net, etc. to develop your server-side app.
Go with this option.
Well javascript is a client side scripting where as your database runs on a server. So firstly you cannot connect to a database for executing any query from client side i.e javascript and also you need to setup a server side service which can connect to the database and execute the query and give you the result at the client side. You can refer any client-server architecture for this on the web.

How to detect a server in the network using JS?

Basically, I want to make a peer to peer architecture, using JavaScript (Ionic).
Since, JS cannot create sockets/etc; a NodeJS server has to be introduced between the clients; acting as the Socket.IO server between the clients.
The problem with this, is that the Socket.IO (NodeJS) server would need to be automatically found within the local network -- by the clients (instead of hardcoded/configured).
Are there any ways to implement such a thing; or alternatives to this architecture?
Thanks for the help!
Are there any ways to implement such a thing; or alternatives to this architecture?
Currently your architecture is using a browser app plus a Node app that users need to have on their network just to create TCP connections.
What you can do instead is create an Electron app that combines a Node app, a browser app, and a browser itself. See:
https://electron.atom.io/
With Electron you can write your frontend code almost the same way as for the regular browser, but you can use the entire Node API including the TCP sockets so there will be no need to create a separate Node app and to search for that app in the network. This can greatly simplify your architecture.
Note: this is not an answer to the first part of the question: "How to detect a server in the network using JS?" but to the second part of the question: "Are there any ways to implement such a thing; or alternatives to this architecture?" Detecting the servers on the local network with client-side JavaScript will not be easy - and in fact it shouldn't be even possible because websites being able to scan your LAN for active services would be a serious problem for privacy and security.

Reading and writing client files from a web application

I need to implement a mechanism in order for a remote web application to communicate with a local desktop (WinForms) application that I cannot modify nor have the source of (except by decompiling). This happens by writing a file to the temporary folder that the desktop application will consume, and waiting for that application to "return" by writing another file into temp folder. Folder has to be temp folder.
Question
Is there a Javascript way to access the file system in a non sandboxed way, even by setting specific browser configuration options?
Environment
The application runs on a private LAN where all computers trust each other within the same AD domain. Plus we are theoretically allowed to map any network drive on any computer. Working in the trust zone, we don't have to care about most security concerns.
Background explanation
I have a PowerBuilder desktop application that I need to "port" to web (using J2EE) and install to a separate server, local to the same LAN. This application (named GP) currently starts a process of the child application (GC) that will not show any UI, instead it will listen for two files on a temporary directory.
When GP needs to open a window from the GC process, it will write two files: GP_to_GC.txt with a syntax I have documentation of, and GP_to_GC.flg that serves as flag file. GC will delete both after retaining and parsing the content of txt file, thus showing the appropriate UI form based on input.
The "return" is exactly the opposite. GC will write a pair of GC_to_GP files to temp and GP will refresh its views.
How can I do this with JavaScript?
Based on what I'm reading, you are porting a Desktop based Java EE application to a web application? If so, then you can continue using Java and access the folder that way; no need to use JavaScript.
What is unclear is that you're saying you can't modify anything, yet you're trying to port an application. Which is it?
If you can't modify anything, and the only thing you can do is drop JavaScript into an existing web application, then your solution is rather simple:
Create an HTTP API application that sits somewhere that has access to those folders, and issue a POST request to that API that will then read and write to the file system. It can be in any server side language you choose: Javascript (Node.js), C#, Java, PHP, whatever. It simply needs the ability to access the file system through the webserver, and most frameworks provide that capability.
I can't give you any code because you haven't mentioned which server side language you want to use to accomplish this approach.

Node.js + Node-Webkit + Node-SerialPort Based Application - Is this Possible?

I am new to Node.js and before I go head first into taking on a new technology and migrating my c# based application, I wanted to make sure what I had in mind is possible with Node.js and if it is recommended.
So please let me know your opinion!
My application has the following requirements:-
TCP server (to receive packets from TCP clients such as smart phones, computers etc.)
Serial port access (To control a hardware device)
Web server facilities (to serve HTML5 pages or provide web services intefaces)
Simple native app like GUI for configuration.
All of this needs to be packaged nicely for end users to install simply.
Why I would want to do this you may ask?? The reason I am most interested in using Node.js is due to the cross platform nature, including the ability to install on cheap single board/embedded computers.
This is my thinking:-
Node.js - to provide the TCP server, serve HTML5 pages and provide web services interfaces.
Node-Webkit - to provide the simple native app like configuration interface. I also believe that it provides the ability to package my application for simple distribution, but I am not sure? (I could leave out Node-Webkit if there was another way to package my app for simple distribution. Although it is preferred as even having to find the IP Address of the computer so as to access a web browser interface would be tricky for some of my users.)
Node-SerialPort - to provide the ability to communicate with the hardware device. The instructions will come from 1 of three sources. 1) TCP connection 2) HTML5 Webpage Initiated 3) Web Services Initiated.
That's what most people use Node.js for
https://npmjs.org/search?q=serial+port
Again, that's what most people use Node.js for
Because of 1 and 3, the most obvious UI for node.js apps is the browser. Write a config page to control your app. Using node-webkit is overkill, just use whatever browser is already available. Node can run multiple listeners on multiple ports, serving the same app.
npm install is pretty simple.
Go learn how to write simple Node.js apps (with express for easy http servering, and jade or nunjucks for easy html templating) and then move up from there.
Point 5. I understand the fact of having an installer. I would suggest that the .msi or .exe will create a Windows Service for NodeJs. Then the node js server will launch at Windows startup and the end user will access the browser with
http://localhost:< a port number>/.
Packaging NodeJS : To package nodejs, you can copy the nodejs.exe from the installation directory of nodejs into the directory where you developp the node application. Then zip everything. You unzip it on another computer and it will execute.

Advantages JavaScript+HTML5 over XAMP on a local computer

I have this idea of developing an application (or a companion application to another web based application) on a client. My initial idea was to run it on a XAMP stack on the client. Although this is perfectly feasible, I was thinking of a more compact approach using javascipt+html5 (with web storage / indexed db). I think that not running a web and database server would allow my application to become less resource-intensive. Any ideas please.
What are you trying to accomplish with your app? Keep in mind if someone clears the cache, they can delete all the data that was in the local storage.
As to "resource intensive", is this personal resources (like paying for a server)? I rarely would advise anyone in making an app that is client side only with no server side backup, unless it's something you only need to use on one computer.
I think you are forgetting one thing, you still need a web server to serve the HTML and javascript to the client.
However could create a Adobe AIR app using javascript and sqlite.
http://www.adobe.com/devnet/air/articles/getting_started_air_js.html

Categories

Resources