N
N
Nadim Zakirov2020-06-09 19:37:54
JavaScript
Nadim Zakirov, 2020-06-09 19:37:54

How to restart OpenServer remotely with a regular GET request?

I have almost ready solution, but there was a slight difficulty.

I know that OpenServer has a web muzzle:
5edfb9349f637576674726.png
To restart it is enough to follow a link of this type:
localhost:1515/restart
To confirm the rights, Basic Authentication authorization is used there.

Accordingly, nothing prevents me from simply remotely making a GET request to my server with the necessary headers:

jQuery.ajax({
  url: 'http://123.123.123.123:1515/restart',
  headers: {
    'Authorization': 'Basic ' + btoa('admin:admin')
  },
  success: function(response){
    console.log(response);
  },
  error: function(obj) {
    alert('Ошибка!');
  }
});


But alas, fucking CORS interferes! I just can't make this same GET request from someone else's domain, but I just need it from someone else's! In general, please tell me which file in OpenServer is responsible for displaying the web muzzle? Where should I put sparse headers for the web face?

<?php header('Access-Control-Allow-Origin: *');

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
Nadim Zakirov, 2020-06-10
@zkrvndm

Damn, I should have read how Basic Auth works first. The solution turned out to be surprisingly simple, if I want to remotely restart the server, then I can initiate the desired request NOT from my native domain like this:

open_server_restart_window = window.open('');
open_server_restart_window.location.href = 'http://login:[email protected]:1515/restart';
setTimeout(function() { open_server_restart_window.close(); }, 3000);

In a similar way, you can generate an iframe and use a redirect form inside it. Of course, you need to replace the login, password and server address in the link with your own. With such a request, CORS does not interfere in any way, and the signal to restart completely reaches the server and works fine.

S
SagePtr, 2020-06-09
@SagePtr

If there is PHP on the same server, then what prevents a script from being written that will pull the desired internal URL with curl?

A
Anton, 2020-06-09
@Yadalay

The option with the console command does not suit you? For example:

curl -v -X GET -H "Authorization: Basic TOKEN" "Content-Type: application/json" "http://123.123.123.123:1515/restart"

Where TOKEN = value from your example: btoa('admin:admin')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question