Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to run a Node script from a web page?

I'am searching for days now but could not get an answer. I would like to do the following:

  1. User connects to editor.html (Apache2 with basic http auth)
  2. User want to open a file (lets say /home/user1/myfile.txt) on the server with his user/pass (same as in passwd)
  3. Node.js Script gets startet with user rights from above and user can edit file

The Node Script will handle the connection via websockets and read/writes files.

I think the biggest problem is that its not possible to run a node script on the server from a web page... and I don´t want to involve any php/cgi scripts... only Apache and Node.js / JS.

Please also comment or answer if you know that it is really not possible...

Thanks!

Kodak

Edit: The workflow should be the following: User access webpage -> enters his credential (same as in passwd) -> node.js script gets started with the user rights of the logged in user -> files getting read or written with user rights

Biggest Problem: who starts the Node.js script? Apache? How?

like image 462
Nico Avatar asked Oct 30 '13 15:10

Nico


1 Answers

I hate to be this person, but...

That is not the way node is designed, it is designed to use the event loop, I would recommend having node serve the static files, maybe using apache as a proxy, then when someone requests a certain page, doing what ever needs to be done, if you really must spawn a child process, use child_process.spawn, as for the rights of the user, I recommend just passing in a code, like 1=admin, 2=user, 3=guest, and the child process can do what is needs.

like image 50
Ari Porad Avatar answered Oct 18 '22 09:10

Ari Porad