Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shutdown computer via web page

I have web based application which automatically loads on kiosk mode (full-screen) in chromium web browser on client's Computer wich is powered by Windows 7. I want to place a shutdown button on web page, so that user can directly shutdown the computer.

  • Is there any possibility to achieve this?
  • What are the best solutions for both Windows & Linux?

-P.S-

I've full control over client's computer. (installing other software or browser extensions). it is a touch screen POS unit.

like image 267
Kevin Avatar asked Dec 06 '22 19:12

Kevin


2 Answers

As you have control over the target machine, this is completely feasible. One way to do it is by introducing a separate component to perform the shutdown.

  1. Create a console application (using C#, for example) that listens to stdin, that shuts down the machine when it receives the right input. Machine shutdown from C# is not entirely trivial, but Stackoverflow knows how it is done.

  2. Register this application with a proper manifest given the Google Chrome Native Messaging specification.

  3. Call this extension from your webpage (on shutdownButton.click(), for instance) using Message Passing.

The individual steps are a bit too broad to fully detail them in a single answer, but you can always open new questions on them if they give you any trouble.

like image 156
Paul-Jan Avatar answered Dec 25 '22 06:12

Paul-Jan


Because of security reasons this is simply not possible without running something outside of your browser.

If however the page is served from a server and you want to shutdown this server, keep reading:

A solution which would be possible is to run a server in the background, for example node.js.

On your node.js server you could listen for a specific url you are calling, on the trigger of this event you could send a shutdown command to your host. This however opens some security issues, you need to block this call to node from the outside (or not if you want others to be able to shut it down). And your node.js server has to be running with root rights which is also risky.

Take a look at https://github.com/typicode/stop-server maybe you can find something in there that's usefull to you.

like image 28
Dirk-Jan Avatar answered Dec 25 '22 06:12

Dirk-Jan