0

Good afternoon, I have a frequently asked question, for example,

<button>Check</button>

Is it possible somehow without refreshing the page to send a request via SSH to a virtual machine running Ubuntu?

For example:

The csgo server is on a permanent machine, it has possible options:
IP: 192.168.44.122/94.32.143.84
PORT for SSH: 44
USER NAME: test
PASSWORD: test


Django is on local machine 127.0.0.1:8000 or localhost:8000.

The csgo server is started with "./csgoserver start". Is it possible somehow to send a request with "./csgoserver start" to the local machine, on the click of a button on the page, to start the server?

I searched for information and did not find it. With the help of ajax, if I understand correctly, it is possible to send a request only if there are servers on the same machine, right? I would be grateful for the answer where should I look, what to study, so that I can implement this idea. One guy suggested that you can look towards REST, but I can't figure out how to implement what I need through REST.

JDie
  • 13
  • 3

1 Answers1

0

So you want to execute a script/program on a machine (the virtual machine) from another (here your local machine).

  • Yes SSH is one way you can do that. Try ssh -p 44 test@192.168.44.122 "csgoserver start" (side note: I'm assuming here that the . in ./csgoserver start is the user's home directory. . means "current directory"... that's another topic, but make sure you understand relative vs. absolute paths in unix-like systems)
  • This can be done in Python from your Django view, which should receive a request (an ajax request is fine if you don't want the page to refresh) from the button click (How can I send an Ajax Request on button click from a form with 2 buttons?). This answer should help you with the details of using SSH in python: Perform commands over ssh with Python

Keep security in mind before deploying this publicly though (i.e read the Django documentation on authentication, CSRF tokens etc...)

Clepsyd
  • 496
  • 2
  • 10