What is the best or easiest way to run script on http request

1

There is this server to which I have remote desktop access. It's Windows machine and I use it to deploy code to staging server (which also runs on this machine) so we can test our pull-request before merging them to develop branch. Right now I'm doing it manually, but I already wrote small batch script which allows me to automate the process. So basically now I'm only have to connect to this computer and run this script providing some params to it. It's still a pain, and I want to setup slash commandhttps://api.slack.com/slash-commands in our team's slack to be able to trigger this script execution right from our team slack channel. So, to do it I need a web server accessible from the outer web to send my POST request with params there. But a. this machine is behind our work vpn b. There's no server there that can accept such request

I'm a little bit lost. Event if I could setup some server there to listen to this request, it still wouldn't be accessible to outer Internet right? or would it? But then wouldn't it be security risk to expose such endpoint for POST requests?

So I have this vague idea which might be silly, but I just want someone experienced in these things to tell me where to look, to give me direction. So what I'm thinking, maybe I could setup some service (like daemon) which would be running on this remote computer constantly and checking some other server every now and then. Like pinging some server on the Internet with frequent GET requests. This other server would be public server accesible to my slack integration. It would receive POST request with my params from slack and store it. Then when next GET from my remote comuter would come it would answer with what I sent to it.

This is probably very stupid idea, but that's the only one that I have. Any suggestions? Comments?

dKab

Posted 2017-03-13T22:49:36.247

Reputation: 171

Answers

2

Disclaimer - if you are looking for Windows specifics, this answer does not have it (I'm a Linux system admin, so I understand the technologies and have done similar things in a Linux environment - Windows will be similar)

There are (at least) 2 ways of solving this problem - Depending on your timeframes, your idea of having an external server which you can pole on a regular basis to initiate a deployment is a good one - it provides a level of isolation of your network while getting the job done.

The alternative way would be to run a web server on your LAN system. You should be able to add a standard WAMP stack to your computer (Windows, Apache, MySQL, PHP), then code a PHP website to handle the web requests, SANITIZE THE INPUT and execute the script. You would also need to port-forward/pinhole an appropriate port from your router to the web server - and, for good measure, may want to enable HTTPS on it as well.

An option C would be to set up WAMP as above, and get a LEB (Low end box) and set up as a VPN server on the LEB and use the web server as a client. Set up NAT, Firewalling and port forwarding on the LEB to bypass your internal VPN and allow traffic to flow as required. You may also need to set the MTU on the box to 1400 or so because you are encapsulating a VPN in a VPN.

davidgo

Posted 2017-03-13T22:49:36.247

Reputation: 49 152

1

Ajax Ajax is the traditional way of making an asynchronous HTTP request. Data can be sent using the HTTP POST method and received using the HTTP GET method. Let's take a look and make a GET request. I will use JSONPlaceholder, a free online REST API for developers that returns random data in JSON format.

To make an HTTP call in Ajax, you must initialize a new method XMLHttpRequest (), specify the end point of the URL and the HTTP method (in this case, GET). Finally, we use the open () method to link the HTTP method and the end point of the URL and call the send () method to trigger the request.

We record the HTTP response to the console using the XMLHTTPRequest.onreadystatechange property that contains the event handler that will be called when the readystatechanged event is activated.

const Http = new XMLHttpRequest (); const url = 'https: //jsonplaceholder.typicode.com/posts'; Http.open ("GET", url); Http.send (); Http.onreadystatechange = (e) => { console.log (Http.responseText) } If you see your browser's console, it will return a data matrix in JSON format. But how would we know if the request is made? In other words, how can we handle the answers with Ajax?

The onreadystatechange property has two methods, readyState and status that allow us to verify the status of our request.

If readyState is equal to 4, it means that the request has been made. The readyState property has 5 responses. Learn more about this here.

In addition to making an Ajax call directly with JavaScript, there are other more powerful methods to make an HTTP call, such as $ .Ajax, which is a jQuery method. I will discuss that now.

Usman Aslam

Posted 2017-03-13T22:49:36.247

Reputation: 11

0

Building on the excellent points made by @davidgo.

  1. Install a full stack on your local machine with WAMP.

  2. Open a secure tunnel to the Internet. You can either build this on your own or use an existing product. I can recommend ngrok which is providing a secure VPN tunnel out-of-the box and works nicely with Slack.

  3. Check with the security office / security policies of your company to make sure you solution is in compliance.

Erik Kalkoken

Posted 2017-03-13T22:49:36.247

Reputation: 131