1

I have a website. It uses vanilla JavaScript. I have access to all the client computers which use the site. My goal was to run a shell script prompted by a JavaScript function from the website. It is, of course, not possible for security reasons (a website accessing the computer's files while using it).

So my other idea: I want to create a software that somehow monitors the currently open website, and monitors if a certain function (which is known of course) was called, then this program can run a shell script.

Example: I have a function called IncomingCall() in JavaScript on my website. I want a software to be constantly running on the client computers and run example.sh if IncomingCall() is called. The website is on a server and the monitoring software and the shell script are on the client computers, which I have access to (no security hazard, no malicious intent).

So my question is, what language or technology could I use for this purpose, if this is possible at all, and how? I understand this is rather vague, but I have no clue how this could be done.

Edit: I want to run a shell script because I want to change the input of the TV connected to the computer to HDMI when a call is incoming on the site.

tkrisz2
  • 59
  • 5
  • Hi tkrisz2, what is it that your shell script does exactly when it's executed? Maybe it's possible to write the same functionality in JavaScript, so you won't need to execute an external shell script. – Tycho Dec 19 '21 at 13:21
  • 1
    Hi Tycho. I want to change the input of the TV connected to the computer to HDMI when a call is incoming on the site (Jitsi Meet). So I don't think it's possible to do using JavaScript. – tkrisz2 Dec 19 '21 at 13:25

1 Answers1

1

Since you have access to all clients you can run a local server on the every client. Using XMLHttpRequest in JavaScript you can connect to this server and send a HTTP request. When the server receives such a request it can execute the shell script.

Here is an simple example on how to run a server in Python. If you prefer an other language you can look for an other examples, there are a lot out there. Possibly even as a shell script, depending on which system you are running.

It is not possible in JavaScript by default to connect to the localhost if the site, who initiates the connection, is hosted on an other domain. You need to configure your local server to allow such an connection (Mozilla explanation). See example here in Python how to configure this.

Below is an example in JavaScript on how to initiate such an connection.

  let errFunc = async function (e) {
    alert("Could not connect to the server. Please check your internet connection");
  }

  let func = function (e) {
    if (this.status == 200) {
      alert("Succes");
    } else {
      alert("Error retrieving file '" + this.responseURL + "' from the server.");
    }
  }

    let req = new XMLHttpRequest();
    req.addEventListener("error", errFunc);
    req.addEventListener("timeout", errFunc);
    req.addEventListener("load", func);


  req.open("GET", "http://localhost/runScrip", true);
  req.send();
Tycho
  • 238
  • 1
  • 8