-2

There is a local area network, machines are in same address space.

I have one manager node which controls other machines. Is there a way to execute a script on any of these machines? (Note: SSH is not enabled and we cannot install any code on these machines except manager machine)

Currently, its done by opening a http session in browser, and then providing username and password, followed by the buttons on the page for each script. I need to automate this in Go. Is this possible?

Eg of one such button:

`<form ACTION="enableSsh.cgi" method="get">
    <b>
        <input type="SUBMIT" VALUE="Enable SSH Service">
        <input type=hidden name=stamp value="########">
        <input type=hidden name=token value="********">
        <input type=hidden name=frame value="$%$%$%$%">
    </b>
</form>`
kostix
  • 51,517
  • 14
  • 93
  • 176
Aakash Goyal
  • 1,051
  • 4
  • 12
  • 44
  • Your question is not clear at all. How do you enable SSH on a machine without access to it? What is the web application? And whats the relation to Go? – Arman Ordookhani Dec 12 '17 at 07:35
  • I hope I corrected the mistakes mentioned in the comments. – Aakash Goyal Dec 12 '17 at 07:43
  • @Gauranga There's little information there that we can use. We can perhaps guess that your manager machine already can do what you want it to do - but that part is very unclear. If it can already do this, you need to reverse engineer the code you have running on your machines that does this, or ask whoever wrote this code what they have done. If the manager machine already can enable ssh on your other machines, those machines run some non-standard services - It's hard for anyone that does not have access to your machines to figure out how they work. – nos Dec 12 '17 at 07:46
  • ok, let me try if I can get more details. These machines are actually 3rd party machines. And currently, its happening via web. I need to automate that in Golang. – Aakash Goyal Dec 12 '17 at 07:50
  • I guess you may be able to do this. Check in the browser what network traffic - http request-response exchange is happening. You probably may be able to do the same using Go. – Ravi R Dec 12 '17 at 07:57
  • Sure, let me try that as well. – Aakash Goyal Dec 12 '17 at 08:01

2 Answers2

1

Currently, its done by opening a http session in browser, and then providing username and password, followed by the buttons on the page for each script. I need to automate this.

I think you don't need to care about interface at all, until you find a way to execute scripts in backend. From my point of view, it's impossible to execute scripts on the machine without setting up at least SSHD on them. To have your script executed, you need to have some kind of server working on remote machine to handle your requests.

Also, have a look at Configuration Management Systems, such as: Ansible, SaltStack, and so on, because even SSH seems to be a too low-level tool for your use-case.

Vitaly Isaev
  • 5,392
  • 6
  • 45
  • 64
  • Thank you for answer. I just need a confirmation if its not possible. I tried all possible ways and failed. So, thought of checking once before giving up :) – Aakash Goyal Dec 12 '17 at 07:53
1

Yes, it's possible to do solely with the Go standard library.

The things to study, in this order:

  1. How HTML forms are encoded and sent to HTTP servers by the Internet browsers.

    The things to get familiar with:

  2. When a HTML form is submitted, the data sent to the HTTP server is typically encoded in one of two forms:

    • The application/x-www-form-urlencoded encoding is used to make GET requests and
    • The multipart/form-data encoding is used to make POST requests.

    In your example, the form has the method="get" attribute which indicates the form submission uses GET and hence the application/x-www-form-urlencoded encoding for its data.

  3. The net/http package in the Go standard library which can be used to make HTTP requests.

With all this things in place, you need to make a HTTP GET request to a proper server and URL, with a proper set of parameters.

The server is the same from which you get that HTML page. The URL will be /enableSsh.cgi.

Now you just need to make up the request and to it.

Here is one example but really googling for golang+get+query+with+parameters will bring you myriads of similar examples. The query parameters are those form fields—stamp, token and frame, and their values are, well, what is about to be submitted.


In the case you'll need to POST a form with the multipart/form-data encoding, you'd use the mime/multipart package in the Go standard library, whose Writer type can be used to build a stream of data encoded according to the multipart/form-data rules.

Community
  • 1
  • 1
kostix
  • 51,517
  • 14
  • 93
  • 176